Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // JavaScript Document
- var buildON = {};
- (function ($) {
- "use strict";
- // site current culture
- var lang = "en-CA";
- ($('#lng') != null && $('#lng').val() != "") ? lang = $('#lng').val() : "en-CA";
- buildON.options = {
- mobileWidth: 768
- };
- //until funcitons
- function FindItemByKey(key, arrayData) {
- var findItem = $.grep(arrayData, function (e) {
- return e.Key == key;
- });
- console.log(key + ":");
- console.log(findItem);
- return findItem;
- }
- /*function FindItemByGuid(guid, arrayData) {
- if (guid != "" && guid != undefined){
- var result = $.grep(arrayData, function (e) { return e.ItemGuid == guid; });
- if (result.length > 0) {
- return result[0].Name;
- }
- }
- return guid;
- }*/
- function FindItemByGuid(guid, arrayData) {
- console.log(typeof(guid));
- if (guid != "" && guid != undefined){
- if (typeof(guid) == "object") {
- console.log(guid);
- var stringName = "";
- var arrGuid = guid;
- for (var i = 0; i < arrGuid.length; i++) {
- var result = $.grep(arrayData, function (e) { return e.ItemGuid == arrGuid[i]; });
- if (result.length > 0) {
- stringName += result[0].Name + ", ";
- }
- }
- return stringName;
- }
- if (typeof(guid) == "string") {
- var result = $.grep(arrayData, function (e) { return e.ItemGuid == guid; });
- if (result.length > 0) {
- return result[0].Name;
- }
- }
- return guid;
- }
- /*if (guid != "" && guid != undefined){
- var arrGuid = guid.split(",");
- for (i = 0; i < arrGuid.length; i++) {
- var result = $.grep(arrayData, function (e) { return e.ItemGuid == arrGuid[i]; });
- if (result.length > 0) {
- stringName += result[0].Name + ", ";
- }
- }
- }*/
- return stringName;
- }
- // ADOBE ACCESSIBLE MEGA MENU
- var isAccessibleFlag = false;
- buildON.accessibleNav = function () {
- if ($(window).width() > buildON.options.mobileWidth && !isAccessibleFlag) {
- /**
- * Wrap accessibleMegaMenu() in window.width()
- * 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.
- * If user resizes screen the nav is borked.
- */
- // initialize the megamenu
- $('.pri-nav nav').accessibleMegaMenu();
- $('.pri-nav.desktop .search.nav-item a').click(function (e) {
- e.preventDefault();
- $('.pri-nav.desktop .search.nav-item').toggleClass('expanded');
- });
- // right-align last nav item that isn't search or donate
- $('.pri-nav.desktop ul.nav-menu > li').slice(-3).addClass('last-items');
- // hack so that the megamenu doesn't show flash of css animation after the page loads.
- setTimeout(function () {
- $('body').removeClass('init');
- }, 500);
- isAccessibleFlag = true;
- // hack for tablets
- if ($("html").hasClass("mod-touch")) {
- $(".desktop .accessible-megamenu-top-nav-item").not($(".search")).each(function () {
- var link = $(this).find("> a[aria-haspopup='true']");
- if (link.length) {
- // get page language
- var lang = $('html')[0].lang;
- var overviewText = " Overview";
- // To do: get french translation for "overview"
- /*
- if (lang == "fr") {
- overviewText = "french overview";
- }
- */
- $(link).clone().prependTo($(this).find("ul")).wrap("<li></li>").append(overviewText);
- }
- });
- }
- /** hide search on click outside of search box
- * http://benalman.com/code/projects/jquery-outside-events/examples/clickoutside/
- */
- // elements on which to bind the event
- var elems = $(".pri-nav.desktop .search.nav-item");
- // Clear any previous highlights
- $(document)
- .bind('click', function (event) {
- elems
- //.removeClass( 'event-outside' )
- .children('a');
- })
- .trigger('click');
- // Bind the 'clickoutside' event to each test element
- elems.bind('clickoutside', function (event) {
- var elem = $(this),
- target = $(event.target);
- // Highlight this element
- elem
- //.addClass( 'event-outside' )
- .removeClass('expanded')
- .children('a');
- });
- }
- };
- buildON.accessibleNav();
- // TABS
- buildON.tabs = function () {
- $('ul.tabs li').click(function () {
- var tab_id = $(this).attr('data-tab');
- $('ul.tabs li').removeClass('current');
- $('.tab-content').removeClass('current');
- $(this).addClass('current');
- $("#" + tab_id).addClass('current');
- $('ul.tabs').removeClass('open');
- });
- // My dashboard nav dropdown on header change button colour
- $('.dashboard-nav').hover(function () {
- $('ul.dashboard-nav-menu').toggleClass('open');
- $('.dashboard-nav .btn').toggleClass('dashboard-nav-btn-reverse');
- });
- // Click on my workshops, profile, education etc.
- $('.dashboard-nav-menu li a').click(function (e) {
- if ((this).href.indexOf('#dashboardChecklistDefault') > -1) {
- e.preventDefault();
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#dashboardChecklistDefault').addClass('current');
- $('#navChecklist').addClass('current');
- }
- if ((this).href.indexOf('#dashboardProfileDefault') > -1) {
- e.preventDefault();
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#dashboardProfileDefault').addClass('current');
- $('#navProfile').addClass('current');
- }
- if ((this).href.indexOf('#dashboardEmploymentHistoryDefault') > -1) {
- e.preventDefault();
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#dashboardEmploymentHistoryDefault').addClass('current');
- $('#navEmploymentHistory').addClass('current');
- }
- if ((this).href.indexOf('#dashboardEducationDefault') > -1) {
- e.preventDefault();
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#dashboardEducationDefault').addClass('current');
- $('#navEducation').addClass('current');
- }
- if ((this).href.indexOf('#dashboardAchievementsDefault') > -1) {
- e.preventDefault();
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#dashboardAchievementsDefault').addClass('current');
- $('#navAchievements').addClass('current');
- }
- });
- };
- buildON.tabs();
- // tabs dropdown on mobile
- buildON.tabsMobileDD = function () {
- $('.tabs-mobile').click(function (e) {
- e.preventDefault();
- $('ul.tabs').toggleClass('open');
- });
- };
- buildON.tabsMobileDD();
- // EQUAL HEIGHTS - MATCH HEIGHT PLUGIN
- buildON.equalHeights = function () {
- $(".cta-list a").matchHeight();
- $(".grid-list a").matchHeight();
- $(".logo-donate > div").matchHeight();
- $(".band .cta").matchHeight();
- $(".row .cta").matchHeight();
- $(".story-list a").matchHeight();
- $(".schedule-grid.week > ul > li").matchHeight();
- $(".schedule-grid.week .grid-blocks").matchHeight(false);
- $(".schedule-grid.day .block").matchHeight();
- $(".program-category-block").matchHeight();
- $(".col.border-left").matchHeight();
- // set min heights for col-match columns so accordion content doesn't get hidden
- if (matchMedia('only screen and (min-width: 992px)').matches) {
- var mainColHeight = $(".col-match.main-col").height();
- var sideColHeight = $(".col-match.side-col").height();
- $(".col-match.side-col .inner").css("min-height", mainColHeight);
- $(".col-match.main-col").css("min-height", sideColHeight);
- }
- };
- buildON.equalHeights();
- // TRUNCATE
- buildON.truncate = function () {
- $('.workshop-title').dotdotdot({
- ellipsis: '...',
- watch: true,
- height: 35
- });
- $('.workshop-description').dotdotdot({
- ellipsis: '...',
- watch: true,
- height: 100
- });
- };
- buildON.truncate();
- // FILE UPLOADER
- buildON.fileUploader = function () {
- $(document).on('change', '.btn-file :file', function () {
- var input = $(this),
- numFiles = input.get(0).files ? input.get(0).files.length : 1,
- label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
- input.trigger('fileselect', [numFiles, label]);
- });
- $(document).ready(function () {
- $('.btn-file :file').on('fileselect', function (event, numFiles, label) {
- var input = $(this).parents('.input-group').find(':text'),
- log = numFiles > 1 ? numFiles + ' files selected' : label;
- if (input.length) {
- input.val(log);
- } else {
- if (log) alert(log);
- }
- });
- });
- };
- buildON.fileUploader();
- // MOBILE NAV
- buildON.mobileNav = function () {
- var siteWrap = ".site-wrap",
- siteWrapHeight = $(siteWrap).outerHeight(),
- nav = ".pri-nav",
- navMobile = nav + '.mobile',
- navDesktop = nav + '.desktop',
- navMobileContainer = "#mobile-nav-container",
- navMobileToggle = "#mobile-nav-toggle",
- navMobileLength = $(navMobile).length,
- navMobileLastItem = navMobile + ' li:last-child a';
- var openMobileNav = function () {
- $('body').addClass('mobile-nav-open');
- },
- closeMobileNav = function () {
- $('body').removeClass('mobile-nav-open');
- },
- toggleMobileNav = function () {
- if (!$('body').hasClass('mobile-nav-open')) {
- openMobileNav();
- } else {
- closeMobileNav();
- }
- };
- $(navMobileToggle).click(function (e) {
- e.preventDefault();
- // show/hide the nav
- toggleMobileNav();
- });
- // close mobile nav on click outside the nav
- $(siteWrap).click(function () {
- if ($('body').hasClass('mobile-nav-open')) {
- //closeMobileNav();
- }
- });
- // close nav when last nav item loses focus
- $(navMobileLastItem).focusout(function () {
- closeMobileNav();
- });
- // set nav height to viewport height
- // and recalculate on orientation change.
- $(navMobile).css('height', $(window).innerHeight());
- window.addEventListener("orientationchange", function () {
- $(navMobile).css('height', $(window).innerHeight());
- }, false);
- // fix bug introduced by twitter feed widget
- $('#twttrHubFrame').attr('tabindex', '-1');
- };
- buildON.mobileNav();
- // MOBILE SECONDARY NAV
- buildON.mobileSecNav = function () {
- $(".sec-nav-toggle").click(function (e) {
- e.preventDefault();
- $(".secondary-nav ul").slideToggle();
- });
- $(".sec-nav-content-toggle").click(function (e) {
- e.preventDefault();
- $("#contet-page-nav").toggleClass("open");
- });
- };
- buildON.mobileSecNav();
- // DESKTOP SECONDARY NAV
- buildON.secNav = function () {
- $('.secondary-nav').find('ul').parent().addClass('has-children');
- };
- buildON.secNav();
- // HELPERS
- /** for each element that is classed as 'pull-down',
- * set its margin-top to the difference between its own height
- * and the height of its parent
- */
- buildON.pullDown = function () {
- $('.pull-down').each(function () {
- $(this).css('margin-top', $(this).parent().height() - $(this).height());
- });
- };
- buildON.pullDown();
- // IFRAME Z-INDEX FIX
- buildON.fixIframeZindex = function () {
- $("iframe").each(function () {
- var ifr_source = $(this).attr('src');
- if (typeof ifr_source !== "undefined") {
- var wmode = "wmode=transparent";
- if (ifr_source.indexOf('?') != -1) $(this).attr('src', ifr_source + '&' + wmode);
- else $(this).attr('src', ifr_source + '?' + wmode);
- }
- });
- };
- //Magnific Popup Modal
- buildON.magnificPopup = function () {
- // uci# tooltip modal
- $('.popup-modal-uci').magnificPopup();
- // step2 not qualified modal
- //$('#popup-modal-notQualified').magnificPopup();
- // remove education history modal
- //$('.popup-modal-removeEducationHistory').magnificPopup();
- // remove work history modal
- //$('.popup-modal-removeWorkHistory').magnificPopup();
- $(document).on('click', '.popup-modal-dismiss', function (e) {
- $.magnificPopup.close();
- });
- };
- buildON.magnificPopup();
- // Registration form
- buildON.registrationForm = function () {
- //Education Info Constructor
- function EducationInfo() {
- this.educationLevel = ko.observable();
- this.schoolName = ko.observable();
- this.completed = ko.observable();
- this.startDate = ko.observable();
- this.endDate = ko.observable();
- };
- function LangTesting() {
- this.langTest1 = ko.observable(false);
- this.langTest2 = ko.observable(false);
- this.langTest3 = ko.observable(false);
- };
- function WorkTesting() {
- this.jobOffer = ko.observable(false);
- this.collegeOfTrades = ko.observable();
- this.canadaApprenticeProcess = ko.observable();
- this.choice1 = ko.observable();
- this.choice2 = ko.observable();
- this.choice3 = ko.observable();
- this.choice4 = ko.observable();
- };
- //Work Info Constructor
- function WorkInfo() {
- this.workTitle = ko.observable();
- this.workName = ko.observable();
- this.typeOfWork = ko.observableArray([]);
- this.yearsExp = ko.observable();
- this.countryOfEmployment = ko.observable();
- this.jobOffer = ko.observable();
- };
- //User Meta data constructor
- function Meta() {
- this.culture = ko.observable('en-CA');
- this.displayStep1 = ko.observable(true);
- this.displayStep2 = ko.observable(false);
- this.displayStep3 = ko.observable(false);
- this.displayStep4 = ko.observable(false);
- this.displayStep5 = ko.observable(false);
- this.displayStep6 = ko.observable(false);
- }
- //User Constructor
- function User() {
- this.firstName = ko.observable();
- this.lastName = ko.observable();
- this.email = ko.observable();
- this.skype = ko.observable();
- this.birthday = ko.observable();
- this.preferredLanguage = ko.observable();
- this.tradeInterest = ko.observable();
- this.consentRegistration = ko.observable();
- this.approvedImmigrate = ko.observable();
- this.originCountry = ko.observable();
- this.immigrateOntario = ko.observable();
- this.livingOutsideCanada = ko.observable();
- this.tradesKnowledge = ko.observable();
- this.referal = ko.observable();
- this.username = ko.observable();
- this.password = ko.observable();
- this.uciNumber = ko.observable();
- this.gender = ko.observable();
- this.immigrationStatus = ko.observable();
- this.consentResearch = ko.observable();
- this.driversLicense = ko.observable();
- this.workHistory = ko.observableArray([]);
- this.educationHistory = ko.observableArray([]);
- this.id = ko.observable(null);
- this.guid = ko.observable('guid');
- this.englishTesting = ko.observable(new LangTesting());
- this.frenchTesting = ko.observable(new LangTesting());
- this.workTesting = ko.observable(new WorkTesting());
- };
- //Main Knockout View Model
- var AppViewModel = function () {
- var self = this;
- //Custom table Lookup Data init
- self.tradesLookup = ko.observableArray([]);
- self.countriesLookup = ko.observableArray([]);
- self.educationLookup = ko.observableArray([]);
- self.englishSkillsLookup = ko.observableArray([]);
- self.frenchSkillsLookup = ko.observableArray([]);
- self.immigrationStatusLookup = ko.observableArray([]);
- self.servicesLookup = ko.observableArray([]);
- self.yearsOfExperienceLookup = ko.observableArray([]);
- self.typeOfWorkLookup = ko.observableArray([]);
- self.familiarLevelLookup = ko.observableArray([]);
- self.preferLangLookup = ko.observableArray([]);
- self.genderLookup = ko.observableArray([]);
- $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
- if (data.Result != null) {
- console.log(data.Result);
- var tradeItem = FindItemByKey("BuildON.Trades", data.Result);
- if (tradeItem != undefined && tradeItem != null) {
- self.tradesLookup(tradeItem[0].Data);
- }
- var countryItem = FindItemByKey("BuildON.OriginCountry", data.Result);
- if (countryItem != undefined && countryItem != null) {
- self.countriesLookup(countryItem[0].Data);
- }
- var educationItem = FindItemByKey("BuildON.EducationLevel", data.Result);
- if (educationItem != undefined && educationItem != null) {
- self.educationLookup(educationItem[0].Data);
- }
- var englishItem = FindItemByKey("BuildON.EnglishSkills", data.Result);
- if (englishItem != undefined && englishItem != null) {
- self.englishSkillsLookup(englishItem[0].Data);
- }
- var frenchItem = FindItemByKey("BuildON.FrenchSkills", data.Result);
- if (frenchItem != undefined && frenchItem != null) {
- self.frenchSkillsLookup(frenchItem[0].Data);
- }
- var statusItem = FindItemByKey("BuildON.ImmigrationStatus", data.Result);
- if (statusItem != undefined && statusItem != null) {
- self.immigrationStatusLookup(statusItem[0].Data);
- }
- var servicesItem = FindItemByKey("BuildON.Services", data.Result);
- if (servicesItem != undefined && servicesItem != null) {
- self.servicesLookup(servicesItem[0].Data);
- }
- var yearsItem = FindItemByKey("BuildON.YearsOfExperience", data.Result);
- if (yearsItem != undefined && yearsItem != null) {
- self.yearsOfExperienceLookup(yearsItem[0].Data);
- }
- var typeOfWorkItem = FindItemByKey("BuildON.TypeOfWork", data.Result);
- if (typeOfWorkItem != undefined && typeOfWorkItem != null) {
- self.typeOfWorkLookup(typeOfWorkItem[0].Data);
- }
- var familiarLevelItem = FindItemByKey("BuildON.FamiliarLevel", data.Result);
- if (familiarLevelItem != undefined && familiarLevelItem != null) {
- self.familiarLevelLookup(familiarLevelItem[0].Data);
- }
- var preferLangItem = FindItemByKey("BuildON.PreferredLanguage", data.Result);
- if (preferLangItem != undefined && preferLangItem != null) {
- self.preferLangLookup(preferLangItem[0].Data);
- }
- var genderItem = FindItemByKey("BuildON.Gender", data.Result);
- if (genderItem != undefined && genderItem != null) {
- self.genderLookup(genderItem[0].Data);
- }
- }
- });
- //Push original objects to history arrays
- self.user = ko.observable(new User());
- self.meta = ko.observable(new Meta());
- self.save = function () {
- console.log(ko.toJSON(self));
- };
- self.addEducationHistory = function () {
- self.user().educationHistory.push(new EducationInfo());
- var numItems = $('.radioGroup').length * 2;
- var newAttr1 = 'completeRadio' + (numItems - 1);
- var newAttr2 = 'completeRadio' + (numItems);
- var newName = 'completedSchool' + newAttr2;
- $('.radioGroup').last().find('label[for=completeRadio1]').attr('for', newAttr1);
- $('.radioGroup').last().find('label[for=completeRadio2]').attr('for', newAttr2);
- $('.radioGroup').last().find('input[id=completeRadio1]').attr('id', newAttr1);
- $('.radioGroup').last().find('input[id=completeRadio2]').attr('id', newAttr2);
- $('.radioGroup').last().find('input').attr('name', newName);
- // custom select styles
- $('.select-item select').customSelect();
- $('.popup-modal-removeEducationHistory').magnificPopup();
- };
- self.addWorkHistory = function () {
- self.user().workHistory.push(new WorkInfo());
- var numItems = $('.checkboxGroup').length * 4;
- var newAttr1 = 'workCheckbox' + (numItems - 3);
- var newAttr2 = 'workCheckbox' + (numItems - 2);
- var newAttr3 = 'workCheckbox' + (numItems - 1);
- var newAttr4 = 'workCheckbox' + (numItems);
- $('.checkboxGroup').last().find('label[for=workCheckbox1]').attr('for', newAttr1);
- $('.checkboxGroup').last().find('label[for=workCheckbox2]').attr('for', newAttr2);
- $('.checkboxGroup').last().find('label[for=workCheckbox3]').attr('for', newAttr3);
- $('.checkboxGroup').last().find('label[for=workCheckbox4]').attr('for', newAttr4);
- $('.checkboxGroup').last().find('input[id=workCheckbox1]').attr('id', newAttr1);
- $('.checkboxGroup').last().find('input[id=workCheckbox2]').attr('id', newAttr2);
- $('.checkboxGroup').last().find('input[id=workCheckbox3]').attr('id', newAttr3);
- $('.checkboxGroup').last().find('input[id=workCheckbox4]').attr('id', newAttr4);
- $('.checkboxGroup').last().find('input').attr('name', newAttr4);
- // custom select styles
- $('.select-item select').customSelect();
- $('.popup-modal-removeWorkHistory').magnificPopup();
- };
- self.removeEducationHistory = function () {
- var firstItem = self.user().educationHistory().length - 1;
- var lastItem = self.user().educationHistory().length - 1;
- var educationHist = self.user().educationHistory();
- console.log(educationHist);
- educationHist.splice(lastItem, 1);
- console.log(educationHist);
- self.user().educationHistory(educationHist);
- };
- self.removeWorkHistory = function () {
- var firstItem = self.user().workHistory().length - 1;
- var lastItem = self.user().workHistory().length - 1;
- var workHist = self.user().workHistory();
- console.log(workHist);
- workHist.splice(lastItem, 1);
- console.log(workHist);
- self.user().workHistory(workHist);
- };
- self.skipEducation = function () {
- //Sets all the values from this step to undefined
- self.user().educationHistory([]);
- self.user().englishTesting().langTest1(undefined);
- self.user().englishTesting().langTest2(undefined);
- self.user().englishTesting().langTest3(undefined);
- self.user().frenchTesting().langTest1(undefined);
- self.user().frenchTesting().langTest2(undefined);
- self.user().frenchTesting().langTest3(undefined);
- self.user().driversLicense(undefined);
- //Skips to step 6
- self.meta().displayStep5(false);
- self.meta().displayStep6(true);
- $('.warningText').hide();
- $('.step5').addClass('complete');
- $('.step6').addClass('active');
- };
- self.skipWork = function () {
- //Sets all the values from this step to undefined
- self.user().workHistory([]);
- self.user().workTesting().jobOffer(undefined);
- self.user().workTesting().choice1(undefined);
- self.user().workTesting().choice2(undefined);
- self.user().workTesting().choice3(undefined);
- self.user().workTesting().choice4(undefined);
- self.user().workTesting().collegeOfTrades(undefined);
- self.user().workTesting().canadaApprenticeProcess(undefined);
- };
- self.checkDate = function (date) {
- var reg =
- /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/g;
- if (reg.test(date)) {
- return true;
- } else {
- return false;
- }
- }
- self.checkEmail = function (email) {
- 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;
- if (reg.test(email)) {
- return true;
- } else {
- return false;
- }
- }
- self.checkUci = function (uci) {
- var reg = /^\d{4}\-\d{4}$/;
- if (reg.test(uci)) {
- return true;
- } else {
- return false;
- }
- };
- self.checkStep1 = function () {
- if (self.user().consentRegistration() == true) {
- $('.warningTextconsentRegistration').hide();
- } else {
- $('.warningTextconsentRegistration').show();
- }
- if (self.user().tradeInterest() == '' || self.user().tradeInterest() == undefined) {
- $('.warningTexttradeInterest').show();
- } else {
- $('.warningTexttradeInterest').hide();
- }
- if (self.user().consentRegistration() == true && self.user().tradeInterest() !== '' && self.user().tradeInterest() !== undefined) {
- self.meta().displayStep1(false);
- self.meta().displayStep2(true);
- $('.warningText').hide();
- // set wizard step class
- $('.step1').removeClass('active');
- $('.step1').addClass('complete');
- $('.step2').addClass('active');
- $('#popup-modal-notQualified').magnificPopup();
- $("html, body").scrollTop(0);
- }
- }
- self.checkStep2 = function () {
- var errors = [];
- //Pushing specific errors based on the users answers
- //Sorry for how verbose this is...
- if (self.user().approvedImmigrate() == '2') {
- errors.push("Only canidates who have been approved for Immigration may register for the BuildON Program");
- } else if (self.user().approvedImmigrate() == undefined) {
- $('.warningTextapprovedImmigrate').show();
- } else {
- $('.warningTextapprovedImmigrate').hide();
- }
- if (self.user().immigrateOntario() == '2') {
- errors.push("Only canidates who plan to immigrate to Ontario may register for the BuildON Program");
- } else if (self.user().immigrateOntario() == undefined) {
- $('.warningTextimmigrateOntario').show();
- } else {
- $('.warningTextimmigrateOntario').hide();
- }
- if (self.user().livingOutsideCanada() == '2') {
- errors.push("Only canidates who are currently living outside Canada may register for the BuildON Program");
- } else if (self.user().livingOutsideCanada() == undefined) {
- $('.warningTextlivingOutsideCanada').show();
- } else {
- $('.warningTextlivingOutsideCanada').hide();
- }
- if (String(self.user().originCountry()) === 'Other') {
- errors.push("I'm sorry, the BuildON program is not available to canidates from your country of origin");
- } else {
- $('.warningTextoriginCountry').hide();
- }
- if (self.user().originCountry() == undefined) {
- $('.warningTextoriginCountry').show();
- } else {
- $('.warningTextoriginCountry').hide();
- }
- //If all the users selections are acceptable, hide all the red warning text and move to the next step on the form
- 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') {
- self.meta().displayStep2(false);
- self.meta().displayStep3(true);
- $('.warningText').hide();
- $('.step2').removeClass('active');
- $('.step2').addClass('complete');
- $('.step3').addClass('active');
- //Scroll to top of page after changing steps
- $("html, body").scrollTop(0);
- }
- //Log out all the errors for why they can't register for the program, if there are errors
- if (errors.length > 0) {
- $('#popup-modal-notQualified').attr('href', '#notQualified-modal');
- console.log(errors);
- $('#popup-modal-notQualified').magnificPopup();
- } else {
- $('#popup-modal-notQualified').attr('href', '');
- }
- }
- self.checkStep3 = function () {
- if (self.user().tradesKnowledge() == undefined) {
- $('.warningTexttradesKnowledge').show();
- } else { $('.warningTexttradesKnowledge').hide(); }
- if (self.user().referal() == undefined || self.user().referal() == '') {
- $('.warningTextreferal').show();
- } else { $('.warningTextreferal').hide(); }
- //If all the users selections are acceptable, hide all the red warning text and move to the next step on the form
- if (self.user().tradesKnowledge() != undefined && self.user().referal() != '') {
- self.meta().displayStep3(false);
- self.meta().displayStep4(true);
- $('.warningText').hide();
- // set wizard step class
- $('.step3').removeClass('active');
- $('.step3').addClass('complete');
- $('.step4').addClass('active');
- $("html, body").scrollTop(0);
- }
- }
- self.checkStep4 = function () {
- //Displaying specific errors based on the users answers
- //Sorry for how verbose this is...
- if (self.user().username() == undefined || self.user().username() == "") {
- $('.warningTextusername').show();
- } else { $('.warningTextusername').hide(); }
- if (self.user().password() == undefined || self.user().password() == "") {
- $('.warningTextpassword').show();
- } else { $('.warningTextpassword').hide(); }
- if (self.user().firstName() == undefined || self.user().firstName() == "") {
- $('.warningTextfirstName').show();
- } else { $('.warningTextfirstName').hide(); }
- if (self.user().lastName() == undefined || self.user().lastName() == "") {
- $('.warningTextlastName').show();
- } else { $('.warningTextlastName').hide(); }
- if (self.checkUci(self.user().uciNumber()) == false) {
- $('.warningTextuciNumber').show();
- } else { $('.warningTextuciNumber').hide(); }
- if (self.user().gender() == undefined) {
- $('.warningTextgender').show();
- } else { $('.warningTextgender').hide(); }
- if (self.user().preferredLanguage() == undefined) {
- $('.warningTextpreferredLanguage').show();
- } else { $('.warningTextpreferredLanguage').hide(); }
- if (self.user().immigrationStatus() == undefined) {
- $('.warningTextimmigrationStatus').show();
- } else { $('.warningTextimmigrationStatus').hide(); }
- if (self.user().consentResearch() == undefined || self.user().consentResearch() == false) {
- $('.warningTextconsentResearch').show();
- } else { $('.warningTextconsentResearch').hide(); }
- if (self.checkDate(self.user().birthday()) == false) {
- $('.warningTextbirthday').show();
- } else { $('.warningTextbirthday').hide(); }
- if (self.checkEmail(self.user().email()) == false) {
- $('.warningTextemail').show();
- } else { $('.warningTextemail').hide(); }
- //If all the users selections are acceptable, hide all the red warning text and move to the next step on the form
- 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())) {
- self.meta().displayStep4(false);
- self.meta().displayStep5(true);
- $('.warningText').hide();
- // set wizard step class
- $('.step4').removeClass('active');
- $('.step4').addClass('complete');
- $('.step5').addClass('active');
- $("html, body").scrollTop(0);
- }
- }
- self.checkStep5 = function () {
- //RegEx for Start/Finished dates in the Education section (must fit MM/DD/YYYY format)
- var allEducationDates = document.querySelectorAll('.educationDates1');
- if (self.user().educationHistory()[0].educationLevel() !== undefined && self.user().educationHistory()[0].educationLevel() !== "") {
- $.each(allEducationDates, function (index, value) {
- var currentVal = $(this).val();
- if (self.checkDate(currentVal)) {
- self.meta().displayStep5(false);
- self.meta().displayStep6(true);
- $('.warningText').hide();
- $('.step5').addClass('complete');
- $('.step6').addClass('active');
- } else {
- $('.warningTextDate').show();
- $('.warningTextCompleted').show();
- $('.warningTextinstitutionName').show();
- return false;
- }
- });
- } else {
- //If all the users selections are acceptable, hide all the red warning text and move to the next step on the form
- self.meta().displayStep5(false);
- self.meta().displayStep6(true);
- $('.warningText').hide();
- $('.step5').removeClass('active');
- $('.step5').addClass('complete');
- $('.step6').addClass('active');
- $("html, body").scrollTop(0);
- }
- }
- self.checkStep6 = function () {
- 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() == "") {
- $('.warningText').show();
- return false;
- }
- if (self.user().workTesting().collegeOfTrades() == undefined) {
- $('.warningText').show();
- return false;
- }
- if (self.user().workTesting().canadaApprenticeProcess() == undefined) {
- $('.warningText').show();
- return false;
- }
- else {
- $('.warningText').hide();
- var registrationData = self.save();
- console.log(registrationData);
- var settings = {
- "async": true,
- "crossDomain": true,
- "url": "/api/registration/save",
- "method": "POST",
- "headers": {
- "content-type": "application/json",
- "cache-control": "no-cache",
- "postman-token": "e278808a-783c-7ea2-fc88-1df5f5422b25"
- },
- "data": registrationData
- }
- $.ajax(settings).done(function (response) {
- console.log(response);
- });
- }
- }
- // Go back button
- // Check the HTML for each individual section on the form-it's visibility is controlled by changes to these states
- self.goBackStep1 = function () {
- self.meta().displayStep2(false);
- self.meta().displayStep1(true);
- // set wizard step class
- $('.step2').removeClass('active');
- $('.step1').removeClass('complete');
- $('.step1').addClass('active');
- $("html, body").scrollTop(0);
- }
- self.goBackStep2 = function () {
- self.meta().displayStep3(false);
- self.meta().displayStep2(true);
- // set wizard step class
- $('.step3').removeClass('active');
- $('.step2').removeClass('complete');
- $('.step2').addClass('active');
- $("html, body").scrollTop(0);
- }
- self.goBackStep3 = function () {
- self.meta().displayStep4(false);
- self.meta().displayStep3(true);
- // set wizard step class
- $('.step4').removeClass('active');
- $('.step3').removeClass('complete');
- $('.step3').addClass('active');
- $("html, body").scrollTop(0);
- }
- self.goBackStep4 = function () {
- self.meta().displayStep5(false);
- self.meta().displayStep4(true);
- // set wizard step class
- $('.step5').removeClass('active');
- $('.step4').removeClass('complete');
- $('.step4').addClass('active');
- $("html, body").scrollTop(0);
- }
- self.goBackStep5 = function () {
- self.meta().displayStep6(false);
- self.meta().displayStep5(true);
- // set wizard step class
- $('.step6').removeClass('active');
- $('.step5').removeClass('complete');
- $('.step5').addClass('active');
- $("html, body").scrollTop(0);
- }
- //They click a div with class step
- $('.step').click(function () {
- if ($(this).hasClass('complete')) {
- //Save the current step they're on so you know how many steps to go back (check for class of active)
- var currentStep = $('.active').attr('id');
- var intendedStep = $(this).attr('id');
- currentStep = 'display' + currentStep + '(false)';
- intendedStep = 'display' + intendedStep + '(true)';
- //Remove class of active and complete from all Steps that are higher than the intendedStep
- switch (intendedStep) {
- case 'displayStep1(true)':
- self.goBackStep5();
- self.goBackStep4();
- self.goBackStep3();
- self.goBackStep2();
- self.goBackStep1();
- break;
- case 'displayStep2(true)':
- self.goBackStep5();
- self.goBackStep4();
- self.goBackStep3();
- self.goBackStep2();
- break;
- case 'displayStep3(true)':
- self.goBackStep5();
- self.goBackStep4();
- self.goBackStep3();
- break;
- case 'displayStep4(true)':
- self.goBackStep5();
- self.goBackStep4();
- break;
- case 'displayStep5(true)':
- self.goBackStep5();
- break;
- }
- }
- });
- self.user().educationHistory.push(new EducationInfo());
- self.user().workHistory.push(new WorkInfo());
- $('.step1').addClass('active');
- $('.warningText').hide();
- };
- var viewModel = new AppViewModel();
- ko.applyBindings(viewModel, document.getElementById("registration-form"));
- };
- if ($('#registration-form').html() != undefined) {
- buildON.registrationForm();
- }
- //My Dashboard
- buildON.myDashboard = function() {
- //Education Info Constructor
- function EducationInfo(level, name, completed, start, end) {
- var self = this;
- self.educationLevel = ko.observable(level);
- self.schoolName = ko.observable(name);
- self.completed = ko.observable(completed);
- self.startDate = ko.observable(start);
- self.endDate = ko.observable(end);
- };
- function LangTesting() {
- var self = this;
- self.langTest1 = ko.observable();
- self.langTest2 = ko.observable();
- self.langTest3 = ko.observable();
- };
- function WorkTesting() {
- var self = this;
- self.jobOffer = ko.observable();
- self.collegeOfTrades = ko.observable();
- self.canadaApprenticeProcess = ko.observable();
- self.choice1 = ko.observable();
- self.choice2 = ko.observable();
- self.choice3 = ko.observable();
- self.choice4 = ko.observable();
- };
- //Work Info Constructor
- function WorkInfo(title, name, type, yearsexp, countryofemployment, joboffer) {
- var self = this;
- self.workTitle = ko.observable(title);
- self.workName = ko.observable(name);
- self.typeOfWork = ko.observableArray([type]);
- self.yearsExp = ko.observable(yearsexp);
- self.countryOfEmployment = ko.observable(countryofemployment);
- self.jobOffer = ko.observable(joboffer);
- };
- //User Constructor
- function User() {
- var self = this;
- self.firstname = ko.observable();
- self.lastname = ko.observable();
- self.email = ko.observable();
- self.skype = ko.observable();
- self.birthday = ko.observable();
- self.preferredLanguage = ko.observable();
- self.tradeInterest = ko.observable();
- self.consentRegistration = ko.observable();
- self.approvedImmigrate = ko.observable();
- self.originCountry = ko.observable();
- self.immigrateOntario = ko.observable();
- self.livingOutsideCanada = ko.observable();
- self.tradesKnowledge = ko.observable();
- self.referal = ko.observable();
- self.username = ko.observable();
- self.password = ko.observable();
- self.uciNumber = ko.observable();
- self.gender = ko.observable();
- self.immigrationStatus = ko.observable();
- self.consentResearch = ko.observable();
- self.driversLicense = ko.observable();
- self.englishTesting = ko.observable(new LangTesting());
- self.frenchTesting = ko.observable(new LangTesting());
- self.workTesting = ko.observable(new WorkTesting());
- self.id = ko.observable();
- self.guid = ko.observable();
- self.workHistory = ko.observableArray([]);
- self.educationHistory = ko.observableArray([]);
- };
- var ProfileViewModel = function () {
- var self = this;
- //Overview is a property to watch for what element is being selected to edit
- //It's value will be set to the index of the element the user wants to edit. Ensures only that element is editable
- self.overview = ko.observable(null);
- //Same as overview but checking for edit state on the dashboard sections to be enabled
- self.editingEducationHistory = ko.observable(false);
- self.editingWorkHistory = ko.observable(false);
- self.editingProfile = ko.observable(false);
- //Same as overview but checking for add state on the dashboard sections to be enabled
- self.addingWork = ko.observable(false);
- self.addingEducation = ko.observable(false);
- //Create User object on the View Model to track all changes
- self.user = ko.observable(new User());
- //Debugging function to see what the current Model values are
- self.save = function () {
- console.log(ko.toJSON(self));
- console.log('--USER--');
- console.log(ko.toJSON(self.user()));
- };
- //Adds a new instance of the Work Info 'class' to the History array
- self.addWorkHistory = function () {
- self.user().workHistory.push(new WorkInfo());
- };
- //Adds a new instance of the Education Info 'class' to the History array
- self.addEducationHistory = function () {
- self.user().educationHistory.push(new EducationInfo());
- };
- //CRUD Functionality
- self.editProfile = function ($index) {
- self.editingProfile(true);
- };
- self.saveProfile = function ($index) {
- self.editingProfile(false);
- };
- self.editEducationHistory = function (id) {
- console.log(id());
- self.overview(id());
- self.editingEducationHistory(true);
- };
- self.editWorkHistory = function (id) {
- console.log(id());
- self.overview(id());
- self.editingWorkHistory(true);
- };
- self.newWorkElement = function () {
- self.addingWork(true);
- };
- self.newEducationElement = function () {
- self.addingEducation(true);
- };
- self.saveChange = function () {
- self.overview(null);
- self.editingWorkHistory(false);
- self.editingEducationHistory(false);
- self.addingWork(false);
- self.addingEducation(false);
- };
- self.saveWorkElement = function () {
- self.overview(null);
- self.editingWorkHistory(false);
- self.editingEducationHistory(false);
- self.addingWork(false);
- self.addingEducation(false);
- self.user().workHistory.push(new WorkInfo('Dev', 'Goog', [1, 2, 3], 'More than 10', 'France'));
- };
- self.saveEducationElement = function () {
- self.overview(null);
- self.editingWorkHistory(false);
- self.editingEducationHistory(false);
- self.addingWork(false);
- self.addingEducation(false);
- self.user().educationHistory.push(new EducationInfo('Uni', 'UofT', true, '09/10/2030', '09/10/2035'));
- };
- self.cancelChange = function () {
- self.overview(null);
- self.editingProfile(false);
- self.editingWorkHistory(false);
- self.editingEducationHistory(false);
- self.addingWork(false);
- self.addingEducation(false);
- };
- self.removeWork = function ($index) {
- self.user().workHistory.remove(this);
- };
- self.removeEducation = function ($index) {
- self.user().educationHistory.remove(this);
- };
- //Custom table Lookup Data init
- self.tradesLookup = ko.observableArray([]);
- self.countriesLookup = ko.observableArray([]);
- self.educationLookup = ko.observableArray([]);
- self.englishSkillsLookup = ko.observableArray([]);
- self.frenchSkillsLookup = ko.observableArray([]);
- self.immigrationStatusLookup = ko.observableArray([]);
- self.immigrationClassLookup = ko.observableArray([]);
- self.servicesLookup = ko.observableArray([]);
- self.yearsOfExperienceLookup = ko.observableArray([]);
- self.typeOfWorkLookup = ko.observableArray([]);
- self.familiarLevelLookup = ko.observableArray([]);
- self.preferLangLookup = ko.observableArray([]);
- self.genderLookup = ko.observableArray([]);
- self.destinationLookup = ko.observableArray([]);
- self.languageLevelLookup = ko.observableArray([]);
- self.maritalStatusLookup = ko.observableArray([]);
- $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
- if (data.Result != null) {
- var arrData = data.Result;
- var tradeItem = FindItemByKey("BuildON.Trades", arrData);
- if (tradeItem != undefined && tradeItem != null) {
- self.tradesLookup(tradeItem[0].Data);
- }
- var countryItem = FindItemByKey("BuildON.OriginCountry", arrData);
- if (countryItem != undefined && countryItem != null) {
- self.countriesLookup(countryItem[0].Data);
- }
- var educationItem = FindItemByKey("BuildON.EducationLevel", arrData);
- if (educationItem != undefined && educationItem != null) {
- self.educationLookup(educationItem[0].Data);
- }
- var englishItem = FindItemByKey("BuildON.EnglishSkills", arrData);
- if (englishItem != undefined && englishItem != null) {
- self.englishSkillsLookup(englishItem[0].Data);
- }
- var frenchItem = FindItemByKey("BuildON.FrenchSkills", arrData);
- if (frenchItem != undefined && frenchItem != null) {
- self.frenchSkillsLookup(frenchItem[0].Data);
- }
- var statusItem = FindItemByKey("BuildON.ImmigrationStatus", arrData);
- if (statusItem != undefined && statusItem != null) {
- self.immigrationStatusLookup(statusItem[0].Data);
- }
- var immigrationClassItem = FindItemByKey("BuildON.ImmigrationClass", arrData);
- if (immigrationClassItem != undefined && immigrationClassItem != null) {
- self.immigrationStatusLookup(immigrationClassItem[0].Data);
- }
- var servicesItem = FindItemByKey("BuildON.Services", arrData);
- if (servicesItem != undefined && servicesItem != null) {
- self.servicesLookup(servicesItem[0].Data);
- }
- var yearsItem = FindItemByKey("BuildON.YearsOfExperience", arrData);
- if (yearsItem != undefined && yearsItem != null) {
- self.yearsOfExperienceLookup(yearsItem[0].Data);
- }
- var typeOfWorkItem = FindItemByKey("BuildON.TypeOfWork", arrData);
- if (typeOfWorkItem != undefined && typeOfWorkItem != null) {
- self.typeOfWorkLookup(typeOfWorkItem[0].Data);
- }
- var familiarLevelItem = FindItemByKey("BuildON.FamiliarLevel", arrData);
- if (familiarLevelItem != undefined && familiarLevelItem != null) {
- self.familiarLevelLookup(familiarLevelItem[0].Data);
- }
- var preferLangItem = FindItemByKey("BuildON.PreferredLanguage", arrData);
- if (preferLangItem != undefined && preferLangItem != null) {
- self.preferLangLookup(preferLangItem[0].Data);
- }
- var genderItem = FindItemByKey("BuildON.Gender", arrData);
- if (genderItem != undefined && genderItem != null) {
- self.genderLookup(genderItem[0].Data);
- }
- var destinationItem = FindItemByKey("BuildON.Destination", arrData);
- if (destinationItem != undefined && destinationItem != null) {
- self.destinationLookup(destinationItem[0].Data);
- }
- var langLevelItem = FindItemByKey("BuildON.LanguageLevel", arrData);
- if (langLevelItem != undefined && langLevelItem != null) {
- self.languageLevelLookup(langLevelItem[0].Data);
- }
- var maritalStatusItem = FindItemByKey("BuildON.MaritalStatus", arrData);
- if (maritalStatusItem != undefined && maritalStatusItem != null) {
- self.maritalStatusLookup(maritalStatusItem[0].Data);
- }
- }
- });
- self.GetGender = function (guid) {
- return FindItemByGuid(guid, self.genderLookup());
- };
- self.GetTrade = function (guid) {
- return FindItemByGuid(guid, self.tradesLookup());
- };
- self.GetCountry = function (guid) {
- return FindItemByGuid(guid, self.countriesLookup());
- };
- self.GetEducation = function (guid) {
- return FindItemByGuid(guid, self.educationLookup());
- };
- self.GetEnglishSkill = function (guid) {
- return FindItemByGuid(guid, self.englishSkillsLookup());
- };
- self.GetFrenchSkill = function (guid) {
- return FindItemByGuid(guid, self.frenchSkillsLookup());
- };
- self.GetImmigrationStatus = function (guid) {
- return FindItemByGuid(guid, self.immigrationStatusLookup());
- };
- self.GetImmigrationClass = function (guid) {
- return FindItemByGuid(guid, self.immigrationClassLookup());
- };
- self.GetService = function (guid) {
- return FindItemByGuid(guid, self.servicesLookup());
- };
- self.GetYearOfExperience = function (guid) {
- return FindItemByGuid(guid, self.yearsOfExperienceLookup());
- };
- self.GetWrokType = function (guid) {
- return FindItemByGuid(guid, self.typeOfWorkLookup());
- };
- self.GetFamiliarLevel = function (guid) {
- return FindItemByGuid(guid, self.familiarLevelLookup());
- };
- self.GetPreferLang = function (guid) {
- return FindItemByGuid(guid, self.preferLangLookup());
- };
- self.GetDestination = function (guid) {
- return FindItemByGuid(guid, self.destinationLookup());
- };
- self.GetMaritalStatus = function (guid) {
- return FindItemByGuid(guid, self.maritalStatusLookup());
- };
- self.GetLanguageLevel = function (guid) {
- return FindItemByGuid(guid, self.languageLevelLookup());
- };
- var userid = 72
- var settings = {
- "async": true,
- "crossDomain": true,
- "url": "/api/ClientUser?id=" + userid,
- "method": "GET",
- "headers": {
- "cache-control": "no-cache",
- "postman-token": "e57a474c-3fb5-8945-5487-45ac9047cadb",
- }
- };
- $.ajax(settings).done(function (data) {
- console.log(data);
- //Updating Profile Info
- self.user(ko.mapping.fromJS(data.Result));
- //Change First Title on Education Dashboard
- $('.education-title').first().text('Highest Education Level');
- /*
- $('.edit-link').click(function(){
- editLink = $(this).context;
- console.log(editLink);
- currentName = $(editLink).attr('name');
- editEle = $("[name="+currentName+"]").find('.edit');
- infoEle = $("[name="+currentName+"]").find('.current-info');
- console.log(editEle);
- console.log(infoEle);
- $(infoEle).hide();
- $(editEle).show();
- });
- */
- });
- }
- var viewModel = new ProfileViewModel();
- ko.applyBindings(viewModel, document.getElementById("dashboard-home"));
- };
- if ($('#dashboard-home').html() != undefined) {
- buildON.myDashboard();
- }
- }(jQuery));
- $(window).on('resize', function () {
- // hide autocomplete dropdown on resize
- $(".ui-autocomplete").css('display', 'none');
- });
- // custom select box styling
- // call for update panel refresh
- $(function pageLoad(sender, args) {
- $('.select-item select').customSelect();
- });
- // reCaptcha
- var captchaValid = false;
- function captchaCallback() {
- captchaValid = true;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement