1(function (app, $, Backbone, _, utils) { 2 'use strict'; 3 4 // ================================= 5 var MoveView = Backbone.View.extend({ 6 7 // ================================= 8 initialize: function () { 9 10 if (this.$el.length === 0) 11 return; 12 13 $.validator.addMethod("can_postal", function (value, element) { return this.optional(element) || app.common.VALIDATE_CAN_POSTAL_REGEX.test(value); }); 14 $.validator.addMethod("min_date", function (value, element, params) { 15 16 // value is in ISO date format; Date constructor assumes time zone is UTC when parsing an ISO string, but that's an invalid assumption 17 // 18 var utcTimeFromValue = new Date(value); 19 var timeFromValue = new Date(utcTimeFromValue.getTime() + (utcTimeFromValue.getTimezoneOffset() * 60000)); 20 21 return this.optional(element) || timeFromValue >= new Date(params); 22 }); 23 24 this.appState = this.model.get('app_state'); 25 26 this.listenTo(this.appState, 'change:active_primary_group_accounts', this.render); 27 this.render(); 28 }, 29 30 // ================================= 31 moveSubmitHandler: function (formEl) { 32 33 var form = $(formEl); 34 var formValues = {}; 35 36 form.find(":input:not(:radio), :radio:checked").each(function (index, elm) { 37 if (formValues.hasOwnProperty(elm.name)) 38 formValues[elm.name] += ',' + $(elm).val(); 39 else 40 formValues[elm.name] = $(elm).val(); 41 }); 42 43 var $updated = $('div.form-success-message').hide(); 44 app.common.onFormSubmitStart(form); 45 46 $.post(app.common.WEBURL + '/move/?CFID=' + localStorage.getItem("cfid") + '&CFTOKEN=' + encodeURIComponent(localStorage.getItem("cftoken")) + '&method=dispatch&action=move', formValues, null, 'json') 47 48 .then(function (resp, textStatus, jqXHR) { // resp: { bool success, string message, any data } 49 50 if (resp.success === true) 51 $updated.show(); 52 else 53 app.common.showFormError('There was a problem updating your address. Please contact customer service at 1.877.360.3464 x 3 or [email protected] to complete your move.'); 54 55 app.common.onFormSubmitComplete(form, false); // keep disabled on success, or backend error 56 }) 57 .fail(function (jqXHR, textStatus, errorThrown) { 58 59 app.common.showFormError('There was a problem updating your address. Please try again.'); 60 app.common.onFormSubmitComplete(form, true); 61 }); 62 }, 63 64 // ================================= 65 render: function () { 66 67 var accounts = this.appState.get('active_primary_group_accounts'); 68 69 var hasVariableAccount = false; 70 _.each(accounts, function (account) { hasVariableAccount = hasVariableAccount || account.billing_option === 'variable'; }); 71 72 var serviceAddresses = new app.AddressCollection(); 73 serviceAddresses.initializex({ accounts: accounts }); 74 75 new app.ServiceAddressCollectionView({ 76 el: this.$('#account-info-more'), 77 collection: serviceAddresses, 78 mode: 'radio' 79 }); 80 81 this.$('.variable').toggle(hasVariableAccount); 82 83 this.$('input.datepicker').datepicker('destroy'); 84 this.$('input.datepicker[name=move_in_date]').datepicker({ 85 dateFormat: "yy-mm-dd", 86 showOn: "focus", 87 onSelect: function (dateText, inst) { 88 $(this).valid() 89 } 90 }); 91 92 var $moveOutInput = this.$('input.datepicker[name=move_out_date]').datepicker({ 93 dateFormat: "yy-mm-dd", 94 showOn: "focus", 95 onSelect: function (dateText, inst) { 96 //on date selection in move out date, create new date and add 1 day to put in move in date 97 let moveOutDate = $('input.datepicker[name=move_out_date]').datepicker('getDate') 98 let newDate = $('input.datepicker[name=move_out_date]').datepicker('getDate') 99 newDate.setDate(newDate.getDate() + 1); 100 $('input.datepicker[name=move_in_date]').datepicker("option", "minDate", moveOutDate); 101 $('input.datepicker[name=move_in_date]').datepicker("setDate", newDate); 102 $('input.datepicker[name=move_in_date]').change(); 103 $(this).valid(); 104 } 105 }); 106 107 $('input.datepicker[name=move_in_date]').on("change", function () { 108 $('input.datepicker[name=move_in_date]').valid(); 109 }) 110 111 let moveInGreater = function (moveOutDate, moveInDate) { 112 let moveOut = new Date(moveOutDate); 113 let moveIn = new Date(moveInDate); 114 115 if (moveIn < moveOut) return false;
116 return true; 117 } 118 119 jQuery.validator.addMethod("moveInGreater", function (value, element) { 120 return moveInGreater($('input.datepicker[name=move_out_date]').datepicker('getDate'), $('input.datepicker[name=move_in_date]').datepicker('getDate')) 121 }, "Move in date should be after the selected move out date"); 122 123 var form = $('form[name=move-form]'); 124 form.validate({ 125 submitHandler: this.moveSubmitHandler, 126 showErrors: function (errorMap, errorList) { app.common.showFormValidationErrors(form, errorMap, errorList); }, 127 onfocusout: app.common.VALIDATE_ON_FOCUSOUT, 128 rules: { 129 consumer_ids: { required: true }, 130 move_out_date: { required: true, dateISO: true, moveInGreater: true }, 131 move_in_date: { required: true, dateISO: true, moveInGreater: true }, 132 address: { required: true }, 133 suite: { required: false }, 134 city: { required: true }, 135 province: { required: true }, 136 postal: { required: true, can_postal: true } 137 }, 138 messages: { 139 move_in_date: { 140 moveInGreater: jQuery.validator.format("Enter a date after Move out date") 141 } 142 } 143 }); 144 145 form.find('#continue a, a.form-btn:not(.nosubmit)').on('click', function (e) { e.preventDefault(); form.submit(); }); 146 147 // Pretty hacky - should be listening for events generated by ServiceAddressCollectionView or something like that 148 // 149 var setMinMoveOutDate = function (serviceAddress) { 150 151 var minMoveOutDate = new Date(0); 152 153 var maxBilledUntilDate = serviceAddress ? serviceAddress.get('max_billed_until_date') : null; 154 if (maxBilledUntilDate) { 155 minMoveOutDate = new Date(maxBilledUntilDate.getTime()); 156 minMoveOutDate.setDate(minMoveOutDate.getDate()); 157 } 158 159 $moveOutInput.datepicker("option", "minDate", minMoveOutDate); 160 $moveOutInput.rules("remove"); 161 $moveOutInput.rules("add", { required: true, dateISO: true, min_date: minMoveOutDate }); 162 }; 163 164 var radioChangeHandler = function (e) { 165 166 var serviceAddressIndex = form.find('input[type=radio]:checked').closest('.billing-entry').data('key'); 167 setMinMoveOutDate(serviceAddresses.at(serviceAddressIndex)); 168 }; 169 170 form.find('input[type=radio]').off('change', radioChangeHandler).on('change', radioChangeHandler); 171 172 if (serviceAddresses.length === 1) 173 setMinMoveOutDate(serviceAddresses.at(0)); 174 } 175 }); 176 177 // ================================= 178 app.MoveView = MoveView; 179 180})(window.mybf, jQuery, Backbone, _, bullfrog.utils);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.