1 2var customers = { 3 data: [], 4 detailed: {}, 5 external: [], 6 total: 0, 7 filter: { 8 search: "", 9 size: 50, 10 page: 1, 11 tags: [], 12 authLevel: -1, 13 sort: "firstName", 14 sortType: "asc", 15 archived: false, 16 riskLevel: "" 17 }, 18 filters: { 19 tags: [], 20 authLevels: [], 21 archivedOptions: [] // True/false 22 }, 23 getWithFilter: function () { 24 service.call("customers/filter", {filter: customers.filter}, customers.filteredReturned); 25 }, 26 filteredReturned: function (e) { 27 if (e.status !== "success") { 28 growler.error(e.message); 29 } else { 30 customers.data = e.data.data; 31 customers.total = e.data.total; 32 customers.filters = e.data.filters; 33 context.set("customers", customers.data); 34 context.set("customersFilters", customers.filters); 35 } 36 $(".loader").removeClass("open"); 37 }, 38 get: function() { 39 service.call("customers", customers.filter, customers.returned); 40 }, 41 all: function() { 42 var params = Object.assign({}, customers.filter); 43 params.size = 100000; 44 service.call("customers", params, customers.allReturned); 45 customers.get(); 46 }, 47 getDevices: function(id) { 48 service.call("member/devices", { id: id }, (results) => { 49 if (results.data) context.set("devices", results.data); 50 }); 51 }, 52 returned: function(e) { 53 $(".loader").removeClass("open"); 54 if (e.error) growler.error(e.error); 55 else { 56 customers.data = e.data; 57 customers.total = e.total; 58 context.set("customers", customers.data); 59 } 60 }, 61 allReturned: function(e) { 62 if (e.error) growler.error(e.error); 63 else { 64 customers.data = e.data; 65 customers.total = e.total; 66 context.set("allcustomers", customers.data); 67 } 68 }, 69 password: function(id, password) { 70 var params = customers.filter; 71 params.id = id; 72 params.password = password; 73 service.call("setpassword", params, customers.returned); 74 }, 75 upgrade: function(id, auth) { 76 var params = customers.filter; 77 params.id = id; 78 params.authorization = Number(auth); 79 service.call("upgradeAccount", params, customers.returned); 80 }, 81 saveAdmin: function(firstName, lastName, emailAddress, password, authorization, permissions, id) { 82 $(".loader").addClass("open"); 83 var params = customers.filter; 84 params.id = id; 85 params.firstName = firstName; 86 params.lastName = lastName; 87 params.emailAddress = emailAddress; 88 params.password = password; 89 params.authorization = authorization; 90 params.permissions = permissions; 91 params.all = true; 92 service.call("admin", params, customers.returned); 93 }, 94 save: function(firstName, lastName, emailAddress, password, authorization, id) { 95 var params = customers.filter; 96 params.id = id; 97 params.firstName = firstName; 98 params.lastName = lastName; 99 params.emailAddress = emailAddress; 100 params.password = password; 101 params.authorization = authorization; 102 params.all = true; 103 service.call("customer", params, customers.returned); 104 }, 105 saveDetails: function(id, emailAddress, firstName, lastName, phoneNumber, shippingId, street, city, state, country, zipCode, billingId, billingStreet, billingCity, billingState, billingCountry, billingZipCode, externalId, tags, appInstalled) { 106 var params = customers.filter; 107 params.id = id; 108 params.firstName = firstName; 109 params.lastName = lastName; 110 params.phoneNumber = phoneNumber; 111 params.emailAddress = emailAddress; 112 params.shippingId = shippingId; 113 params.street = street; 114 params.city = city; 115 params.state = state; 116 params.country = country; 117 params.zipCode = zipCode; 118 params.billingId = billingId; 119 params.billingStreet = billingStreet; 120 params.billingCity = billingCity; 121 params.billingState = billingState; 122 params.billingCountry = billingCountry; 123 params.billingZipCode = billingZipCode; 124 params.externalId = externalId; 125 params.appInstalled = appInstalled; 126 params.tags = tags; 127 params.all = false; 128 service.call("customer", params, customers.detailsSaved); 129 }, 130 delete: function(ids) { 131 var params = customers.filter; 132 params.ids = ids;
133 service.call("customer", params, customers.returned, "DELETE"); 134 }, 135 restore: function(ids) { 136 var params = customers.filter; 137 params.ids = ids; 138 service.call("customer/restore", params, customers.returned); 139 }, 140 deleteAdmins: function(ids) { 141 var params = customers.filter; 142 params.ids = ids; 143 service.call("admin", params, customers.returned, "DELETE"); 144 }, 145 findById: function(id) { 146 for (var i=0; i<customers.data.length; i++) { 147 if (customers.data[i].memberId==id) return customers.data[i]; 148 } 149 return null; 150 }, 151 export: function() { 152 $(".export").addClass("loading").html("Exporting..."); 153 fetch('/api/customers/export') 154 .then(response => { 155 if (!response.ok) throw new Error('Export failed'); 156 return response.blob(); 157 }) 158 .then(blob => { 159 var a = document.createElement('a'); 160 a.href = window.URL.createObjectURL(blob); 161 a.download = "Customers.csv"; 162 document.body.appendChild(a); 163 a.click(); 164 document.body.removeChild(a); 165 window.URL.revokeObjectURL(a.href); 166 $(".export").removeClass("loading").html("Export"); 167 growler.success("Customers export complete - check your downloads"); 168 }) 169 .catch(error => { 170 console.error('Export customers error:', error); 171 $(".export").removeClass("loading").html("Export"); 172 growler.error("Failed to export customers: " + (error?.message || "Unknown error")); 173 }); 174 }, 175 details: function(id) { 176 service.call("customer", { id: id }, customers.detailsReturned, "GET"); 177 }, 178 getFraudRisk: function(id, returnTo, handleError) { 179 service.call("fraud/members/" + id, {}, returnTo, "GET", handleError); 180 }, 181 getFraudBlockingOptions: function(id, returnTo, handleError) { 182 service.call("blockRule/customer/" + id, {}, returnTo, "GET", handleError); 183 }, 184 startFraudScan: function(scan, returnTo) { 185 service.call("fraud/scan", scan, returnTo); 186 }, 187 getFraudScanStatus: function(returnTo) { 188 service.call("fraud/scan/status", {}, returnTo, "GET"); 189 }, 190 posdetails: function(id) { 191 service.call("customer", { posId: id }, customers.detailsReturned, "GET"); 192 }, 193 detailsReturned: function(e) { 194 if (e.error) { 195 growler.error(e.error); 196 setTimeout(() => { 197 window.location = '/admin/customers'; 198 }, 3000); 199 } else { 200 customers.detailed = e; 201 context.set("customer", customers.detailed); 202 } 203 }, 204 detailsSaved: function(e) { 205 $(".loading").removeClass("open"); 206 if (e.error) growler.error(e.error); 207 else { 208 growler.success("Customer Information has been Saved.") 209 customers.detailed = e; 210 context.set("customer", customers.detailed); 211 } 212 }, 213 getExternal(first, last, email) { 214 var params = { 215 first: first, 216 last: last, 217 email: email 218 }; 219 service.call("listCustomerExternal", params, customers.externalReturned); 220 }, 221 externalReturned: function(e) { 222 if (e.error) growler.error(e.error); 223 else { 224 customers.external = e.data; 225 context.set("externalCustomers", e.data); 226 } 227 }, 228 import: function(customer) { 229 var params = customers.filter; 230 params.customer = customer; 231 service.call("importCustomer", params, customers.imported); 232 }, 233 imported: function(e) { 234 growler.success("Customer Imported"); 235 customers.returned(e); 236 }, 237 getShipping: function(id) { 238 service.call("customeraddress", { id: id }, customers.shippingReturned); 239 }, 240 shippingReturned: function(e) { 241 if (e.error) growler.error(e.error); 242 else { 243 customers.shipping = e; 244 context.set("shipping", e); 245 } 246 }, 247 getBilling: function(id) { 248 service.call("customeraddress", { id: id }, customers.billingReturned); 249 }, 250 billingReturned: function(e) { 251 if (e.error) growler.error(e.error); 252 else { 253 customers.billing = e; 254 context.set("billing", e); 255 } 256 }, 257 getOrders: function(id) { 258 var params = orders.filter; 259 params.member = id; 260 params.size = 100; 261 service.call("orders", params, customers.ordersReturned); 262 }, 263 ordersReturned: function(e) { 264 if (e.error) growler.error(e.error); 265 else { 266 customers.orders = e.data; 267 context.set("orders", e.data); 268 } 269 }, 270 getInStore: function(id) { 271 service.call("instore", { member: id }, customers.instoreReturned); 272 }, 273 instoreReturned: function(e) { 274 if (e.error) growler.error(e.error); 275 else { 276 customers.instore = e.data;
277 context.set("instore", e.data); 278 } 279 }, 280 next: function() { 281 if (!isLast()) customers.filter.page++; 282 else customers.filter.page = 1; 283 customers.get(); 284 }, 285 prev: function() { 286 if (customers.filter.page>1) customers.filter.page--; 287 else customers.filter.page = Math.ceil(customers.total/customers.filter.size); 288 customers.get(); 289 }, 290 isLast: function() { 291 return (customers.total<=(customers.filter.page*customers.filter.size)); 292 }, 293 isFirst: function() { 294 return customers.filter.page==1; 295 }, 296 pageTotal: function() { 297 return Math.ceil(customers.total/customers.filter.size); 298 }, 299 goto: function(page) { 300 if (page<=customers.pageTotal()&&page>=1) { 301 customers.filter.page = page; 302 customers.get(); 303 } 304 }, 305 views: function(id) { 306 service.call("productViews", { id: id }, customers.viewsReturned); 307 }, 308 viewsReturned: function(e) { 309 if (e.error) console.log(e); 310 else { 311 context.set("views", e.data); 312 } 313 }, 314 wishlist: function(id) { 315 console.log("Fetching wishlist for member ID:", id); 316 service.call("wishlist/admin/details", { id: id }, customers.wishlistReturned); 317 }, 318 wishlistReturned: function(e) { 319 console.log("Wishlist API response:", e); 320 if (e.error) { 321 console.error("Wishlist error:", e.error); 322 } else { 323 console.log("Setting wishlist context with data:", e.data); 324 context.set("wishlist", e.data); 325 } 326 } 327}
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.