function ResultsDisplay(quote){ var _this = this; this.quote = quote; this.loginBox = $('#login'); this.loginCancelBtn = $('#loginCancel'); this.loginProceedBtn = $('#loginProceed'); this.orderInfoBox = $('#orderInfo'); this.orderInfoCancelBtn = $('#orderInfoCancel'); this.orderInfoProceedBtn = $('#orderInfoProceed'); this.opened = false; this.init = function(){ //サイドバーの見積開始ボタン $('#sidebar_estimate_button').on('click', function(){ $(this).removeClass('exeBtn').hide(); _this.quote.exec(); }); //サイドバーの見積保存ボタン $('#sidebar_saveBtn') .on('mousedown', _this.btnMdClosure($('#sidebar_saveBtn'))) .on('click', _this.saveBtnClkClosure()); //サイドバーの注文ボタン $('#sidebar_orderBtn') .on('mousedown', _this.btnMdClosure($('#sidebar_orderBtn'))) .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._updateSidebarValues = function(data){ $('#sidebar_itemName').html(data.itemName); $('#sidebar_itemQuant').html(data.itemQuant); $('#sidebar_subTotal').html(data.subTotal); $('#sidebar_totalAmount').html(data.totalAmount); $('#sidebar_manufacturingPeriod').html(data.manufacturingPeriod); $('#sidebar_shipExDate').html(data.shipExDate); $('#sidebar_shipExDateBase').html(data.shipExDateBase); } this.show = function(msg){ // サイドバーに見積結果を表示 _this._updateSidebarValues({ itemName: _this._itemName(), itemQuant: _this.quote._getVal('quantity'), subTotal: _this.quote.numFormat(msg.sub_total), totalAmount: _this.quote.numFormat(msg.sub_total + msg.tax), manufacturingPeriod: msg.manufacturing_period, shipExDate: _this._toYYYY年MM月DD日_曜_(msg.ship_ex_date), shipExDateBase: _this._toMM_DD_曜_HH_mm(msg.ship_ex_date_base) }); // サイドバー表示制御 $('#sidebar_results_wrapper').show(); $('#sidebar_estimate_button').hide(); $('#sidebar_error_wrapper').hide(); $('#sidebar_shipExDateBase_row').show(); $('#sidebar_notice').show(); $('#sidebar_saveBtn').show(); $('#sidebar_orderBtn').show(); _this.mode_clear(); _this.opened = true; } this._itemName = function(){ var shape = _this.quote._getVal('shape'); var pR = _this.quote._getVal('rightSideProcessing'); var pL = _this.quote._getVal('leftSideProcessing'); var inner; if(shape == '1'){ inner = _this._processingName(pL) + '/' + _this._processingName(pR); }else if(shape == '2' || shape == '3'){ inner = _this._shapeName(shape) + '/' + _this._processingName(pR); }else{ inner = _this._shapeName(shape); } return inner; } 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 ''; } } this._processingName = function(sideProcessing){ if(sideProcessing == '1'){ return '切り落とし'; }else if(sideProcessing == '2'){ return '電線剥き'; }else if(sideProcessing == '3'){ return '電線剥き + 予備はんだ'; }else{ return ''; } } 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(){ // エラー表示中はサイドバーを維持 if (!_this.quote._sidebarErrorsShown) { $('#sidebar_results_wrapper').hide(); } _this.opened = false; _this.quote.quoteExeBtn.hijackEnterkeyEvent(); //enterキーを「見積計算」に割り当てる(その他の実行ボタンを無効化) } this.errorHandler = function(hasError){ if(hasError){ // サイドバーにプレースホルダ値を表示 _this._updateSidebarValues({ itemName: _this._itemName(), itemQuant: '-', subTotal: '-', totalAmount: '-', manufacturingPeriod: '-', shipExDate: '-年-月-日(-)', shipExDateBase: '' }); // サイドバー表示制御 $('#sidebar_results_wrapper').show(); $('#sidebar_estimate_button').hide(); $('#sidebar_shipExDateBase_row').hide(); $('#sidebar_notice').hide(); $('#sidebar_saveBtn').hide(); $('#sidebar_orderBtn').hide(); }else{ $('#sidebar_shipExDateBase_row').show(); $('#sidebar_notice').show(); $('#sidebar_saveBtn').show(); $('#sidebar_orderBtn').show(); } _this.quote._sidebarErrorsShown = hasError; } /* * ============== BUTTON CLOSURES ================ */ this.btnMdClosure = function(btnObj){ var c = function(){ btnObj.addClass('pressed'); setTimeout(function(){btnObj.removeClass('pressed')}, 100); }; 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('sidebar_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(); }