Advertisement
Guest User

mainjs

a guest
May 16th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  // JavaScript Document
  2.  
  3. var buildON = {};
  4. (function ($) {
  5.     "use strict";
  6.  
  7.     $('.englishBtn').click(function () {
  8.         $.cookie("BuildONPreferredCultureSet", "en", { expires: 365, path: '/' });
  9.     });
  10.  
  11.     $('.frenchBtn').click(function () {
  12.         $.cookie("BuildONPreferredCultureSet", "fr", { expires: 365, path: '/' });
  13.     });
  14.  
  15.     $('.popup-modal-removeEducationHistory').magnificPopup();
  16.     $('.popup-modal-removeWorkHistory').magnificPopup();
  17.  
  18.  
  19.     // site current culture
  20.     var lang = "en-CA";
  21.     ($('#lng') != null && $('#lng').val() != "") ? lang = $('#lng').val() : "en-CA";
  22.  
  23.     // empty GUID
  24.     var emptyGuid = "00000000-0000-0000-0000-000000000000";
  25.  
  26.     buildON.options = {
  27.         mobileWidth: 768
  28.     };
  29.  
  30.     //until funcitons
  31.     function FindItemByKey(key, arrayData) {
  32.         var findItem = $.grep(arrayData, function (e) {
  33.             return e.Key == key;
  34.         });
  35.         return findItem;
  36.     }
  37.     /*function FindItemByGuid(guid, arrayData) {
  38.         if (guid != "" && guid != undefined){
  39.             var result = $.grep(arrayData, function (e) { return e.ItemGuid == guid; });
  40.             if (result.length > 0) {
  41.                 return result[0].Name;
  42.             }
  43.         }
  44.         return guid;
  45.     }*/
  46.  
  47.     function FindItemByGuid(guid, arrayData) {
  48.         var stringName = "";
  49.  
  50.         if (guid != "" && guid != undefined) {
  51.             if (typeof (guid) == "object") {
  52.                 var arrGuid = guid;
  53.                 for (var i = 0; i < arrGuid.length; i++) {
  54.                     var result = $.grep(arrayData, function (e) { return e.ItemGuid == arrGuid[i]; });
  55.                     if (result.length > 0) {
  56.                         if (stringName === "") {
  57.                             stringName += result[0].Name;
  58.                         } else {
  59.                             stringName += ", " + result[0].Name;
  60.                         }
  61.                     }
  62.                 }
  63.                 return stringName;
  64.             }
  65.  
  66.             if (typeof (guid) == "string") {
  67.                 var result = $.grep(arrayData, function (e) { return e.ItemGuid == guid; });
  68.                 if (result.length > 0) {
  69.                     return result[0].Name;
  70.                 } else {
  71.                     return guid;
  72.                 }
  73.             }
  74.             return guid;
  75.         }
  76.  
  77.         return stringName;
  78.     }
  79.  
  80.  
  81.     // ADOBE ACCESSIBLE MEGA MENU
  82.     var isAccessibleFlag = false;
  83.     buildON.accessibleNav = function () {
  84.         if ($(window).width() > buildON.options.mobileWidth && !isAccessibleFlag) {
  85.             /**
  86.             * Wrap accessibleMegaMenu() in window.width()
  87.             * Bug fix for screens that load less than mobileWidth. Since the nav is display:none on load the JS fires and does not init properly.
  88.             * If user resizes screen the nav is borked.
  89.             */
  90.  
  91.             // initialize the megamenu
  92.             $('.pri-nav nav').accessibleMegaMenu();
  93.  
  94.             $('.pri-nav.desktop .search.nav-item a').click(function (e) {
  95.                 e.preventDefault();
  96.                 $('.pri-nav.desktop .search.nav-item').toggleClass('expanded');
  97.             });
  98.  
  99.             // right-align last nav item that isn't search or donate
  100.             $('.pri-nav.desktop ul.nav-menu > li').slice(-3).addClass('last-items');
  101.  
  102.             // hack so that the megamenu doesn't show flash of css animation after the page loads.
  103.             setTimeout(function () {
  104.                 $('body').removeClass('init');
  105.             }, 500);
  106.             isAccessibleFlag = true;
  107.  
  108.             // hack for tablets
  109.             if ($("html").hasClass("mod-touch")) {
  110.                 $(".desktop .accessible-megamenu-top-nav-item").not($(".search")).each(function () {
  111.                     var link = $(this).find("> a[aria-haspopup='true']");
  112.                     if (link.length) {
  113.                         // get page language
  114.                         var lang = $('html')[0].lang;
  115.                         var overviewText = " Overview";
  116.                         // To do: get french translation for "overview"
  117.                         /*
  118.                         if (lang == "fr") {
  119.                           overviewText = "french overview";
  120.                         }
  121.                         */
  122.                         $(link).clone().prependTo($(this).find("ul")).wrap("<li></li>").append(overviewText);
  123.                     }
  124.                 });
  125.             }
  126.  
  127.  
  128.  
  129.  
  130.             /** hide search on click outside of search box
  131.              * http://benalman.com/code/projects/jquery-outside-events/examples/clickoutside/
  132.              */
  133.  
  134.             // elements on which to bind the event
  135.             var elems = $(".pri-nav.desktop .search.nav-item");
  136.  
  137.             // Clear any previous highlights
  138.             $(document)
  139.               .bind('click', function (event) {
  140.                   elems
  141.                     //.removeClass( 'event-outside' )
  142.                     .children('a');
  143.               })
  144.               .trigger('click');
  145.  
  146.             // Bind the 'clickoutside' event to each test element
  147.             elems.bind('clickoutside', function (event) {
  148.                 var elem = $(this),
  149.                 target = $(event.target);
  150.  
  151.                 // Highlight this element
  152.                 elem
  153.                   //.addClass( 'event-outside' )
  154.                   .removeClass('expanded')
  155.                   .children('a');
  156.             });
  157.  
  158.         }
  159.     };
  160.     buildON.accessibleNav();
  161.  
  162.     // TABS
  163.     buildON.tabs = function () {
  164.         $('ul.tabs li').click(function () {
  165.             var tab_id = $(this).attr('data-tab');
  166.             $('ul.tabs li').removeClass('current');
  167.             $('.tab-content').removeClass('current');
  168.             $(this).addClass('current');
  169.             $("#" + tab_id).addClass('current');
  170.             $('ul.tabs').removeClass('open');
  171.         });
  172.  
  173.         // My dashboard nav dropdown on header change button colour
  174.         $('.dashboard-nav').hover(function () {
  175.             $('ul.dashboard-nav-menu').toggleClass('open');
  176.             $('.dashboard-nav .btn').toggleClass('dashboard-nav-btn-reverse');
  177.         });
  178.  
  179.         // Click on my workshops, profile, education etc.
  180.         $('.dashboard-nav-menu li a').click(function () {
  181.  
  182.             if ((this).href.indexOf('#t1') > -1) {
  183.                 //e.preventDefault();
  184.                 var tab_id = $('ul.tabs li').attr('data-tab');
  185.                 $('.tab-content').removeClass('current');
  186.                 $('.tab-link').removeClass('current');
  187.                 $('#t1').addClass('current');
  188.                 $('#navChecklist').addClass('current');
  189.                 $('html,body').animate({ scrollTop: 0 }, 100);
  190.             }
  191.  
  192.             if ((this).href.indexOf('#t2') > -1) {
  193.                 //e.preventDefault();
  194.                 var tab_id = $('ul.tabs li').attr('data-tab');
  195.                 $('.tab-content').removeClass('current');
  196.                 $('.tab-link').removeClass('current');
  197.                 $('#t2').addClass('current');
  198.                 $('#navProfile').addClass('current');
  199.                 $('html,body').animate({ scrollTop: 0 }, 100);
  200.             }
  201.  
  202.             if ((this).href.indexOf('#t3') > -1) {
  203.                 //e.preventDefault();
  204.                 var tab_id = $('ul.tabs li').attr('data-tab');
  205.                 $('.tab-content').removeClass('current');
  206.                 $('.tab-link').removeClass('current');
  207.                 $('#t3').addClass('current');
  208.                 $('#navEmploymentHistory').addClass('current');
  209.                 $('html,body').animate({ scrollTop: 0 }, 100);
  210.             }
  211.  
  212.             if ((this).href.indexOf('#t4') > -1) {
  213.                 //e.preventDefault();
  214.                 var tab_id = $('ul.tabs li').attr('data-tab');
  215.                 $('.tab-content').removeClass('current');
  216.                 $('.tab-link').removeClass('current');
  217.                 $('#t4').addClass('current');
  218.                 $('#navEducation').addClass('current');
  219.                 $('html,body').animate({ scrollTop: 0 }, 100);
  220.             }
  221.  
  222.             if ((this).href.indexOf('#t5') > -1) {
  223.                 //e.preventDefault();
  224.                 var tab_id = $('ul.tabs li').attr('data-tab');
  225.                 $('.tab-content').removeClass('current');
  226.                 $('.tab-link').removeClass('current');
  227.                 $('#t5').addClass('current');
  228.                 $('#navAchievements').addClass('current');
  229.                 $('html,body').animate({ scrollTop: 0 }, 100);
  230.             }
  231.  
  232.  
  233.         });
  234.  
  235.  
  236.  
  237.  
  238.     };
  239.     buildON.tabs();
  240.  
  241.     // tabs dropdown on mobile
  242.     buildON.tabsMobileDD = function () {
  243.         $('.tabs-mobile').click(function (e) {
  244.             e.preventDefault();
  245.             $('ul.tabs').toggleClass('open');
  246.         });
  247.     };
  248.     buildON.tabsMobileDD();
  249.  
  250.     // EQUAL HEIGHTS - MATCH HEIGHT PLUGIN
  251.     buildON.equalHeights = function () {
  252.         $(".row .cta").matchHeight();
  253.         $(".col.border-left").matchHeight();
  254.         $(".workshop-tile").matchHeight();
  255.  
  256.         // set min heights for col-match columns so accordion content doesn't get hidden
  257.         if (matchMedia('only screen and (min-width: 992px)').matches) {
  258.             var mainColHeight = $(".col-match.main-col").height();
  259.             var sideColHeight = $(".col-match.side-col").height();
  260.             $(".col-match.side-col .inner").css("min-height", mainColHeight);
  261.             $(".col-match.main-col").css("min-height", sideColHeight);
  262.         }
  263.  
  264.     };
  265.     buildON.equalHeights();
  266.  
  267.  
  268.     // TRUNCATE
  269.     buildON.truncate = function () {
  270.         $('.workshop-title').dotdotdot({
  271.             ellipsis: '...',
  272.             watch: true,
  273.             height: 35
  274.         });
  275.         $('.workshop-description').dotdotdot({
  276.             ellipsis: '...',
  277.             watch: true,
  278.             height: 100
  279.         });
  280.     };
  281.     buildON.truncate();
  282.  
  283.  
  284.     // MOBILE NAV
  285.     buildON.mobileNav = function () {
  286.         var siteWrap = ".site-wrap",
  287.             siteWrapHeight = $(siteWrap).outerHeight(),
  288.             nav = ".pri-nav",
  289.             navMobile = nav + '.mobile',
  290.             navDesktop = nav + '.desktop',
  291.             navMobileContainer = "#mobile-nav-container",
  292.             navMobileToggle = "#mobile-nav-toggle",
  293.             navMobileLength = $(navMobile).length,
  294.             navMobileLastItem = navMobile + ' li:last-child a';
  295.  
  296.         var openMobileNav = function () {
  297.             $('body').addClass('mobile-nav-open');
  298.         },
  299.           closeMobileNav = function () {
  300.               $('body').removeClass('mobile-nav-open');
  301.           },
  302.           toggleMobileNav = function () {
  303.               if (!$('body').hasClass('mobile-nav-open')) {
  304.                   openMobileNav();
  305.               } else {
  306.                   closeMobileNav();
  307.               }
  308.           };
  309.         $(navMobileToggle).click(function (e) {
  310.             e.preventDefault();
  311.             // show/hide the nav
  312.             toggleMobileNav();
  313.         });
  314.  
  315.         // close mobile nav on click outside the nav
  316.         $(siteWrap).click(function () {
  317.             if ($('body').hasClass('mobile-nav-open')) {
  318.                 //closeMobileNav();
  319.             }
  320.         });
  321.  
  322.         // close nav when last nav item loses focus
  323.         $(navMobileLastItem).focusout(function () {
  324.             closeMobileNav();
  325.         });
  326.  
  327.         // set nav height to viewport height
  328.         // and recalculate on orientation change.
  329.         $(navMobile).css('height', $(window).innerHeight());
  330.         window.addEventListener("orientationchange", function () {
  331.             $(navMobile).css('height', $(window).innerHeight());
  332.         }, false);
  333.  
  334.         // fix bug introduced by twitter feed widget
  335.         $('#twttrHubFrame').attr('tabindex', '-1');
  336.  
  337.     };
  338.     buildON.mobileNav();
  339.  
  340.  
  341.     // MOBILE SECONDARY NAV
  342.     buildON.mobileSecNav = function () {
  343.         $(".sec-nav-toggle").click(function (e) {
  344.             e.preventDefault();
  345.             $(".secondary-nav").toggleClass("open");
  346.         });
  347.  
  348.         $(".sec-nav-content-toggle").click(function (e) {
  349.             e.preventDefault();
  350.             $("#contet-page-nav").toggleClass("open");
  351.         });
  352.     };
  353.     buildON.mobileSecNav();
  354.  
  355.  
  356.     // DESKTOP SECONDARY NAV
  357.     buildON.secNav = function () {
  358.         $('.secondary-nav').find('ul').parent().addClass('has-children');
  359.     };
  360.     buildON.secNav();
  361.  
  362.  
  363.     // HELPERS
  364.  
  365.     /** for each element that is classed as 'pull-down',
  366.      *  set its margin-top to the difference between its own height
  367.      *  and the height of its parent
  368.      */
  369.     buildON.pullDown = function () {
  370.         $('.pull-down').each(function () {
  371.             $(this).css('margin-top', $(this).parent().height() - $(this).height());
  372.         });
  373.     };
  374.     buildON.pullDown();
  375.  
  376.     // IFRAME Z-INDEX FIX
  377.     buildON.fixIframeZindex = function () {
  378.         $("iframe").each(function () {
  379.             var ifr_source = $(this).attr('src');
  380.             if (typeof ifr_source !== "undefined") {
  381.                 var wmode = "wmode=transparent";
  382.                 if (ifr_source.indexOf('?') != -1) $(this).attr('src', ifr_source + '&' + wmode);
  383.                 else $(this).attr('src', ifr_source + '?' + wmode);
  384.             }
  385.         });
  386.     };
  387.  
  388.     //Magnific Popup Modal
  389.     buildON.magnificPopup = function () {
  390.         // uci# tooltip modal
  391.         $('.popup-modal-uci').magnificPopup();
  392.         // step2 not qualified modal
  393.         //$('#popup-modal-notQualified').magnificPopup();
  394.         // remove education history modal
  395.         //$('.popup-modal-removeEducationHistory').magnificPopup();
  396.         // remove work history modal
  397.         //$('.popup-modal-removeWorkHistory').magnificPopup();
  398.  
  399.         $(document).on('click', '.popup-modal-dismiss', function (e) {
  400.             $.magnificPopup.close();
  401.         });
  402.     };
  403.     buildON.magnificPopup();
  404.  
  405.     // Registration form
  406.     buildON.registrationForm = function () {
  407.  
  408.         //Education Info Constructor
  409.         function EducationInfo() {
  410.             this.educationLevel = ko.observable();
  411.             this.schoolName = ko.observable();
  412.             this.completed = ko.observable();
  413.             this.startDate = ko.observable();
  414.             this.endDate = ko.observable();
  415.         };
  416.  
  417.         function LangTesting() {
  418.             this.langTest1 = ko.observable();
  419.             this.langTest2 = ko.observable();
  420.             this.langTest3 = ko.observable();
  421.         };
  422.  
  423.         function WorkTesting() {
  424.             var self = this;
  425.  
  426.             self.jobOffer = ko.observable();
  427.             self.collegeOfTrades = ko.observable();
  428.             self.canadaApprenticeProcess = ko.observable();
  429.  
  430.             self.choice1 = ko.observable();
  431.             self.choice2 = ko.observable();
  432.             self.choice3 = ko.observable();
  433.             self.choice4 = ko.observable();
  434.         };
  435.  
  436.         //Work Info Constructor
  437.         function WorkInfo() {
  438.             this.workTitle = ko.observable();
  439.             this.workName = ko.observable();
  440.             this.typeOfWork = ko.observableArray([]);
  441.             this.yearsExp = ko.observable();
  442.             this.countryOfEmployment = ko.observable();
  443.             this.lastYearWorkedInField = ko.observable();
  444.         };
  445.  
  446.         //User Meta data constructor
  447.         function Meta() {
  448.             this.culture = ko.observable('en-CA');
  449.             this.displayStep1 = ko.observable(true);
  450.             this.displayStep2 = ko.observable(false);
  451.             this.displayStep3 = ko.observable(false);
  452.             this.displayStep4 = ko.observable(false);
  453.             this.displayStep5 = ko.observable(false);
  454.             this.displayStep6 = ko.observable(false);
  455.         }
  456.  
  457.         //User Constructor
  458.         function User() {
  459.             this.firstName = ko.observable();
  460.             this.lastName = ko.observable();
  461.             this.email = ko.observable();
  462.             this.skype = ko.observable();
  463.             this.birthday = ko.observable();
  464.             this.preferredLanguage = ko.observable();
  465.             this.tradeInterest = ko.observable();
  466.             this.consentRegistration = ko.observable();
  467.             this.approvedImmigrate = ko.observable();
  468.             this.originCountry = ko.observable();
  469.             this.originCountryOther = ko.observable();
  470.             this.immigrateOntario = ko.observable();
  471.             this.livingOutsideCanada = ko.observable();
  472.             this.tradesKnowledge = ko.observable();
  473.             this.referral = ko.observable();
  474.             this.username = ko.observable();
  475.             this.password = ko.observable();
  476.             this.uciNumber = ko.observable();
  477.             this.gender = ko.observable();
  478.             this.immigrationStatus = ko.observable();
  479.             self.immigrationClass = ko.observable();
  480.             this.consentResearch = ko.observable();
  481.             this.driversLicense = ko.observable();
  482.             self.preferredName = ko.observable('--');
  483.             self.maritalStatus = ko.observable('--');
  484.             self.motherTongue = ko.observable('--');
  485.             self.otherLang = ko.observable('--');
  486.             self.preferredDestination = ko.observable('--');
  487.             self.englishLanguageLevel = ko.observable('--');
  488.             self.frenchLanguageLevel = ko.observable('--');
  489.             self.specialCircumstances = ko.observable('--');
  490.  
  491.             this.workHistory = ko.observableArray([]);
  492.             this.educationHistory = ko.observableArray([]);
  493.  
  494.             this.id = ko.observable(null);
  495.             this.guid = ko.observable('guid');
  496.  
  497.             this.englishTesting = ko.observable({});
  498.             this.frenchTesting = ko.observable({});
  499.             this.workTesting = ko.observable(new WorkTesting());
  500.  
  501.         };
  502.  
  503.         //Main Knockout View Model
  504.         var AppViewModel = function () {
  505.             var self = this;
  506.             self.mEnglishSkills = ko.observableArray([]);
  507.             self.mFrenchSkills = ko.observableArray([]);
  508.             //Custom table Lookup Data init
  509.             self.tradesLookup = ko.observableArray([]);
  510.             self.countriesLookup = ko.observableArray([]);
  511.             self.educationLookup = ko.observableArray([]);
  512.             self.englishSkillsLookup = ko.observableArray([]);
  513.             self.frenchSkillsLookup = ko.observableArray([]);
  514.             self.immigrationStatusLookup = ko.observableArray([]);
  515.             self.servicesLookup = ko.observableArray([]);
  516.             self.yearsOfExperienceLookup = ko.observableArray([]);
  517.             self.typeOfWorkLookup = ko.observableArray([]);
  518.             self.familiarLevelLookup = ko.observableArray([]);
  519.             self.preferLangLookup = ko.observableArray([]);
  520.             self.genderLookup = ko.observableArray([]);
  521.             self.reasonsLookup = ko.observableArray([]);
  522.  
  523.             $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
  524.                 if (data.Result != null) {
  525.                     var tradeItem = FindItemByKey("BuildON.Trades", data.Result);
  526.                     if (tradeItem != undefined && tradeItem != null) {
  527.                         self.tradesLookup(tradeItem[0].Data);
  528.                     }
  529.  
  530.                     var countryItem = FindItemByKey("BuildON.OriginCountry", data.Result);
  531.                     if (countryItem != undefined && countryItem != null) {
  532.                         self.countriesLookup(countryItem[0].Data);
  533.                     }
  534.  
  535.                     var educationItem = FindItemByKey("BuildON.EducationLevel", data.Result);
  536.                     if (educationItem != undefined && educationItem != null) {
  537.                         self.educationLookup(educationItem[0].Data);
  538.                     }
  539.  
  540.                     var englishItem = FindItemByKey("BuildON.EnglishSkills", data.Result);
  541.                     if (englishItem != undefined && englishItem != null) {
  542.                         self.englishSkillsLookup(englishItem[0].Data);
  543.                     }
  544.  
  545.                     var frenchItem = FindItemByKey("BuildON.FrenchSkills", data.Result);
  546.                     if (frenchItem != undefined && frenchItem != null) {
  547.                         self.frenchSkillsLookup(frenchItem[0].Data);
  548.                     }
  549.  
  550.                     var statusItem = FindItemByKey("BuildON.ImmigrationStatus", data.Result);
  551.                     if (statusItem != undefined && statusItem != null) {
  552.                         self.immigrationStatusLookup(statusItem[0].Data);
  553.                     }
  554.  
  555.                     var servicesItem = FindItemByKey("BuildON.Services", data.Result);
  556.                     if (servicesItem != undefined && servicesItem != null) {
  557.                         self.servicesLookup(servicesItem[0].Data);
  558.                     }
  559.  
  560.                     var yearsItem = FindItemByKey("BuildON.YearsOfExperience", data.Result);
  561.                     if (yearsItem != undefined && yearsItem != null) {
  562.                         self.yearsOfExperienceLookup(yearsItem[0].Data);
  563.                     }
  564.  
  565.                     var typeOfWorkItem = FindItemByKey("BuildON.TypeOfWork", data.Result);
  566.                     if (typeOfWorkItem != undefined && typeOfWorkItem != null) {
  567.                         self.typeOfWorkLookup(typeOfWorkItem[0].Data);
  568.                     }
  569.  
  570.                     var familiarLevelItem = FindItemByKey("BuildON.FamiliarLevel", data.Result);
  571.                     if (familiarLevelItem != undefined && familiarLevelItem != null) {
  572.                         self.familiarLevelLookup(familiarLevelItem[0].Data);
  573.                     }
  574.  
  575.                     var preferLangItem = FindItemByKey("BuildON.PreferredLanguage", data.Result);
  576.                     if (preferLangItem != undefined && preferLangItem != null) {
  577.                         self.preferLangLookup(preferLangItem[0].Data);
  578.                     }
  579.  
  580.                     var genderItem = FindItemByKey("BuildON.Gender", data.Result);
  581.                     if (genderItem != undefined && genderItem != null) {
  582.                         self.genderLookup(genderItem[0].Data);
  583.                     }
  584.  
  585.                     var reasonsItem = FindItemByKey("BuildON.ReasonsNotQualifying", data.Result);
  586.                     if (reasonsItem != undefined && reasonsItem != null) {
  587.                         self.reasonsLookup(reasonsItem[0].Data);
  588.                     }
  589.                 }
  590.             });
  591.  
  592.  
  593.             //Push original objects to history arrays
  594.             self.user = ko.observable(new User());
  595.             self.meta = ko.observable(new Meta());
  596.  
  597.             self.addEducationHistory = function () {
  598.                 self.user().educationHistory.push(new EducationInfo());
  599.  
  600.                 var numItems = $('.radioGroup').length * 2;
  601.                 var newAttr1 = 'completeRadio' + (numItems - 1);
  602.                 var newAttr2 = 'completeRadio' + (numItems);
  603.                 var newName = 'completedSchool' + newAttr2;
  604.  
  605.                 $('.radioGroup').last().find('label[for=completeRadio1]').attr('for', newAttr1);
  606.                 $('.radioGroup').last().find('label[for=completeRadio2]').attr('for', newAttr2);
  607.  
  608.                 $('.radioGroup').last().find('input[id=completeRadio1]').attr('id', newAttr1);
  609.                 $('.radioGroup').last().find('input[id=completeRadio2]').attr('id', newAttr2);
  610.                 $('.radioGroup').last().find('input').attr('name', newName);
  611.  
  612.                 // custom select styles
  613.                 $('.select-item select').customSelect();
  614.                 $('.popup-modal-removeEducationHistory').magnificPopup();
  615.             };
  616.  
  617.             self.addWorkHistory = function () {
  618.                 self.user().workHistory.push(new WorkInfo());
  619.  
  620.                 var numItems = $('.checkboxGroup').length * 4;
  621.                 var newAttr1 = 'workCheckbox' + (numItems - 3);
  622.                 var newAttr2 = 'workCheckbox' + (numItems - 2);
  623.                 var newAttr3 = 'workCheckbox' + (numItems - 1);
  624.                 var newAttr4 = 'workCheckbox' + (numItems);
  625.  
  626.                 $('.checkboxGroup').last().find('label[for=workCheckbox0]').attr('for', newAttr1);
  627.                 $('.checkboxGroup').last().find('label[for=workCheckbox1]').attr('for', newAttr2);
  628.                 $('.checkboxGroup').last().find('label[for=workCheckbox2]').attr('for', newAttr3);
  629.                 $('.checkboxGroup').last().find('label[for=workCheckbox3]').attr('for', newAttr4);
  630.  
  631.                 $('.checkboxGroup').last().find('input[id=workCheckbox0]').attr('id', newAttr1);
  632.                 $('.checkboxGroup').last().find('input[id=workCheckbox1]').attr('id', newAttr2);
  633.                 $('.checkboxGroup').last().find('input[id=workCheckbox2]').attr('id', newAttr3);
  634.                 $('.checkboxGroup').last().find('input[id=workCheckbox3]').attr('id', newAttr4);
  635.  
  636.                 $('.checkboxGroup').last().find('input').attr('name', newAttr4);
  637.  
  638.                 // custom select styles
  639.                 $('.select-item select').customSelect();
  640.                 $('.popup-modal-removeWorkHistory').magnificPopup();
  641.             };
  642.  
  643.             self.removeEducationHistory = function () {
  644.                 var firstItem = self.user().educationHistory().length - 1;
  645.                 var lastItem = self.user().educationHistory().length - 1;
  646.                 var educationHist = self.user().educationHistory();
  647.  
  648.                 educationHist.splice(lastItem, 1);
  649.                 self.user().educationHistory(educationHist);
  650.  
  651.             };
  652.  
  653.             self.removeWorkHistory = function () {
  654.                 var firstItem = self.user().workHistory().length - 1;
  655.                 var lastItem = self.user().workHistory().length - 1;
  656.                 var workHist = self.user().workHistory();
  657.  
  658.                 workHist.splice(lastItem, 1);
  659.                 self.user().workHistory(workHist);
  660.             };
  661.  
  662.             self.skipEducation = function () {
  663.                 //Sets all the values from this step to undefined
  664.                 self.user().educationHistory([]);
  665.                 self.user().englishTesting({});
  666.                 self.user().frenchTesting({});
  667.                 self.user().driversLicense(undefined);
  668.  
  669.                 //Skips to step 6
  670.                 self.meta().displayStep5(false);
  671.                 self.meta().displayStep6(true);
  672.                 $('.warningText').hide();
  673.                 $('.step5').addClass('complete');
  674.                 $('.step6').addClass('active');
  675.             };
  676.  
  677.             self.skipWork = function () {
  678.                 //Sets all the values from this step to undefined
  679.                 self.user().workTesting().jobOffer(undefined);
  680.  
  681.                 self.user().workTesting().choice1(undefined);
  682.                 self.user().workTesting().choice2(undefined);
  683.                 self.user().workTesting().choice3(undefined);
  684.                 self.user().workTesting().choice4(undefined);
  685.                 self.user().workTesting().collegeOfTrades(undefined);
  686.                 self.user().workTesting().canadaApprenticeProcess(undefined);
  687.  
  688.                 var registrationData = ko.toJSON(self);
  689.  
  690.                 var settings = {
  691.                     "async": true,
  692.                     "crossDomain": true,
  693.                     "url": "/api/registration/save",
  694.                     "method": "POST",
  695.                     "headers": {
  696.                         "content-type": "application/json",
  697.                         "cache-control": "no-cache",
  698.                         "postman-token": "e278808a-783c-7ea2-fc88-1df5f5422b25"
  699.                     },
  700.                     "data": registrationData
  701.                 }
  702.  
  703.                 $.ajax(settings).done(function (response) {
  704.                     var errors = response.Result.errors;
  705.  
  706.                     if (errors.length > 0) {
  707.                         $('.warningText.errors').remove();
  708.                         $.map(errors, function (error) {
  709.                             var output = "<p class='warningText errors'><strong>" + error.message + "</strong></p>";
  710.                             $('.wizard-steps').after(output);
  711.                             $('.warningText.errors').show();
  712.                             $("html, body").scrollTop(0);
  713.                         });
  714.                     } else {
  715.                         self.user().workHistory([]);
  716.                         document.location.href = $('#hideSuccessPageUrl').val();
  717.                     }
  718.  
  719.                 });
  720.             };
  721.  
  722.             // check year has to be 4 digits and between 1950 and current year
  723.             self.checkLastYearWorkedInField = function (input) {
  724.                 var reg = /^\d{4}$/;
  725.                 if (!reg.test(input)) {
  726.                     return false;
  727.                 }
  728.  
  729.                 var year = Number(input);
  730.                 if (year >= 1950 && year <= currentYear) {
  731.                     return true;
  732.                 } else {
  733.                     return false;
  734.                 }
  735.             }
  736.  
  737.             self.checkDate = function (date) {
  738.                 var reg =
  739.                 /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/g;
  740.                 if (reg.test(date)) {
  741.                     return true;
  742.                 } else {
  743.                     return false;
  744.                 }
  745.             }
  746.  
  747.             self.checkEmail = function (email) {
  748.                 var reg = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
  749.                 if (reg.test(email)) {
  750.                     return true;
  751.                 } else {
  752.                     return false;
  753.                 }
  754.             }
  755.  
  756.             self.checkUci = function (uci) {
  757.                 var reg = /^\d{4}\-\d{4}$/;
  758.  
  759.                 if (reg.test(uci)) {
  760.                     return true;
  761.                 } else {
  762.                     return false;
  763.                 }
  764.             };
  765.  
  766.  
  767.             self.checkStep1 = function () {
  768.  
  769.                 for (var enProp in self.englishSkillsLookup()) {
  770.                     var lookUpGuid = self.englishSkillsLookup()[enProp]["ItemGuid"];
  771.                     // see if lookUpGuid is in
  772.                     self.user().englishTesting()[lookUpGuid] = false;
  773.                 }
  774.  
  775.                 for (var frProp in self.frenchSkillsLookup()) {
  776.                     var lookUpGuid = self.frenchSkillsLookup()[frProp]["ItemGuid"];
  777.                     // see if lookUpGuid is in
  778.                     self.user().frenchTesting()[lookUpGuid] = false;
  779.                 }
  780.  
  781.                 if (self.user().consentRegistration() == true) {
  782.                     $('.warningTextconsentRegistration').hide();
  783.                 } else {
  784.                     $('.warningTextconsentRegistration').show();
  785.                 }
  786.  
  787.                 if (self.user().tradeInterest() == '' || self.user().tradeInterest() == undefined) {
  788.                     $('.warningTexttradeInterest').show();
  789.                 } else {
  790.                     $('.warningTexttradeInterest').hide();
  791.                 }
  792.  
  793.                 if (captchaValid === false) {
  794.                     $('.warningTextRecaptcha').show();
  795.                 } else {
  796.                     $('.warningTextRecaptcha').hide();
  797.                 }
  798.  
  799.                 if (self.user().consentRegistration() == true && self.user().tradeInterest() !== '' && self.user().tradeInterest() !== undefined && captchaValid) {
  800.                     self.meta().displayStep1(false);
  801.                     self.meta().displayStep2(true);
  802.  
  803.                     $('.warningText').hide();
  804.                     // set wizard step class
  805.                     $('.step1').removeClass('active');
  806.                     $('.step1').addClass('complete');
  807.                     $('.step2').addClass('active');
  808.                     $('#popup-modal-notQualified').magnificPopup();
  809.                     $("html, body").scrollTop(0);
  810.  
  811.                 }
  812.             }
  813.  
  814.             self.checkStep2 = function () {
  815.                 var errors = [];
  816.  
  817.                 //Pushing specific errors based on the users answers
  818.                 //Sorry for how verbose this is...
  819.                 if (self.user().approvedImmigrate() == 'false' || self.user().approvedImmigrate() == false) {
  820.                     errors.push(self.reasonsLookup()[0].ItemGuid);
  821.                 } else if (self.user().approvedImmigrate() === undefined) {
  822.                     $('.warningTextapprovedImmigrate').show();
  823.                 } else {
  824.                     $('.warningTextapprovedImmigrate').hide();
  825.                 }
  826.  
  827.                 if (self.user().immigrateOntario() == 'false' || self.user().immigrateOntario() == false) {
  828.                     errors.push(self.reasonsLookup()[2].ItemGuid);
  829.                 } else if (self.user().immigrateOntario() === undefined) {
  830.                     $('.warningTextimmigrateOntario').show();
  831.                 } else {
  832.                     $('.warningTextimmigrateOntario').hide();
  833.                 }
  834.  
  835.                 if (self.user().livingOutsideCanada() === undefined) {
  836.                     $('.warningTextlivingOutsideCanada').show();
  837.                 } else {
  838.                     $('.warningTextlivingOutsideCanada').hide();
  839.                 }
  840.  
  841.  
  842.                 //TO-DO: make this global variable?
  843.                 var otherCountry = 'f4a46169-f778-4140-80a9-0e671dd3ee60';
  844.  
  845.                 if (String(self.user().originCountry()) === otherCountry && self.user().originCountryOther() === undefined || self.user().originCountryOther() === "") {
  846.                     $('.warningTextoriginCountryOther').show();
  847.                 } else {
  848.                     $('.warningTextoriginCountryOther').hide();
  849.                 }
  850.  
  851.                 if (self.user().originCountry() === undefined || self.user().originCountry() === '') {
  852.                     $('.warningTextoriginCountry').show();
  853.                 } else {
  854.                     $('.warningTextoriginCountry').hide();
  855.                 }
  856.  
  857.                 //If all the users selections are acceptable, hide all the red warning text and move to the next step on the form
  858.                 if (self.user().approvedImmigrate() == 'true' && self.user().immigrateOntario() != undefined && self.user().originCountry() !== undefined && self.user().originCountry() !== otherCountry || self.user().originCountryOther() !== undefined) {
  859.                     self.meta().displayStep2(false);
  860.                     self.meta().displayStep3(true);
  861.                     $('.warningText').hide();
  862.                     $('.step2').removeClass('active');
  863.                     $('.step2').addClass('complete');
  864.                     $('.step3').addClass('active');
  865.                     //Scroll to top of page after changing steps
  866.                     $("html, body").scrollTop(0);
  867.                 }
  868.  
  869.                 //Log out all the errors for why they can't register for the program, if there are errors
  870.                 if (errors.length > 0) {
  871.                     //get Not Qualify url and appending the right reasons GUIDS in the query string.
  872.  
  873.                     var failUrl = $('#hrefReasonTop').attr('href');
  874.                     failUrl += "?reasons=" + errors.join();
  875.  
  876.                     $('#hrefReasonTop').attr('href', failUrl);
  877.                     $('#hrefReasonBtm').attr('href', failUrl);
  878.  
  879.                     $('#popup-modal-notQualified').attr('href', '#notQualified-modal');
  880.                 } else {
  881.                     $('#popup-modal-notQualified').attr('href', '');
  882.                 }
  883.             }
  884.  
  885.  
  886.             self.checkStep3 = function () {
  887.                 if (self.user().tradesKnowledge() === undefined) {
  888.                     $('.warningTexttradesKnowledge').show();
  889.                 } else { $('.warningTexttradesKnowledge').hide(); }
  890.  
  891.                 if (self.user().referral() === undefined || self.user().referral() === '') {
  892.                     $('.warningTextreferral').show();
  893.                 } else {
  894.                     $('.warningTextreferral').hide();
  895.                 }
  896.  
  897.                 //If all the users selections are acceptable, hide all the red warning text and move to the next step on the form
  898.                 if (self.user().tradesKnowledge() !== undefined && self.user().referral() !== undefined) {
  899.                     self.meta().displayStep3(false);
  900.                     self.meta().displayStep4(true);
  901.                     $('.warningText').hide();
  902.                     // set wizard step class
  903.                     $('.step3').removeClass('active');
  904.                     $('.step3').addClass('complete');
  905.                     $('.step4').addClass('active');
  906.  
  907.                     $("html, body").scrollTop(0);
  908.                 }
  909.             }
  910.  
  911.             self.checkStep4 = function () {
  912.                 //Displaying specific errors based on the users answers
  913.                 //Sorry for how verbose this is...
  914.  
  915.                 var pass = self.user().password();
  916.                 var reg = /^(?=.*(\W)).{6,20}$/i;
  917.  
  918.                 if (self.user().username() == undefined || self.user().username() == "") {
  919.                     $('.warningTextusername').show();
  920.                 } else { $('.warningTextusername').hide(); }
  921.  
  922.                 if (self.user().password() == undefined || self.user().password() == "" || reg.test(pass) == false) {
  923.                     $('.warningTextpassword').show();
  924.                 } else { $('.warningTextpassword').hide(); }
  925.  
  926.                 if (self.user().firstName() == undefined || self.user().firstName() == "") {
  927.                     $('.warningTextfirstName').show();
  928.                 } else { $('.warningTextfirstName').hide(); }
  929.  
  930.                 if (self.user().lastName() == undefined || self.user().lastName() == "") {
  931.                     $('.warningTextlastName').show();
  932.                 } else { $('.warningTextlastName').hide(); }
  933.  
  934.                 if (self.checkUci(self.user().uciNumber()) == false) {
  935.                     $('.warningTextuciNumber').show();
  936.                 } else { $('.warningTextuciNumber').hide(); }
  937.  
  938.                 if (self.user().gender() == undefined) {
  939.                     $('.warningTextgender').show();
  940.                 } else { $('.warningTextgender').hide(); }
  941.  
  942.                 if (self.user().preferredLanguage() == undefined) {
  943.                     $('.warningTextpreferredLanguage').show();
  944.                 } else { $('.warningTextpreferredLanguage').hide(); }
  945.  
  946.                 if (self.user().immigrationStatus() == undefined) {
  947.                     $('.warningTextimmigrationStatus').show();
  948.                 } else { $('.warningTextimmigrationStatus').hide(); }
  949.  
  950.                 if (self.user().consentResearch() == undefined || self.user().consentResearch() == false) {
  951.                     $('.warningTextconsentResearch').show();
  952.                 } else { $('.warningTextconsentResearch').hide(); }
  953.  
  954.                 if (self.checkDate(self.user().birthday()) == false) {
  955.                     $('.warningTextbirthday').show();
  956.                 } else { $('.warningTextbirthday').hide(); }
  957.  
  958.                 if (self.checkEmail(self.user().email()) == false) {
  959.                     $('.warningTextemail').show();
  960.                 } else { $('.warningTextemail').hide(); }
  961.  
  962.                 //If all the users selections are acceptable, hide all the red warning text and move to the next step on the form
  963.                 if (self.user().consentResearch() && self.user().immigrationStatus() && self.user().preferredLanguage() && self.user().gender() && self.checkUci(self.user().uciNumber()) == true && self.user().lastName() && self.user().firstName() && self.user().username() && reg.test(pass) == true && self.checkDate(self.user().birthday()) && self.checkEmail(self.user().email())) {
  964.                     self.meta().displayStep4(false);
  965.                     self.meta().displayStep5(true);
  966.                     $('.warningText').hide();
  967.                     // set wizard step class
  968.                     $('.step4').removeClass('active');
  969.                     $('.step4').addClass('complete');
  970.                     $('.step5').addClass('active');
  971.  
  972.                     $("html, body").scrollTop(0);
  973.                 } else {
  974.                     $("html, body").scrollTop(0);
  975.                 }
  976.  
  977.             }
  978.  
  979.             self.checkStep5 = function () {
  980.  
  981.                 for (var prop in self.user().englishTesting()) {
  982.                     if (self.mEnglishSkills().indexOf(prop) != -1) {
  983.                         self.user().englishTesting()[prop] = true;
  984.                     } else {
  985.                         self.user().englishTesting()[prop] = false;
  986.                     }
  987.                 }
  988.  
  989.                 for (var prop in self.user().frenchTesting()) {
  990.                     if (self.mFrenchSkills().indexOf(prop) != -1) {
  991.                         self.user().frenchTesting()[prop] = true;
  992.                     } else {
  993.                         self.user().frenchTesting()[prop] = false;
  994.                     }
  995.                 }
  996.  
  997.                 //RegEx for Start/Finished dates in the Education section (must fit MM/DD/YYYY format)
  998.                 var allEducationDates = document.querySelectorAll('.educationDates');
  999.                 var allStartDates = document.querySelectorAll('.startDates');
  1000.                 var allEndDates = document.querySelectorAll('.endDates');
  1001.  
  1002.                 if (self.user().educationHistory()[0].completed() === undefined) {
  1003.                     $('.warningTextCompleted').show();
  1004.                 } else {
  1005.                     $('.warningTextCompleted').hide();
  1006.                 }
  1007.  
  1008.                 if (self.user().educationHistory()[0].schoolName() === undefined) {
  1009.                     $('.warningTextinstitutionName').show();
  1010.                 } else {
  1011.                     $('.warningTextinstitutionName').hide();
  1012.                 }
  1013.  
  1014.                 if (self.user().educationHistory()[0].educationLevel() !== undefined && self.user().educationHistory()[0].educationLevel() !== "") {
  1015.                     var forwardStart = true;
  1016.                     var forwardEnd = true;
  1017.  
  1018.                     $.each(allStartDates, function (index, value) {
  1019.                         var currentVal = $(this).val();
  1020.                         var currentEle = $(this).context;
  1021.                         if (self.checkDate(currentVal)) {
  1022.                             $(currentEle).parent().next('.warningTextDate').hide();
  1023.                         } else {
  1024.                             forwardStart = false;
  1025.                             $(currentEle).parent().next('.warningTextDate').show();
  1026.                         }
  1027.                     });
  1028.  
  1029.                     $.each(allEndDates, function (index, value) {
  1030.                         var currentVal = $(this).val();
  1031.                         var currentEle = $(this).context;
  1032.                         if (self.checkDate(currentVal)) {
  1033.                             $(currentEle).parent().next('.warningTextDate').hide();
  1034.                         } else {
  1035.                             forwardEnd = false;
  1036.                             $(currentEle).parent().next('.warningTextDate').show();
  1037.                         }
  1038.                     });
  1039.  
  1040.                     if (forwardStart && forwardEnd) {
  1041.                         self.meta().displayStep5(false);
  1042.                         self.meta().displayStep6(true);
  1043.                         $('.warningText').hide();
  1044.  
  1045.                         $('.step5').removeClass('active');
  1046.                         $('.step5').addClass('complete');
  1047.                         $('.step6').addClass('active');
  1048.  
  1049.                         $("html, body").scrollTop(0);
  1050.                     }
  1051.  
  1052.                 } else {
  1053.                     //If all the users selections are acceptable, hide all the red warning text and move to the next step on the form
  1054.                     self.meta().displayStep5(false);
  1055.                     self.meta().displayStep6(true);
  1056.                     $('.warningText').hide();
  1057.  
  1058.                     $('.step5').removeClass('active');
  1059.                     $('.step5').addClass('complete');
  1060.                     $('.step6').addClass('active');
  1061.  
  1062.                     $("html, body").scrollTop(0);
  1063.                 }
  1064.             }
  1065.  
  1066.             self.checkStep6 = function () {
  1067.                 var allLastWorkedDates = document.querySelectorAll('.lastWorkedDates');
  1068.                 var yearErrors = [];
  1069.  
  1070.                 var registrationData = ko.toJSON(self);
  1071.  
  1072.                 $.each(allLastWorkedDates, function (index, value) {
  1073.                     var currentVal = $(this).val();
  1074.                     var currentEle = $(this).context;
  1075.  
  1076.                     if(currentVal != ""){
  1077.                         if (self.checkLastYearWorkedInField(currentVal)) {
  1078.                             $(currentEle).parent().next('.warningTextwhenLastWorkedInField').hide();
  1079.                         } else {
  1080.                             yearErrors.push('error');
  1081.                             $(currentEle).parent().next('.warningTextwhenLastWorkedInField').show();
  1082.                         }
  1083.                     }
  1084.  
  1085.                 });
  1086.  
  1087.                 if (yearErrors.length > 0) {
  1088.                     $('.warningText.errors').show();
  1089.                     $("html, body").scrollTop(0);
  1090.  
  1091.                 } else {
  1092.                     var settings = {
  1093.                         "async": true,
  1094.                         "crossDomain": true,
  1095.                         "url": "/api/registration/save",
  1096.                         "method": "POST",
  1097.                         "headers": {
  1098.                             "content-type": "application/json",
  1099.                             "cache-control": "no-cache",
  1100.                             "postman-token": "e278808a-783c-7ea2-fc88-1df5f5422b25"
  1101.                         },
  1102.                         "data": registrationData
  1103.                     }
  1104.  
  1105.                     $.ajax(settings).done(function (response) {
  1106.                         var errors = response.Result.errors;
  1107.  
  1108.                         if (errors.length > 0) {
  1109.                             $('.warningText.errors').remove();
  1110.                             $.map(errors, function (error) {
  1111.                                 var output = "<p class='warningText errors'><strong>" + error.message + "</strong></p>";
  1112.                                 $('.wizard-steps').after(output);
  1113.                                 $('.warningText.errors').show();
  1114.                                 $("html, body").scrollTop(0);
  1115.                             });
  1116.                         } else {
  1117.                             document.location.href = $('#hideSuccessPageUrl').val();
  1118.                         }
  1119.  
  1120.                     });
  1121.                 }
  1122.  
  1123.  
  1124.  
  1125.             }
  1126.  
  1127.             // Go back button
  1128.             // Check the HTML for each individual section on the form-it's visibility is controlled by changes to these states
  1129.  
  1130.             self.goBackStep1 = function () {
  1131.                 self.meta().displayStep2(false);
  1132.                 self.meta().displayStep1(true);
  1133.  
  1134.                 // set wizard step class
  1135.                 $('.step2').removeClass('active');
  1136.                 $('.step1').removeClass('complete');
  1137.                 $('.step1').addClass('active');
  1138.  
  1139.                 $("html, body").scrollTop(0);
  1140.             }
  1141.  
  1142.             self.goBackStep2 = function () {
  1143.                 self.meta().displayStep3(false);
  1144.                 self.meta().displayStep2(true);
  1145.  
  1146.                 // set wizard step class
  1147.                 $('.step3').removeClass('active');
  1148.                 $('.step2').removeClass('complete');
  1149.                 $('.step2').addClass('active');
  1150.  
  1151.                 $("html, body").scrollTop(0);
  1152.             }
  1153.  
  1154.             self.goBackStep3 = function () {
  1155.                 self.meta().displayStep4(false);
  1156.                 self.meta().displayStep3(true);
  1157.  
  1158.                 // set wizard step class
  1159.                 $('.step4').removeClass('active');
  1160.                 $('.step3').removeClass('complete');
  1161.                 $('.step3').addClass('active');
  1162.  
  1163.                 $("html, body").scrollTop(0);
  1164.             }
  1165.  
  1166.             self.goBackStep4 = function () {
  1167.                 self.meta().displayStep5(false);
  1168.                 self.meta().displayStep4(true);
  1169.  
  1170.                 // set wizard step class
  1171.                 $('.step5').removeClass('active');
  1172.                 $('.step4').removeClass('complete');
  1173.                 $('.step4').addClass('active');
  1174.  
  1175.                 $("html, body").scrollTop(0);
  1176.             }
  1177.  
  1178.             self.goBackStep5 = function () {
  1179.                 self.meta().displayStep6(false);
  1180.                 self.meta().displayStep5(true);
  1181.  
  1182.                 var educationLength = self.user().educationHistory().length;
  1183.  
  1184.                 if (educationLength == 0) {
  1185.                     self.user().educationHistory.push(new EducationInfo());
  1186.                 }
  1187.  
  1188.                 // set wizard step class
  1189.                 $('.step6').removeClass('active');
  1190.                 $('.step5').removeClass('complete');
  1191.                 $('.step5').addClass('active');
  1192.  
  1193.                 $("html, body").scrollTop(0);
  1194.             }
  1195.  
  1196.  
  1197.             //They click a div with class step
  1198.             $('.step').click(function () {
  1199.                 if ($(this).hasClass('complete')) {
  1200.                     //Save the current step they're on so you know how many steps to go back (check for class of active)
  1201.                     var currentStep = $('.active').attr('id');
  1202.                     var intendedStep = $(this).attr('id');
  1203.                     currentStep = 'display' + currentStep + '(false)';
  1204.                     intendedStep = 'display' + intendedStep + '(true)';
  1205.  
  1206.                     //Remove class of active and complete from all Steps that are higher than the intendedStep
  1207.                     switch (intendedStep) {
  1208.                         case 'displayStep1(true)':
  1209.                             self.goBackStep5();
  1210.                             self.goBackStep4();
  1211.                             self.goBackStep3();
  1212.                             self.goBackStep2();
  1213.                             self.goBackStep1();
  1214.                             break;
  1215.  
  1216.                         case 'displayStep2(true)':
  1217.                             self.goBackStep5();
  1218.                             self.goBackStep4();
  1219.                             self.goBackStep3();
  1220.                             self.goBackStep2();
  1221.                             break;
  1222.  
  1223.                         case 'displayStep3(true)':
  1224.                             self.goBackStep5();
  1225.                             self.goBackStep4();
  1226.                             self.goBackStep3();
  1227.                             break;
  1228.  
  1229.                         case 'displayStep4(true)':
  1230.                             self.goBackStep5();
  1231.                             self.goBackStep4();
  1232.                             break;
  1233.  
  1234.                         case 'displayStep5(true)':
  1235.                             self.goBackStep5();
  1236.                             break;
  1237.                     }
  1238.                 }
  1239.  
  1240.             });
  1241.  
  1242.  
  1243.             self.user().educationHistory.push(new EducationInfo());
  1244.             self.user().workHistory.push(new WorkInfo());
  1245.             $('.step1').addClass('active');
  1246.             $('.warningText').hide();
  1247.         };
  1248.         var viewModel = new AppViewModel();
  1249.         ko.applyBindings(viewModel, document.getElementById("registration-form"));
  1250.     };
  1251.     if ($('#registration-form').html() != undefined) {
  1252.         buildON.registrationForm();
  1253.     }
  1254.  
  1255.     //My Dashboard
  1256.     buildON.myDashboard = function () {
  1257.         // My Dashboard dropdown on header
  1258.         var url = window.location.href;
  1259.  
  1260.         if ((url).indexOf('#t1') > -1) {
  1261.             var tab_id = $('ul.tabs li').attr('data-tab');
  1262.             $('.tab-content').removeClass('current');
  1263.             $('.tab-link').removeClass('current');
  1264.             $('#t1').addClass('current');
  1265.             $('#navChecklist').addClass('current');
  1266.             $('html,body').animate({ scrollTop: 0 }, 100);
  1267.         }
  1268.  
  1269.         if ((url).indexOf('#t2') > -1) {
  1270.             var tab_id = $('ul.tabs li').attr('data-tab');
  1271.             $('.tab-content').removeClass('current');
  1272.             $('.tab-link').removeClass('current');
  1273.             $('#t2').addClass('current');
  1274.             $('#navProfile').addClass('current');
  1275.             $('html,body').animate({ scrollTop: 0 }, 100);
  1276.         }
  1277.  
  1278.         if ((url).indexOf('#t3') > -1) {
  1279.             var tab_id = $('ul.tabs li').attr('data-tab');
  1280.             $('.tab-content').removeClass('current');
  1281.             $('.tab-link').removeClass('current');
  1282.             $('#t3').addClass('current');
  1283.             $('#navEmploymentHistory').addClass('current');
  1284.             $('html,body').animate({ scrollTop: 0 }, 100);
  1285.         }
  1286.  
  1287.         if ((url).indexOf('#t4') > -1) {
  1288.             var tab_id = $('ul.tabs li').attr('data-tab');
  1289.             $('.tab-content').removeClass('current');
  1290.             $('.tab-link').removeClass('current');
  1291.             $('#t4').addClass('current');
  1292.             $('#navEducation').addClass('current');
  1293.             $('html,body').animate({ scrollTop: 0 }, 100);
  1294.         }
  1295.  
  1296.         if ((url).indexOf('#t5') > -1) {
  1297.             var tab_id = $('ul.tabs li').attr('data-tab');
  1298.             $('.tab-content').removeClass('current');
  1299.             $('.tab-link').removeClass('current');
  1300.             $('#t5').addClass('current');
  1301.             $('#navAchievements').addClass('current');
  1302.             $('html,body').animate({ scrollTop: 0 }, 100);
  1303.         }
  1304.  
  1305.  
  1306.  
  1307.         //Education Info Constructor
  1308.         function EducationInfo(level, name, complete, start, end) {
  1309.             var self = this;
  1310.  
  1311.             self.educationLevel = ko.observable(level);
  1312.             self.schoolName = ko.observable(name);
  1313.             self.completed = ko.observable(complete);
  1314.             self.startDate = ko.observable(start);
  1315.             self.endDate = ko.observable(end);
  1316.         };
  1317.  
  1318.         function LangTesting() {
  1319.             var self = this;
  1320.  
  1321.             self.langTest1 = ko.observable();
  1322.             self.langTest2 = ko.observable();
  1323.             self.langTest3 = ko.observable();
  1324.         };
  1325.  
  1326.         function WorkTesting() {
  1327.             var self = this;
  1328.  
  1329.             self.jobOffer = ko.observable();
  1330.             self.collegeOfTrades = ko.observable();
  1331.             self.canadaApprenticeProcess = ko.observable();
  1332.  
  1333.             self.choice1 = ko.observable();
  1334.             self.choice2 = ko.observable();
  1335.             self.choice3 = ko.observable();
  1336.             self.choice4 = ko.observable();
  1337.         };
  1338.  
  1339.         //Work Info Constructor
  1340.         function WorkInfo(title, name, type, yearsexp, countryofemployment, lastyearworkedinfield) {
  1341.             var self = this;
  1342.  
  1343.             self.workTitle = ko.observable(title);
  1344.             self.workName = ko.observable(name);
  1345.             self.typeOfWork = ko.observableArray(type);
  1346.             self.yearsExp = ko.observable(yearsexp);
  1347.             self.countryOfEmployment = ko.observable(countryofemployment);
  1348.             self.lastYearWorkedInField = ko.observable(lastyearworkedinfield);
  1349.         };
  1350.  
  1351.         //User Constructor
  1352.         function User() {
  1353.             var self = this;
  1354.  
  1355.             self.firstname = ko.observable();
  1356.             self.lastname = ko.observable();
  1357.             self.preferredName = ko.observable();
  1358.             self.email = ko.observable();
  1359.             self.skype = ko.observable();
  1360.             self.birthday = ko.observable();
  1361.             self.preferredLanguage = ko.observable();
  1362.             self.motherTongue = ko.observable('--');
  1363.             self.otherLang = ko.observable('--');
  1364.             self.specialCircumstances = ko.observable('--');
  1365.             self.tradeInterest = ko.observable();
  1366.             self.consentRegistration = ko.observable();
  1367.             self.approvedImmigrate = ko.observable();
  1368.             self.originCountry = ko.observable();
  1369.             self.immigrateOntario = ko.observable();
  1370.             self.livingOutsideCanada = ko.observable();
  1371.             self.tradesKnowledge = ko.observable();
  1372.             self.referral = ko.observable();
  1373.             self.username = ko.observable();
  1374.             self.password = ko.observable();
  1375.             self.uciNumber = ko.observable();
  1376.             self.gender = ko.observable();
  1377.             self.immigrationStatus = ko.observable();
  1378.             self.immigrationClass = ko.observable();
  1379.             self.preferredDestination = ko.observable('--');
  1380.             self.consentResearch = ko.observable();
  1381.             self.driversLicense = ko.observable();
  1382.             self.englishTesting = ko.observable({});
  1383.             self.frenchTesting = ko.observable();
  1384.             self.englishLanguageLevel = ko.observable('--');
  1385.             self.frenchLanguageLevel = ko.observable('--');
  1386.             self.workTesting = ko.observable(new WorkTesting());
  1387.             self.maritalStatus = ko.observable('--');
  1388.  
  1389.             //self.newJobTitle = ko.observable();
  1390.             //self.newCompanyName = ko.observable();
  1391.             //self.newTypeOfWork = ko.observableArray([]);
  1392.             //self.newYearsExp = ko.observable();
  1393.             //self.newCountryEmployment = ko.observable();
  1394.  
  1395.  
  1396.  
  1397.             self.id = ko.observable();
  1398.             self.guid = ko.observable();
  1399.  
  1400.             self.workHistory = ko.observableArray([]);
  1401.             self.educationHistory = ko.observableArray([]);
  1402.         };
  1403.  
  1404.  
  1405.  
  1406.         var ProfileViewModel = function () {
  1407.             var self = this;
  1408.  
  1409.             //Overview is a property to watch for what element is being selected to edit
  1410.             //It's value will be set to the index of the element the user wants to edit. Ensures only that element is editable
  1411.             self.overview = ko.observable(null);
  1412.             //Same as overview but checking for edit state on the dashboard sections to be enabled
  1413.             self.editingEducationHistory = ko.observable(false);
  1414.             self.editingWorkHistory = ko.observable(false);
  1415.             self.editingProfile = ko.observable(false);
  1416.             //Same as overview but checking for add state on the dashboard sections to be enabled
  1417.             self.addingWork = ko.observable(false);
  1418.             self.addingEducation = ko.observable(false);
  1419.  
  1420.  
  1421.             self.newJobTitle = ko.observable();
  1422.             self.newCompanyName = ko.observable();
  1423.             self.newTypeOfWork = ko.observableArray([]); //'d6bae28a-ea86-4c01-8254-e91312c39a13'
  1424.             self.newYearsExp = ko.observable();
  1425.             self.newCountryEmployment = ko.observable();
  1426.             self.newWorkedInField = ko.observable();
  1427.  
  1428.             self.newEduLevel = ko.observable();
  1429.             self.newSchoolName = ko.observable();
  1430.             self.newComplete = ko.observable();
  1431.             self.newStart = ko.observable();
  1432.             self.newEnd = ko.observable();
  1433.  
  1434.             //Create User object on the View Model to track all changes
  1435.             self.user = ko.observable(new User());
  1436.  
  1437.             //Adds a new instance of the Work Info 'class' to the History array
  1438.             self.addWorkHistory = function () {
  1439.                 self.user().workHistory.push(new WorkInfo());
  1440.             };
  1441.  
  1442.             //Adds a new instance of the Education Info 'class' to the History array
  1443.             self.addEducationHistory = function () {
  1444.                 self.user().educationHistory.push(new EducationInfo());
  1445.             };
  1446.  
  1447.             //CRUD Functionality
  1448.             self.editProfile = function ($index) {
  1449.                 self.editingProfile(true);
  1450.  
  1451.                 if(self.user().workTesting.jobOffer() == true){
  1452.                     $('.jobOfferYes').show();
  1453.                     $('.jobOfferNo').hide();
  1454.                 } else {
  1455.                     $('.jobOfferYes').hide();
  1456.                     $('.jobOfferNo').show();
  1457.                 }
  1458.  
  1459.                 // custom select styles
  1460.                 $('.select-item select').customSelect();
  1461.             };
  1462.  
  1463.  
  1464.             self.editEducationHistory = function (id) {
  1465.                 self.overview(id());
  1466.                 self.editingEducationHistory(true);
  1467.                 // custom select styles
  1468.                 $('.select-item select').customSelect();
  1469.             };
  1470.  
  1471.             self.editWorkHistory = function (id) {
  1472.                 self.overview(id());
  1473.                 self.editingWorkHistory(true);
  1474.                 // custom select styles
  1475.                 $('.select-item select').customSelect();
  1476.             };
  1477.  
  1478.             self.newWorkElement = function () {
  1479.  
  1480.                 self.newJobTitle('');
  1481.                 self.newCompanyName('');
  1482.                 self.newTypeOfWork([]);
  1483.                 self.newYearsExp();
  1484.                 self.newCountryEmployment('');
  1485.                 self.newWorkedInField('');
  1486.  
  1487.                 self.addingWork(true);
  1488.                 // custom select styles
  1489.                 $('.select-item select').customSelect();
  1490.  
  1491.                 $('.popup-modal-removeEducationHistory').magnificPopup();
  1492.                 $('.popup-modal-removeWorkHistory').magnificPopup();
  1493.             };
  1494.  
  1495.             self.newEducationElement = function () {
  1496.  
  1497.                 self.newEduLevel();
  1498.                 self.newSchoolName('');
  1499.                 self.newComplete();
  1500.                 self.newStart('');
  1501.                 self.newEnd('');
  1502.  
  1503.                 self.addingEducation(true);
  1504.                 // custom select styles
  1505.                 $('.select-item select').customSelect();
  1506.  
  1507.                 $('.popup-modal-removeEducationHistory').magnificPopup();
  1508.                 $('.popup-modal-removeWorkHistory').magnificPopup();
  1509.             };
  1510.  
  1511.             // check year has to be 4 digits and between 1950 and current year
  1512.             self.checkLastYearWorkedInField = function (input) {
  1513.                 var reg = /^\d{4}$/;
  1514.                 if (!reg.test(input)) {
  1515.                     return false;
  1516.                 }
  1517.  
  1518.                 var year = Number(input);
  1519.                 if (year >= 1950 && year <= currentYear) {
  1520.                     return true;
  1521.                 } else {
  1522.                     return false;
  1523.                 }
  1524.             }
  1525.  
  1526.             self.saveNewWork = function () {
  1527.  
  1528.                 if (self.newJobTitle() == undefined || self.newJobTitle() == "") {
  1529.                     self.newJobTitle('--');
  1530.                 }
  1531.  
  1532.                 if (self.newCompanyName() == undefined || self.newCompanyName() == "") {
  1533.                     self.newCompanyName('--');
  1534.                 }
  1535.  
  1536.                 if (self.newCountryEmployment() == undefined || self.newCountryEmployment() == "") {
  1537.                     self.newCountryEmployment('--');
  1538.                 }
  1539.  
  1540.                 var title = self.newJobTitle();
  1541.                 var company = self.newCompanyName();
  1542.                 var type = self.newTypeOfWork();
  1543.                 var yearsExp = self.newYearsExp();
  1544.                 var country = self.newCountryEmployment();
  1545.                 var workedinfield = self.newWorkedInField();
  1546.  
  1547.                 if (title == "" && company == "" && yearsExp == undefined && country == "" && type.length == 0 || self.checkLastYearWorkedInField(workedinfield) == false) {
  1548.                     $('.warningText.errors').remove();
  1549.                     $('.employmentHistory-header').after('<p class="warningText errors" style="display: block"><strong>Please enter some valid employment history information</strong></p>');
  1550.                 } else {
  1551.  
  1552.                     self.user().workHistory.push(new WorkInfo(title, company, type, yearsExp, country, workedinfield));
  1553.  
  1554.                     var registrationData = ko.toJSON(self.user());
  1555.                     var settings = {
  1556.                         "async": true,
  1557.                         "crossDomain": true,
  1558.                         "url": "/api/ClientUser/save",
  1559.                         "method": "POST",
  1560.                         "headers": {
  1561.                             "content-type": "application/json",
  1562.                             "cache-control": "no-cache",
  1563.                             "postman-token": "e278808a-783c-7ea2-fc88-1df5f5422b25"
  1564.                         },
  1565.                         "data": registrationData
  1566.                     }
  1567.  
  1568.                     $.ajax(settings).done(function (response) {
  1569.                         var errors = response.Result.errors;
  1570.  
  1571.                         if (errors.length > 0) {
  1572.                             self.user().workHistory.pop();
  1573.                             $('.warningText.errors').remove();
  1574.                             $.map(errors, function (error) {
  1575.                                 var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
  1576.                                 $('.employmentHistory-header').after(output);
  1577.                             });
  1578.                         } else {
  1579.                             $('.warningText.errors').remove();
  1580.                             self.overview(null);
  1581.                             self.editingWorkHistory(false);
  1582.                             self.editingEducationHistory(false);
  1583.                             self.addingWork(false);
  1584.                             self.addingEducation(false);
  1585.                             $('.popup-modal-removeWorkHistory').magnificPopup();
  1586.                         }
  1587.  
  1588.                     });
  1589.                 }
  1590.  
  1591.             };
  1592.  
  1593.             self.saveNewEducation = function () {
  1594.  
  1595.                 if (self.newSchoolName() == undefined || self.newSchoolName() == "") {
  1596.                     self.newSchoolName('--');
  1597.                 }
  1598.  
  1599.                 var level = self.newEduLevel();
  1600.                 var name = self.newSchoolName();
  1601.                 var complete = self.newComplete();
  1602.                 var start = self.newStart();
  1603.                 var end = self.newEnd();
  1604.  
  1605.                 if(level != undefined || name != "" || start != "" || end != "") {
  1606.                     self.user().educationHistory.push(new EducationInfo(level, name, complete, start, end));
  1607.  
  1608.                     var registrationData = ko.toJSON(self.user());
  1609.                     var settings = {
  1610.                         "async": true,
  1611.                         "crossDomain": true,
  1612.                         "url": "/api/ClientUser/save",
  1613.                         "method": "POST",
  1614.                         "headers": {
  1615.                             "content-type": "application/json",
  1616.                             "cache-control": "no-cache",
  1617.                             "postman-token": "e278808a-783c-7ea2-fc88-1df5f5422b25"
  1618.                         },
  1619.                         "data": registrationData
  1620.                     }
  1621.  
  1622.                     $.ajax(settings).done(function (response) {
  1623.                         var errors = response.Result.errors;
  1624.  
  1625.                         if (errors.length > 0) {
  1626.                             $('.warningText.errors').remove();
  1627.                             self.user().educationHistory.pop();
  1628.                             $.map(errors, function (error) {
  1629.                                 var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
  1630.                                 $('.education-header').after(output);
  1631.                             });
  1632.                             $('html,body').animate({ scrollTop: 0 }, 100);
  1633.                         } else {
  1634.                             $('.warningText.errors').remove();
  1635.                             self.overview(null);
  1636.                             self.editingWorkHistory(false);
  1637.                             self.editingEducationHistory(false);
  1638.                             self.addingWork(false);
  1639.                             self.addingEducation(false);
  1640.                             $('.popup-modal-removeEducationHistory').magnificPopup();
  1641.                         }
  1642.  
  1643.                     });
  1644.                 } else {
  1645.                     $('.warningText.errors').remove();
  1646.                     $('.education-header').after('<p class="warningText errors" style="display: block"><strong>Please enter some valid education history information</strong></p>');
  1647.                 }
  1648.  
  1649.             };
  1650.  
  1651.             self.saveChange = function () {
  1652.                 self.overview(null);
  1653.                 self.editingWorkHistory(false);
  1654.                 self.editingEducationHistory(false);
  1655.                 self.addingWork(false);
  1656.                 self.addingEducation(false);
  1657.  
  1658.                 $('.popup-modal-removeEducationHistory').magnificPopup();
  1659.                 $('.popup-modal-removeWorkHistory').magnificPopup();
  1660.             };
  1661.  
  1662.             self.saveWorkElement = function () {
  1663.  
  1664.                 if (this.workTitle() == undefined || this.workTitle() == "") {
  1665.                     this.workTitle('--');
  1666.                 }
  1667.  
  1668.                 if (this.workName() == undefined || this.workName() == "") {
  1669.                     this.workName('--');
  1670.                 }
  1671.  
  1672.                 if (this.countryOfEmployment() == undefined || this.countryOfEmployment() == "") {
  1673.                     this.countryOfEmployment('--');
  1674.                 }
  1675.  
  1676.                 var title = this.workTitle();
  1677.                 var company = this.workName();
  1678.                 var type = this.typeOfWork();
  1679.                 var yearsExp = this.yearsExp();
  1680.                 var country = this.countryOfEmployment();
  1681.                 var workedinfield = this.lastYearWorkedInField();
  1682.  
  1683.                 if (title == "" && company == "" && yearsExp == undefined && country == "" && type.length == 0 || self.checkLastYearWorkedInField(workedinfield) == false) {
  1684.                     $('.warningText.errors').remove();
  1685.                     $('.employmentHistory-header').after('<p class="warningText errors" style="display: block"><strong>Please enter some valid employment history information</strong></p>');
  1686.                 } else {
  1687.                     $('.warningText.errors').remove();
  1688.                     var registrationData = ko.toJSON(self.user());
  1689.                     var settings = {
  1690.                         "async": true,
  1691.                         "crossDomain": true,
  1692.                         "url": "/api/ClientUser/save",
  1693.                         "method": "POST",
  1694.                         "headers": {
  1695.                             "content-type": "application/json",
  1696.                             "cache-control": "no-cache",
  1697.                             "postman-token": "e278808a-783c-7ea2-fc88-1df5f5422b25"
  1698.                         },
  1699.                         "data": registrationData
  1700.                     }
  1701.  
  1702.                     $.ajax(settings).done(function (response) {
  1703.                         var errors = response.Result.errors;
  1704.  
  1705.                         if (errors.length > 0) {
  1706.                             $('.warningText.errors').remove();
  1707.                             $.map(errors, function (error) {
  1708.                                 var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
  1709.                                 $('.employmentHistory-header').after(output);
  1710.                             });
  1711.                         } else {
  1712.                             self.overview(null);
  1713.                             self.editingWorkHistory(false);
  1714.                             self.editingEducationHistory(false);
  1715.                             self.addingWork(false);
  1716.                             self.addingEducation(false);
  1717.                             $('.popup-modal-removeWorkHistory').magnificPopup();
  1718.                         }
  1719.  
  1720.                     });
  1721.                 }
  1722.  
  1723.             };
  1724.  
  1725.             self.saveEducationElement = function () {
  1726.                 var registrationData = ko.toJSON(self.user());
  1727.                 var settings = {
  1728.                     "async": true,
  1729.                     "crossDomain": true,
  1730.                     "url": "/api/ClientUser/save",
  1731.                     "method": "POST",
  1732.                     "headers": {
  1733.                         "content-type": "application/json",
  1734.                         "cache-control": "no-cache",
  1735.                         "postman-token": "e278808a-783c-7ea2-fc88-1df5f5422b25"
  1736.                     },
  1737.                     "data": registrationData
  1738.                 }
  1739.  
  1740.                 $.ajax(settings).done(function (response) {
  1741.                     var errors = response.Result.errors;
  1742.  
  1743.                     if (errors.length > 0) {
  1744.                         $('.warningText.errors').remove();
  1745.                         $.map(errors, function (error) {
  1746.                             var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
  1747.                             $('.education-header').after(output);
  1748.                         });
  1749.                     } else {
  1750.                         self.overview(null);
  1751.                         self.editingWorkHistory(false);
  1752.                         self.editingEducationHistory(false);
  1753.                         self.addingWork(false);
  1754.                         self.addingEducation(false);
  1755.                         $('.popup-modal-removeEducationHistory').magnificPopup();
  1756.                     }
  1757.  
  1758.                 });
  1759.  
  1760.             };
  1761.  
  1762.             self.saveProfile = function ($index) {
  1763.                 var registrationData = ko.toJSON(self.user());
  1764.  
  1765.                 var settings = {
  1766.                     "async": true,
  1767.                     "crossDomain": true,
  1768.                     "url": "/api/ClientUser/save",
  1769.                     "method": "POST",
  1770.                     "headers": {
  1771.                         "content-type": "application/json",
  1772.                         "cache-control": "no-cache",
  1773.                         "postman-token": "e278808a-783c-7ea2-fc88-1df5f5422b25"
  1774.                     },
  1775.                     "data": registrationData
  1776.                 }
  1777.  
  1778.                 $.ajax(settings).done(function (response) {
  1779.                     var errors = response.Result.errors;
  1780.  
  1781.                     if (errors.length > 0) {
  1782.                         $('.warningText.errors').remove();
  1783.  
  1784.                         $.map(errors, function (error) {
  1785.                             var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
  1786.                             $('.profile-header').after(output);
  1787.                         });
  1788.  
  1789.                         if(self.user().workTesting.jobOffer() == true){
  1790.                             $('.jobOfferYes').show();
  1791.                             $('.jobOfferNo').hide();
  1792.                         } else {
  1793.                             $('.jobOfferYes').hide();
  1794.                             $('.jobOfferNo').show();
  1795.                         }
  1796.                         $('html,body').animate({ scrollTop: 0 }, 100);
  1797.                     } else {
  1798.                         if (self.user().motherTongue() == '') {
  1799.                             self.user().motherTongue('--');
  1800.                         }
  1801.  
  1802.                         if (self.user().otherLang() == '') {
  1803.                             self.user().otherLang('--');
  1804.                         }
  1805.  
  1806.                         if (self.user().specialCircumstances() == '') {
  1807.                             self.user().specialCircumstances('--');
  1808.                         }
  1809.  
  1810.                         if (self.user().preferredName() == '') {
  1811.                             self.user().preferredName('--');
  1812.                         }
  1813.  
  1814.                         if (self.user().skype() == '') {
  1815.                             self.user().skype('--');
  1816.                         }
  1817.  
  1818.                         if (self.user().maritalStatus() == emptyGuid) {
  1819.                             self.user().maritalStatus('--');
  1820.                         }
  1821.  
  1822.                         if (self.user().preferredDestination() == emptyGuid) {
  1823.                             self.user().preferredDestination('--');
  1824.                         }
  1825.  
  1826.                         if (self.user().englishLanguageLevel() == emptyGuid) {
  1827.                             self.user().englishLanguageLevel('--');
  1828.                         }
  1829.  
  1830.                         if (self.user().frenchLanguageLevel() == emptyGuid) {
  1831.                             self.user().frenchLanguageLevel('--');
  1832.                         }
  1833.  
  1834.                         if (self.user().immigrationClass() == emptyGuid) {
  1835.                             self.user().immigrationClass('--');
  1836.                         }
  1837.  
  1838.                         if(self.user().workTesting.jobOffer() == true){
  1839.                             $('.jobOfferYes').show();
  1840.                             $('.jobOfferNo').hide();
  1841.                         } else {
  1842.                             $('.jobOfferYes').hide();
  1843.                             $('.jobOfferNo').show();
  1844.                         }
  1845.  
  1846.                         $('.warningText.errors').remove();
  1847.                         self.editingProfile(false);
  1848.                         if(self.user().workTesting.jobOffer() == true){
  1849.                             $('.jobOfferYes').show();
  1850.                             $('.jobOfferNo').hide();
  1851.                         } else {
  1852.                             $('.jobOfferYes').hide();
  1853.                             $('.jobOfferNo').show();
  1854.                         }
  1855.                     }
  1856.  
  1857.                     if(self.user().workTesting.jobOffer() == true){
  1858.                         $('.jobOfferYes').show();
  1859.                         $('.jobOfferNo').hide();
  1860.                     } else {
  1861.                         $('.jobOfferYes').hide();
  1862.                         $('.jobOfferNo').show();
  1863.                     }
  1864.  
  1865.                 });
  1866.                 if(self.user().workTesting.jobOffer() == true){
  1867.                     $('.jobOfferYes').show();
  1868.                     $('.jobOfferNo').hide();
  1869.                 } else {
  1870.                     $('.jobOfferYes').hide();
  1871.                     $('.jobOfferNo').show();
  1872.                 }
  1873.             };
  1874.  
  1875.             self.cancelChange = function () {
  1876.  
  1877.                 var settings = {
  1878.                     "async": true,
  1879.                     "crossDomain": true,
  1880.                     "url": "/api/ClientUser?id=" + userid,
  1881.                     "method": "GET",
  1882.                     "headers": {
  1883.                         "cache-control": "no-cache",
  1884.                         "postman-token": "e57a474c-3fb5-8945-5487-45ac9047cadb",
  1885.                     }
  1886.  
  1887.                 };
  1888.  
  1889.                 $.ajax(settings).done(function (data) {
  1890.                     //Updating Profile Info
  1891.                     var aUser = ko.mapping.fromJS(data.Result);
  1892.                     self.user(ko.mapping.fromJS(data.Result));
  1893.  
  1894.                     //Change First Title on Education Dashboard
  1895.                     $('.education-title').first().text('Highest Education Level');
  1896.                     $('.popup-modal-removeWorkHistory').magnificPopup();
  1897.                     $('.popup-modal-removeEducationHistory').magnificPopup();
  1898.  
  1899.                     if (self.user().motherTongue() == '') {
  1900.                         self.user().motherTongue('--');
  1901.                     }
  1902.  
  1903.                     if (self.user().otherLang() == '') {
  1904.                         self.user().otherLang('--');
  1905.                     }
  1906.  
  1907.                     if (self.user().specialCircumstances() == '') {
  1908.                         self.user().specialCircumstances('--');
  1909.                     }
  1910.  
  1911.                     if (self.user().preferredName() == '') {
  1912.                         self.user().preferredName('--');
  1913.                     }
  1914.  
  1915.                     if (self.user().skype() == '') {
  1916.                         self.user().skype('--');
  1917.                     }
  1918.  
  1919.                     if (self.user().maritalStatus() == emptyGuid) {
  1920.                         self.user().maritalStatus('--');
  1921.                     }
  1922.  
  1923.                     if (self.user().preferredDestination() == emptyGuid) {
  1924.                         self.user().preferredDestination('--');
  1925.                     }
  1926.  
  1927.                     if (self.user().englishLanguageLevel() == emptyGuid) {
  1928.                         self.user().englishLanguageLevel('--');
  1929.                     }
  1930.  
  1931.                     if (self.user().frenchLanguageLevel() == emptyGuid) {
  1932.                         self.user().frenchLanguageLevel('--');
  1933.                     }
  1934.  
  1935.                     if (self.user().immigrationClass() == emptyGuid) {
  1936.                         self.user().immigrationClass('--');
  1937.                     }
  1938.  
  1939.                     if(self.user().workTesting.jobOffer() == true){
  1940.                         $('.jobOfferYes').show();
  1941.                         $('.jobOfferNo').hide();
  1942.                     }
  1943.  
  1944.                     if(self.user().workTesting.jobOffer() == false){
  1945.                         $('.jobOfferNo').show();
  1946.                         $('.jobOfferYes').hide();
  1947.                     }
  1948.  
  1949.                 });
  1950.  
  1951.                 if(self.user().workTesting.jobOffer() == true){
  1952.                     $('.jobOfferYes').show();
  1953.                     $('.jobOfferNo').hide();
  1954.                 } else {
  1955.                     $('.jobOfferYes').hide();
  1956.                     $('.jobOfferNo').show();
  1957.                 }
  1958.  
  1959.                 self.overview(null);
  1960.                 self.editingProfile(false);
  1961.                 self.editingWorkHistory(false);
  1962.                 self.editingEducationHistory(false);
  1963.                 self.addingWork(false);
  1964.                 self.addingEducation(false);
  1965.                 $('.warningText.errors').remove();
  1966.             };
  1967.  
  1968.             self.removeWork = function ($index) {
  1969.                 self.user().workHistory.remove(this);
  1970.  
  1971.                 var registrationData = ko.toJSON(self.user());
  1972.  
  1973.                 var settings = {
  1974.                     "async": true,
  1975.                     "crossDomain": true,
  1976.                     "url": "/api/ClientUser/save",
  1977.                     "method": "POST",
  1978.                     "headers": {
  1979.                         "content-type": "application/json",
  1980.                         "cache-control": "no-cache",
  1981.                         "postman-token": "e278808a-783c-7ea2-fc88-1df5f5422b25"
  1982.                     },
  1983.                     "data": registrationData
  1984.                 }
  1985.  
  1986.                 $.ajax(settings).done(function (response) {
  1987.  
  1988.                     $('.popup-modal-removeEducationHistory').magnificPopup();
  1989.                     $('.popup-modal-removeWorkHistory').magnificPopup();
  1990.                     var errors = response.Result.errors;
  1991.  
  1992.                     if (errors.length > 0) {
  1993.                         $.map(errors, function (error) {
  1994.                             var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
  1995.                             $('.employmentHistory-header').after(output);
  1996.                         });
  1997.                     }
  1998.                 });
  1999.  
  2000.             };
  2001.  
  2002.             self.removeEducation = function ($index) {
  2003.                 self.user().educationHistory.remove(this);
  2004.  
  2005.                 var registrationData = ko.toJSON(self.user());
  2006.  
  2007.                 var settings = {
  2008.                     "async": true,
  2009.                     "crossDomain": true,
  2010.                     "url": "/api/ClientUser/save",
  2011.                     "method": "POST",
  2012.                     "headers": {
  2013.                         "content-type": "application/json",
  2014.                         "cache-control": "no-cache",
  2015.                         "postman-token": "e278808a-783c-7ea2-fc88-1df5f5422b25"
  2016.                     },
  2017.                     "data": registrationData
  2018.                 }
  2019.  
  2020.                 $.ajax(settings).done(function (response) {
  2021.  
  2022.                     $('.popup-modal-removeEducationHistory').magnificPopup();
  2023.                     $('.popup-modal-removeWorkHistory').magnificPopup();
  2024.                     var errors = response.Result.errors;
  2025.  
  2026.                     if (errors.length > 0) {
  2027.                         $.map(errors, function (error) {
  2028.                             var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
  2029.                             $('.education-header').after(output);
  2030.                         });
  2031.                     }
  2032.                 });
  2033.  
  2034.             };
  2035.  
  2036.             //Custom table Lookup Data init
  2037.             self.tradesLookup = ko.observableArray([]);
  2038.             self.countriesLookup = ko.observableArray([]);
  2039.             self.educationLookup = ko.observableArray([]);
  2040.             self.englishSkillsLookup = ko.observableArray([]);
  2041.             self.frenchSkillsLookup = ko.observableArray([]);
  2042.             self.immigrationStatusLookup = ko.observableArray([]);
  2043.             self.immigrationClassLookup = ko.observableArray([]);
  2044.             self.servicesLookup = ko.observableArray([]);
  2045.             self.yearsOfExperienceLookup = ko.observableArray([]);
  2046.             self.typeOfWorkLookup = ko.observableArray([]);
  2047.             self.familiarLevelLookup = ko.observableArray([]);
  2048.             self.preferLangLookup = ko.observableArray([]);
  2049.             self.genderLookup = ko.observableArray([]);
  2050.             self.destinationLookup = ko.observableArray([]);
  2051.             self.languageLevelLookup = ko.observableArray([]);
  2052.             self.maritalStatusLookup = ko.observableArray([]);
  2053.  
  2054.             $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
  2055.                 if (data.Result != null) {
  2056.                     var arrData = data.Result;
  2057.                     var tradeItem = FindItemByKey("BuildON.Trades", arrData);
  2058.                     if (tradeItem != undefined && tradeItem != null) {
  2059.                         self.tradesLookup(tradeItem[0].Data);
  2060.                     }
  2061.  
  2062.                     var countryItem = FindItemByKey("BuildON.OriginCountry", arrData);
  2063.                     if (countryItem != undefined && countryItem != null) {
  2064.                         self.countriesLookup(countryItem[0].Data);
  2065.                     }
  2066.  
  2067.                     var educationItem = FindItemByKey("BuildON.EducationLevel", arrData);
  2068.                     if (educationItem != undefined && educationItem != null) {
  2069.                         self.educationLookup(educationItem[0].Data);
  2070.                     }
  2071.  
  2072.                     var englishItem = FindItemByKey("BuildON.EnglishSkills", arrData);
  2073.                     if (englishItem != undefined && englishItem != null) {
  2074.                         self.englishSkillsLookup(englishItem[0].Data);
  2075.                     }
  2076.  
  2077.                     var frenchItem = FindItemByKey("BuildON.FrenchSkills", arrData);
  2078.                     if (frenchItem != undefined && frenchItem != null) {
  2079.                         self.frenchSkillsLookup(frenchItem[0].Data);
  2080.                     }
  2081.  
  2082.                     var statusItem = FindItemByKey("BuildON.ImmigrationStatus", arrData);
  2083.                     if (statusItem != undefined && statusItem != null) {
  2084.                         self.immigrationStatusLookup(statusItem[0].Data);
  2085.                     }
  2086.  
  2087.                     var immigrationClassItem = FindItemByKey("BuildON.ImmigrationClass", arrData);
  2088.                     if (immigrationClassItem != undefined && immigrationClassItem != null) {
  2089.                         self.immigrationClassLookup(immigrationClassItem[0].Data);
  2090.                     }
  2091.  
  2092.                     var servicesItem = FindItemByKey("BuildON.Services", arrData);
  2093.                     if (servicesItem != undefined && servicesItem != null) {
  2094.                         self.servicesLookup(servicesItem[0].Data);
  2095.                     }
  2096.  
  2097.                     var yearsItem = FindItemByKey("BuildON.YearsOfExperience", arrData);
  2098.                     if (yearsItem != undefined && yearsItem != null) {
  2099.                         self.yearsOfExperienceLookup(yearsItem[0].Data);
  2100.                     }
  2101.  
  2102.                     var typeOfWorkItem = FindItemByKey("BuildON.TypeOfWork", arrData);
  2103.                     if (typeOfWorkItem != undefined && typeOfWorkItem != null) {
  2104.                         self.typeOfWorkLookup(typeOfWorkItem[0].Data);
  2105.                     }
  2106.  
  2107.                     var familiarLevelItem = FindItemByKey("BuildON.FamiliarLevel", arrData);
  2108.                     if (familiarLevelItem != undefined && familiarLevelItem != null) {
  2109.                         self.familiarLevelLookup(familiarLevelItem[0].Data);
  2110.                     }
  2111.  
  2112.                     var preferLangItem = FindItemByKey("BuildON.PreferredLanguage", arrData);
  2113.                     if (preferLangItem != undefined && preferLangItem != null) {
  2114.                         self.preferLangLookup(preferLangItem[0].Data);
  2115.                     }
  2116.  
  2117.                     var genderItem = FindItemByKey("BuildON.Gender", arrData);
  2118.                     if (genderItem != undefined && genderItem != null) {
  2119.                         self.genderLookup(genderItem[0].Data);
  2120.                     }
  2121.  
  2122.                     var destinationItem = FindItemByKey("BuildON.Destination", arrData);
  2123.                     if (destinationItem != undefined && destinationItem != null) {
  2124.                         self.destinationLookup(destinationItem[0].Data);
  2125.                     }
  2126.  
  2127.                     var langLevelItem = FindItemByKey("BuildON.LanguageLevel", arrData);
  2128.                     if (langLevelItem != undefined && langLevelItem != null) {
  2129.                         self.languageLevelLookup(langLevelItem[0].Data);
  2130.                     }
  2131.  
  2132.                     var maritalStatusItem = FindItemByKey("BuildON.MaritalStatus", arrData);
  2133.                     if (maritalStatusItem != undefined && maritalStatusItem != null) {
  2134.                         self.maritalStatusLookup(maritalStatusItem[0].Data);
  2135.                     }
  2136.  
  2137.                 }
  2138.             });
  2139.  
  2140.  
  2141.             self.GetGender = function (guid) {
  2142.                 return FindItemByGuid(guid, self.genderLookup());
  2143.             };
  2144.             self.GetTrade = function (guid) {
  2145.                 return FindItemByGuid(guid, self.tradesLookup());
  2146.             };
  2147.             self.GetCountry = function (guid) {
  2148.                 return FindItemByGuid(guid, self.countriesLookup());
  2149.             };
  2150.             self.GetEducation = function (guid) {
  2151.                 return FindItemByGuid(guid, self.educationLookup());
  2152.             };
  2153.             self.GetEnglishSkill = function (guid) {
  2154.                 return FindItemByGuid(guid, self.englishSkillsLookup());
  2155.             };
  2156.             self.GetFrenchSkill = function (guid) {
  2157.                 return FindItemByGuid(guid, self.frenchSkillsLookup());
  2158.             };
  2159.             self.GetImmigrationStatus = function (guid) {
  2160.                 return FindItemByGuid(guid, self.immigrationStatusLookup());
  2161.             };
  2162.             self.GetImmigrationClass = function (guid) {
  2163.                 return FindItemByGuid(guid, self.immigrationClassLookup());
  2164.             };
  2165.             self.GetService = function (guid) {
  2166.                 return FindItemByGuid(guid, self.servicesLookup());
  2167.             };
  2168.             self.GetYearOfExperience = function (guid) {
  2169.                 return FindItemByGuid(guid, self.yearsOfExperienceLookup());
  2170.             };
  2171.             self.GetWrokType = function (guid) {
  2172.                 return FindItemByGuid(guid, self.typeOfWorkLookup());
  2173.             };
  2174.             self.GetFamiliarLevel = function (guid) {
  2175.                 return FindItemByGuid(guid, self.familiarLevelLookup());
  2176.             };
  2177.             self.GetPreferLang = function (guid) {
  2178.                 return FindItemByGuid(guid, self.preferLangLookup());
  2179.             };
  2180.             self.GetDestination = function (guid) {
  2181.                 return FindItemByGuid(guid, self.destinationLookup());
  2182.             };
  2183.             self.GetMaritalStatus = function (guid) {
  2184.                 return FindItemByGuid(guid, self.maritalStatusLookup());
  2185.             };
  2186.             self.GetLanguageLevel = function (guid) {
  2187.                 return FindItemByGuid(guid, self.languageLevelLookup());
  2188.             };
  2189.  
  2190.  
  2191.             var settings = {
  2192.                 "async": true,
  2193.                 "crossDomain": true,
  2194.                 "url": "/api/ClientUser?id=" + userid,
  2195.                 "method": "GET",
  2196.                 "headers": {
  2197.                     "cache-control": "no-cache",
  2198.                     "postman-token": "e57a474c-3fb5-8945-5487-45ac9047cadb",
  2199.                 }
  2200.  
  2201.             };
  2202.  
  2203.             $.ajax(settings).done(function (data) {
  2204.                 //Updating Profile Info
  2205.                 var aUser = ko.mapping.fromJS(data.Result);
  2206.                 self.user(ko.mapping.fromJS(data.Result));
  2207.  
  2208.                 //Change First Title on Education Dashboard
  2209.                 $('.education-title').first().text('Highest Education Level');
  2210.                 $('.popup-modal-removeWorkHistory').magnificPopup();
  2211.                 $('.popup-modal-removeEducationHistory').magnificPopup();
  2212.  
  2213.                 if (self.user().motherTongue() == '') {
  2214.                     self.user().motherTongue('--');
  2215.                 }
  2216.  
  2217.                 if (self.user().otherLang() == '') {
  2218.                     self.user().otherLang('--');
  2219.                 }
  2220.  
  2221.                 if (self.user().specialCircumstances() == '') {
  2222.                     self.user().specialCircumstances('--');
  2223.                 }
  2224.  
  2225.                 if (self.user().preferredName() == '') {
  2226.                     self.user().preferredName('--');
  2227.                 }
  2228.  
  2229.                 if (self.user().skype() == '') {
  2230.                     self.user().skype('--');
  2231.                 }
  2232.  
  2233.                 if (self.user().maritalStatus() == emptyGuid) {
  2234.                     self.user().maritalStatus('--');
  2235.                 }
  2236.  
  2237.                 if (self.user().preferredDestination() == emptyGuid) {
  2238.                     self.user().preferredDestination('--');
  2239.                 }
  2240.  
  2241.                 if (self.user().englishLanguageLevel() == emptyGuid) {
  2242.                     self.user().englishLanguageLevel('--');
  2243.                 }
  2244.  
  2245.                 if (self.user().frenchLanguageLevel() == emptyGuid) {
  2246.                     self.user().frenchLanguageLevel('--');
  2247.                 }
  2248.  
  2249.                 if (self.user().immigrationClass() == emptyGuid) {
  2250.                     self.user().immigrationClass('--');
  2251.                 }
  2252.  
  2253.                 if(self.user().workTesting.jobOffer() == true){
  2254.                     $('.jobOfferYes').show();
  2255.                     $('.jobOfferNo').hide();
  2256.                 }
  2257.  
  2258.                 if(self.user().workTesting.jobOffer() == false){
  2259.                     $('.jobOfferNo').show();
  2260.                     $('.jobOfferYes').hide();
  2261.                 }
  2262.  
  2263.             });
  2264.  
  2265.         }
  2266.  
  2267.         var viewModel = new ProfileViewModel();
  2268.         ko.applyBindings(viewModel, document.getElementById("dashboard-home"));
  2269.     };
  2270.     if ($('.user-mydashboard').html() != undefined) {
  2271.         buildON.myDashboard();
  2272.     }
  2273.  
  2274.     //Add/Edit Workshop
  2275.     buildON.addEditWorkshop = function() {
  2276.  
  2277.  
  2278.         var workshopViewModle = function (moduleLookup) {
  2279.  
  2280.             var self = this;
  2281.  
  2282.             // variables
  2283.             var isReady = false;
  2284.             var mediasNum = 0;
  2285.             var hidWorkshopGuid = $('#hidWorkshopGuid') != undefined ? $('#hidWorkshopGuid').val() : "";
  2286.             var addAnotherUrl = $('#hidAddEditUrl') != undefined ? $('#hidAddEditUrl').val() : "";
  2287.             var workshopDetailsUrl = $('#hidWorkshopDetailsUrl') != undefined ? $('#hidWorkshopDetailsUrl').val() : "";
  2288.  
  2289.             // Workshop Video
  2290.             function WorkshopVideo(workshopguid, titleen, titlefr, urlen, urlfr, sortorder, type) {
  2291.                 var self = this;
  2292.                 // View Model Object variables
  2293.                 self.workshopguid = ko.observable(workshopguid);
  2294.                 self.titleen = ko.observable(titleen);
  2295.                 self.titlefr = ko.observable(titlefr);
  2296.                 self.urlen = ko.observable(urlen);
  2297.                 self.urlfr = ko.observable(urlfr);
  2298.                 self.sortorder = ko.observable(sortorder);
  2299.                 self.type = ko.observable(type);
  2300.             }
  2301.  
  2302.             // Workshop Document
  2303.             function WorkshopDocument(workshopguid, fileen, filetitleen, filefr, filetitlefr, sortorder, type) {
  2304.                 var self = this;
  2305.                 // View Model Object variables
  2306.                 self.workshopguid = ko.observable(workshopguid);
  2307.                 self.fileen = ko.observable(fileen);
  2308.                 self.filetitleen = ko.observable(filetitleen);
  2309.                 self.filefr = ko.observable(filefr);
  2310.                 self.filetitlefr = ko.observable(filetitlefr);
  2311.                 self.sortorder = ko.observable(sortorder);
  2312.                 self.type = ko.observable(type);
  2313.             }
  2314.  
  2315.             //Workshop media (video + document) object
  2316.             function WorkshopMedia(workshopguid, titleen, titlefr, urlen, urlfr, fileen, filefr, filetitleen, filetitlefr, sortorder, type) {
  2317.                 var self = this;
  2318.  
  2319.                 self.workshopguid = ko.observable(workshopguid);
  2320.                 self.titleen = ko.observable(titleen);
  2321.                 self.titlefr = ko.observable(titlefr);
  2322.                 self.urlen = ko.observable(urlen);
  2323.                 self.urlfr = ko.observable(urlfr);
  2324.                 self.fileen = ko.observable(fileen);
  2325.                 self.filetitleen = ko.observable(filetitleen);
  2326.                 self.filefr = ko.observable(filefr);
  2327.                 self.filetitlefr = ko.observable(filetitlefr);
  2328.                 self.sortorder = ko.observable(sortorder);
  2329.                 self.type = ko.observable(type);
  2330.             }
  2331.  
  2332.             self.isNew = ko.observable(false);
  2333.             self.hasError = ko.observable(false);
  2334.  
  2335.             self.moduleLookup = ko.observableArray(moduleLookup);
  2336.  
  2337.             // Workshop media observable variable to store all videos and documents, and it is used for getting the right sort order of these items too
  2338.             self.workshopMedias = ko.observableArray([]);
  2339.  
  2340.             // Initialize workshpVO with MAPPING
  2341.             self.workshopVO = ko.mapping.fromJS([]);
  2342.  
  2343.             $.ajax({
  2344.                 type: 'GET',
  2345.                 contentType: 'application/json',
  2346.                 url: "/api/Workshop?guid=" + hidWorkshopGuid,
  2347.                 async: false,
  2348.                 success: function(data) {
  2349.                     if (data.Success && data.Result != null) {
  2350.                         self.workshopVO = ko.mapping.fromJS(data.Result);
  2351.                         mediasNum = self.workshopVO.workshopvideos().length + self.workshopVO.workshopdocuments().length;
  2352.  
  2353.                         for (var i = 0; i < self.workshopVO.workshopvideos().length; i++) {
  2354.                             var newVideo = new WorkshopMedia(hidWorkshopGuid, self.workshopVO.workshopvideos()[i].titleen(), self.workshopVO.workshopvideos()[i].titlefr(), self.workshopVO.workshopvideos()[i].urlen(), self.workshopVO.workshopvideos()[i].urlfr(), "", "", "", "", self.workshopVO.workshopvideos()[i].sortorder(), 'video');
  2355.  
  2356.                             self.workshopMedias.push(newVideo);
  2357.                         }
  2358.                         for (var i = 0; i < self.workshopVO.workshopdocuments().length; i++) {
  2359.                             var newDoc = new WorkshopMedia(hidWorkshopGuid, "", "", "", "", self.workshopVO.workshopdocuments()[i].fileen(), self.workshopVO.workshopdocuments()[i].filefr(), self.workshopVO.workshopdocuments()[i].filetitleen(), self.workshopVO.workshopdocuments()[i].filetitlefr(), self.workshopVO.workshopdocuments()[i].sortorder(), 'document');
  2360.  
  2361.                             self.workshopMedias.push(newDoc);
  2362.                         }
  2363.  
  2364.                         // Order the workshopMEdias by SortOrder coming from database
  2365.                         self.workshopMedias.sort(function(a, b) {
  2366.                             var aID = a.sortorder();
  2367.                             var bID = b.sortorder();
  2368.                             return (aID == bID) ? 0 : (aID > bID) ? 1 : -1;
  2369.                         });
  2370.  
  2371.                         // Reset the order just in case the data was not correct in DB
  2372.                         SetOrder();
  2373.  
  2374.                         isReady = (self.workshopVO != undefined ? true : false);
  2375.                         self.isNew(self.workshopVO != undefined && self.workshopVO.id() == 0 ? true : false);
  2376.                     } else {
  2377.                         // TODO redirect to Error page
  2378.  
  2379.                     }
  2380.                 },
  2381.                 error: function() {
  2382.                     //TODO error handler?
  2383.                 }
  2384.             });
  2385.  
  2386.  
  2387.             // Add Video
  2388.             self.videotitleen = ko.observable("");
  2389.             self.videotitlefr = ko.observable("");
  2390.             self.videourlen = ko.observable("");
  2391.             self.videourlfr = ko.observable("");
  2392.             self.addVideo = function() {
  2393.  
  2394.                 $('#popup-modal-saveWorkshop').magnificPopup();
  2395.                 $('#popup-modal-saveWorkshopAgain').magnificPopup();
  2396.  
  2397.                 if (self.videourlfr() != "" && self.videourlfr() != undefined && self.videotitlefr() != "" && self.videotitlefr() != undefined && self.videourlen() != "" && self.videourlen() != undefined && self.videotitleen() != "" && self.videotitleen() != undefined) {
  2398.                     $('.warningTextAddedFiles').hide();
  2399.                     mediasNum++;
  2400.                     var newVideo = (new WorkshopVideo(hidWorkshopGuid));
  2401.                     newVideo.id = 0;
  2402.                     newVideo.guid = "";
  2403.                     newVideo.titleen(self.videotitleen());
  2404.                     newVideo.titlefr(self.videotitlefr());
  2405.                     newVideo.urlen(self.videourlen());
  2406.                     newVideo.urlfr(self.videourlfr());
  2407.                     newVideo.sortorder(mediasNum);
  2408.  
  2409.                     // Add Video to WorkshopVideos arrary
  2410.                     self.workshopVO.workshopvideos().push(newVideo);
  2411.  
  2412.                     var newMedia = new WorkshopMedia(hidWorkshopGuid, self.videotitleen(), self.videotitlefr(), self.videourlen(), self.videourlfr(), "", "", "", "", mediasNum, "video");
  2413.  
  2414.                     // Add Video to WorkshopMedias arrary
  2415.                     self.workshopMedias.push(newMedia);
  2416.  
  2417.                     // Reset the "Add Associated Videos" section observable variables
  2418.                     self.videotitleen("");
  2419.                     self.videotitlefr("");
  2420.                     self.videourlen("");
  2421.                     self.videourlfr("");
  2422.  
  2423.                     //Hide any potential error messages
  2424.                     $('.warningTextVidTitleEn').hide();
  2425.                     $('.warningTextVidTitleFr').hide();
  2426.                     $('.warningTextVidUrlFr').hide();
  2427.                     $('.warningTextVidUrlEn').hide();
  2428.                 } else {
  2429.                     //Check to make sure video title has been set
  2430.                     if (self.videotitleen() == "" || self.videotitleen() == undefined) {
  2431.                         $('.warningTextVidTitleEn').show();
  2432.                     } else {
  2433.                         $('.warningTextVidTitleEn').hide();
  2434.                     }
  2435.  
  2436.                     //Check to make sure video title has been set
  2437.                     if (self.videotitlefr() == "" || self.videotitlefr() == undefined) {
  2438.                         $('.warningTextVidTitleFr').show();
  2439.                     } else {
  2440.                         $('.warningTextVidTitleFr').hide();
  2441.                     }
  2442.  
  2443.                     //Check to make sure video URL has been set
  2444.                     if (self.videourlen() == "" || self.videourlen() == undefined) {
  2445.                         $('.warningTextVidUrlEn').show();
  2446.                     } else {
  2447.                         $('.warningTextVidUrlEn').hide();
  2448.                     }
  2449.  
  2450.                     //Check to make sure video URL has been set
  2451.                     if (self.videourlfr() == "" || self.videourlfr() == undefined) {
  2452.                         $('.warningTextVidUrlFr').show();
  2453.                     } else {
  2454.                         $('.warningTextVidUrlFr').hide();
  2455.                     }
  2456.                 }
  2457.             }
  2458.  
  2459.             // Add Document
  2460.             self.documentfileen = ko.observable("");
  2461.             self.documenttitleen = ko.observable("");
  2462.             self.documentfilefr = ko.observable("");
  2463.             self.documenttitlefr = ko.observable("");
  2464.             self.addDocument = function() {
  2465.  
  2466.                 //Getting the value for the Document PDF Fields-if they're set we need to check the Title field later
  2467.                 var workshopPDFen = $('.document-en .MediaSelector .EditingFormMediaPathTextBox').val();
  2468.                 var workshopPDFfr = $('.document-fr .MediaSelector .EditingFormMediaPathTextBox').val();
  2469.  
  2470.                 $('.warningTextPdfEn').show();
  2471.                 $('.warningTextPdfFr').show();
  2472.                 $('.warningTextDocTitleFr').show();
  2473.                 $('.warningTextDocTitleEn').show();
  2474.  
  2475.                 if (self.documenttitlefr() == undefined || self.documenttitlefr() == "") {
  2476.                     $('.warningTextDocTitleFr').show();
  2477.                 } else {
  2478.                     $('.warningTextDocTitleFr').hide();
  2479.                 }
  2480.  
  2481.                 if (self.documenttitleen() == undefined || self.documenttitleen() == "") {
  2482.                     $('.warningTextDocTitleEn').show();
  2483.                 } else {
  2484.                     $('.warningTextDocTitleEn').hide();
  2485.                 }
  2486.  
  2487.                 //If English or French PDFs have been uploaded, check to make sure they have a title set
  2488.                 if (workshopPDFfr != "") {
  2489.                     $('.warningTextPdfFr').hide();
  2490.  
  2491.                     if (workshopPDFen == "") {
  2492.                         $('.warningTextPdfEn').show();
  2493.                     } else {
  2494.                         $('.warningTextPdfEn').hide();
  2495.                     }
  2496.  
  2497.                     if (self.documenttitlefr() == undefined || self.documenttitlefr() == "") {
  2498.                         $('.warningTextDocTitleFr').show();
  2499.                     } else {
  2500.                         $('.warningTextDocTitleFr').hide();
  2501.                     }
  2502.                 }
  2503.  
  2504.                 if (workshopPDFen != "") {
  2505.                     $('.warningTextPdfEn').hide();
  2506.  
  2507.                     if (workshopPDFfr == "") {
  2508.                         $('.warningTextPdfFr').show();
  2509.                     } else {
  2510.                         $('.warningTextPdfFr').hide();
  2511.                     }
  2512.  
  2513.                     if (self.documenttitleen() == undefined || self.documenttitleen() == "") {
  2514.                         $('.warningTextDocTitleEn').show();
  2515.                     } else {
  2516.                         $('.warningTextDocTitleEn').hide();
  2517.                     }
  2518.                 }
  2519.  
  2520.                 if (workshopPDFen != "" && workshopPDFfr != "") {
  2521.                     if (self.documenttitleen() == undefined || self.documenttitleen() == "") {
  2522.                         $('.warningTextDocTitleEn').show();
  2523.                     }
  2524.  
  2525.                     if (self.documenttitlefr() == undefined || self.documenttitlefr() == "") {
  2526.                         $('.warningTextDocTitleFr').show();
  2527.                     } else if (self.documenttitlefr() != "" && self.documenttitleen() != "") {
  2528.                         $('.warningTextDocTitleEn').hide();
  2529.                         $('.warningTextDocTitleFr').hide();
  2530.                         mediasNum++;
  2531.                         // Due to Media Selector form control, we need to set the file name to observable variables
  2532.                         var enFileName = $('.document-en .MediaSelector .EditingFormMediaPathTextBox').val();
  2533.                         self.documentfileen(enFileName);
  2534.                         var frFileName = $('.document-fr .MediaSelector .EditingFormMediaPathTextBox').val();
  2535.                         self.documentfilefr(frFileName);
  2536.  
  2537.                         var newDocument = (new WorkshopDocument(hidWorkshopGuid, self.documentfileen(), self.documenttitleen(), self.documentfilefr(), self.documenttitlefr(), mediasNum, 'document'));
  2538.                         newDocument.id = 0;
  2539.                         newDocument.guid = "";
  2540.  
  2541.                         // Add Document to WorkshopDocuments arrary
  2542.                         self.workshopVO.workshopdocuments.push(newDocument);
  2543.  
  2544.                         // Add Document to workshopMedias arrary
  2545.                         self.workshopMedias.push(new WorkshopMedia(hidWorkshopGuid, "", "", "", "", newDocument.fileen(), newDocument.filefr(), newDocument.filetitleen(), newDocument.filetitlefr(), mediasNum, 'document'));
  2546.  
  2547.                         // Reset the "Add Associated Documents" section observable variables
  2548.                         self.documentfileen("");
  2549.                         self.documenttitleen("");
  2550.                         self.documentfilefr("");
  2551.                         self.documenttitlefr("");
  2552.                     }
  2553.                 }
  2554.  
  2555.             }
  2556.  
  2557.             // Remove workshop media
  2558.             self.removeItem = function(item) {
  2559.                 if (confirm("Are you sure you want to remove this item?")) {
  2560.                     var type = item.type();
  2561.  
  2562.                     self.workshopMedias.remove(item);
  2563.  
  2564.                     // remove item from self.workshopVO video or document
  2565.                     if (type != undefined && type.toLowerCase() === "video") {
  2566.                         var newVideos = self.workshopVO.workshopvideos()
  2567.                             .filter(function(el) {
  2568.                                     return el.titleen() !== item.titleen() && el.titlefr() !== item.titlefr();
  2569.                                 }
  2570.                             );
  2571.                         self.workshopVO.workshopvideos([]);
  2572.                         self.workshopVO.workshopvideos(newVideos);
  2573.                     } else if (type != undefined && type.toLowerCase() === "document") {
  2574.                         var newDocuments = self.workshopVO.workshopdocuments()
  2575.                             .filter(function(el) {
  2576.                                     return el.fileen() !== item.fileen() && el.filetitleen() !== item.filetitleen();
  2577.                                 }
  2578.                             );
  2579.                         self.workshopVO.workshopdocuments([]);
  2580.                         self.workshopVO.workshopdocuments(newDocuments);
  2581.                     }
  2582.                 }
  2583.             };
  2584.  
  2585.             // Move workshop media up
  2586.             self.moveUp = function(itemIndex) {
  2587.                 var i = self.workshopMedias.indexOf(itemIndex);
  2588.                 if (i >= 1) {
  2589.                     var array = self.workshopMedias();
  2590.                     self.workshopMedias.splice(i - 1, 2, array[i], array[i - 1]);
  2591.  
  2592.                     SetOrder();
  2593.                 }
  2594.             };
  2595.  
  2596.             // Move workshop media down
  2597.             self.moveDown = function(itemIndex) {
  2598.                 var i = self.workshopMedias.indexOf(itemIndex);
  2599.                 var array = self.workshopMedias();
  2600.                 if (i < array.length - 1) {
  2601.                     self.workshopMedias.splice(i, 2, array[i + 1], array[i]);
  2602.  
  2603.                     SetOrder();
  2604.                 }
  2605.             };
  2606.  
  2607.             // Save workshop
  2608.             function ValidateForm() {
  2609.                 if (self.workshopMedias().length == 0) {
  2610.                     $('.warningTextAddedFiles').show();
  2611.                 } else {
  2612.                     $('.warningTextAddedFiles').hide();
  2613.                 }
  2614.  
  2615.                 //Check to make sure a module has been selected
  2616.                 if (self.workshopVO.moduleguid() == undefined) {
  2617.                     $('.warningTextModule').show();
  2618.                 } else {
  2619.                     $('.warningTextModule').hide();
  2620.                 }
  2621.  
  2622.                 //Check to make sure an image title has been added
  2623.                 if (self.workshopVO.titleen() == "") {
  2624.                     $('.warningTextTitleEn').show();
  2625.                 } else {
  2626.                     $('.warningTextTitleEn').hide();
  2627.                 }
  2628.  
  2629.                 //Check to make sure an image title has been added
  2630.                 if (self.workshopVO.titlefr() == "") {
  2631.                     $('.warningTextTitleFr').show();
  2632.                 } else {
  2633.                     $('.warningTextTitleFr').hide();
  2634.                 }
  2635.  
  2636.                 //Check to make sure a short description has been added
  2637.                 if (self.workshopVO.summaryen() == "") {
  2638.                     $('.warningTextSummaryEn').show();
  2639.                 } else {
  2640.                     $('.warningTextSummaryEn').hide();
  2641.                 }
  2642.  
  2643.                 //Check to make sure a short description has been added
  2644.                 if (self.workshopVO.summaryfr() == "") {
  2645.                     $('.warningTextSummaryFr').show();
  2646.                 } else {
  2647.                     $('.warningTextSummaryFr').hide();
  2648.                 }
  2649.  
  2650.                 //Check all values together to make sure they're valid
  2651.                 if (self.workshopVO.moduleguid() != undefined && self.workshopVO.summaryen() != "" && self.workshopVO.summaryfr() != "" && self.workshopVO.titleen() != "" && self.workshopVO.titlefr() != "" && self.workshopMedias().length > 0) {
  2652.                     $('#popup-modal-saveWorkshop').attr('href', '#saveWorkshop-modal');
  2653.                     $('#popup-modal-saveWorkshopAgain').attr('href', '#saveWorkshopAgain-modal');
  2654.                     self.hasError(false);
  2655.                 } else {
  2656.                     $('#popup-modal-saveWorkshop').attr('href', '');
  2657.                     $('#popup-modal-saveWorkshopAgain').attr('href', '');
  2658.                     self.hasError(true);
  2659.                 }
  2660.             }
  2661.  
  2662.             self.saveWorkshop = function() {
  2663.                 // Due to Media Selector form control, we need to set the worshop image to observable variables
  2664.                 var workshopImage = $('.workshop-image .MediaSelector .EditingFormMediaPathTextBox').val();
  2665.                 self.workshopVO.image(workshopImage);
  2666.  
  2667.  
  2668.                 //Check to make sure an image alt text has been added if workshop image is selected
  2669.                 if (self.workshopVO.image() != "") {
  2670.  
  2671.                     if (self.workshopVO.imagealten() == "") {
  2672.                         $('.warningAltTextEn').show();
  2673.                     } else {
  2674.                         $('.warningAltTextEn').hide();
  2675.                     }
  2676.  
  2677.                     if (self.workshopVO.imagealtfr() == "") {
  2678.                         $('.warningAltTextFr').show();
  2679.                     } else {
  2680.                         $('.warningAltTextFr').hide();
  2681.                     }
  2682.  
  2683.  
  2684.                 }
  2685.  
  2686.                 // Validate form
  2687.                 ValidateForm();
  2688.  
  2689.                 if (!self.hasError()) {
  2690.                     submit(false);
  2691.                 }
  2692.  
  2693.             };
  2694.  
  2695.             self.saveAndReset = function() {
  2696.                 ValidateForm();
  2697.                 if (!self.hasError()) {
  2698.                     submit(true);
  2699.                 }
  2700.             }; // prevent user from leaving page on unsaved mode
  2701.  
  2702.             self.displayMode = function(type) {
  2703.                 // Initially "Kari" uses the "active" template, while the others use "inactive"
  2704.                 return type === "video" ? "videoTemplate" : "documentTemplate";
  2705.             }
  2706.  
  2707.             // Set the workshopMedias observable array sort order
  2708.             function SetOrder() {
  2709.                 var order = 0;
  2710.                 for (var media in self.workshopMedias()) {
  2711.                     order++;
  2712.  
  2713.                     self.workshopMedias()[media].sortorder(order);
  2714.                     var type = self.workshopMedias()[media].type();
  2715.  
  2716.                     // reset self.workshopVO video and document sort order as well
  2717.                     if (type === "video") {
  2718.                         for (var video in self.workshopVO.workshopvideos()) {
  2719.                             if (self.workshopVO.workshopvideos()[video].titleen() === self.workshopMedias()[media].titleen()) {
  2720.                                 self.workshopVO.workshopvideos()[video].sortorder(order);
  2721.                             }
  2722.                         }
  2723.                     }
  2724.                     if (type === "document") {
  2725.                         for (var document in self.workshopVO.workshopdocuments()) {
  2726.                             if (self.workshopVO.workshopdocuments()[document].filetitleen() === self.workshopMedias()[media].filetitleen()) {
  2727.                                 self.workshopVO.workshopdocuments()[document].sortorder(order);
  2728.                             }
  2729.                         }
  2730.                     }
  2731.                 }
  2732.  
  2733.             }
  2734.  
  2735.             function submit(reload) {
  2736.  
  2737.                 var workshopData = ko.toJSON(self.workshopVO);
  2738.                 // ajax call API to save asset
  2739.                 $.ajax({
  2740.                     url: "/api/workshop/",
  2741.                     type: "POST",
  2742.                     data: workshopData,
  2743.                     contentType: 'application/json',
  2744.                     cache: false,
  2745.                     processData: false,
  2746.                     success: function(data) {
  2747.                         //ko.mapping.fromJS(data.Result, viewModel);
  2748.                         if (data.Success) {
  2749.                             //viewModel.errors.showAllMessages(false);
  2750.                             if (reload) {
  2751.                                 if (addAnotherUrl != "") {
  2752.                                     $('#hrefReasonBtmAgain').attr('href', addAnotherUrl);
  2753.                                 }
  2754.                             } else {
  2755.                                 // Save and redirect to the web part setting for SaveURL property
  2756.                                 if (workshopDetailsUrl != "") {
  2757.                                     var url = workshopDetailsUrl + "?guid=" + hidWorkshopGuid;
  2758.                                     //location.href = url;
  2759.                                     $('#hrefReasonBtm').attr('href', url);
  2760.                                 }
  2761.                             }
  2762.                         } else {
  2763.                             if (data.Result.errors.length != null && data.Result.errors.length > 0) {
  2764.                                 var errors = data.Result.errors;
  2765.                                 $('.warningText.errors').remove();
  2766.                                 $.map(errors, function(error) {
  2767.                                     var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
  2768.                                     $('#page-header').after(output);
  2769.                                     $('.warningText.errors').show();
  2770.                                     $("html, body").scrollTop(0);
  2771.                                 });
  2772.                                 //var url = workshopDetailsUrl + "?guid=" + hidWorkshopGuid;
  2773.                                 //$('#hrefReasonBtm').attr('href', url);
  2774.                                 // TODO Showing Fail to store the data message in the model?
  2775.                             }
  2776.  
  2777.                         }
  2778.                     }, //IF PROBLEM WITH AJAX CALL
  2779.                     error: function(data) {
  2780.                         // TODO Shwoing Generic System error message in the model.
  2781.                     }
  2782.  
  2783.                 });
  2784.             }
  2785.  
  2786.         };
  2787.  
  2788.         //Initialize ModuleLookup for dropdown, call back will do viewmodel binding
  2789.         $.ajax({
  2790.             type: 'GET',
  2791.             contentType: 'application/json',
  2792.             url: "/api/lookupdata?culture=" + lang + "&classname=BuildON.WorkshopModule",
  2793.             async: false,
  2794.             success: function (data) {
  2795.                 if (data.Success && data.Result != null) {
  2796.                     // VieModel Binding
  2797.                     var moduleLookup = data.Result;
  2798.                     var viewModel = new workshopViewModle(moduleLookup);
  2799.                     ko.applyBindings(viewModel);
  2800.                     $('#popup-modal-saveWorkshop').magnificPopup();
  2801.                     $('#popup-modal-saveWorkshopAgain').magnificPopup();
  2802.                 }
  2803.             },
  2804.             error: function () {
  2805.                 //TODO error handler?
  2806.             }
  2807.         });
  2808.     };
  2809.     if ($('.addEditWorkshops').html() != undefined) { buildON.addEditWorkshop(); }
  2810.  
  2811.     //Co-ordinator Unassigned cases
  2812.     buildON.coordinatorUnassignedCases = function () {
  2813.  
  2814.         var casesViewModel = function() {
  2815.  
  2816.             var self = this;
  2817.             self.preferLangLookup = ko.observableArray([]);
  2818.             self.countriesLookup = ko.observableArray([]);
  2819.             self.immigrationStatusLookup = ko.observableArray([]);
  2820.  
  2821.             var overviewUrl = $('#hidCaseUserDetailsUrl').val();
  2822.             self.caseoverview = ko.observable(overviewUrl);
  2823.  
  2824.             // initial look up table
  2825.             $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
  2826.                 if (data.Result != null) {
  2827.  
  2828.                     var countryItem = FindItemByKey("BuildON.OriginCountry", data.Result);
  2829.                     if (countryItem != undefined && countryItem != null) {
  2830.                         self.countriesLookup(countryItem[0].Data);
  2831.                     }
  2832.  
  2833.                     var statusItem = FindItemByKey("BuildON.ImmigrationStatus", data.Result);
  2834.                     if (statusItem != undefined && statusItem != null) {
  2835.                         self.immigrationStatusLookup(statusItem[0].Data);
  2836.                     }
  2837.  
  2838.                     var preferLangItem = FindItemByKey("BuildON.PreferredLanguage", data.Result);
  2839.                     if (preferLangItem != undefined && preferLangItem != null) {
  2840.                         self.preferLangLookup(preferLangItem[0].Data);
  2841.                     }
  2842.  
  2843.                 }
  2844.                 $('.popup-modal-assignCase').magnificPopup();
  2845.             });
  2846.  
  2847.  
  2848.  
  2849.             self.cases = ko.observableArray([]);
  2850.             self.isReady = ko.observable(false);
  2851.             self.assignedCounciler = ko.observable();
  2852.  
  2853.             self.GetImmigrationStatus = function (guid) {
  2854.                 return FindItemByGuid(guid, self.immigrationStatusLookup());
  2855.             };
  2856.             self.GetLanguage = function (guid) {
  2857.                 return FindItemByGuid(guid, self.preferLangLookup());
  2858.             };
  2859.             self.GetOriginCountry = function (guid) {
  2860.                 return FindItemByGuid(guid, self.countriesLookup());
  2861.             };
  2862.  
  2863.             //Initialize
  2864.             $.ajax({
  2865.                 type: 'GET',
  2866.                 contentType: 'application/json',
  2867.                 url: "/api/ClientUserCases?assigned=false",
  2868.                 async: false,
  2869.                 success: function(data) {
  2870.                     $('.popup-modal-assignCase').magnificPopup();
  2871.                     if (data.Success && data.Result != null) {
  2872.                         ko.utils.arrayForEach(data.Result, function(entry) {
  2873.                             self.cases.push(entry);
  2874.                         });
  2875.                         self.isReady(true);
  2876.                     }
  2877.                 },
  2878.                 error: function() {
  2879.                     //TODO error handler?
  2880.                 }
  2881.  
  2882.             });
  2883.  
  2884.             self.dismissModal = function() {
  2885.                 setTimeout(function(){ location.reload(); }, 300);
  2886.             };
  2887.  
  2888.             // TODO implement method for Assign Case
  2889.             self.AssignCase = function(id, ecid) {
  2890.                 // API url for assign: /api/clientusercases?id=17&ecid=70
  2891.                 var selectedId = this.id;
  2892.  
  2893.                 $.ajax({
  2894.                     type: 'GET',
  2895.                     contentType: 'application/json',
  2896.                     url: "/api/clientusercases?clientUserId=" + selectedId + "&ecid=" + self.assignedCounciler(),
  2897.                     async: false,
  2898.                     success: function(data) {
  2899.                         if (data.Success && data.Result != null) {
  2900.                             // Get the id, then check the self.case to remove the case
  2901.                             $.each(self.cases(), function(index, obj){
  2902.                                 if(this['id'] == data.Result.id){
  2903.                                     self.cases().splice(index, 1);
  2904.                                     $('.popup-modal-assignCase').magnificPopup('open');
  2905.                                     //setTimeout(function(){ location.reload(); }, 500);
  2906.                                 }
  2907.                             });
  2908.                         }
  2909.                     },
  2910.                     error: function() {
  2911.                         //TODO error handler?
  2912.                         var errors = data.Result.errors;
  2913.  
  2914.                         $('.warningText.errors').remove();
  2915.                         $.map(errors, function (error) {
  2916.                             var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
  2917.                             $('.case-title').after(output);
  2918.                         });
  2919.  
  2920.                     }
  2921.                 });
  2922.             }
  2923.             self.assignedCounciler.subscribe(function(newValue) {
  2924.                 // API url for assign: /api/clientusercases?id=17&ecid=70
  2925.                 self.assignedCounciler(newValue);
  2926.             });
  2927.         };
  2928.  
  2929.         // VieModel Binding
  2930.         var viewModel = new casesViewModel();
  2931.         ko.applyBindings(viewModel);
  2932.     };
  2933.     if ($('#Coordinator-Unassigned-Cases').html() != undefined) {
  2934.         buildON.coordinatorUnassignedCases();
  2935.     }
  2936.  
  2937.     buildON.coordinatorAssignedCases = function () {
  2938.  
  2939.         var casesViewModel = function () {
  2940.  
  2941.             var self = this;
  2942.             self.preferLangLookup = ko.observableArray([]);
  2943.             self.countriesLookup = ko.observableArray([]);
  2944.             self.immigrationStatusLookup = ko.observableArray([]);
  2945.  
  2946.             var overviewUrl = $('#hidCaseUserDetailsUrl').val();
  2947.             self.caseoverview = ko.observable(overviewUrl);
  2948.  
  2949.             // initial look up table
  2950.             $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
  2951.                 if (data.Result != null) {
  2952.  
  2953.                     var countryItem = FindItemByKey("BuildON.OriginCountry", data.Result);
  2954.                     if (countryItem != undefined && countryItem != null) {
  2955.                         self.countriesLookup(countryItem[0].Data);
  2956.                     }
  2957.  
  2958.                     var statusItem = FindItemByKey("BuildON.ImmigrationStatus", data.Result);
  2959.                     if (statusItem != undefined && statusItem != null) {
  2960.                         self.immigrationStatusLookup(statusItem[0].Data);
  2961.                     }
  2962.  
  2963.                     var preferLangItem = FindItemByKey("BuildON.PreferredLanguage", data.Result);
  2964.                     if (preferLangItem != undefined && preferLangItem != null) {
  2965.                         self.preferLangLookup(preferLangItem[0].Data);
  2966.                     }
  2967.  
  2968.                 }
  2969.  
  2970.                 $('.popup-modal-unassignCase').magnificPopup();
  2971.                 $('.popup-modal-assignCase').magnificPopup();
  2972.             });
  2973.  
  2974.             self.cases = ko.observableArray([]);
  2975.             self.isReady = ko.observable(false);
  2976.             self.assignedCounciler = ko.observable();
  2977.  
  2978.             self.GetImmigrationStatus = function (guid) {
  2979.                 return FindItemByGuid(guid, self.immigrationStatusLookup());
  2980.             };
  2981.             self.GetLanguage = function (guid) {
  2982.                 return FindItemByGuid(guid, self.preferLangLookup());
  2983.             };
  2984.             self.GetOriginCountry = function (guid) {
  2985.                 return FindItemByGuid(guid, self.countriesLookup());
  2986.             };
  2987.  
  2988.             //Initialize
  2989.             $.ajax({
  2990.                 type: 'GET',
  2991.                 contentType: 'application/json',
  2992.                 url: "/api/ClientUserCases?assigned=true",
  2993.                 async: false,
  2994.                 success: function (data) {
  2995.                     if (data.Success && data.Result != null) {
  2996.                         ko.utils.arrayForEach(data.Result, function (entry) {
  2997.                             self.cases.push(entry);
  2998.                         });
  2999.                         $('.popup-modal-unassignCase').magnificPopup();
  3000.                         $('.popup-modal-assignCase').magnificPopup();
  3001.                         self.isReady(true);
  3002.                     }
  3003.                     $('.popup-modal-unassignCase').magnificPopup();
  3004.                     $('.popup-modal-assignCase').magnificPopup();
  3005.                 },
  3006.                 error: function () {
  3007.                     //TODO error handler?
  3008.                 }
  3009.             });
  3010.  
  3011.             self.dismissModal = function() {
  3012.                 setTimeout(function(){ location.reload(); }, 300);
  3013.             };
  3014.  
  3015.             self.unassignCase = function(id, ecid){
  3016.                 var selectedId = this.id;
  3017.  
  3018.                 $.ajax({
  3019.                     type: 'GET',
  3020.                     contentType: 'application/json',
  3021.                     url: "/api/clientusercases?clientUserId=" + selectedId + "&ecid=0",
  3022.                     async: false,
  3023.                     success: function(data) {
  3024.                         if (data.Success && data.Result != null) {
  3025.                             $('.popup-modal-unassignCase').attr('href', '#unassignCase-modal');
  3026.                             $('.popup-modal-unassignCase').magnificPopup('open');
  3027.                         }
  3028.                     },
  3029.                     error: function() {
  3030.                         //TODO error handler?
  3031.                         var errors = data.Result.errors;
  3032.  
  3033.                         $('.warningText.errors').remove();
  3034.                         $.map(errors, function (error) {
  3035.                             var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
  3036.                             $('.case-title').after(output);
  3037.                         });
  3038.  
  3039.                     }
  3040.                 });
  3041.             };
  3042.  
  3043.             // TODO implement method for Assign Case
  3044.             self.AssignCase = function(id, ecid) {
  3045.                 // API url for assign: /api/clientusercases?id=17&ecid=70
  3046.                 var selectedId = this.id;
  3047.  
  3048.                 $.ajax({
  3049.                     type: 'GET',
  3050.                     contentType: 'application/json',
  3051.                     url: "/api/clientusercases?clientUserId=" + selectedId + "&ecid=" + self.assignedCounciler(),
  3052.                     async: false,
  3053.                     success: function(data) {
  3054.                         if (data.Success && data.Result != null) {
  3055.                             $('.popup-modal-assignCase').magnificPopup('open');
  3056.                         }
  3057.                     },
  3058.                     error: function() {
  3059.                         //TODO error handler?
  3060.                         var errors = data.Result.errors;
  3061.  
  3062.                         $('.warningText.errors').remove();
  3063.                         $.map(errors, function (error) {
  3064.                             var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
  3065.                             $('.case-title').after(output);
  3066.                         });
  3067.  
  3068.                     }
  3069.                 });
  3070.             };
  3071.  
  3072.             self.assignedCounciler.subscribe(function(newValue) {
  3073.                 // API url for assign: /api/clientusercases?id=17&ecid=70
  3074.                 self.assignedCounciler(newValue);
  3075.             });
  3076.  
  3077.         };
  3078.  
  3079.         // VieModel Binding
  3080.         var viewModel = new casesViewModel();
  3081.         ko.applyBindings(viewModel);
  3082.     };
  3083.     if ($('#Coordinator-Assigned-Cases').html() != undefined) {
  3084.         buildON.coordinatorAssignedCases();
  3085.         $('.popup-modal-unassignCase').magnificPopup();
  3086.         $('.popup-modal-assignCase').magnificPopup();
  3087.     }
  3088.  
  3089.     // Workshop library
  3090.     buildON.workshopLibrary = function () {
  3091.         $('.workshop-tile').click(function () {
  3092.             var isMobile = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/);
  3093.             if (isMobile != null) {
  3094.                 // TODO: if markup changes, this functionality needs to be updated
  3095.                 window.location = this.children[2].children[2].children[0].href;
  3096.             } else {
  3097.                 return;
  3098.             }
  3099.         });
  3100.     };
  3101.     buildON.workshopLibrary();
  3102.  
  3103.     // Workshop details
  3104.     buildON.workshopDetails = function () {
  3105.         var workshopViewModel = function () {
  3106.             var self = this;
  3107.  
  3108.             var deleteRedirectUrl = $('#hidDeleteUrl') != undefined ? $('#hidDeleteUrl').val() : "";
  3109.             var workshopGuid = $('#hidWorkshopGuid') != undefined ? $('#hidWorkshopGuid').val() : "";
  3110.  
  3111.             // Initialize workshopVO with MAPPING - will be used for workshop elements data-bind
  3112.             var isReady = false;
  3113.             self.workshopVO = ko.mapping.fromJS([]);
  3114.  
  3115.             var getUrl = "/api/Workshop?guid=" + workshopGuid;
  3116.             $.ajax({
  3117.                 type: 'GET',
  3118.                 contentType: 'application/json',
  3119.                 url: getUrl,
  3120.                 async: false,
  3121.                 success: function (data) {
  3122.                     if (data.Success && data.Result != null) {
  3123.                         if (data.Result.id == 0) {
  3124.                             //location.href = errorUrl;
  3125.                         } else {
  3126.                             self.workshopVO = ko.mapping.fromJS(data.Result);
  3127.                             isReady = self.workshopVO != undefined ? true : false;
  3128.                         }
  3129.                     } else {
  3130.                         // redirect to Error page
  3131.                         //location.href = errorUrl;
  3132.                     }
  3133.                 },
  3134.                 error: function () {
  3135.                     //
  3136.                 }
  3137.             });
  3138.  
  3139.             // Delete Workshop
  3140.             self.showDeleteConfirmation = ko.observable(true);
  3141.             self.showDeleteSuccess = ko.observable(false);
  3142.             self.showDeleteFail = ko.observable(false);
  3143.             self.deleteWorkshop = function() {
  3144.                 var strDeleteUrl = "/api/Workshop?GUID=" + workshopGuid;
  3145.                 $.ajax({
  3146.                     url: strDeleteUrl,
  3147.                     type: 'DELETE',
  3148.                     success: function(data) {
  3149.                         // Do something after successful delete
  3150.                         self.showDeleteSuccess(true);
  3151.                         if (data.Success) {
  3152.                             self.showDeleteSuccess(true);
  3153.                             $('.hrefReasonBtm').attr('href', deleteRedirectUrl);
  3154.  
  3155.                         } else {
  3156.                             // Fail to delete
  3157.                             self.showDeleteSuccess(false);
  3158.                         }
  3159.                     },
  3160.                     error: function(data) {
  3161.                         self.showDeleteSuccess(false);
  3162.                     },
  3163.  
  3164.                 });
  3165.             };
  3166.         };
  3167.  
  3168.         // VieModel Binding
  3169.         var viewModel = new workshopViewModel();
  3170.         ko.applyBindings(viewModel);
  3171.     };
  3172.     if ($('#workshop-details').html() != undefined) { buildON.workshopDetails(); }
  3173.     $('#popup-modal-removeWorkshop').magnificPopup();
  3174.  
  3175.  
  3176.     // My Cases
  3177.     buildON.myCases = function () {
  3178.         var myCasesViewModel = function () {
  3179.             var self = this;
  3180.             var overviewUrl = $('#hidCaseUserDetailsUrl').val();
  3181.             self.caseoverview = ko.observable(overviewUrl);
  3182.             self.preferLangLookup = ko.observableArray([]);
  3183.             self.countriesLookup = ko.observableArray([]);
  3184.             self.immigrationStatusLookup = ko.observableArray([]);
  3185.  
  3186.             // initial look up table
  3187.             $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
  3188.                 if (data.Result != null) {
  3189.  
  3190.                     var countryItem = FindItemByKey("BuildON.OriginCountry", data.Result);
  3191.                     if (countryItem != undefined && countryItem != null) {
  3192.                         self.countriesLookup(countryItem[0].Data);
  3193.                     }
  3194.  
  3195.                     var statusItem = FindItemByKey("BuildON.ImmigrationStatus", data.Result);
  3196.                     if (statusItem != undefined && statusItem != null) {
  3197.                         self.immigrationStatusLookup(statusItem[0].Data);
  3198.                     }
  3199.  
  3200.                     var preferLangItem = FindItemByKey("BuildON.PreferredLanguage", data.Result);
  3201.                     if (preferLangItem != undefined && preferLangItem != null) {
  3202.                         self.preferLangLookup(preferLangItem[0].Data);
  3203.                     }
  3204.  
  3205.                 }
  3206.             });
  3207.  
  3208.             self.cases = ko.observableArray([]);
  3209.  
  3210.             self.GetImmigrationStatus = function (guid) {
  3211.                 return FindItemByGuid(guid, self.immigrationStatusLookup());
  3212.             };
  3213.             self.GetLanguage = function (guid) {
  3214.                 return FindItemByGuid(guid, self.preferLangLookup());
  3215.             };
  3216.             self.GetOriginCountry = function (guid) {
  3217.                 return FindItemByGuid(guid, self.countriesLookup());
  3218.             };
  3219.  
  3220.             //Initialize
  3221.             $.ajax({
  3222.                 type: 'GET',
  3223.                 contentType: 'application/json',
  3224.                 url: "/api/ClientUserCases/GetMyCase?id=" + userid,
  3225.                 async: false,
  3226.                 success: function (data) {
  3227.                     if (data.Success && data.Result != null) {
  3228.                         ko.utils.arrayForEach(data.Result, function (entry) {
  3229.                             self.cases.push(entry);
  3230.                         });
  3231.  
  3232.                     }
  3233.                 },
  3234.                 error: function () {
  3235.                     //TODO error handler?
  3236.                 }
  3237.             });
  3238.         };
  3239.  
  3240.         // VieModel Binding
  3241.         var viewModel = new myCasesViewModel();
  3242.         ko.applyBindings(viewModel);
  3243.  
  3244.     };
  3245.     if ($('#my-cases').html() != undefined) { buildON.myCases(); }
  3246.  
  3247. }(jQuery));
  3248.  
  3249.  
  3250. $(window).on('resize', function () {
  3251.     // hide autocomplete dropdown on resize
  3252.     $(".ui-autocomplete").css('display', 'none');
  3253. });
  3254.  
  3255. // custom select box styling
  3256. // call for update panel refresh
  3257. $(function pageLoad(sender, args) {
  3258.     $('.select-item select').customSelect();
  3259. });
  3260.  
  3261. // reCaptcha
  3262. var captchaValid = false;
  3263.  
  3264. function captchaCallback() {
  3265.     captchaValid = true;
  3266. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement