Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2016
116
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.     // site current culture
  8.     var lang = "en-CA";
  9.     ($('#lng') != null && $('#lng').val() != "") ? lang = $('#lng').val() : "en-CA";
  10.  
  11.  
  12.     buildON.options = {
  13.         mobileWidth: 768
  14.     };
  15.  
  16.     //until funcitons
  17.     function FindItemByKey(key, arrayData) {
  18.         var findItem = $.grep(arrayData, function (e) {
  19.             return e.Key == key;
  20.         });
  21.         console.log(key + ":");
  22.         console.log(findItem);
  23.         return findItem;
  24.     }
  25.     /*function FindItemByGuid(guid, arrayData) {
  26.         if (guid != "" && guid != undefined){
  27.             var result = $.grep(arrayData, function (e) { return e.ItemGuid == guid; });
  28.             if (result.length > 0) {
  29.                 return result[0].Name;
  30.             }
  31.         }
  32.         return guid;
  33.     }*/
  34.  
  35.     function FindItemByGuid(guid, arrayData) {
  36.         var stringName = "";
  37.         console.log(typeof(guid));
  38.  
  39.         /*if (guid != "" && guid != undefined){
  40.             var arrGuid = guid.split(",");
  41.  
  42.             for (i = 0; i < arrGuid.length; i++) {
  43.                 var result = $.grep(arrayData, function (e) { return e.ItemGuid == arrGuid[i]; });
  44.                 if (result.length > 0) {
  45.                     stringName += result[0].Name + ", ";
  46.                 }
  47.             }
  48.         }*/        
  49.  
  50.         return stringName;
  51.     }
  52.  
  53.  
  54.     // ADOBE ACCESSIBLE MEGA MENU
  55.     var isAccessibleFlag = false;
  56.     buildON.accessibleNav = function () {
  57.         if ($(window).width() > buildON.options.mobileWidth && !isAccessibleFlag) {
  58.             /**
  59.             * Wrap accessibleMegaMenu() in window.width()
  60.             * 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.
  61.             * If user resizes screen the nav is borked.
  62.             */
  63.  
  64.             // initialize the megamenu
  65.             $('.pri-nav nav').accessibleMegaMenu();
  66.  
  67.             $('.pri-nav.desktop .search.nav-item a').click(function (e) {
  68.                 e.preventDefault();
  69.                 $('.pri-nav.desktop .search.nav-item').toggleClass('expanded');
  70.             });
  71.  
  72.             // right-align last nav item that isn't search or donate
  73.             $('.pri-nav.desktop ul.nav-menu > li').slice(-3).addClass('last-items');
  74.  
  75.             // hack so that the megamenu doesn't show flash of css animation after the page loads.
  76.             setTimeout(function () {
  77.                 $('body').removeClass('init');
  78.             }, 500);
  79.             isAccessibleFlag = true;
  80.  
  81.             // hack for tablets
  82.             if ($("html").hasClass("mod-touch")) {
  83.                 $(".desktop .accessible-megamenu-top-nav-item").not($(".search")).each(function () {
  84.                     var link = $(this).find("> a[aria-haspopup='true']");
  85.                     if (link.length) {
  86.                         // get page language
  87.                         var lang = $('html')[0].lang;
  88.                         var overviewText = " Overview";
  89.                         // To do: get french translation for "overview"
  90.                         /*
  91.                         if (lang == "fr") {
  92.                           overviewText = "french overview";
  93.                         }
  94.                         */
  95.                         $(link).clone().prependTo($(this).find("ul")).wrap("<li></li>").append(overviewText);
  96.                     }
  97.                 });
  98.             }
  99.  
  100.  
  101.  
  102.  
  103.             /** hide search on click outside of search box
  104.              * http://benalman.com/code/projects/jquery-outside-events/examples/clickoutside/
  105.              */
  106.  
  107.             // elements on which to bind the event
  108.             var elems = $(".pri-nav.desktop .search.nav-item");
  109.  
  110.             // Clear any previous highlights
  111.             $(document)
  112.               .bind('click', function (event) {
  113.                   elems
  114.                     //.removeClass( 'event-outside' )
  115.                     .children('a');
  116.               })
  117.               .trigger('click');
  118.  
  119.             // Bind the 'clickoutside' event to each test element
  120.             elems.bind('clickoutside', function (event) {
  121.                 var elem = $(this),
  122.                 target = $(event.target);
  123.  
  124.                 // Highlight this element
  125.                 elem
  126.                   //.addClass( 'event-outside' )
  127.                   .removeClass('expanded')
  128.                   .children('a');
  129.             });
  130.  
  131.         }
  132.     };
  133.     buildON.accessibleNav();
  134.  
  135.  
  136.  
  137.     // TABS
  138.     buildON.tabs = function () {
  139.         $('ul.tabs li').click(function () {
  140.             var tab_id = $(this).attr('data-tab');
  141.             $('ul.tabs li').removeClass('current');
  142.             $('.tab-content').removeClass('current');
  143.             $(this).addClass('current');
  144.             $("#" + tab_id).addClass('current');
  145.             $('ul.tabs').removeClass('open');
  146.         });
  147.  
  148.         // My dashboard nav dropdown on header change button colour
  149.         $('.dashboard-nav').hover(function () {
  150.             $('ul.dashboard-nav-menu').toggleClass('open');
  151.             $('.dashboard-nav .btn').toggleClass('dashboard-nav-btn-reverse');
  152.         });
  153.  
  154.         // Click on my workshops, profile, education etc.
  155.         $('.dashboard-nav-menu li a').click(function () {
  156.  
  157.             if ((this).href.indexOf('#t1') > -1) {
  158.                 //e.preventDefault();
  159.                 var tab_id = $('ul.tabs li').attr('data-tab');
  160.                 $('.tab-content').removeClass('current');
  161.                 $('.tab-link').removeClass('current');
  162.                 $('#t1').addClass('current');
  163.                 $('#navChecklist').addClass('current');
  164.                 $('html,body').animate({ scrollTop: 0 }, 100);
  165.             }
  166.  
  167.             if ((this).href.indexOf('#t2') > -1) {
  168.                 //e.preventDefault();
  169.                 var tab_id = $('ul.tabs li').attr('data-tab');
  170.                 $('.tab-content').removeClass('current');
  171.                 $('.tab-link').removeClass('current');
  172.                 $('#t2').addClass('current');
  173.                 $('#navProfile').addClass('current');
  174.                 $('html,body').animate({ scrollTop: 0 }, 100);
  175.             }
  176.  
  177.             if ((this).href.indexOf('#t3') > -1) {
  178.                 //e.preventDefault();
  179.                 var tab_id = $('ul.tabs li').attr('data-tab');
  180.                 $('.tab-content').removeClass('current');
  181.                 $('.tab-link').removeClass('current');
  182.                 $('#t3').addClass('current');
  183.                 $('#navEmploymentHistory').addClass('current');
  184.                 $('html,body').animate({ scrollTop: 0 }, 100);
  185.             }
  186.  
  187.             if ((this).href.indexOf('#t4') > -1) {
  188.                 //e.preventDefault();
  189.                 var tab_id = $('ul.tabs li').attr('data-tab');
  190.                 $('.tab-content').removeClass('current');
  191.                 $('.tab-link').removeClass('current');
  192.                 $('#t4').addClass('current');
  193.                 $('#navEducation').addClass('current');
  194.                 $('html,body').animate({ scrollTop: 0 }, 100);
  195.             }
  196.  
  197.             if ((this).href.indexOf('#t5') > -1) {
  198.                 //e.preventDefault();
  199.                 var tab_id = $('ul.tabs li').attr('data-tab');
  200.                 $('.tab-content').removeClass('current');
  201.                 $('.tab-link').removeClass('current');
  202.                 $('#t5').addClass('current');
  203.                 $('#navAchievements').addClass('current');
  204.                 $('html,body').animate({ scrollTop: 0 }, 100);
  205.             }
  206.  
  207.  
  208.         });
  209.  
  210.  
  211.  
  212.  
  213.     };
  214.     buildON.tabs();
  215.  
  216.     // tabs dropdown on mobile
  217.     buildON.tabsMobileDD = function () {
  218.         $('.tabs-mobile').click(function (e) {
  219.             e.preventDefault();
  220.             $('ul.tabs').toggleClass('open');
  221.         });
  222.     };
  223.     buildON.tabsMobileDD();
  224.  
  225.     // EQUAL HEIGHTS - MATCH HEIGHT PLUGIN
  226.     buildON.equalHeights = function () {
  227.         $(".cta-list a").matchHeight();
  228.         $(".grid-list a").matchHeight();
  229.         $(".logo-donate > div").matchHeight();
  230.         $(".band .cta").matchHeight();
  231.         $(".row .cta").matchHeight();
  232.         $(".story-list a").matchHeight();
  233.         $(".schedule-grid.week > ul > li").matchHeight();
  234.         $(".schedule-grid.week .grid-blocks").matchHeight(false);
  235.         $(".schedule-grid.day .block").matchHeight();
  236.         $(".program-category-block").matchHeight();
  237.         $(".col.border-left").matchHeight();
  238.  
  239.         // set min heights for col-match columns so accordion content doesn't get hidden
  240.         if (matchMedia('only screen and (min-width: 992px)').matches) {
  241.             var mainColHeight = $(".col-match.main-col").height();
  242.             var sideColHeight = $(".col-match.side-col").height();
  243.             $(".col-match.side-col .inner").css("min-height", mainColHeight);
  244.             $(".col-match.main-col").css("min-height", sideColHeight);
  245.         }
  246.  
  247.     };
  248.     buildON.equalHeights();
  249.  
  250.  
  251.     // TRUNCATE
  252.     buildON.truncate = function () {
  253.         $('.workshop-title').dotdotdot({
  254.             ellipsis: '...',
  255.             watch: true,
  256.             height: 35
  257.         });
  258.         $('.workshop-description').dotdotdot({
  259.             ellipsis: '...',
  260.             watch: true,
  261.             height: 100
  262.         });
  263.     };
  264.     buildON.truncate();
  265.  
  266.  
  267.     // FILE UPLOADER
  268.     buildON.fileUploader = function () {
  269.         $(document).on('change', '.btn-file :file', function () {
  270.             var input = $(this),
  271.                 numFiles = input.get(0).files ? input.get(0).files.length : 1,
  272.                 label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
  273.             input.trigger('fileselect', [numFiles, label]);
  274.         });
  275.  
  276.         $(document).ready(function () {
  277.             $('.btn-file :file').on('fileselect', function (event, numFiles, label) {
  278.  
  279.                 var input = $(this).parents('.input-group').find(':text'),
  280.                     log = numFiles > 1 ? numFiles + ' files selected' : label;
  281.  
  282.                 if (input.length) {
  283.                     input.val(log);
  284.                 } else {
  285.                     if (log) alert(log);
  286.                 }
  287.  
  288.             });
  289.         });
  290.     };
  291.     buildON.fileUploader();
  292.  
  293.     // MOBILE NAV
  294.     buildON.mobileNav = function () {
  295.         var siteWrap = ".site-wrap",
  296.             siteWrapHeight = $(siteWrap).outerHeight(),
  297.             nav = ".pri-nav",
  298.             navMobile = nav + '.mobile',
  299.             navDesktop = nav + '.desktop',
  300.             navMobileContainer = "#mobile-nav-container",
  301.             navMobileToggle = "#mobile-nav-toggle",
  302.             navMobileLength = $(navMobile).length,
  303.             navMobileLastItem = navMobile + ' li:last-child a';
  304.  
  305.         var openMobileNav = function () {
  306.             $('body').addClass('mobile-nav-open');
  307.         },
  308.           closeMobileNav = function () {
  309.               $('body').removeClass('mobile-nav-open');
  310.           },
  311.           toggleMobileNav = function () {
  312.               if (!$('body').hasClass('mobile-nav-open')) {
  313.                   openMobileNav();
  314.               } else {
  315.                   closeMobileNav();
  316.               }
  317.           };
  318.         $(navMobileToggle).click(function (e) {
  319.             e.preventDefault();
  320.             // show/hide the nav
  321.             toggleMobileNav();
  322.         });
  323.  
  324.         // close mobile nav on click outside the nav
  325.         $(siteWrap).click(function () {
  326.             if ($('body').hasClass('mobile-nav-open')) {
  327.                 //closeMobileNav();
  328.             }
  329.         });
  330.  
  331.         // close nav when last nav item loses focus
  332.         $(navMobileLastItem).focusout(function () {
  333.             closeMobileNav();
  334.         });
  335.  
  336.         // set nav height to viewport height
  337.         // and recalculate on orientation change.
  338.         $(navMobile).css('height', $(window).innerHeight());
  339.         window.addEventListener("orientationchange", function () {
  340.             $(navMobile).css('height', $(window).innerHeight());
  341.         }, false);
  342.  
  343.         // fix bug introduced by twitter feed widget
  344.         $('#twttrHubFrame').attr('tabindex', '-1');
  345.  
  346.     };
  347.     buildON.mobileNav();
  348.  
  349.  
  350.     // MOBILE SECONDARY NAV
  351.     buildON.mobileSecNav = function () {
  352.         $(".sec-nav-toggle").click(function (e) {
  353.             e.preventDefault();
  354.             $(".secondary-nav ul").slideToggle();
  355.         });
  356.         $(".sec-nav-content-toggle").click(function (e) {
  357.             e.preventDefault();
  358.             $("#contet-page-nav").toggleClass("open");
  359.         });
  360.     };
  361.     buildON.mobileSecNav();
  362.  
  363.     // DESKTOP SECONDARY NAV
  364.     buildON.secNav = function () {
  365.         $('.secondary-nav').find('ul').parent().addClass('has-children');
  366.     };
  367.     buildON.secNav();
  368.  
  369.  
  370.     // HELPERS
  371.  
  372.     /** for each element that is classed as 'pull-down',
  373.      *  set its margin-top to the difference between its own height
  374.      *  and the height of its parent
  375.      */
  376.     buildON.pullDown = function () {
  377.         $('.pull-down').each(function () {
  378.             $(this).css('margin-top', $(this).parent().height() - $(this).height());
  379.         });
  380.     };
  381.     buildON.pullDown();
  382.  
  383.     // IFRAME Z-INDEX FIX
  384.     buildON.fixIframeZindex = function () {
  385.         $("iframe").each(function () {
  386.             var ifr_source = $(this).attr('src');
  387.             if (typeof ifr_source !== "undefined") {
  388.                 var wmode = "wmode=transparent";
  389.                 if (ifr_source.indexOf('?') != -1) $(this).attr('src', ifr_source + '&' + wmode);
  390.                 else $(this).attr('src', ifr_source + '?' + wmode);
  391.             }
  392.         });
  393.     };
  394.  
  395.     //Magnific Popup Modal
  396.     buildON.magnificPopup = function () {
  397.         // uci# tooltip modal
  398.         $('.popup-modal-uci').magnificPopup();
  399.         // step2 not qualified modal
  400.         //$('#popup-modal-notQualified').magnificPopup();
  401.         // remove education history modal
  402.         //$('.popup-modal-removeEducationHistory').magnificPopup();
  403.         // remove work history modal
  404.         //$('.popup-modal-removeWorkHistory').magnificPopup();
  405.  
  406.         $(document).on('click', '.popup-modal-dismiss', function (e) {
  407.             $.magnificPopup.close();
  408.         });
  409.     };
  410.     buildON.magnificPopup();
  411.  
  412.     // Registration form
  413.     buildON.registrationForm = function () {
  414.         //Education Info Constructor
  415.         function EducationInfo() {
  416.             this.educationLevel = ko.observable();
  417.             this.schoolName = ko.observable();
  418.             this.completed = ko.observable();
  419.             this.startDate = ko.observable();
  420.             this.endDate = ko.observable();
  421.         };
  422.  
  423.         function LangTesting() {
  424.             this.langTest1 = ko.observable(false);
  425.             this.langTest2 = ko.observable(false);
  426.             this.langTest3 = ko.observable(false);
  427.         };
  428.  
  429.         function WorkTesting() {
  430.             this.jobOffer = ko.observable(false);
  431.             this.collegeOfTrades = ko.observable();
  432.             this.canadaApprenticeProcess = ko.observable();
  433.  
  434.             this.choice1 = ko.observable();
  435.             this.choice2 = ko.observable();
  436.             this.choice3 = ko.observable();
  437.             this.choice4 = ko.observable();
  438.         };
  439.  
  440.         //Work Info Constructor
  441.         function WorkInfo() {
  442.             this.workTitle = ko.observable();
  443.             this.workName = ko.observable();
  444.             this.typeOfWork = ko.observableArray([]);
  445.             this.yearsExp = ko.observable();
  446.             this.countryOfEmployment = ko.observable();
  447.             this.jobOffer = ko.observable();
  448.  
  449.         };
  450.  
  451.         //User Meta data constructor
  452.         function Meta() {
  453.             this.culture = ko.observable('en-CA');
  454.             this.displayStep1 = ko.observable(true);
  455.             this.displayStep2 = ko.observable(false);
  456.             this.displayStep3 = ko.observable(false);
  457.             this.displayStep4 = ko.observable(false);
  458.             this.displayStep5 = ko.observable(false);
  459.             this.displayStep6 = ko.observable(false);
  460.         }
  461.  
  462.         //User Constructor
  463.         function User() {
  464.             this.firstName = ko.observable();
  465.             this.lastName = ko.observable();
  466.             this.email = ko.observable();
  467.             this.skype = ko.observable();
  468.             this.birthday = ko.observable();
  469.             this.preferredLanguage = ko.observable();
  470.             this.tradeInterest = ko.observable();
  471.             this.consentRegistration = ko.observable();
  472.             this.approvedImmigrate = ko.observable();
  473.             this.originCountry = ko.observable();
  474.             this.immigrateOntario = ko.observable();
  475.             this.livingOutsideCanada = ko.observable();
  476.             this.tradesKnowledge = ko.observable();
  477.             this.referal = ko.observable();
  478.             this.username = ko.observable();
  479.             this.password = ko.observable();
  480.             this.uciNumber = ko.observable();
  481.             this.gender = ko.observable();
  482.             this.immigrationStatus = ko.observable();
  483.             this.consentResearch = ko.observable();
  484.             this.driversLicense = ko.observable();
  485.  
  486.             this.workHistory = ko.observableArray([]);
  487.             this.educationHistory = ko.observableArray([]);
  488.  
  489.             this.id = ko.observable(null);
  490.             this.guid = ko.observable('guid');
  491.  
  492.             this.englishTesting = ko.observable(new LangTesting());
  493.             this.frenchTesting = ko.observable(new LangTesting());
  494.             this.workTesting = ko.observable(new WorkTesting());
  495.  
  496.         };
  497.  
  498.         //Main Knockout View Model
  499.         var AppViewModel = function () {
  500.             var self = this;
  501.  
  502.             //Custom table Lookup Data init
  503.             self.tradesLookup = ko.observableArray([]);
  504.             self.countriesLookup = ko.observableArray([]);
  505.             self.educationLookup = ko.observableArray([]);
  506.             self.englishSkillsLookup = ko.observableArray([]);
  507.             self.frenchSkillsLookup = ko.observableArray([]);
  508.             self.immigrationStatusLookup = ko.observableArray([]);
  509.             self.servicesLookup = ko.observableArray([]);
  510.             self.yearsOfExperienceLookup = ko.observableArray([]);
  511.             self.typeOfWorkLookup = ko.observableArray([]);
  512.             self.familiarLevelLookup = ko.observableArray([]);
  513.             self.preferLangLookup = ko.observableArray([]);
  514.             self.genderLookup = ko.observableArray([]);
  515.  
  516.             $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
  517.                 if (data.Result != null) {
  518.                     console.log(data.Result);
  519.                     var tradeItem = FindItemByKey("BuildON.Trades", data.Result);
  520.                     if (tradeItem != undefined && tradeItem != null) {
  521.                         self.tradesLookup(tradeItem[0].Data);
  522.                     }
  523.  
  524.                     var countryItem = FindItemByKey("BuildON.OriginCountry", data.Result);
  525.                     if (countryItem != undefined && countryItem != null) {
  526.                         self.countriesLookup(countryItem[0].Data);
  527.                     }
  528.  
  529.                     var educationItem = FindItemByKey("BuildON.EducationLevel", data.Result);
  530.                     if (educationItem != undefined && educationItem != null) {
  531.                         self.educationLookup(educationItem[0].Data);
  532.                     }
  533.  
  534.                     var englishItem = FindItemByKey("BuildON.EnglishSkills", data.Result);
  535.                     if (englishItem != undefined && englishItem != null) {
  536.                         self.englishSkillsLookup(englishItem[0].Data);
  537.                     }
  538.  
  539.                     var frenchItem = FindItemByKey("BuildON.FrenchSkills", data.Result);
  540.                     if (frenchItem != undefined && frenchItem != null) {
  541.                         self.frenchSkillsLookup(frenchItem[0].Data);
  542.                     }
  543.  
  544.                     var statusItem = FindItemByKey("BuildON.ImmigrationStatus", data.Result);
  545.                     if (statusItem != undefined && statusItem != null) {
  546.                         self.immigrationStatusLookup(statusItem[0].Data);
  547.                     }
  548.  
  549.                     var servicesItem = FindItemByKey("BuildON.Services", data.Result);
  550.                     if (servicesItem != undefined && servicesItem != null) {
  551.                         self.servicesLookup(servicesItem[0].Data);
  552.                     }
  553.  
  554.                     var yearsItem = FindItemByKey("BuildON.YearsOfExperience", data.Result);
  555.                     if (yearsItem != undefined && yearsItem != null) {
  556.                         self.yearsOfExperienceLookup(yearsItem[0].Data);
  557.                     }
  558.  
  559.                     var typeOfWorkItem = FindItemByKey("BuildON.TypeOfWork", data.Result);
  560.                     if (typeOfWorkItem != undefined && typeOfWorkItem != null) {
  561.                         self.typeOfWorkLookup(typeOfWorkItem[0].Data);
  562.                     }
  563.  
  564.                     var familiarLevelItem = FindItemByKey("BuildON.FamiliarLevel", data.Result);
  565.                     if (familiarLevelItem != undefined && familiarLevelItem != null) {
  566.                         self.familiarLevelLookup(familiarLevelItem[0].Data);
  567.                     }
  568.  
  569.                     var preferLangItem = FindItemByKey("BuildON.PreferredLanguage", data.Result);
  570.                     if (preferLangItem != undefined && preferLangItem != null) {
  571.                         self.preferLangLookup(preferLangItem[0].Data);
  572.                     }
  573.  
  574.                     var genderItem = FindItemByKey("BuildON.Gender", data.Result);
  575.                     if (genderItem != undefined && genderItem != null) {
  576.                         self.genderLookup(genderItem[0].Data);
  577.                     }
  578.                 }
  579.             });
  580.  
  581.  
  582.             //Push original objects to history arrays
  583.             self.user = ko.observable(new User());
  584.             self.meta = ko.observable(new Meta());
  585.             self.save = function () {
  586.                 console.log(ko.toJSON(self));
  587.             };
  588.  
  589.             self.addEducationHistory = function () {
  590.                 self.user().educationHistory.push(new EducationInfo());
  591.  
  592.                 var numItems = $('.radioGroup').length * 2;
  593.                 var newAttr1 = 'completeRadio' + (numItems - 1);
  594.                 var newAttr2 = 'completeRadio' + (numItems);
  595.                 var newName = 'completedSchool' + newAttr2;
  596.  
  597.                 $('.radioGroup').last().find('label[for=completeRadio1]').attr('for', newAttr1);
  598.                 $('.radioGroup').last().find('label[for=completeRadio2]').attr('for', newAttr2);
  599.  
  600.                 $('.radioGroup').last().find('input[id=completeRadio1]').attr('id', newAttr1);
  601.                 $('.radioGroup').last().find('input[id=completeRadio2]').attr('id', newAttr2);
  602.                 $('.radioGroup').last().find('input').attr('name', newName);
  603.  
  604.                 // custom select styles
  605.                 $('.select-item select').customSelect();
  606.                 $('.popup-modal-removeEducationHistory').magnificPopup();
  607.             };
  608.  
  609.             self.addWorkHistory = function () {
  610.                 self.user().workHistory.push(new WorkInfo());
  611.  
  612.                 var numItems = $('.checkboxGroup').length * 4;
  613.                 var newAttr1 = 'workCheckbox' + (numItems - 3);
  614.                 var newAttr2 = 'workCheckbox' + (numItems - 2);
  615.                 var newAttr3 = 'workCheckbox' + (numItems - 1);
  616.                 var newAttr4 = 'workCheckbox' + (numItems);
  617.  
  618.                 $('.checkboxGroup').last().find('label[for=workCheckbox1]').attr('for', newAttr1);
  619.                 $('.checkboxGroup').last().find('label[for=workCheckbox2]').attr('for', newAttr2);
  620.                 $('.checkboxGroup').last().find('label[for=workCheckbox3]').attr('for', newAttr3);
  621.                 $('.checkboxGroup').last().find('label[for=workCheckbox4]').attr('for', newAttr4);
  622.  
  623.                 $('.checkboxGroup').last().find('input[id=workCheckbox1]').attr('id', newAttr1);
  624.                 $('.checkboxGroup').last().find('input[id=workCheckbox2]').attr('id', newAttr2);
  625.                 $('.checkboxGroup').last().find('input[id=workCheckbox3]').attr('id', newAttr3);
  626.                 $('.checkboxGroup').last().find('input[id=workCheckbox4]').attr('id', newAttr4);
  627.  
  628.                 $('.checkboxGroup').last().find('input').attr('name', newAttr4);
  629.  
  630.                 // custom select styles
  631.                 $('.select-item select').customSelect();
  632.                 $('.popup-modal-removeWorkHistory').magnificPopup();
  633.             };
  634.  
  635.             self.removeEducationHistory = function () {
  636.                 var firstItem = self.user().educationHistory().length - 1;
  637.                 var lastItem = self.user().educationHistory().length - 1;
  638.                 var educationHist = self.user().educationHistory();
  639.  
  640.                 console.log(educationHist);
  641.                 educationHist.splice(lastItem, 1);
  642.                 console.log(educationHist);
  643.                 self.user().educationHistory(educationHist);
  644.  
  645.             };
  646.  
  647.             self.removeWorkHistory = function () {
  648.                 var firstItem = self.user().workHistory().length - 1;
  649.                 var lastItem = self.user().workHistory().length - 1;
  650.                 var workHist = self.user().workHistory();
  651.  
  652.                 console.log(workHist);
  653.                 workHist.splice(lastItem, 1);
  654.                 console.log(workHist);
  655.                 self.user().workHistory(workHist);
  656.             };
  657.  
  658.             self.skipEducation = function () {
  659.                 //Sets all the values from this step to undefined
  660.                 self.user().educationHistory([]);
  661.                 self.user().englishTesting().langTest1(undefined);
  662.                 self.user().englishTesting().langTest2(undefined);
  663.                 self.user().englishTesting().langTest3(undefined);
  664.                 self.user().frenchTesting().langTest1(undefined);
  665.                 self.user().frenchTesting().langTest2(undefined);
  666.                 self.user().frenchTesting().langTest3(undefined);
  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().workHistory([]);
  680.                 self.user().workTesting().jobOffer(undefined);
  681.  
  682.                 self.user().workTesting().choice1(undefined);
  683.                 self.user().workTesting().choice2(undefined);
  684.                 self.user().workTesting().choice3(undefined);
  685.                 self.user().workTesting().choice4(undefined);
  686.                 self.user().workTesting().collegeOfTrades(undefined);
  687.                 self.user().workTesting().canadaApprenticeProcess(undefined);
  688.             };
  689.  
  690.             self.checkDate = function (date) {
  691.                 var reg =
  692.                 /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/g;
  693.                 if (reg.test(date)) {
  694.                     return true;
  695.                 } else {
  696.                     return false;
  697.                 }
  698.             }
  699.  
  700.             self.checkEmail = function (email) {
  701.                 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;
  702.                 if (reg.test(email)) {
  703.                     return true;
  704.                 } else {
  705.                     return false;
  706.                 }
  707.             }
  708.  
  709.             self.checkUci = function (uci) {
  710.                 var reg = /^\d{4}\-\d{4}$/;
  711.  
  712.                 if (reg.test(uci)) {
  713.                     return true;
  714.                 } else {
  715.                     return false;
  716.                 }
  717.             };
  718.  
  719.             self.checkStep1 = function () {
  720.                 if (self.user().consentRegistration() == true) {
  721.                     $('.warningTextconsentRegistration').hide();
  722.                 } else {
  723.                     $('.warningTextconsentRegistration').show();
  724.                 }
  725.  
  726.                 if (self.user().tradeInterest() == '' || self.user().tradeInterest() == undefined) {
  727.                     $('.warningTexttradeInterest').show();
  728.                 } else {
  729.                     $('.warningTexttradeInterest').hide();
  730.                 }
  731.  
  732.                 if (self.user().consentRegistration() == true && self.user().tradeInterest() !== '' && self.user().tradeInterest() !== undefined) {
  733.                     self.meta().displayStep1(false);
  734.                     self.meta().displayStep2(true);
  735.  
  736.                     $('.warningText').hide();
  737.                     // set wizard step class
  738.                     $('.step1').removeClass('active');
  739.                     $('.step1').addClass('complete');
  740.                     $('.step2').addClass('active');
  741.                     $('#popup-modal-notQualified').magnificPopup();
  742.                     $("html, body").scrollTop(0);
  743.  
  744.                 }
  745.             }
  746.  
  747.             self.checkStep2 = function () {
  748.                 var errors = [];
  749.  
  750.                 //Pushing specific errors based on the users answers
  751.                 //Sorry for how verbose this is...
  752.                 if (self.user().approvedImmigrate() == '2') {
  753.                     errors.push("Only canidates who have been approved for Immigration may register for the BuildON Program");
  754.                 } else if (self.user().approvedImmigrate() == undefined) {
  755.                     $('.warningTextapprovedImmigrate').show();
  756.                 } else {
  757.                     $('.warningTextapprovedImmigrate').hide();
  758.                 }
  759.  
  760.                 if (self.user().immigrateOntario() == '2') {
  761.                     errors.push("Only canidates who plan to immigrate to Ontario may register for the BuildON Program");
  762.                 } else if (self.user().immigrateOntario() == undefined) {
  763.                     $('.warningTextimmigrateOntario').show();
  764.                 } else {
  765.                     $('.warningTextimmigrateOntario').hide();
  766.                 }
  767.  
  768.                 if (self.user().livingOutsideCanada() == '2') {
  769.                     errors.push("Only canidates who are currently living outside Canada may register for the BuildON Program");
  770.                 } else if (self.user().livingOutsideCanada() == undefined) {
  771.                     $('.warningTextlivingOutsideCanada').show();
  772.                 } else {
  773.                     $('.warningTextlivingOutsideCanada').hide();
  774.                 }
  775.  
  776.                 if (String(self.user().originCountry()) === 'Other') {
  777.                     errors.push("I'm sorry, the BuildON program is not available to canidates from your country of origin");
  778.                 } else {
  779.                     $('.warningTextoriginCountry').hide();
  780.                 }
  781.  
  782.                 if (self.user().originCountry() == undefined) {
  783.                     $('.warningTextoriginCountry').show();
  784.                 } else {
  785.                     $('.warningTextoriginCountry').hide();
  786.                 }
  787.  
  788.                 //If all the users selections are acceptable, hide all the red warning text and move to the next step on the form
  789.                 if (self.user().approvedImmigrate() == '1' && self.user().immigrateOntario() == '1' && self.user().livingOutsideCanada() == '1' && String(self.user().originCountry()) !== 'Other' && String(self.user().originCountry()) !== 'Select a country') {
  790.                     self.meta().displayStep2(false);
  791.                     self.meta().displayStep3(true);
  792.                     $('.warningText').hide();
  793.                     $('.step2').removeClass('active');
  794.                     $('.step2').addClass('complete');
  795.                     $('.step3').addClass('active');
  796.                     //Scroll to top of page after changing steps
  797.                     $("html, body").scrollTop(0);
  798.                 }
  799.  
  800.                 //Log out all the errors for why they can't register for the program, if there are errors
  801.                 if (errors.length > 0) {
  802.                     $('#popup-modal-notQualified').attr('href', '#notQualified-modal');
  803.                     console.log(errors);
  804.                     $('#popup-modal-notQualified').magnificPopup();
  805.                 } else {
  806.                     $('#popup-modal-notQualified').attr('href', '');
  807.                 }
  808.  
  809.             }
  810.  
  811.             self.checkStep3 = function () {
  812.                 if (self.user().tradesKnowledge() == undefined) {
  813.                     $('.warningTexttradesKnowledge').show();
  814.                 } else { $('.warningTexttradesKnowledge').hide(); }
  815.  
  816.                 if (self.user().referal() == undefined || self.user().referal() == '') {
  817.                     $('.warningTextreferal').show();
  818.                 } else { $('.warningTextreferal').hide(); }
  819.  
  820.                 //If all the users selections are acceptable, hide all the red warning text and move to the next step on the form
  821.                 if (self.user().tradesKnowledge() != undefined && self.user().referal() != '') {
  822.                     self.meta().displayStep3(false);
  823.                     self.meta().displayStep4(true);
  824.                     $('.warningText').hide();
  825.                     // set wizard step class
  826.                     $('.step3').removeClass('active');
  827.                     $('.step3').addClass('complete');
  828.                     $('.step4').addClass('active');
  829.  
  830.                     $("html, body").scrollTop(0);
  831.                 }
  832.             }
  833.  
  834.             self.checkStep4 = function () {
  835.                 //Displaying specific errors based on the users answers
  836.                 //Sorry for how verbose this is...
  837.  
  838.                 if (self.user().username() == undefined || self.user().username() == "") {
  839.                     $('.warningTextusername').show();
  840.                 } else { $('.warningTextusername').hide(); }
  841.  
  842.                 if (self.user().password() == undefined || self.user().password() == "") {
  843.                     $('.warningTextpassword').show();
  844.                 } else { $('.warningTextpassword').hide(); }
  845.  
  846.                 if (self.user().firstName() == undefined || self.user().firstName() == "") {
  847.                     $('.warningTextfirstName').show();
  848.                 } else { $('.warningTextfirstName').hide(); }
  849.  
  850.                 if (self.user().lastName() == undefined || self.user().lastName() == "") {
  851.                     $('.warningTextlastName').show();
  852.                 } else { $('.warningTextlastName').hide(); }
  853.  
  854.                 if (self.checkUci(self.user().uciNumber()) == false) {
  855.                     $('.warningTextuciNumber').show();
  856.                 } else { $('.warningTextuciNumber').hide(); }
  857.  
  858.                 if (self.user().gender() == undefined) {
  859.                     $('.warningTextgender').show();
  860.                 } else { $('.warningTextgender').hide(); }
  861.  
  862.                 if (self.user().preferredLanguage() == undefined) {
  863.                     $('.warningTextpreferredLanguage').show();
  864.                 } else { $('.warningTextpreferredLanguage').hide(); }
  865.  
  866.                 if (self.user().immigrationStatus() == undefined) {
  867.                     $('.warningTextimmigrationStatus').show();
  868.                 } else { $('.warningTextimmigrationStatus').hide(); }
  869.  
  870.                 if (self.user().consentResearch() == undefined || self.user().consentResearch() == false) {
  871.                     $('.warningTextconsentResearch').show();
  872.                 } else { $('.warningTextconsentResearch').hide(); }
  873.  
  874.                 if (self.checkDate(self.user().birthday()) == false) {
  875.                     $('.warningTextbirthday').show();
  876.                 } else { $('.warningTextbirthday').hide(); }
  877.  
  878.                 if (self.checkEmail(self.user().email()) == false) {
  879.                     $('.warningTextemail').show();
  880.                 } else { $('.warningTextemail').hide(); }
  881.  
  882.                 //If all the users selections are acceptable, hide all the red warning text and move to the next step on the form
  883.                 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() && self.user().password() && self.checkDate(self.user().birthday()) && self.checkEmail(self.user().email())) {
  884.                     self.meta().displayStep4(false);
  885.                     self.meta().displayStep5(true);
  886.                     $('.warningText').hide();
  887.                     // set wizard step class
  888.                     $('.step4').removeClass('active');
  889.                     $('.step4').addClass('complete');
  890.                     $('.step5').addClass('active');
  891.  
  892.                     $("html, body").scrollTop(0);
  893.                 }
  894.  
  895.             }
  896.  
  897.             self.checkStep5 = function () {
  898.                 //RegEx for Start/Finished dates in the Education section (must fit MM/DD/YYYY format)
  899.                 var allEducationDates = document.querySelectorAll('.educationDates1');
  900.                 if (self.user().educationHistory()[0].educationLevel() !== undefined && self.user().educationHistory()[0].educationLevel() !== "") {
  901.                     $.each(allEducationDates, function (index, value) {
  902.                         var currentVal = $(this).val();
  903.                         if (self.checkDate(currentVal)) {
  904.                             self.meta().displayStep5(false);
  905.                             self.meta().displayStep6(true);
  906.                             $('.warningText').hide();
  907.  
  908.                             $('.step5').addClass('complete');
  909.                             $('.step6').addClass('active');
  910.  
  911.                         } else {
  912.                             $('.warningTextDate').show();
  913.                             $('.warningTextCompleted').show();
  914.                             $('.warningTextinstitutionName').show();
  915.  
  916.                             return false;
  917.                         }
  918.                     });
  919.                 } else {
  920.                     //If all the users selections are acceptable, hide all the red warning text and move to the next step on the form
  921.                     self.meta().displayStep5(false);
  922.                     self.meta().displayStep6(true);
  923.                     $('.warningText').hide();
  924.  
  925.                     $('.step5').removeClass('active');
  926.                     $('.step5').addClass('complete');
  927.                     $('.step6').addClass('active');
  928.  
  929.                     $("html, body").scrollTop(0);
  930.                 }
  931.             }
  932.  
  933.             self.checkStep6 = function () {
  934.  
  935.                 if (self.user().workTesting().choice1() == undefined || self.user().workTesting().choice1() == "" || self.user().workTesting().choice2() == undefined || self.user().workTesting().choice2() == "" || self.user().workTesting().choice3() == undefined || self.user().workTesting().choice3() == "" || self.user().workTesting().choice4() == undefined || self.user().workTesting().choice4() == "") {
  936.                     $('.warningText').show();
  937.                     return false;
  938.                 }
  939.  
  940.                 if (self.user().workTesting().collegeOfTrades() == undefined) {
  941.                     $('.warningText').show();
  942.                     return false;
  943.                 }
  944.  
  945.                 if (self.user().workTesting().canadaApprenticeProcess() == undefined) {
  946.                     $('.warningText').show();
  947.                     return false;
  948.                 }
  949.  
  950.                 else {
  951.                     $('.warningText').hide();
  952.                     var registrationData = self.save();
  953.                     console.log(registrationData);
  954.  
  955.                     var settings = {
  956.                         "async": true,
  957.                         "crossDomain": true,
  958.                         "url": "/api/registration/save",
  959.                         "method": "POST",
  960.                         "headers": {
  961.                             "content-type": "application/json",
  962.                             "cache-control": "no-cache",
  963.                             "postman-token": "e278808a-783c-7ea2-fc88-1df5f5422b25"
  964.                         },
  965.                         "data": registrationData
  966.                     }
  967.  
  968.                     $.ajax(settings).done(function (response) {
  969.                         console.log(response);
  970.                     });
  971.                 }
  972.  
  973.             }
  974.  
  975.             // Go back button
  976.             // Check the HTML for each individual section on the form-it's visibility is controlled by changes to these states
  977.  
  978.             self.goBackStep1 = function () {
  979.                 self.meta().displayStep2(false);
  980.                 self.meta().displayStep1(true);
  981.  
  982.                 // set wizard step class
  983.                 $('.step2').removeClass('active');
  984.                 $('.step1').removeClass('complete');
  985.                 $('.step1').addClass('active');
  986.  
  987.                 $("html, body").scrollTop(0);
  988.             }
  989.  
  990.             self.goBackStep2 = function () {
  991.                 self.meta().displayStep3(false);
  992.                 self.meta().displayStep2(true);
  993.  
  994.                 // set wizard step class
  995.                 $('.step3').removeClass('active');
  996.                 $('.step2').removeClass('complete');
  997.                 $('.step2').addClass('active');
  998.  
  999.                 $("html, body").scrollTop(0);
  1000.             }
  1001.  
  1002.             self.goBackStep3 = function () {
  1003.                 self.meta().displayStep4(false);
  1004.                 self.meta().displayStep3(true);
  1005.  
  1006.                 // set wizard step class
  1007.                 $('.step4').removeClass('active');
  1008.                 $('.step3').removeClass('complete');
  1009.                 $('.step3').addClass('active');
  1010.  
  1011.                 $("html, body").scrollTop(0);
  1012.             }
  1013.  
  1014.             self.goBackStep4 = function () {
  1015.                 self.meta().displayStep5(false);
  1016.                 self.meta().displayStep4(true);
  1017.  
  1018.                 // set wizard step class
  1019.                 $('.step5').removeClass('active');
  1020.                 $('.step4').removeClass('complete');
  1021.                 $('.step4').addClass('active');
  1022.  
  1023.                 $("html, body").scrollTop(0);
  1024.             }
  1025.  
  1026.             self.goBackStep5 = function () {
  1027.                 self.meta().displayStep6(false);
  1028.                 self.meta().displayStep5(true);
  1029.  
  1030.                 // set wizard step class
  1031.                 $('.step6').removeClass('active');
  1032.                 $('.step5').removeClass('complete');
  1033.                 $('.step5').addClass('active');
  1034.  
  1035.                 $("html, body").scrollTop(0);
  1036.             }
  1037.  
  1038.  
  1039.             //They click a div with class step
  1040.             $('.step').click(function () {
  1041.                 if ($(this).hasClass('complete')) {
  1042.                     //Save the current step they're on so you know how many steps to go back (check for class of active)
  1043.                     var currentStep = $('.active').attr('id');
  1044.                     var intendedStep = $(this).attr('id');
  1045.                     currentStep = 'display' + currentStep + '(false)';
  1046.                     intendedStep = 'display' + intendedStep + '(true)';
  1047.  
  1048.                     //Remove class of active and complete from all Steps that are higher than the intendedStep
  1049.                     switch (intendedStep) {
  1050.                         case 'displayStep1(true)':
  1051.                             self.goBackStep5();
  1052.                             self.goBackStep4();
  1053.                             self.goBackStep3();
  1054.                             self.goBackStep2();
  1055.                             self.goBackStep1();
  1056.                             break;
  1057.  
  1058.                         case 'displayStep2(true)':
  1059.                             self.goBackStep5();
  1060.                             self.goBackStep4();
  1061.                             self.goBackStep3();
  1062.                             self.goBackStep2();
  1063.                             break;
  1064.  
  1065.                         case 'displayStep3(true)':
  1066.                             self.goBackStep5();
  1067.                             self.goBackStep4();
  1068.                             self.goBackStep3();
  1069.                             break;
  1070.  
  1071.                         case 'displayStep4(true)':
  1072.                             self.goBackStep5();
  1073.                             self.goBackStep4();
  1074.                             break;
  1075.  
  1076.                         case 'displayStep5(true)':
  1077.                             self.goBackStep5();
  1078.                             break;
  1079.                     }
  1080.                 }
  1081.  
  1082.             });
  1083.  
  1084.  
  1085.             self.user().educationHistory.push(new EducationInfo());
  1086.             self.user().workHistory.push(new WorkInfo());
  1087.             $('.step1').addClass('active');
  1088.             $('.warningText').hide();
  1089.         };
  1090.         var viewModel = new AppViewModel();
  1091.         ko.applyBindings(viewModel, document.getElementById("registration-form"));
  1092.     };
  1093.     if ($('#registration-form').html() != undefined) {
  1094.         buildON.registrationForm();
  1095.     }
  1096.  
  1097.     //My Dashboard
  1098.     buildON.myDashboard = function () {
  1099.  
  1100.         // My Dashboard dropdown on header
  1101.         var url = window.location.href;
  1102.  
  1103.         if ((url).indexOf('#t1') > -1) {
  1104.             var tab_id = $('ul.tabs li').attr('data-tab');
  1105.             $('.tab-content').removeClass('current');
  1106.             $('.tab-link').removeClass('current');
  1107.             $('#t1').addClass('current');
  1108.             $('#navChecklist').addClass('current');
  1109.             $('html,body').animate({ scrollTop: 0 }, 100);
  1110.         }
  1111.  
  1112.         if ((url).indexOf('#t2') > -1) {
  1113.             var tab_id = $('ul.tabs li').attr('data-tab');
  1114.             $('.tab-content').removeClass('current');
  1115.             $('.tab-link').removeClass('current');
  1116.             $('#t2').addClass('current');
  1117.             $('#navProfile').addClass('current');
  1118.             $('html,body').animate({ scrollTop: 0 }, 100);
  1119.         }
  1120.  
  1121.         if ((url).indexOf('#t3') > -1) {
  1122.             var tab_id = $('ul.tabs li').attr('data-tab');
  1123.             $('.tab-content').removeClass('current');
  1124.             $('.tab-link').removeClass('current');
  1125.             $('#t3').addClass('current');
  1126.             $('#navEmploymentHistory').addClass('current');
  1127.             $('html,body').animate({ scrollTop: 0 }, 100);
  1128.         }
  1129.  
  1130.         if ((url).indexOf('#t4') > -1) {
  1131.             var tab_id = $('ul.tabs li').attr('data-tab');
  1132.             $('.tab-content').removeClass('current');
  1133.             $('.tab-link').removeClass('current');
  1134.             $('#t4').addClass('current');
  1135.             $('#navEducation').addClass('current');
  1136.             $('html,body').animate({ scrollTop: 0 }, 100);
  1137.         }
  1138.  
  1139.         if ((url).indexOf('#t5') > -1) {
  1140.             var tab_id = $('ul.tabs li').attr('data-tab');
  1141.             $('.tab-content').removeClass('current');
  1142.             $('.tab-link').removeClass('current');
  1143.             $('#t5').addClass('current');
  1144.             $('#navAchievements').addClass('current');
  1145.             $('html,body').animate({ scrollTop: 0 }, 100);
  1146.         }
  1147.  
  1148.  
  1149.  
  1150.         //Education Info Constructor
  1151.         function EducationInfo() {
  1152.             var self = this;
  1153.  
  1154.             self.educationLevel = ko.observable();
  1155.             self.schoolName = ko.observable();
  1156.             self.completed = ko.observable();
  1157.             self.startDate = ko.observable();
  1158.             self.endDate = ko.observable();
  1159.             self.completed = ko.observable();
  1160.         };
  1161.  
  1162.         function LangTesting() {
  1163.             var self = this;
  1164.  
  1165.             self.langTest1 = ko.observable();
  1166.             self.langTest2 = ko.observable();
  1167.             self.langTest3 = ko.observable();
  1168.         };
  1169.  
  1170.         function WorkTesting() {
  1171.             var self = this;
  1172.  
  1173.             self.jobOffer = ko.observable();
  1174.             self.collegeOfTrades = ko.observable();
  1175.             self.canadaApprenticeProcess = ko.observable();
  1176.  
  1177.             self.choice1 = ko.observable();
  1178.             self.choice2 = ko.observable();
  1179.             self.choice3 = ko.observable();
  1180.             self.choice4 = ko.observable();
  1181.         };
  1182.  
  1183.         //Work Info Constructor
  1184.         function WorkInfo() {
  1185.             var self = this;
  1186.  
  1187.             self.workTitle = ko.observable('Title');
  1188.             self.workName = ko.observable('Name');
  1189.             self.typeOfWork = ko.observableArray(['Type of Work']);
  1190.             self.yearsExp = ko.observable('Years Experience');
  1191.             self.countryOfEmployment = ko.observable('Country of Employment');
  1192.             self.jobOffer = ko.observable('Job Offer');
  1193.         };
  1194.  
  1195.         //User Constructor
  1196.         function User() {
  1197.             var self = this;
  1198.  
  1199.             self.firstname = ko.observable();
  1200.             self.lastname = ko.observable();
  1201.             self.email = ko.observable();
  1202.             self.skype = ko.observable();
  1203.             self.birthday = ko.observable();
  1204.             self.preferredLanguage = ko.observable();
  1205.             self.tradeInterest = ko.observable();
  1206.             self.consentRegistration = ko.observable();
  1207.             self.approvedImmigrate = ko.observable();
  1208.             self.originCountry = ko.observable();
  1209.             self.immigrateOntario = ko.observable();
  1210.             self.livingOutsideCanada = ko.observable();
  1211.             self.tradesKnowledge = ko.observable();
  1212.             self.referal = ko.observable();
  1213.             self.username = ko.observable();
  1214.             self.password = ko.observable();
  1215.             self.uciNumber = ko.observable();
  1216.             self.gender = ko.observable();
  1217.             self.immigrationStatus = ko.observable();
  1218.             self.consentResearch = ko.observable();
  1219.             self.driversLicense = ko.observable();
  1220.             self.englishTesting = ko.observable(new LangTesting());
  1221.             self.frenchTesting = ko.observable(new LangTesting());
  1222.             self.workTesting = ko.observable(new WorkTesting());
  1223.  
  1224.             self.id = ko.observable();
  1225.             self.guid = ko.observable();
  1226.  
  1227.             self.workHistory = ko.observableArray([]);
  1228.             self.educationHistory = ko.observableArray([]);
  1229.         };
  1230.  
  1231.  
  1232.  
  1233.         var ProfileViewModel = function () {
  1234.             var self = this;
  1235.  
  1236.             //Overview is a property to watch for what element is being selected to edit
  1237.                 //It's value will be set to the index of the element the user wants to edit. Ensures only that element is editable
  1238.             self.overview = ko.observable(null);
  1239.  
  1240.             self.editingEducationHistory = ko.observable(false);
  1241.             self.editingWorkHistory = ko.observable(false);
  1242.             //Same as overview but checking for edit state on the profile to be enabled
  1243.             self.editingProfile = ko.observable(false);
  1244.  
  1245.             self.addingWork = ko.observable(false);
  1246.             self.addingEducation = ko.observable(false);
  1247.  
  1248.             self.newWorkElement = function () {
  1249.                 self.addingWork(true);
  1250.             };
  1251.  
  1252.             self.newEducationElement = function () {
  1253.                 self.addingEducation(true);
  1254.             };
  1255.  
  1256.             //Create User object on the View Model to track all changes
  1257.             self.user = ko.observable(new User());
  1258.  
  1259.             //Debugging function to see what the current Model values are
  1260.             self.save = function () {
  1261.                 console.log(ko.toJSON(self));
  1262.                 console.log('--USER--');
  1263.                 console.log(ko.toJSON(self.user()));
  1264.             };
  1265.  
  1266.             //Adds a new instance of the Work Info 'class' to the History array
  1267.             self.addWorkHistory = function () {
  1268.                 self.user().workHistory.push(new WorkInfo());
  1269.             };
  1270.  
  1271.             //Adds a new instance of the Education Info 'class' to the History array
  1272.             self.addEducationHistory = function () {
  1273.                 self.user().educationHistory.push(new EducationInfo());
  1274.             };
  1275.  
  1276.             //CRUD Functionality
  1277.             self.editProfile = function ($index) {
  1278.                 self.editingProfile(true);
  1279.             };
  1280.  
  1281.             self.saveProfile = function ($index) {
  1282.                 self.editingProfile(false);
  1283.             };
  1284.  
  1285.             self.editEducationHistory = function (id) {
  1286.                 console.log(id());
  1287.                 self.overview(id());
  1288.                 self.editingEducationHistory(true);
  1289.             };
  1290.  
  1291.             self.editWorkHistory = function (id) {
  1292.                 console.log(id());
  1293.                 self.overview(id());
  1294.                 self.editingWorkHistory(true);
  1295.             };
  1296.  
  1297.             self.saveChange = function () {
  1298.                 self.overview(null);
  1299.                 self.editingWorkHistory(false);
  1300.                 self.editingEducationHistory(false);
  1301.                 self.addingWork(false);
  1302.                 self.addingEducation(false);
  1303.             };
  1304.  
  1305.             self.cancelChange = function () {
  1306.                 self.overview(null);
  1307.                 self.editingProfile(false);
  1308.                 self.editingWorkHistory(false);
  1309.                 self.editingEducationHistory(false);
  1310.                 self.addingWork(false);
  1311.                 self.addingEducation(false);
  1312.             };
  1313.  
  1314.             self.removeWork = function ($index) {
  1315.                 self.user().workHistory.remove(this);
  1316.             };
  1317.  
  1318.             self.removeEducation = function ($index) {
  1319.                 self.user().educationHistory.remove(this);
  1320.             };
  1321.  
  1322.             //Custom table Lookup Data init
  1323.             self.tradesLookup = ko.observableArray([]);
  1324.             self.countriesLookup = ko.observableArray([]);
  1325.             self.educationLookup = ko.observableArray([]);
  1326.             self.englishSkillsLookup = ko.observableArray([]);
  1327.             self.frenchSkillsLookup = ko.observableArray([]);
  1328.             self.immigrationStatusLookup = ko.observableArray([]);
  1329.             self.immigrationClassLookup = ko.observableArray([]);
  1330.             self.servicesLookup = ko.observableArray([]);
  1331.             self.yearsOfExperienceLookup = ko.observableArray([]);
  1332.             self.typeOfWorkLookup = ko.observableArray([]);
  1333.             self.familiarLevelLookup = ko.observableArray([]);
  1334.             self.preferLangLookup = ko.observableArray([]);
  1335.             self.genderLookup = ko.observableArray([]);
  1336.             self.destinationLookup = ko.observableArray([]);
  1337.             self.languageLevelLookup = ko.observableArray([]);
  1338.             self.maritalStatusLookup = ko.observableArray([]);
  1339.  
  1340.             $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
  1341.                if (data.Result != null) {
  1342.                     var arrData = data.Result;
  1343.                     var tradeItem = FindItemByKey("BuildON.Trades", arrData);
  1344.                     if (tradeItem != undefined && tradeItem != null) {
  1345.                         self.tradesLookup(tradeItem[0].Data);
  1346.                     }
  1347.  
  1348.                     var countryItem = FindItemByKey("BuildON.OriginCountry", arrData);
  1349.                     if (countryItem != undefined && countryItem != null) {
  1350.                         self.countriesLookup(countryItem[0].Data);
  1351.                     }
  1352.  
  1353.                     var educationItem = FindItemByKey("BuildON.EducationLevel", arrData);
  1354.                     if (educationItem != undefined && educationItem != null) {
  1355.                         self.educationLookup(educationItem[0].Data);
  1356.                     }
  1357.  
  1358.                     var englishItem = FindItemByKey("BuildON.EnglishSkills", arrData);
  1359.                     if (englishItem != undefined && englishItem != null) {
  1360.                         self.englishSkillsLookup(englishItem[0].Data);
  1361.                     }
  1362.  
  1363.                     var frenchItem = FindItemByKey("BuildON.FrenchSkills", arrData);
  1364.                     if (frenchItem != undefined && frenchItem != null) {
  1365.                         self.frenchSkillsLookup(frenchItem[0].Data);
  1366.                     }
  1367.  
  1368.                     var statusItem = FindItemByKey("BuildON.ImmigrationStatus", arrData);
  1369.                     if (statusItem != undefined && statusItem != null) {
  1370.                         self.immigrationStatusLookup(statusItem[0].Data);
  1371.                     }
  1372.  
  1373.                     var immigrationClassItem = FindItemByKey("BuildON.ImmigrationClass", arrData);
  1374.                     if (immigrationClassItem != undefined && immigrationClassItem != null) {
  1375.                         self.immigrationStatusLookup(immigrationClassItem[0].Data);
  1376.                     }
  1377.  
  1378.                     var servicesItem = FindItemByKey("BuildON.Services", arrData);
  1379.                     if (servicesItem != undefined && servicesItem != null) {
  1380.                         self.servicesLookup(servicesItem[0].Data);
  1381.                     }
  1382.  
  1383.                     var yearsItem = FindItemByKey("BuildON.YearsOfExperience", arrData);
  1384.                     if (yearsItem != undefined && yearsItem != null) {
  1385.                         self.yearsOfExperienceLookup(yearsItem[0].Data);
  1386.                     }
  1387.  
  1388.                     var typeOfWorkItem = FindItemByKey("BuildON.TypeOfWork", arrData);
  1389.                     if (typeOfWorkItem != undefined && typeOfWorkItem != null) {
  1390.                         self.typeOfWorkLookup(typeOfWorkItem[0].Data);
  1391.                     }
  1392.  
  1393.                     var familiarLevelItem = FindItemByKey("BuildON.FamiliarLevel", arrData);
  1394.                     if (familiarLevelItem != undefined && familiarLevelItem != null) {
  1395.                         self.familiarLevelLookup(familiarLevelItem[0].Data);
  1396.                     }
  1397.  
  1398.                     var preferLangItem = FindItemByKey("BuildON.PreferredLanguage", arrData);
  1399.                     if (preferLangItem != undefined && preferLangItem != null) {
  1400.                         self.preferLangLookup(preferLangItem[0].Data);
  1401.                     }
  1402.  
  1403.                     var genderItem = FindItemByKey("BuildON.Gender", arrData);
  1404.                     if (genderItem != undefined && genderItem != null) {
  1405.                         self.genderLookup(genderItem[0].Data);
  1406.                     }
  1407.  
  1408.                     var destinationItem = FindItemByKey("BuildON.Destination", arrData);
  1409.                     if (destinationItem != undefined && destinationItem != null) {
  1410.                         self.destinationLookup(destinationItem[0].Data);
  1411.                     }
  1412.  
  1413.                     var langLevelItem = FindItemByKey("BuildON.LanguageLevel", arrData);
  1414.                     if (langLevelItem != undefined && langLevelItem != null) {
  1415.                         self.languageLevelLookup(langLevelItem[0].Data);
  1416.                     }
  1417.  
  1418.                     var maritalStatusItem = FindItemByKey("BuildON.MaritalStatus", arrData);
  1419.                     if (maritalStatusItem != undefined && maritalStatusItem != null) {
  1420.                         self.maritalStatusLookup(maritalStatusItem[0].Data);
  1421.                     }
  1422.                 }
  1423.             });
  1424.  
  1425.  
  1426.             self.GetGender = function (guid) {
  1427.                return FindItemByGuid(guid, self.genderLookup());
  1428.             };
  1429.             self.GetTrade = function (guid) {
  1430.                 return FindItemByGuid(guid, self.tradesLookup());
  1431.             };
  1432.             self.GetCountry = function (guid) {
  1433.                 return FindItemByGuid(guid, self.countriesLookup());
  1434.             };
  1435.             self.GetEducation = function (guid) {
  1436.                 return FindItemByGuid(guid, self.educationLookup());
  1437.             };
  1438.             self.GetEnglishSkill = function (guid) {
  1439.                 return FindItemByGuid(guid, self.englishSkillsLookup());
  1440.             };
  1441.             self.GetFrenchSkill = function (guid) {
  1442.                 return FindItemByGuid(guid, self.frenchSkillsLookup());
  1443.             };
  1444.             self.GetImmigrationStatus = function (guid) {
  1445.                 return FindItemByGuid(guid, self.immigrationStatusLookup());
  1446.             };
  1447.             self.GetImmigrationClass = function (guid) {
  1448.                 return FindItemByGuid(guid, self.immigrationClassLookup());
  1449.             };
  1450.             self.GetService = function (guid) {
  1451.                 return FindItemByGuid(guid, self.servicesLookup());
  1452.             };
  1453.             self.GetYearOfExperience = function (guid) {
  1454.                 return FindItemByGuid(guid, self.yearsOfExperienceLookup());
  1455.             };
  1456.             self.GetWrokType = function (guid) {
  1457.                 return FindItemByGuid(guid, self.typeOfWorkLookup());
  1458.             };
  1459.             self.GetFamiliarLevel = function (guid) {
  1460.                 return FindItemByGuid(guid, self.familiarLevelLookup());
  1461.             };
  1462.             self.GetPreferLang = function (guid) {
  1463.                 return FindItemByGuid(guid, self.preferLangLookup());
  1464.             };
  1465.             self.GetDestination = function (guid) {
  1466.                 return FindItemByGuid(guid, self.destinationLookup());
  1467.             };
  1468.             self.GetMaritalStatus = function (guid) {
  1469.                 return FindItemByGuid(guid, self.maritalStatusLookup());
  1470.             };
  1471.             self.GetLanguageLevel = function (guid) {
  1472.                 return FindItemByGuid(guid, self.languageLevelLookup());
  1473.             };
  1474.  
  1475.             var userid = 72
  1476.             var settings = {
  1477.                 "async": true,
  1478.                 "crossDomain": true,
  1479.                 "url": "/api/ClientUser?id=" + userid,
  1480.                 "method": "GET",
  1481.                 "headers": {
  1482.                     "cache-control": "no-cache",
  1483.                     "postman-token": "e57a474c-3fb5-8945-5487-45ac9047cadb",
  1484.                 }
  1485.  
  1486.             };
  1487.  
  1488.             $.ajax(settings).done(function (data) {
  1489.                 console.log(data);
  1490.  
  1491.                 //Updating Profile Info
  1492.                 self.user(ko.mapping.fromJS(data.Result));
  1493.  
  1494.                 //Change First Title on Education Dashboard
  1495.                 $('.education-title').first().text('Highest Education Level');
  1496.  
  1497.                 /*
  1498.                           $('.edit-link').click(function(){
  1499.                               editLink = $(this).context;
  1500.                               console.log(editLink);
  1501.                               currentName = $(editLink).attr('name');
  1502.                               editEle = $("[name="+currentName+"]").find('.edit');
  1503.                               infoEle = $("[name="+currentName+"]").find('.current-info');
  1504.                               console.log(editEle);
  1505.                               console.log(infoEle);
  1506.                               $(infoEle).hide();
  1507.                               $(editEle).show();
  1508.                           });
  1509.                 */
  1510.  
  1511.  
  1512.             });
  1513.  
  1514.         }
  1515.  
  1516.         var viewModel = new ProfileViewModel();
  1517.         ko.applyBindings(viewModel, document.getElementById("dashboard-home"));
  1518.     };
  1519.     if ($('#dashboard-home').html() != undefined) {
  1520.         buildON.myDashboard();
  1521.     }
  1522.  
  1523. }(jQuery));
  1524.  
  1525.  
  1526. $(window).on('resize', function () {
  1527.     // hide autocomplete dropdown on resize
  1528.     $(".ui-autocomplete").css('display', 'none');
  1529. });
  1530.  
  1531. // custom select box styling
  1532. // call for update panel refresh
  1533. $(function pageLoad(sender, args) {
  1534.     $('.select-item select').customSelect();
  1535. });
  1536.  
  1537. // reCaptcha
  1538. var captchaValid = false;
  1539.  
  1540. function captchaCallback() {
  1541.     captchaValid = true;
  1542. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement