function ResultsDisplay(quote){ var _this = this; this.quote = quote; this.disp = $('#results_wrapper'); this.resultsBody = $('#results_body'); this.saveBtn = $('#saveBtn'); this.loginBox = $('#login'); this.loginCancelBtn = $('#loginCancel'); this.loginProceedBtn = $('#loginProceed'); this.orderInfoBox = $('#orderInfo'); this.orderInfoCancelBtn = $('#orderInfoCancel'); this.orderInfoProceedBtn = $('#orderInfoProceed'); this.opened = false; this.init = function(){ //closeボタン $('#resultCloseBtn').on('click', _this.closeBtnClkClosure()); //見積保存ボタン _this.saveBtn .on('mousedown', _this.btnMdClosure(_this.saveBtn)) .on('click', _this.saveBtnClkClosure()); //ログインキャンセルボタン _this.loginCancelBtn .on('mousedown', _this.btnMdClosure(_this.loginCancelBtn)) .on('click', _this.loginCancelBtnClkClosure()); //ログイン実行ボタン _this.loginProceedBtn .on('mousedown', _this.btnMdClosure(_this.loginProceedBtn)) .on('click', _this.loginProceedBtnClkClosure()); //注文情報入力キャンセルボタン _this.orderInfoCancelBtn .on('mousedown', _this.btnMdClosure(_this.orderInfoCancelBtn)) .on('click', _this.orderInfoCancelBtnClkClosure()); //注文情報入力送信ボタン _this.orderInfoProceedBtn .on('mousedown', _this.btnMdClosure(_this.orderInfoProceedBtn)) .on('click', _this.orderInfoProceedBtnClkClosure()); } this.show = function(msg){ $('#itemName').html(_this._itemName()); $('#itemQuant').html(_this.quote._getVal('quantity')); $('#subTotal').html(_this.quote.numFormat(msg.sub_total)); $('#totalAmount').html(_this.quote.numFormat(msg.sub_total + msg.tax)); $('#manufacturingPeriod').html(msg.manufacturing_period); $('#shipExDate').html(_this._toYYYY年MM月DD日_曜_(msg.ship_ex_date)); $('#shipExDateBase').html(_this._toMM_DD_曜_HH_mm(msg.ship_ex_date_base)); /* マウスドラッグによりウィンドウの外へ飛び出している場合があるので位置を強制補正 */ _this._fixPosition(); //setTimeout(_this.disp.show(), 5000); //中のコンテンツが格納完了前のタイミングになると、サイズがおかしくなる為、setTimeoutでタイミングずらす。 /* * displayをマウスでドラッグして下半分を枠外にやっておくと、jquery-uiの副作用か、heightに不適切な値が入ることがある。 * 不要なので削除して表示する。 */ _this.disp.css('height', '').css('display','block'); _this.mode_clear(); _this.opened = true; } this._itemName = function(){ var s = 'ハーネス加工('; var shape = _this.quote._getVal('shape'); var pR = _this.quote._getVal('rightSideProcessing'); var pL = _this.quote._getVal('leftSideProcessing'); if(shape == '1'){ s += (_this._processingName(pL) + '/' + _this._processingName(pR) + ')'); }else if(shape == '2' || shape == '3'){ s += (_this._shapeName(shape) + '/' + _this._processingName(pR) + ')'); }else{ s += (_this._shapeName(shape) + ')'); } return s; } this._shapeName = function(shape){ if(shape == '1'){ return '電線のみ'; }else if(shape == '2'){ return '片側コンタクト'; }else if(shape == '3'){ return '片側ハウジング'; }else if(shape == '4'){ return '片側ハウジング・片側コンタクト'; }else if(shape == '5'){ return '両側コンタクト'; }else if(shape == '6'){ return '両側ハウジング'; }else{ return null; } } this._processingName = function(sideProcessing){ if(sideProcessing == '1'){ return '切り落とし'; }else if(sideProcessing == '2'){ return '電線剥き'; }else if(sideProcessing == '3'){ return '電線剥き + 予備はんだ'; }else{ return null; } } this._toYYYY年MM月DD日_曜_ = function(longDate){ var d = new Date(longDate); return d.getFullYear() + '年' + (d.getMonth() + 1) + '月' + d.getDate() + '日' + '(' + _this._dayOfWeek(d.getDay()) + ')'; } this._toMM_DD_曜_HH_mm = function(longDate){ var d = new Date(longDate); return (d.getMonth() + 1) + '/' + d.getDate() + '(' + _this._dayOfWeek(d.getDay()) + ')' + _this._singleNumeric2double(d.getHours()) + ':' + _this._singleNumeric2double(d.getMinutes()); } this._dayOfWeek = function(day){ if(day == 0) return '日'; else if(day == 1) return '月'; else if(day == 2) return '火'; else if(day == 3) return '水'; else if(day == 4) return '木'; else if(day == 5) return '金'; else if(day == 6) return '土'; } this._singleNumeric2double = function(n){ if(n < 10){ return '0' + n; }else{ return n; } } this.hide = function(){ _this.disp.hide(); _this.opened = false; _this.quote.quoteExeBtn.hijackEnterkeyEvent(); //enterキーを「見積計算」に割り当てる(その他の実行ボタンを無効化) } this.errorHandler = function(hasError){ if(hasError){ _this.resultsBody.hide(); _this.saveBtn.hide(); }else{ _this.resultsBody.show(); _this.saveBtn.show(); } } this._fixPosition = function(){ var h = _this.disp.innerHeight(); //_this._getCssPxVal('height'); var w = _this.disp.innerWidth(); var top = _this._getCssPxVal('top'); var left = _this._getCssPxVal('left'); //var vPadding = _this._getCssPxVal('padding-top') + _this._getCssPxVal('padding-bottom'); var winH = $(window).height(); var winW = $(window).width(); if(h && top){ //ウインドウの上部に隠れた場合を検出 if(h + top < 0){ _this.disp.css('top', '0px'); } //ウィンドウの下部に隠れた場合を検出 else if(winH < top){ _this.disp.css('top', winH - 300 + 'px'); } } if(w && left){ //ウィンドウの左部に隠れた場合を検出 if(w + left < 0){ _this.disp.css('left', '0px'); } //ウィンドウの右部に隠れた場合を検出 else if(winW < left){ _this.disp.css('left', winW - 500 + 'px'); } } } this._getCssPxVal = function(prop){ var v = _this.disp.css(prop); return _this._str2pxval(v); } this._str2pxval = function(s){ if(s.indexOf('px') > 0){ return s.replace('px','') - 0; }else{ return null; } } /* * ============== BUTTON CLOSURES ================ */ this.btnMdClosure = function(btnObj){ var c = function(){ btnObj.addClass('pressed'); setTimeout(function(){btnObj.removeClass('pressed')}, 100); }; return c; } this.closeBtnClkClosure = function(){ var c = function(){ _this.hide(); }; return c; } this.saveBtnClkClosure = function(){ var c = function(){ ////ログイン確認 //ログイン済みなら「件名」等入力へ if(_this._loggedin()){ _this.mode_orderInfo(); } //未ログインならログインへ else{ _this.mode_login(); } } return c; } this._loggedin = function(){ var uinfo = _this.quote.getUserInfo(HnsQuote.actionUrl_userInfo); if(uinfo){ return true; }else{ return false; } } this.loginCancelBtnClkClosure = function(){ var c = function(){ _this.mode_clear(); }; return c; } this.loginProceedBtnClkClosure = function(){ var c = function(){ _this.mode_clear(); //loading中表示の為に一旦消す。 _this.quote.login( _this.quote._getVal('uid'), _this.quote._getVal('pwd'), HnsQuote.actionUrl_login, _this.quote.loadingControlWhenLogin, function(msg){ if(msg.isError){ _this.mode_login(); //ログイン画面に戻す if(msg.messages){ $('p#loginErrMsg').html(msg.messages.login_error); }else{ alert('不明なエラー'); } }else{ $('p#loginErrMsg').html(''); _this.mode_orderInfo(); } } ); }; return c; } this.orderInfoCancelBtnClkClosure = function(){ var c = function(){ _this.mode_clear(); }; return c; } this.orderInfoProceedBtnClkClosure = function(){ var c = function(){ //validation(件名) var subjectObj = $('#subject'); if(subjectObj.val().trim() == ''){ subjectObj.focus(); alert('件名を入力してください。'); return; } //validation(関連案件) var sonObj = $('#relationalSummaryOrderNo'); var val = sonObj.val(); val = val.trim().replace(/[A-Za-z0-9]/g, function(s) { return String.fromCharCode(s.charCodeAt(0) - 0xFEE0); }); sonObj.val(val); if( val != '' && !(val.match(/^[0-9a-zA-Z]+$/)) ){ alert('関連案件番号は英数半角文字で入力してください。'); return; } _this.quote.save(); }; return c; } /* * ============== Enter-Key CLOSURES ================ */ this.enterKeyClosure = function(targetBtnId){ var c = function(){ var target = $('#' + targetBtnId + ':visible'); target.click(); }; return c; } /* * 見積結果表示、または入力バリデーションエラー表示状態 */ this.mode_clear = function(){ $('body').removeClass('loading10'); $('body').removeClass('loading11'); _this.quote.quoteExeBtn.hijackEnterkeyEvent(_this.enterKeyClosure('saveBtn')); //enterキーを「見積保存」に割り当てる(その他の実行ボタンを無効化) } /* * ログインフォーム表示状態 */ this.mode_login = function(){ $('body').addClass('loading10'); $('body').removeClass('loading11'); $('#uid').focus(); _this.quote.quoteExeBtn.hijackEnterkeyEvent(_this.enterKeyClosure('loginProceed')); //enterキーを「ログインボタン」に割り当てる(その他の実行ボタンを無効化) } /* * 件名等入力フォーム表示状態 */ this.mode_orderInfo = function(){ $('body').removeClass('loading10'); $('body').addClass('loading11'); $('#subject').focus(); _this.quote.quoteExeBtn.hijackEnterkeyEvent(_this.enterKeyClosure('orderInfoProceed')); //enterキーを「確認画面へ」に割り当てる(その他の実行ボタンを無効化) } //読み込み完了時にinit実行 _this.init(); }