1jQuery.namespace( 'SS.com.Motion' ); 2SS.com.Motion.Popups = function() 3{ 4 var me = this; 5 6 /** 7 * cache the current person record properties 8 */ 9 this.PersonRecord = SS.vars.Person; 10 this.LoggedIn = SS.vars.LoggedIn; 11 this.IsMatched = SS.vars.IsMatched; 12 this.HasUser = SS.vars.HasUser; 13 this.recoverPasswordUrl = null; 14 this.captchaId = null; 15 16 /** 17 * cache the current and referrer popups 18 * @type {mixed} 19 */ 20 this.currentPopUp = false; 21 this.referrerPopUp = false; 22 23 /** 24 * flag to enable/disable the login and register popups after various actions are completed 25 * @type {boolean} 26 */ 27 this.disableLoginRegisterPopUp = false; 28 29 /** 30 * define default messages that will be showin in login popup after various actions are completed 31 * @type {text} 32 */ 33 this.loginMessage = 'Please sign in to manage your Interest List, communicate with a Recruiter, or to update your survey.<br/>'; 34 35 /** 36 * define default message that will be shown in register popup after various actions are completed 37 * @type {text} 38 */ 39 this.registerMessage = 'Our records tell us that all we need to complete your registration is a password. For a richer experience, please choose a password below.'; 40 41 /** 42 * define confirmation messages 43 * @type {{inquire: string, interestList: string, removeInterestList: string, sendToFriend: string}} 44 */ 45 this.confirmationMessages = { 46 inquire: 'Thank you!<br/>We have received your question and you will hear back from a Missions Counselor soon.', 47 interestList: 'Opportunity was added to your interest list', 48 removeInterestList: 'Opportunity was removed from your interest list', 49 sendToFriend: 'Your message was sent.' 50 }; 51 52 /** 53 * Listen to ".add-to-interest-list" and trigger addToInterestList on click 54 */ 55 $('.interest-list .add-to-interest-list').on('click',function( event ){ 56 event.preventDefault(); 57 me.showAddToInterestList( $(this) ); 58 }); 59 60 /** 61 * Listen to ".added-to-interest-list" and trigger removeFromInterestList on click 62 */ 63 $('.interest-list .added-to-interest-list').on('click',function( event ){ 64 event.preventDefault(); 65 me.removeFromInterestList( $(this) ); 66 }); 67 68 /** 69 * Listen to ".inquire" and trigger inquireOpportunity on click 70 */ 71 $('.motion-actions .inquire').on('click',function( event ){ 72 event.preventDefault(); 73 me.inquireOpportunity( $(this) ); 74 }); 75 76 /** 77 * Listen to ".sendToAFriend" and trigger sendToAFriend on click 78 */ 79 $('.motion-actions .sendToAFriend').on('click',function( event ){ 80 event.preventDefault(); 81 me.sendToFriend( $(this) ); 82 }); 83 84 /** 85 * Listen to ".applicationAlreadySubmitted" and show meesage 86 */ 87 $('.motion-actions .applicationAlreadySubmitted').on('click',function( event ){ 88 event.preventDefault(); 89 me.alreadyApplied( $(this) ); 90 }); 91 92 this.init(); 93 94}; 95 96SS.com.Motion.Popups.prototype = { 97 98 init:function(){ 99 var me = this; 100 101 this.siteSettings = {}; 102 this.siteChannelSettings = {}; 103 $.ajax({ 104 url: SS.utils.Router.url({ 105 plugin: 'Motion', 106 controller: 'Motion', 107 action: 'getSettings', 108 ext: 'json' 109 }), 110 cache: false, 111 type: 'POST', 112 dataType : 'json', 113 abortOnRetry: false, 114 success : function(responseData, textStatus, jqXHR){ 115 if( responseData.siteSettings ){ 116 me.siteSettings = responseData.siteSettings 117 } 118 if(responseData.siteChannelSettings){ 119 me.siteChannelSettings = responseData.siteChannelSettings; 120 } 121 } 122 }); 123 124 // Load reCAPTCHA if not already loaded 125 if(typeof grecaptcha == 'undefined') { 126 $.getScript( "https://www.google.com/recaptcha/api.js?render=explicit"); 127 } 128 }, 129 /** 130 * Remove opportunity from the person's interest list 131 * At this point only shows a pop up saying that the opportuynity is already added 132 * @param trigger 133 */ 134 removeFromInterestList: function( trigger ) 135 { 136 //todo: implement remove from interest list actions 137 var me = this; 138 this.referrerPopUp = 'removeFromInterestList'; 139 140 var contentItemId = parseInt(trigger.attr('contentItemId')); 141 142 var alertConfig = { 143 title: 'Opportunity already added', 144 msg: 'This opportunity was already added to your interest list', 145 cls: 'motion-popup opportunity-already-added', 146 closeButton: true, 147 buttons: { 148 ok: { 149 btnText: 'OK', 150 btnCls: false, 151 overCls: false 152 }, 153 cancel: { 154 btnText: 'Remove From Interest List', 155 handler:function(){ 156 $.ajax({ 157 url: SS.route('Motion', 'MotionInterestLists', 'removeFromInterestList', ''), 158 cache: false, 159 type: 'POST', 160 data: { 161 contentItemId: contentItemId 162 }, 163 dataType : 'json', 164 abortOnRetry: false, 165 error : function(jqXHR, textStatus, errorThrown){ 166 me.displayPopUpErrors({ 167 noField: [ 168 'Something went wrong. Please try again.' 169 ] 170 }); 171 }, 172 success : function(responseData, textStatus, jqXHR){ 173 if( responseData.success ){ 174 me.showConfirmation( {} ); 175 176 }else{ 177 me.displayPopUpErrors( responseData.errors ); 178 } 179 } 180 }); 181 } 182 } 183 } 184 }; 185 me.currentPopUp = new SS.customAlert(alertConfig); 186 }, 187 188 /** 189 * Open add to interest list popup 190 * function expect that the trigger dom element to have "contentItemId" html tag set 191 * 192 * @param {object} trigger 193 */ 194 showAddToInterestList: function( trigger ) 195 { 196 var me = this; 197 this.referrerPopUp = 'addToInterestList'; 198 199 var contentItemId = parseInt(trigger.attr('contentItemId')); 200 201 var alertConfig = { 202 title: 'Tell Me More', 203 msg: 204 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Your Name</span><br/>' + 205 '<input type="text" name="firstname" placeholder="First Name" style="width: 48%; float: left;" />' + 206 '<input type="text" placeholder="Last Name" name="lastname" style="width: 48%; float: right;" />' + 207 '<div class="clearfix"></div>' + 208 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Your Email</span><br/>' + 209 '<input type="text" name="email" class="last-row" />', 210 cls: 'motion-popup add-to-interest-list', 211 closeButton: true, 212 buttonAlign: 'right', 213 buttons: { 214 ok: { 215 btnText: 'Add it', 216 btnCls: false, 217 overCls: false, 218 closePopUp: false 219 } 220 }, 221 callback: function( clickedButton ){ 222 me.saveInterestList( contentItemId ); 223 } 224 }; 225 226 // if there is a person save the interest list records else show the popup 227 if( this.PersonRecord ){ 228 me.saveInterestList( contentItemId ); 229 }else{ 230 me.currentPopUp = new SS.customAlert( alertConfig ); 231 } 232 }, 233 234 /** 235 * Open add to inquire popup 236 * function expect that the trigger dom element to have "contentItemId" html tag set 237 * 238 * @param {object} trigger 239 */ 240 inquireOpportunity: function( trigger ) 241 { 242 var me = this; 243 this.referrerPopUp = 'inquire'; 244 var contentItemId = parseInt(trigger.attr('contentItemId')); 245 var popupWidth = parseInt(trigger.attr('data-popup-width')); 246 247 var msg = ''; 248 if( this.PersonRecord ){ 249 msg = 250 (this.LoggedIn?'':'<div class="not-this-person" style="margin-bottom: 10px"><a href="'+SS.route('People', 'People', 'removePersonFromSession', null, null)+'">
250Click here if you are not '+this.PersonRecord.firstname+' '+this.PersonRecord.lastname+'</a></div>')+ 251 '<span>My Question</span><br/>' + 252 '<textarea name="message" class="last-row" rows="6"></textarea>'; 253 }else{ 254 var phone = ""; 255 if(me.siteChannelSettings && me.siteChannelSettings.Motion && Number(me.siteChannelSettings.Motion.inquire_popup_show_phone)){ 256 257 phone = (Number(me.siteChannelSettings.Motion.inquire_popup_require_phone)?'<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" />':'')+ 258 '<span>Your Phone</span><br/><input type="text" name="phone" />'; 259 } 260 261 msg = 262 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Your Name</span><br/>' + 263 '<input type="text" name="firstname" placeholder="First Name" style="width: 48%; float: left;" />' + 264 '<input type="text" placeholder="Last Name" name="lastname" style="width: 48%; float: right;" />' + 265 '<div class="clearfix"></div>' + 266 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Your Email</span><br/>' + 267 '<input type="text" name="email" />'+ 268 phone + 269 '<span>My Question</span><br/>' + 270 '<textarea name="message" class="last-row" rows="6"></textarea>'; 271 } 272 273 var alertConfig = { 274 title: 'Tell Me More', 275 msg: msg, 276 cls: 'motion-popup tell-me-more-inquire', 277 width: popupWidth > 0 ? popupWidth : 300, 278 closeButton: true, 279 buttonAlign: 'right', 280 buttons: { 281 ok: { 282 btnText: 'Ask', 283 btnCls: false, 284 overCls: false, 285 closePopUp: false 286 } 287 }, 288 callback: function( clickedButton ){ 289 me.saveInquire(contentItemId); 290 } 291 }; 292 293 me.currentPopUp = new SS.customAlert( alertConfig ); 294 }, 295 296 /** 297 * Open add to send to friend popup 298 * function expect that the trigger dom element to have "contentItemId" html tag set 299 * 300 * @param {object} trigger 301 */ 302 sendToFriend: function( trigger ) 303 { 304 var me = this; 305 this.referrerPopUp = 'sendToFriend'; 306 var contentItemId = parseInt(trigger.attr('contentItemId')); 307 var popupWidth = parseInt(trigger.attr('data-popup-width')); 308 309 var captchaElement = ''; 310 var usersComponentSettings = this.siteChannelSettings.Users; 311 if(usersComponentSettings.show_captcha && usersComponentSettings.show_captcha !== '0') { 312 captchaElement = '<div class="google-recaptcha"><div class="g-recaptcha"></div></div>'; 313 } 314 315 var msg = ''; 316 var btnCfg = {}; 317 if( this.PersonRecord ){ 318 msg = 319 (this.LoggedIn?'':'<div class="not-this-person" style="margin-bottom: 10px"><a href="'+SS.route('People', 'People', 'removePersonFromSession', null, null)+'">Click here if you are not '+this.PersonRecord.firstname+' '+this.PersonRecord.lastname+'</a></div>')+ 320 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Your Friend\'s Information</span><br/>' + 321 '<input type="text" name="friendfirstname" placeholder="First Name" style="width: 48%; float: left;" />' + 322 '<input type="text" placeholder="Last Name" name="friendlastname" style="width: 48%; float: right;" />' + 323 '<div class="clearfix"></div>' + 324 '<input type="text" name="friendemail" placeholder="Friend\'s Email Address" />'+ 325 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Add a Message</span><br/>' + 326 '<textarea name="message" class="last-row" rows="6"></textarea>' + 327 captchaElement; 328 }else{ 329 msg = 330 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Your Information</span><br/>' + 331 '<input type="text" name="firstname" placeholder="First Name" style="width: 48%; float: left;" />' + 332 '<input type="text" placeholder="Last Name" name="lastname" style="width: 48%; float: right;" />' + 333 '<div class="clearfix"></div>' + 334 '<input type="text" name="email" placeholder="Your Email Address" />'+ 335 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Your Friend\'s Information</span><br/>' + 336 '<input type="text" name="friendfirstname" placeholder="First Name" style="width: 48%; float: left;" />' + 337 '<input type="text" placeholder="Last Name" name="friendlastname" style="width: 48%; float: right;" />' + 338 '<div class="clearfix"></div>' + 339 '<input type="text" name="friendemail" placeholder="Friend\'s Email Address" />'+ 340 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Add a Message</span><br/>' + 341 '<textarea name="message" class="last-row" rows="6"></textarea>' + 342 captchaElement; 343 } 344 345 var alertConfig = { 346 title: 'Send this opportunity to a friend.', 347 msg: msg, 348 cls: 'motion-popup send-to-friend', 349 width: popupWidth > 0 ? popupWidth : 300, 350 closeButton: true, 351 buttonAlign: 'right', 352 buttons: { 353 ok: { 354 btnText: 'Send', 355 btnCls: false, 356 overCls: false, 357 closePopUp: false 358 } 359 }, 360 callback: function( clickedButton ){ 361 me.sendToFriendEmail(contentItemId); 362 } 363 }; 364 365 me.currentPopUp = new SS.customAlert(alertConfig); 366 367 me.currentPopUp._dom.on('aftershow', function(alert) { 368 // Handle reCAPTCHA 369 370 if(!usersComponentSettings.show_captcha || usersComponentSettings.show_captcha === '0') return; 371 372 if(typeof grecaptcha != 'undefined') { 373 me.captchaId = grecaptcha.render($('.motion-popup.send-to-friend .g-recaptcha')[0], { 374 'sitekey': usersComponentSettings.captcha_site_key 375 }) 376 } 377 }); 378 }, 379 380 /** 381 * Show the login popup 382 */ 383 showLogin: function() 384 { 385 var me = this; 386 387 var alertConfig = { 388 title: 'Login', 389 msg: 390 me.loginMessage + '<br/>' + 391 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Username</span><br/>' + 392 '<input class="readonly" type="text" name="username" value="'+me.PersonRecord.email+'" readonly="readonly"/>' + 393 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Password</span><br/>' + 394 '<input type="password" name="password" autocomplete="off"/>' + 395 '<div>' + 396 'Did you forget your password?<br/>' + 397 '<a href="' + (me.recoverPasswordUrl?me.recoverPasswordUrl:'#') + '" style="color: #AD975E;">Recover my password</a>' + 398 '</div>', 399 cls: 'motion-popup login', 400 closeButton: true, 401 buttons: { 402 ok: { 403 btnText: 'Log In', 404 btnCls: false, 405 overCls: false, 406 closePopUp: false 407 }, 408 cancel: { 409 btnText: 'Cancel', 410 btnCls: false, 411 overCls: false 412 } 413 }, 414 callback: function( clickedButton ){ 415 me.processLogin(); 416 } 417 }; 418 419 me.currentPopUp = new SS.customAlert(alertConfig); 420 }, 421 422 /**
423 * Displays a pop up to allow visitors with a contact record 424 * to register and connect it to the new user account 425 * @cfg {string} message 426 */ 427 showRegister: function( message ) 428 { 429 var me = this; 430 var captchaElement = ''; 431 var usersComponentSettings = this.siteChannelSettings.Users; 432 433 if(usersComponentSettings.show_captcha && usersComponentSettings.show_captcha !== '0') { 434 captchaElement = '<div class="google-recaptcha"><div class="g-recaptcha"></div></div>'; 435 } 436 437 me.destroyCurrentPopUp(); 438 var alertConfig = { 439 title: 'Thanks ' + this.PersonRecord.firstname, 440 msg: 441 (message ? message + '<br/><br/>' : '') + 442 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Choose a Password</span><br/>' + 443 '<input type="password" name="User[password]" autocomplete="off"/>' + 444 '<img class="required" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="8" height="7" /><span>Confirm your Password</span><br/>' + 445 '<input type="password" name="User[password_repeat]" autocomplete="off" class="last-row" />' + 446 captchaElement, 447 cls: 'motion-popup register', 448 closeButton: true, 449 runCallbackOnClose: true, 450 buttonAlign: 'right', 451 buttons: { 452 ok: { 453 btnText: 'Submit', 454 btnCls: false, 455 overCls: false, 456 closePopUp: false 457 }, 458 cancel: false 459 }, 460 callback: function( clickedButton ){ 461 me.processRegistration( clickedButton ); 462 } 463 }; 464 me.currentPopUp = new SS.customAlert(alertConfig); 465 466 me.currentPopUp._dom.on('aftershow', function(alert) { 467 // Handle reCAPTCHA 468 469 if(!usersComponentSettings.show_captcha || usersComponentSettings.show_captcha === '0') return; 470 471 if(typeof grecaptcha != 'undefined') { 472 me.captchaId = grecaptcha.render($('.motion-popup.register .g-recaptcha')[0], { 473 'sitekey': usersComponentSettings.captcha_site_key 474 }) 475 } 476 }); 477 }, 478 479 /** 480 * Show a confirmation that the opportunity was added to interest list 481 * and refresh the page or call the callbackFct if set after close 482 * 483 * @param {string} confirmationMessage r A string that will be printed as a confirmation message in the popup 484 * @param {function} callbackFct r A function to execute after the popup is closed or null to refresh the page on close 485 */ 486 showConfirmation: function( buttonsConfig, callbackFct, forceCallback ) 487 { 488 if( !buttonsConfig ){ 489 buttonsConfig = { 490 ok: false, 491 cancel: false 492 }; 493 } 494 if( !callbackFct ){ 495 callbackFct = function(){ 496 document.location.reload(); 497 } 498 } 499 if($.type(forceCallback) == 'undefined'){ 500 forceCallback = true; 501 } 502 503 var confirmationMessage = null; 504 var cls = 'motion-popup confirmation'; 505 if( this.referrerPopUp == 'removeFromInterestList' ){ 506 confirmationMessage = this.confirmationMessages.removeInterestList; 507 cls += ' remove-from-interest-list'; 508 } 509 if( this.referrerPopUp == 'addToInterestList' ){ 510 confirmationMessage = this.confirmationMessages.interestList; 511 cls += ' add-to-interest-list'; 512 } 513 if( this.referrerPopUp == 'inquire' ){ 514 confirmationMessage = this.confirmationMessages.inquire; 515 cls += ' inquire'; 516 } 517 if( this.referrerPopUp == 'sendToFriend' ){ 518 confirmationMessage = this.confirmationMessages.sendToFriend; 519 cls += ' send-to-friend'; 520 } 521 522 this.destroyCurrentPopUp(); 523 524 var alertConfig = { 525 title: ' ', 526 msg: 527 '<div style="text-align: center">' + 528 '<img src="/Motion/img/frontend/green-check-66x66.png" width="66" height="66" /><br/> ' + 529 confirmationMessage + 530 '</div>', 531 cls: cls, 532 closeButton: true, 533 runCallbackOnClose: forceCallback, 534 buttons: buttonsConfig, 535 callback: function( clickedButton ){ 536 callbackFct(clickedButton); 537 } 538 }; 539 this.currentPopUp = new SS.customAlert(alertConfig); 540 }, 541 542 543 /** 544 * Submit add to interest list request 545 * 546 * @param {number} contentItemId 547 */ 548 saveInterestList: function( contentItemId ) 549 { 550 var me = this; 551 $.ajax({ 552 url: SS.route('Motion', 'MotionInterestLists', 'save', ''), 553 cache: false, 554 type: 'POST', 555 data: { 556 firstname: $('.customAlert input[name="firstname"]').val(), 557 lastname: $('.customAlert input[name="lastname"]').val(), 558 email: $('.customAlert input[name="email"]').val(), 559 contentItemId: contentItemId 560 }, 561 dataType : 'json', 562 abortOnRetry: false, 563 error : function(jqXHR, textStatus, errorThrown){ 564 me.displayPopUpErrors({ 565 noField: [ 566 'Something went wrong. Please try again.' 567 ] 568 }); 569 }, 570 success : function(responseData, textStatus, jqXHR){ 571 if( responseData.success ){ 572 // if the person was just created cache the person data properties 573 if( !me.PersonRecord && responseData.person ){ 574 me.PersonRecord = responseData.person; 575 me.HasUser = responseData.hasUser; 576 me.IsMatched = responseData.isMatched; 577 me.LoggedIn = false;
578 } 579 me.recoverPasswordUrl = responseData.recoverPasswordUrl; 580 581 me.afterSubmitURL = responseData.afterSubmit.url; 582 me.afterSubmitTitle = responseData.afterSubmit.title; 583 584 me.markItemAsAddedToInterestList( contentItemId ); 585 586 if(responseData.disableLoginRegisterPopups.length && parseInt(responseData.disableLoginRegisterPopups) == 1){ 587 me.disableLoginRegisterPopUp = true; 588 } 589 if(responseData.loginMsg.length){ 590 me.loginMessage = responseData.loginMsg; 591 } 592 if(responseData.registerMsg.length){ 593 me.registerMessage = responseData.registerMsg; 594 } 595 596 // if there is an authenticated user show the confirmation 597 if( me.LoggedIn || me.disableLoginRegisterPopUp ){ 598 me.showConfirmation({ 599 ok: { 600 btnText: 'Continue to ' + me.afterSubmitTitle, 601 btnCls: false, 602 overCls: false, 603 closePopUp: true 604 } 605 },function(button){ 606 if(button=='ok'){ 607 document.location.href = me.afterSubmitURL 608 }else{ 609 document.location.reload(); 610 } 611 },true); 612 }else{ 613 // if not LoggedIn, IsMatched and HasUser show the login window 614 if( !me.LoggedIn && me.IsMatched && me.HasUser ){ 615 me.destroyCurrentPopUp(); 616 me.showLogin(); 617 }else{ 618 // else show the registration window 619 me.destroyCurrentPopUp(); 620 me.showRegister('Did you know that if you register, we\'ll give you a dashboard to manage your interest list? It\'s easy! Create a password below to complete your registration.'); 621 } 622 } 623 624 }else{ 625 me.displayPopUpErrors( responseData.errors ); 626 } 627 } 628 }); 629 630 }, 631 632 /** 633 * Submit save inquire request 634 * @param {number} contentItemId 635 */ 636 saveInquire: function( contentItemId ) 637 { 638 var me = this; 639 $.ajax({ 640 url: SS.utils.Router.url({ 641 plugin: 'Motion', 642 controller: 'Motion', 643 action: 'inquire' 644 }), 645 cache: false, 646 type: 'POST', 647 data: { 648 firstname: $('.customAlert input[name="firstname"]').val(), 649 lastname: $('.customAlert input[name="lastname"]').val(), 650 email: $('.customAlert input[name="email"]').val(), 651 message: $('.customAlert textarea[name="message"]').val(), 652 phone: $('.customAlert input[name="phone"]').val(), 653 contentItemId: contentItemId 654 }, 655 dataType : 'json', 656 abortOnRetry: false, 657 error : function(jqXHR, textStatus, errorThrown){ 658 me.displayPopUpErrors({ 659 noField: [ 660 'Something went wrong. Please try again.' 661 ] 662 }); 663 }, 664 success : function(responseData, textStatus, jqXHR){ 665 if( responseData.success ){ 666 667 // if the person was just created cache the person data properties 668 if( !me.PersonRecord && responseData.person ){ 669 me.PersonRecord = responseData.person; 670 me.HasUser = responseData.hasUser; 671 me.IsMatched = responseData.isMatched; 672 me.LoggedIn = false;
673 } 674 me.recoverPasswordUrl = responseData.recoverPasswordUrl; 675 676 if(responseData.confirmationMessage.length){ 677 me.confirmationMessages.inquire = responseData.confirmationMessage; 678 } 679 if(responseData.disableLoginRegisterPopups.length && parseInt(responseData.disableLoginRegisterPopups) == 1){ 680 me.disableLoginRegisterPopUp = true; 681 } 682 if(responseData.loginMsg.length){ 683 me.loginMessage = responseData.loginMsg; 684 } 685 if(responseData.registerMsg.length){ 686 me.registerMessage = responseData.registerMsg; 687 } 688 //disableLoginRegisterPopups,loginMsg,registerMsg 689 690 // if there is an authenticated user show the confirmation 691 if( me.LoggedIn || me.disableLoginRegisterPopUp ){ 692 me.showConfirmation( null, function(){} ); 693 }else{ 694 // if not LoggedIn, IsMatched and HasUser show the login window 695 if( !me.LoggedIn && me.IsMatched && me.HasUser ){ 696 me.destroyCurrentPopUp(); 697 me.showLogin(); 698 }else{ 699 // else show the registration window 700 me.destroyCurrentPopUp(); 701 me.showRegister(me.registerMessage); 702 } 703 } 704 }else{ 705 me.displayPopUpErrors(responseData.errors); 706 } 707 } 708 }); 709 710 }, 711 712 /** 713 * Submit send to friend popup data 714 * @param contentItemId 715 */ 716 sendToFriendEmail: function( contentItemId ) 717 { 718 var me = this; 719 720 var captchaResponse = null; 721 if(this.siteChannelSettings.Users.show_captcha && this.siteChannelSettings.Users.show_captcha !== '0') { 722 captchaResponse = grecaptcha.getResponse(me.captchaId); 723 } 724 725 $.ajax({ 726 url: SS.utils.Router.url({ 727 plugin: 'Motion', 728 controller: 'Motion', 729 action: 'sendToFriend' 730 }), 731 cache: false, 732 type: 'POST', 733 data: { 734 firstname: $('.customAlert input[name="firstname"]').val(), 735 lastname: $('.customAlert input[name="lastname"]').val(), 736 email: $('.customAlert input[name="email"]').val(), 737 738 friendfirstname: $('.customAlert input[name="friendfirstname"]').val(), 739 friendlastname: $('.customAlert input[name="friendlastname"]').val(), 740 friendemail: $('.customAlert input[name="friendemail"]').val(), 741 742 message: $('.customAlert textarea[name="message"]').val(), 743 contentItemId: contentItemId, 744 745 'g-recaptcha-response': captchaResponse 746 }, 747 dataType : 'json', 748 abortOnRetry: false, 749 error : function(jqXHR, textStatus, errorThrown){ 750 me.displayPopUpErrors({ 751 noField: [ 752 'Something went wrong. Please try again.' 753 ] 754 }); 755 }, 756 success : function(responseData, textStatus, jqXHR){ 757 if( responseData.success ){ 758 759 // if the person was just created cache the person data properties 760 if( !me.PersonRecord && responseData.person ){ 761 me.PersonRecord = responseData.person; 762 me.HasUser = responseData.hasUser; 763 me.IsMatched = responseData.isMatched; 764 me.LoggedIn = false; 765 } 766 me.recoverPasswordUrl = responseData.recoverPasswordUrl; 767 768 if(responseData.disableLoginRegisterPopups.length && parseInt(responseData.disableLoginRegisterPopups) == 1){ 769 me.disableLoginRegisterPopUp = true; 770 } 771 if(responseData.loginMsg.length){ 772 me.loginMessage = responseData.loginMsg; 773 } 774 if(responseData.registerMsg.length){ 775 me.registerMessage = responseData.registerMsg; 776 } 777 778 // if there is an authenticated user show the confirmation 779 if( me.LoggedIn || me.disableLoginRegisterPopUp ){ 780 me.showConfirmation( null, function(){} ); 781 }else{ 782 // if not LoggedIn, IsMatched and HasUser show the login window 783 if( !me.LoggedIn && me.IsMatched && me.HasUser ){ 784 if(responseData.loginMessage && responseData.loginMessage.length > 0) { 785 me.loginMessage = responseData.loginMessage; 786 } 787 me.destroyCurrentPopUp(); 788 me.showLogin(); 789 }else{ 790 // else show the registration window 791 me.destroyCurrentPopUp(); 792 me.showRegister(me.registerMessage); 793 794 } 795 } 796 }else{ 797 me.displayPopUpErrors(responseData.errors); 798 } 799 }, 800 complete: function() { 801 if (me.captchaId !== null) { 802 grecaptcha.reset(me.captchaId) 803 } 804 } 805 }); 806 }, 807 808 /** 809 * Submit the login request and display login errors or call the callback function if login
809was successfull 810 */ 811 processLogin: function() 812 { 813 var me = this; 814 var username = $('.customAlert input[name="username"]').val(); 815 var password = $('.customAlert input[name="password"]').val(); 816 817 $.ajax({ 818 url: '/users/login.json', 819 cache: false, 820 type: 'POST', 821 data: { 822 'data[User][username]': username, 823 'data[User][password]': password 824 }, 825 dataType : 'json', 826 abortOnRetry: false, 827 error : function(jqXHR, textStatus, errorThrown){ 828 me.displayPopUpErrors({ 829 noField: [ 830 'Something went wrong. Please try again.' 831 ] 832 }); 833 }, 834 success : function(responseData, textStatus, jqXHR){ 835 if( responseData.response.success ){ 836 document.location.reload(); 837 }else{ 838 me.displayPopUpErrors({ 839 noField: [ 840 responseData.response.Error 841 ] 842 }); 843 } 844 } 845 }); 846 }, 847 848 /** 849 * Submit the register request and displays registration errors or load the confirmation popup 850 */ 851 processRegistration: function( clickedButton ) 852 { 853 var me = this; 854 var password = $('.customAlert input[name="User[password]"]').val(); 855 var repeatPassword = $('.customAlert input[name="User[password_repeat]"]').val(); 856 857 var captchaResponse = null; 858 if(this.siteChannelSettings.Users.show_captcha && this.siteChannelSettings.Users.show_captcha !== '0') { 859 captchaResponse = grecaptcha.getResponse(me.captchaId); 860 } 861 862 if( clickedButton == 'close' ){ 863 me.destroyCurrentPopUp(); 864 me.showConfirmation( null, function(){} ); 865 }else{ 866 $.ajax({ 867 url: SS.utils.Router.url({ 868 plugin: 'Users', 869 controller: 'Users', 870 action: 'register' 871 }), 872 cache: false, 873 type: 'POST', 874 data: { 875 'User[password]': password, 876 'User[password_repeat]': repeatPassword, 877 'g-recaptcha-response': captchaResponse 878 }, 879 dataType : 'json', 880 abortOnRetry: false, 881 error : function(jqXHR, textStatus, errorThrown){ 882 me.displayPopUpErrors({ 883 noField: [ 884 'Something went wrong. Please try again.' 885 ] 886 }); 887 }, 888 success : function(responseData, textStatus, jqXHR){ 889 if( responseData.success ){ 890 me.showConfirmation( null, null ); 891 }else{ 892 me.displayPopUpErrors(responseData.errors); 893 } 894 }, 895 complete: function() { 896 if (me.captchaId !== null) { 897 grecaptcha.reset(me.captchaId) 898 } 899 } 900 }); 901 } 902 }, 903 904 /** 905 * Toggle add to interest list triggers 906 * 907 * @param {number} contentItemId 908 */ 909 markItemAsAddedToInterestList: function( contentItemId ) 910 { 911 var addToBtn = $('.interest-list .add-to-interest-list[contentItemId="' + contentItemId + '"]'); 912 var addedToBtn = $('.interest-list .added-to-interest-list[contentItemId="' + contentItemId + '"]'); 913 var buttonsWrapper = addToBtn.parent('.interest-list'); 914 915 if( buttonsWrapper.hasClass('not-added') ){ 916 buttonsWrapper.fadeOut(150,function(){ 917 buttonsWrapper.removeClass('not-added').addClass('added').fadeIn(150); 918 }); 919 }else{ 920 buttonsWrapper.fadeOut(150,function(){ 921 buttonsWrapper.removeClass('added').addClass('not-added').fadeIn(150); 922 }); 923 } 924 }, 925 926 /** 927 * Remove all the past pop up errors and display the new ones if there are any 928 * @param {object} errors 929 */ 930 displayPopUpErrors: function( errors ) 931 { 932 var me = this; 933 var popUp = $('.customAlert'); 934 var popUpErrors = popUp.find('.customAlertError'); 935 var errorText = ''; 936 var formIsValid = true; 937 938 popUp.find('input, textarea, select').removeClass('invalid'); 939 940 popUpErrors.slideUp(100,function(){ 941 popUpErrors.html(''); 942 if(typeof errors == 'object'){ 943 $.each(errors,function( fieldName, errorMessage ){ 944 if( fieldName ){ 945 popUp.find('input[name="' + fieldName + '"]').addClass('invalid'); 946 popUp.find('select[name="' + fieldName + '"]').addClass('invalid'); 947 popUp.find('textarea[name="' + fieldName + '"]').addClass('invalid'); 948 } 949 if( $.type(errorMessage) == 'array' ){ 950 errorText += errorMessage[0] + '<br/>'; 951 }else if( $.type(errorMessage) == 'string' ){ 952 errorText += errorMessage + '<br/>'; 953 } 954 }); 955 popUpErrors.html(errorText).slideDown(150); 956 formIsValid = false;
957 } 958 }); 959 return formIsValid; 960 }, 961 962 /** 963 * Check if any popup is opened and distroy it 964 */ 965 destroyCurrentPopUp: function() 966 { 967 if( this.currentPopUp ){ 968 this.currentPopUp.destroyAlert(); 969 this.currentPopUp = false; 970 } 971 }, 972 973 /** 974 * Show a massage if the current person already has an application for this job 975 * @param trigger 976 */ 977 alreadyApplied: function( trigger ) 978 { 979 this.destroyCurrentPopUp(); 980 981 var alertConfig = { 982 title: 'Already applied', 983 msg: 'You already have applied for this opportunity!', 984 cls: 'motion-popup already-applied-to-opportunity' 985 }; 986 this.currentPopUp = new SS.customAlert(alertConfig); 987 } 988 989};
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.