1"use strict"; 2angular 3 .module("sfmStore") 4 .controller("packageController", function( 5 $scope, 6 $stateParams, 7 $products, 8 $order, 9 $state, 10 $analytics, 11 $sfmActivePolicy, 12 prepProduct, 13 prepPackageProducts 14 ) { 15 var vm = this; 16 var alreadyAdded = $order.getOrder().details.items.filter(function(item) { 17 return item.category_id == 1010; 18 }); 19 if (alreadyAdded.length > 0) { 20 alert( 21 "You've already added an insurance item to your cart. If you would like to change the information provided please remove the item from your cart and re-add it." 22 ); 23 $state.go("storeHome"); 24 } 25 26 vm.analytics = $analytics; 27 vm.addAllowed = true; 28 vm.order = $order; 29 30 vm.form = { 31 effectiveDate: (function() { 32 var dat = new Date(); 33 dat.setDate(dat.getDate() + 1); 34 return dat; 35 })(), 36 expirationDate: (function() { 37 var dat = new Date(); 38 dat.setDate(dat.getDate() + 1); 39 dat.setFullYear(dat.getFullYear() + 1); 40 return dat; 41 })() 42 }; 43 44 $scope.$watch( 45 function() { 46 return $order.getSchool().School_Name; 47 }, 48 function(newVal, oldVal) { 49 if (!angular.isUndefined($order.getSchool().id)) { 50 $products 51 .getQuestionAnswers($order.getSchool().id) 52 .then(function(res) { 53 var data = res.data.data; 54 if (data && data.oldExpDate) { 55 /** 56 * The following lines of code for date conversions should be unncessary 57 * Internet Explorer uses a strange date format that isn't used anywhere else except for IE 58 * The dates returned by mysql work perfectly fine in Chrome, Firefox, Safari, and Edge 59 * IE just had to be different -_- 60 */ 61 // Split timestamp into [ Y, M, D, h, m, s ] 62 var efDt = data.effectiveDate.split(/[- :]/); 63 // Create a date which makes IE happy, the mysql date format works fine in every other browser... 64 data.effectiveDate = new Date( 65 efDt[0], 66 efDt[1] - 1, 67 efDt[2], 68 efDt[3], 69 efDt[4], 70 efDt[5] 71 ); 72 var exDt = data.expirationDate.split(/[- :]/); 73 data.expirationDate = new Date( 74 exDt[0], 75 exDt[1] - 1, 76 exDt[2], 77 exDt[3], 78 exDt[4], 79 exDt[5] 80 ); 81 var oldExDt = data.oldExpDate.split(/[- :]/); 82 data.oldExpDate = new Date( 83 oldExDt[0], 84 oldExDt[1] - 1, 85 oldExDt[2], 86 oldExDt[3], 87 oldExDt[4], 88 oldExDt[5] 89 ); 90 91 var renewalAllowed = angular.copy(data.oldExpDate); 92 renewalAllowed.setMonth(renewalAllowed.getMonth() - 6); 93 var dat = new Date(); 94 if (dat >= renewalAllowed) { 95 if (dat >= data.oldExpDate) { 96 data.effectiveDate = dat.setDate(dat.getDate() + 1); 97 data.expirationDate = dat.setFullYear(dat.getFullYear() + 1); 98 } 99 } else { 100 vm.addAllowed = false; 101 var dates = { 102 renewalDate: renewalAllowed, 103 expDate: data.oldExpDate 104 }; 105 $sfmActivePolicy.showModal(dates); 106 } 107 vm.form = data; 108 } 109 }); 110 } 111 } 112 ); 113 vm.fields = []; 114 vm.product = prepProduct.data.data; 115 vm.packageProducts = prepPackageProducts.data.data; 116 117 // send a view_item event whenever this controller is invoked 118 dataLayer.push({ ecommerce: null }); 119 dataLayer.push({ 120 'event': 'view_item', 121 'ecommerce': { 122 'items': [{ 123 'item_name': vm.product.title, 124 'item_id': String(vm.product.id), 125 'item_category': String(vm.product.category_id), 126 'currency': "USD", 127 'price': Number(vm.product.cost) 128 }] 129 } 130 }); 131 132 vm.addToCart = function() { 133 if (vm.insuranceForm.$valid) { 134 var item = vm.product; 135 // Insurance will only ever have a qty of 1. 136 item.qty = 1; 137 item.subItems = vm.packageProducts; 138 vm.form.additionalInsured = vm.form.additionalInsured || null; 139 item.questions = vm.form; 140 var response = $order.addOrderItem(item); 141 if (!response.success) { 142 vm.submitError = response.error; 143 } 144 145 dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object. 146 dataLayer.push({ 147 'event': 'add_to_cart', 148 'ecommerce': { 149 'items': [{ 150 'item_name': item.title, 151 'item_id': String(item.id), 152 'item_category': String(item.category_id), 153 'quantity': item.qty 154 }] 155 } 156 }); 157 158 $state.go("cart", { 159 previousPage: vm.product.category_id, 160 itemAdded: item 161 }); 162 } else { 163 angular.forEach(vm.insuranceForm.$error.required, function(field) { 164 field.$setDirty(); 165 }); 166 } 167 }; 168 169 $products.getQuestionsByProduct($stateParams.id).then(function(res) { 170 res.data.data.forEach(function(item) { 171 if (item.type === "heading") { 172 vm.fields.push({ 173 template: "<h2>" + item.tpl_description_heading + "</h2>" 174 }); 175 } 176 if (item.tpl_description) { 177 vm.fields.push({ 178 template: 179 "<h3>" + 180 item.tpl_description_heading + 181 "</h3>" + 182 "<div>" + 183 item.tpl_description + 184 "</div>" 185 }); 186 } 187 if ( 188 item.type !== null && 189 item.type !== "heading" && 190 item.type !== "seperator" 191 ) { 192 vm.fields.push({ 193 key: item.key, 194 type: item.type, 195 defaultValue: item.defaultValue || undefined, 196 validators: {}, 197 templateOptions: { 198 type: item.tpl_type || undefined, 199 label: item.tpl_label || undefined, 200 placeholder: item.tpl_placeholder || undefined, 201 min: item.tpl_min || undefined, 202 max: item.tmpl_max || undefined, 203 required: Boolean(Number(item.tpl_required)) || undefined, 204 disabled: Boolean(Number(item.tpl_disabled)) || undefined, 205 options: [], 206 ngOptions: "option.value as option.name for option in to.options" 207 }, 208 expressionProperties: { 209 "form.expirationDate": function($viewValue, $modelValue, scope) { 210 scope.$watch( 211 function() { 212 return scope.model.effectiveDate; 213 }, 214 function(newVal, oldVal) { 215 if (newVal !== oldVal) { 216 var effDt = angular.copy(scope.model.effectiveDate); 217 scope.model.expirationDate = effDt.setFullYear( 218 effDt.getFullYear() + 1 219 ); 220 } 221 } 222 ); 223 } 224 }, 225 controller: function($scope, $sfmManualApplication) { 226 if ( 227 $scope.options.type === "select" || 228 $scope.options.type === "radio" 229 ) { 230 $products.getOptionsByQuestionId(item.id).then(function(res) { 231 $scope.options.templateOptions.options = 232 res.data.data || undefined; 233 $scope.options.defaultValue = 234 res.data.data[0].name || undefined; 235 if ($scope.options.type === "radio") { 236 delete $scope.model[$scope.options.key]; 237 $scope.options.validators.agree = function( 238 $viewValue, 239 $modelValue, 240 scope 241 ) { 242 var value = $viewValue || $modelValue; 243 if (Number(value) === 1 || value === null) { 244 return true; 245 } else if (Number(value) === 0) { 246 $sfmManualApplication.showModal(); 247 return false;
248 } 249 }; 250 } 251 }); 252 } 253 if ( 254 $scope.options.key === "totalAssets" || 255 $scope.options.key === "totalRevenue" 256 ) { 257 $scope.options.templateOptions.addonLeft = { text: "$" }; 258 $scope.options.templateOptions.addonRight = { text: ".00" }; 259 } 260 } 261 }); 262 } 263 if (item.type === "seperator") { 264 vm.fields.push({ 265 template: "<hr>" 266 }); 267 } 268 }); 269 }); 270 271 vm.cartHasInsuranceItem = function() { 272 var insItem = $order.getDuplicateItem("pkg"); 273 if (insItem) { 274 return true; 275 } 276 return false; 277 }; 278 279 $analytics.pushVirtualPageview(window.location.href); 280 });
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.