1VNP.Areas.Customer = new function () { 2 3 var self = this; 4 var social_SOCIAL = ''; 5 var social_UDID = 'web'; 6 var social_DEVICE = 'web'; 7 var social_ISSHOP = false; 8 var autoLogin = false; 9 var canRead = null; 10 var deviceOs = ""; 11 var idCustomer = $(".vc_open_login").attr("data-id-customer"); 12 self.validator; // used to external html template to hide the error message for forgot password 13 14 15 /* ////////////////////////////// 16 // start social login facebook // 17 ///////////////////////////// */ 18 19 self.fb_render = function () { 20 //console.log('fb_render'); 21 FB.login(function (response) { 22 //console.log("fb_render response ",response) 23 if (response.status === 'connected') { 24 connected(); 25 } else if (response.status === 'not_authorized') { 26 // The person is logged into Facebook, but not your app. 27 } else { 28 // The person is not logged into Facebook, so we're not sure if 29 // they are logged into this app or not. 30 } 31 // handle the response 32 }, {scope: 'public_profile,email'}); 33 }; 34 35 var connected = function () { 36 //console.log("connected") 37 FB.getLoginStatus(function (response) { 38 if (response.status === 'connected') { 39 statusChangeCallback(response); 40 //console.log("response auth ", response.authResponse.accessToken); 41 } 42 }) 43 }; 44 45 var statusChangeCallback = function (response) { 46 //console.log("statusChangeCallback"); 47 // The response object is returned with a status field that lets the 48 // app know the current login status of the person. 49 // Full docs on the response object can be found in the documentation 50 // for FB.getLoginStatus(). 51 if (response.status === 'connected') { 52 // Logged into your app and Facebook. 53 //console.log(response) 54 fb_saveUser(response.authResponse.accessToken) 55 //testAPI(); 56 } else if (response.status === 'not_authorized') { 57 // The person is logged into Facebook, but not your app. 58 } else { 59 // The person is not logged into Facebook, so we're not sure if 60 // they are logged into this app or not. 61 } 62 }; 63 64 var fb_saveUser = function (access_token) { 65 handleUser("facebook", access_token); 66 //console.log("access_token ", access_token) 67 }; 68 69 /* 70 * @param social {String} : possible values are "facebook" , "google" , "yahoo" 71 * @access_token {String} : response from facebook or google or yahoo 72 * */ 73 var handleUser = function (social, access_token) { 74 75 $.ajax({ 76 url: VNP.baseUrl + "/webservice/socialResponse.jsp", 77 type: "POST", 78 dataType: "json", 79 data: {social: social, accessToken: access_token}, 80 beforeSend:function(){ 81 $('.vc_loading').show(); 82 }, 83 success: function (data) { 84 if (data.exists) { 85 86 self.loginUser(data.email, data.password); 87 88 } else { 89 90 if (social_ISSHOP) { 91 location.href = VNP.baseUrl + "/shop/privacy.jsp"; 92 } else { 93 var objGet = { 94 returnURL: location.href, 95 social: social, 96 udid: social_UDID, 97 device: social_DEVICE, 98 isShop: social_ISSHOP 99 100 } 101 location.href = VNP.baseUrl + "/includes/login/privacy.jsp?" + $.param(objGet) 102 } 103 104 } 105 } 106 }); 107 108 }; 109 110 /*////////////////////////////// 111 // end social login facebook // 112 //////////////////////////// */ 113 114 /* 115 * get if user can read or not 116 * @return canRead {Boolean} : true / false 117 * */ 118 self.getCanRead = function () { 119 return canRead; 120 }; 121 122 123 /* 124 * set if user can read or not 125 * @param value {Boolean} : true / false 126 */ 127 self.setCanRead = function (value) { 128 canRead = value; 129 }; 130 131 /*////////////////////////////// 132 // start social login google /// 133 /////////////////////////// */ 134 var clicked_trigger = false; 135 self.gplus_render = function (clicked) { 136 if (clicked == true) { 137 clicked_trigger = true; 138 // Additional params including the callback, the rest of the params will 139 // come from the page-level configuration. 140 var additionalParams = { 141 'callback': signinCallback 142 }; 143 gapi.auth.signIn(additionalParams); // Will use page level configuration 144 } 145 } 146 147 var signinCallback = function (authResult) { 148 if (authResult['status']['signed_in']) { 149 // Update the app to reflect a signed in user 150 // Hide the sign-in button now that the user is authorized, for example: 151 //console.log(authResult); 152 gplus_saveUser(authResult['access_token']) 153 } else { 154 // Update the app to reflect a signed out user 155 // Possible error values: 156 // "user_signed_out" - User is signed-out
157 // "access_denied" - User denied access to your app 158 // "immediate_failed" - Could not automatically log in the user 159 //console.log('Sign-in state: ' + authResult['error']); 160 } 161 } 162 163 var gplus_saveUser = function (access_token) { 164 if (clicked_trigger) { 165 handleUser("google", access_token); 166 } 167 } 168 169 /*///////////////////////////// 170 // end social login google // 171 /////////////////////////// */ 172 173 /* login user */ 174 self.loginUser = function (username, password, returnUrl) { 175 176 var $loginErrors = $('#vc_login_errors'); 177 var remember = $('#input_rememberme').is(':checked'); 178 var device = $('input[name=device]').val(); 179 var udid = $('input[name=udid]').val(); 180 181 var validator = new FormValidator({ 182 selectorForm: "#vc_form_login form", 183 classRequired: ".required", 184 errorFormClass: "has-error", 185 errorRequiredText: VNP.getLanguagesKey["login.error.required"], 186 errorEmailText: VNP.getLanguagesKey["login.error.email_invalid"], 187 errorPasswordConfirmText: VNP.getLanguagesKey["login.error.password"], 188 bootstrap: { 189 mode: true, 190 selector: "#vc_login_errors" 191 } 192 }); 193 194 self.validator = validator; 195 196 if(username === "" || password === ""){ 197 validator.checkRequiredFields(); 198 return false; 199 } 200 201 var params = { 202 username: username, 203 password: password, 204 remember: remember, 205 device: device, 206 udid: udid 207 }; 208 209 $.ajax({ 210 url: VNP.baseUrl + "/webservice/internal_login.jsp", 211 dataType: "json", 212 data: params, 213 method: "POST", 214 beforeSend:function(){ 215 $('.vc_loading').show(); 216 }, 217 success: function (data) { 218 // set stats 219 push_stats(stats.category.title, stats.event.login, params.username); 220 221 if (!data.success && data.status == 0) { 222 223 validator.showErrorMessage("", data.error); 224 225 $('.vc_loading').hide(); 226 $.ajax({ 227 url: VNP.baseUrl + "/includes/login/setLoginError.jsp", 228 data: data, 229 dataType: "json" 230 }); 231 232 } else { 233 234 if (returnUrl) { 235 location.href = returnUrl; 236 } else { 237 location.reload(); 238 } 239 240 } 241 } 242 }); 243 244 return false; 245 }; 246 247 self.recoverPassword = function(email){ 248 if( email && $.trim(email) != "") { 249 $.ajax({ 250 type: "POST", 251 data: $.param({emailRecover: email}), 252 dataType: "jsonp", 253 jsonpCallback: 'result', 254 url: VNP.baseUrl + "/webservice/recoverPwSendMail.jsp", 255 success: function (data) { 256 eModal.alert({ 257 css: {"padding": "35px 70px 35px 70px"}, 258 message: data.result, 259 title: VNP.getLanguagesKey["change_password"], 260 useBin: true, 261 classname: "vc_no_footer_dg text-center", 262 buttons: [] 263 }) 264 } 265 }); 266 } else { 267 console.error('Email is empty'); 268 } 269 270 }; 271 272 273 /* recover the password */ 274 self.forgotPassword = function () { 275 276 var validator = new FormValidator({ 277 selectorForm: "#vc_forgot_password_form", 278 classRequired: ".required", 279 errorFormClass: "has-error", 280 bootstrap: { 281 mode: true, 282 selector: "#vc_login_errors" 283 } 284 285 }); 286 287 self.validator = validator; 288 289 $(validator.mandatoryFields).on("keyup", function () { 290 validator.required(this); 291 }); 292 293 var $emailField = $('#input_email'); 294 var $emailValue = $.trim($($emailField).val()); 295 296 validator.checkEmailFormat($emailField[0]); 297 var checkForm = validator.submit(); 298 299 if (checkForm) { 300 301 var params = {emailRecover: $emailValue}; 302 var jsonPost = $.param(params); 303 304 $.ajax({ 305 type: "POST", 306 data: jsonPost, 307 dataType: "jsonp", 308 jsonpCallback: 'result', 309 beforeSend:function(){ 310 $('.vc_loading').show(); 311 }, 312 url: VNP.baseUrl + "/webservice/recoverPwSendMail.jsp", 313 success: function (data) { 314 315 $('.vc_loading').hide(); 316 317 if (data.status == 0) { 318 319 validator.showErrorMessage("", data.result); 320 321 } else { 322 323 validator.showSuccessMessage("", data.result); 324 // set stats 325 push_stats(stats.category.title, stats.event.recover_password, deviceOs); 326 $("#vc_forgot_password_form").hide(); 327 } 328 } 329 330 }); 331 } 332 333 return false;
334 335 }; 336 337 338 /* social login with facebook */ 339 self.loginFacebook = function (flowv2) { 340 if (flowv2) { 341 if (VNP.isAnApp) { 342 location.href = "inapp://login?social=" + social_SOCIAL + "&callback=handleUser" 343 } else { 344 VNP.Areas.Customer.fb_render(); 345 } 346 } else { 347 var thisURL = location.href; 348 var socialURL = VNP.baseUrl + "/books/loginsocial.jsp?social=facebook&urlReturn=" + encodeURIComponent(thisURL); 349 if (window.location.href == top.location.href) { 350 location.href = socialURL; 351 } else { 352 window.open(socialURL, '', 'width=500,height=400'); 353 } 354 } 355 }; 356 357 /* social login with google */ 358 self.loginGoogle = function (flowv2) { 359 360 self.gplus_render(flowv2); 361 362 }; 363 364 /* social login with yahoo */ 365 self.loginYahoo = function () { 366 367 $.ajax({ 368 url: VNP.baseUrl + '/social/yahooclient.jsp', 369 dataType: "json", 370 data: {"getYahooAuthenticationUrl": true, "returnUrl": location.href}, 371 beforeSend:function(){ 372 $('.vc_loading').show(); 373 }, 374 success: function (data) { 375 if (data.authenticationUrl != undefined && data.authenticationUrl.length > 0) { 376 parent.location.href = data.authenticationUrl; 377 } else { 378 alert("Error login with yahoo."); 379 } 380 }, 381 error: function (data) { 382 alert("Error login with yahoo."); 383 } 384 }); 385 386 }; 387 388 /* open order details */ 389 self.openOrderDetails = function (orderId) { 390 var url = VNP.baseUrl + "/includes/shop/return_page_ok.jsp?orderId=" + orderId + "&onlySummary=true"; 391 eModal.iframe(url, VNP.getLanguagesKey["order_details"]); 392 return false; 393 }; 394 395 /* open voucher business */ 396 self.openBusinessForm = function (orderId) { 397 var url = VNP.baseUrl + "/includes/shop/prepareBusinessPage.jsp?orderId=" + orderId; 398 eModal.iframe(url, VNP.getLanguagesKey["order_business_voucher"]); 399 return false; 400 }; 401 402 /* open voucher gift */ 403 self.openGiftForm = function (orderId) { 404 var url = VNP.baseUrl + "/includes/shop/prepareGiftPage.jsp?orderId=" + orderId; 405 eModal.iframe(url, VNP.getLanguagesKey["order_gift_voucher"]); 406 return false; 407 }; 408 409 /* open help desk */ 410 self.openHelpDesk = function (event) { 411 event.preventDefault(); 412 var options = { 413 title: VNP.getLanguagesKey["help_desk_title"], 414 message: $("#vc_help_desk").show(), 415 classname: "vc_no_footer_dg", 416 useBin: true, 417 buttons: [] 418 }; 419 eModal.alert(options); 420 }; 421 422 /* open custom popup, enbled in settings (table editore)*/ 423 self.openCustomPopup = function (event, element, label) { 424 event.preventDefault(); 425 var url = $(element).attr("href"); 426 eModal.iframe(url, label).then(function(response){ 427 $('.v').on('hide.bs.modal', function () { 428 location.reload(); 429 }) 430 }); 431 }; 432 433 /* orders my profile */ 434 435 /* filter to show orders with the same type 436 * @checkbox {HTMLDomElement} element html, must have data-value-type attribute with set the value of the type 437 * */ 438 self.showOrdersByType = function(checkbox){ 439 440 var isShow = checkbox.checked; 441 var type = $(checkbox).attr("data-value-type"); 442 var container = $(".vc_order_details"); 443 var elements = container.find(".vc_order_" + type); 444 var size = elements.length; 445 446 if(size === 0){ 447 return; 448 } 449 450 // show only the selected ones 451 $.each(elements,function(index, $el){ 452 if($($el).parent().parent().hasClass("vc_order_details")){ 453 454 if(isShow){ 455 $($el).parent().parent().parent().removeClass("hidden"); 456 } else { 457 $($el).parent().parent().parent().addClass("hidden"); 458 } 459 460 } 461 }); 462 }; 463 464 465 /* 466 * set the order number for any type of order we have 467 * the elements must have data-value-type with the type set 468 * */ 469 self.setOrdersNumberByType = function(){ 470 471 var container = $(".vc_filters"); 472 var input = container.find("input"); 473 var types = []; 474 475 $.each(input, function(index, element){ 476 var type = $(element).attr("data-value-type") 477 types.push( type ); 478 }); 479 480 $.each(types, function(index, type){ 481 var size = $(".vc_order_" + type).length; 482 var badge = container.find(".number_" + type); 483 if( badge.length > 0){ 484 badge.html("(" + size + ")"); 485 } 486 }); 487 488 }; 489 490 /* logout */ 491 self.logout = function (email) { 492 // set stats 493 push_stats(stats.category.title, stats.event.logout, email); 494 location.href = VNP.baseUrl + "/shop/user.jsp?logout=true&comingFrom="; 495 return false;
496 }; 497 498 // get info user 499 500 // favorites 501 self.deleteFavorites = function (id, element) { 502 var options = { 503 message: VNP.getLanguagesKey["deletePreferitiConfirm"], 504 title: VNP.getLanguagesKey["favorites"], 505 useBin: true, 506 classname: "vc_confirm_dg vc_favorites_dg" 507 }; 508 509 var canDelete = true; 510 511 var response = eModal.confirm(options, null) 512 .then(function () { 513 514 return $.ajax({ 515 url: VNP.baseUrl + '/shop/deletePreferiti.jsp?id=' + id 516 }); 517 518 }, null); 519 520 response.done(function (data) { 521 522 if(data.trim() === "OK"){ 523 524 $(element).parent().parent().fadeOut(function () { 525 $(this).remove(); 526 527 if ($(".vc_card_favorite").length == 0) { 528 529 530 $("#vc_favorites .vc_container_cards").html('<div class="vc_no_results">' 531 + VNP.getLanguagesKey["preferitisuggest"] 532 + '</div>') 533 534 } 535 }); 536 537 } else { 538 539 window.setTimeout(function () { 540 eModal.alert({ 541 css: {"padding": "35px 70px 35px 70px"}, 542 message: VNP.getLanguagesKey["cannotDelete"], 543 useBin: true, 544 classname: "vc_no_footer_dg text-center", 545 buttons: [] 546 }) 547 }, 1000); 548 549 } 550 551 }); 552 553 }; 554 555 self.confirmCancellation = function() { 556 if( confirm(VNP.getLanguagesKey["del_confirmation"]) ) { 557 if(idCustomer != null && !isNaN(parseInt(idCustomer)) && $.trim(idCustomer) != ""){ 558 deleteAccount(idCustomer); 559 } 560 } 561 }; 562 563 function deleteAccount(userId) { 564 if(userId != null && !isNaN(parseInt(userId)) && $.trim(userId) != ""){ 565 $.ajax({ 566 url: VNP.baseUrl + "/webservice/askDeleteAccount.jsp", 567 data: {"userId" : userId}, 568 success: function() { 569 alert(VNP.getLanguagesKey["del_confirmation_ok"]); 570 } 571 }); 572 } 573 574 }; 575 576 577 var getRegistrationForm = function() { 578 579 $.ajax({ 580 url: VNP.baseUrl + '/webservice/userFormHTML5.jsp', 581 data: { 582 "app": "", 583 "destination": VNP.baseUrl + "/customer/" + idCustomer + "/update", 584 "business": "", 585 "notitle": "", 586 "customerId": idCustomer, 587 }, 588 cache: true, 589 beforeSend:function(){ 590 $('.vc_loading').show(); 591 }, 592 success: function (data) { 593 594 $('.vc_loading').hide(); 595 $("#vc_registration_form").append(data); 596 597 setTimeout(function(){ 598 if(typeof initAutocomplete === 'function'){ 599 initAutocomplete(); 600 } 601 },500); 602 603 }, 604 error: function (data) {} 605 }); 606 607 }; 608 609 self.init = function () { 610 getRegistrationForm(); 611 } 612 613};
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.