Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // JavaScript Document
- var buildON = {};
- (function ($) {
- "use strict";
- $('.englishBtn').click(function () {
- $.cookie("BuildONPreferredCultureSet", "en", { expires: 365, path: '/' });
- });
- $('.frenchBtn').click(function () {
- $.cookie("BuildONPreferredCultureSet", "fr", { expires: 365, path: '/' });
- });
- $('.popup-modal-removeEducationHistory').magnificPopup();
- $('.popup-modal-removeWorkHistory').magnificPopup();
- // site current culture
- var lang = "en-CA";
- ($('#lng') != null && $('#lng').val() != "") ? lang = $('#lng').val() : "en-CA";
- // empty GUID
- var emptyGuid = "00000000-0000-0000-0000-000000000000";
- buildON.options = {
- mobileWidth: 768
- };
- //until funcitons
- function FindItemByKey(key, arrayData) {
- var findItem = $.grep(arrayData, function (e) {
- return e.Key == key;
- });
- 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) {
- var stringName = "";
- if (guid != "" && guid != undefined) {
- if (typeof (guid) == "object") {
- 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) {
- if (stringName === "") {
- stringName += result[0].Name;
- } else {
- 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;
- } else {
- return guid;
- }
- }
- return guid;
- }
- 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 () {
- if ((this).href.indexOf('#t1') > -1) {
- //e.preventDefault();
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#t1').addClass('current');
- $('#navChecklist').addClass('current');
- $('html,body').animate({ scrollTop: 0 }, 100);
- }
- if ((this).href.indexOf('#t2') > -1) {
- //e.preventDefault();
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#t2').addClass('current');
- $('#navProfile').addClass('current');
- $('html,body').animate({ scrollTop: 0 }, 100);
- }
- if ((this).href.indexOf('#t3') > -1) {
- //e.preventDefault();
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#t3').addClass('current');
- $('#navEmploymentHistory').addClass('current');
- $('html,body').animate({ scrollTop: 0 }, 100);
- }
- if ((this).href.indexOf('#t4') > -1) {
- //e.preventDefault();
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#t4').addClass('current');
- $('#navEducation').addClass('current');
- $('html,body').animate({ scrollTop: 0 }, 100);
- }
- if ((this).href.indexOf('#t5') > -1) {
- //e.preventDefault();
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#t5').addClass('current');
- $('#navAchievements').addClass('current');
- $('html,body').animate({ scrollTop: 0 }, 100);
- }
- });
- };
- 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 () {
- $(".row .cta").matchHeight();
- $(".col.border-left").matchHeight();
- $(".workshop-tile").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();
- // 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").toggleClass("open");
- });
- $(".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();
- this.langTest2 = ko.observable();
- this.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() {
- this.workTitle = ko.observable();
- this.workName = ko.observable();
- this.typeOfWork = ko.observableArray([]);
- this.yearsExp = ko.observable();
- this.countryOfEmployment = ko.observable();
- this.lastYearWorkedInField = 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.originCountryOther = ko.observable();
- this.immigrateOntario = ko.observable();
- this.livingOutsideCanada = ko.observable();
- this.tradesKnowledge = ko.observable();
- this.referral = ko.observable();
- this.username = ko.observable();
- this.password = ko.observable();
- this.uciNumber = ko.observable();
- this.gender = ko.observable();
- this.immigrationStatus = ko.observable();
- self.immigrationClass = ko.observable();
- this.consentResearch = ko.observable();
- this.driversLicense = ko.observable();
- self.preferredName = ko.observable('--');
- self.maritalStatus = ko.observable('--');
- self.motherTongue = ko.observable('--');
- self.otherLang = ko.observable('--');
- self.preferredDestination = ko.observable('--');
- self.englishLanguageLevel = ko.observable('--');
- self.frenchLanguageLevel = ko.observable('--');
- self.specialCircumstances = ko.observable('--');
- this.workHistory = ko.observableArray([]);
- this.educationHistory = ko.observableArray([]);
- this.id = ko.observable(null);
- this.guid = ko.observable('guid');
- this.englishTesting = ko.observable({});
- this.frenchTesting = ko.observable({});
- this.workTesting = ko.observable(new WorkTesting());
- };
- //Main Knockout View Model
- var AppViewModel = function () {
- var self = this;
- self.mEnglishSkills = ko.observableArray([]);
- self.mFrenchSkills = ko.observableArray([]);
- //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([]);
- self.reasonsLookup = ko.observableArray([]);
- $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
- if (data.Result != null) {
- 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);
- }
- var reasonsItem = FindItemByKey("BuildON.ReasonsNotQualifying", data.Result);
- if (reasonsItem != undefined && reasonsItem != null) {
- self.reasonsLookup(reasonsItem[0].Data);
- }
- }
- });
- //Push original objects to history arrays
- self.user = ko.observable(new User());
- self.meta = ko.observable(new Meta());
- 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=workCheckbox0]').attr('for', newAttr1);
- $('.checkboxGroup').last().find('label[for=workCheckbox1]').attr('for', newAttr2);
- $('.checkboxGroup').last().find('label[for=workCheckbox2]').attr('for', newAttr3);
- $('.checkboxGroup').last().find('label[for=workCheckbox3]').attr('for', newAttr4);
- $('.checkboxGroup').last().find('input[id=workCheckbox0]').attr('id', newAttr1);
- $('.checkboxGroup').last().find('input[id=workCheckbox1]').attr('id', newAttr2);
- $('.checkboxGroup').last().find('input[id=workCheckbox2]').attr('id', newAttr3);
- $('.checkboxGroup').last().find('input[id=workCheckbox3]').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();
- educationHist.splice(lastItem, 1);
- 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();
- workHist.splice(lastItem, 1);
- self.user().workHistory(workHist);
- };
- self.skipEducation = function () {
- //Sets all the values from this step to undefined
- self.user().educationHistory([]);
- self.user().englishTesting({});
- self.user().frenchTesting({});
- 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().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);
- var registrationData = ko.toJSON(self);
- 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) {
- var errors = response.Result.errors;
- if (errors.length > 0) {
- $('.warningText.errors').remove();
- $.map(errors, function (error) {
- var output = "<p class='warningText errors'><strong>" + error.message + "</strong></p>";
- $('.wizard-steps').after(output);
- $('.warningText.errors').show();
- $("html, body").scrollTop(0);
- });
- } else {
- self.user().workHistory([]);
- document.location.href = $('#hideSuccessPageUrl').val();
- }
- });
- };
- // check year has to be 4 digits and between 1950 and current year
- self.checkLastYearWorkedInField = function (input) {
- var reg = /^\d{4}$/;
- if (!reg.test(input)) {
- return false;
- }
- var year = Number(input);
- if (year >= 1950 && year <= currentYear) {
- return true;
- } else {
- return false;
- }
- }
- 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 () {
- for (var enProp in self.englishSkillsLookup()) {
- var lookUpGuid = self.englishSkillsLookup()[enProp]["ItemGuid"];
- // see if lookUpGuid is in
- self.user().englishTesting()[lookUpGuid] = false;
- }
- for (var frProp in self.frenchSkillsLookup()) {
- var lookUpGuid = self.frenchSkillsLookup()[frProp]["ItemGuid"];
- // see if lookUpGuid is in
- self.user().frenchTesting()[lookUpGuid] = false;
- }
- if (self.user().consentRegistration() == true) {
- $('.warningTextconsentRegistration').hide();
- } else {
- $('.warningTextconsentRegistration').show();
- }
- if (self.user().tradeInterest() == '' || self.user().tradeInterest() == undefined) {
- $('.warningTexttradeInterest').show();
- } else {
- $('.warningTexttradeInterest').hide();
- }
- if (captchaValid === false) {
- $('.warningTextRecaptcha').show();
- } else {
- $('.warningTextRecaptcha').hide();
- }
- if (self.user().consentRegistration() == true && self.user().tradeInterest() !== '' && self.user().tradeInterest() !== undefined && captchaValid) {
- 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() == 'false' || self.user().approvedImmigrate() == false) {
- errors.push(self.reasonsLookup()[0].ItemGuid);
- } else if (self.user().approvedImmigrate() === undefined) {
- $('.warningTextapprovedImmigrate').show();
- } else {
- $('.warningTextapprovedImmigrate').hide();
- }
- if (self.user().immigrateOntario() == 'false' || self.user().immigrateOntario() == false) {
- errors.push(self.reasonsLookup()[2].ItemGuid);
- } else if (self.user().immigrateOntario() === undefined) {
- $('.warningTextimmigrateOntario').show();
- } else {
- $('.warningTextimmigrateOntario').hide();
- }
- if (self.user().livingOutsideCanada() === undefined) {
- $('.warningTextlivingOutsideCanada').show();
- } else {
- $('.warningTextlivingOutsideCanada').hide();
- }
- //TO-DO: make this global variable?
- var otherCountry = 'f4a46169-f778-4140-80a9-0e671dd3ee60';
- if (String(self.user().originCountry()) === otherCountry && self.user().originCountryOther() === undefined || self.user().originCountryOther() === "") {
- $('.warningTextoriginCountryOther').show();
- } else {
- $('.warningTextoriginCountryOther').hide();
- }
- if (self.user().originCountry() === undefined || self.user().originCountry() === '') {
- $('.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() == 'true' && self.user().immigrateOntario() != undefined && self.user().originCountry() !== undefined && self.user().originCountry() !== otherCountry || self.user().originCountryOther() !== undefined) {
- 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) {
- //get Not Qualify url and appending the right reasons GUIDS in the query string.
- var failUrl = $('#hrefReasonTop').attr('href');
- failUrl += "?reasons=" + errors.join();
- $('#hrefReasonTop').attr('href', failUrl);
- $('#hrefReasonBtm').attr('href', failUrl);
- $('#popup-modal-notQualified').attr('href', '#notQualified-modal');
- } else {
- $('#popup-modal-notQualified').attr('href', '');
- }
- }
- self.checkStep3 = function () {
- if (self.user().tradesKnowledge() === undefined) {
- $('.warningTexttradesKnowledge').show();
- } else { $('.warningTexttradesKnowledge').hide(); }
- if (self.user().referral() === undefined || self.user().referral() === '') {
- $('.warningTextreferral').show();
- } else {
- $('.warningTextreferral').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().referral() !== undefined) {
- 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...
- var pass = self.user().password();
- var reg = /^(?=.*(\W)).{6,20}$/i;
- if (self.user().username() == undefined || self.user().username() == "") {
- $('.warningTextusername').show();
- } else { $('.warningTextusername').hide(); }
- if (self.user().password() == undefined || self.user().password() == "" || reg.test(pass) == false) {
- $('.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() && reg.test(pass) == true && 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);
- } else {
- $("html, body").scrollTop(0);
- }
- }
- self.checkStep5 = function () {
- for (var prop in self.user().englishTesting()) {
- if (self.mEnglishSkills().indexOf(prop) != -1) {
- self.user().englishTesting()[prop] = true;
- } else {
- self.user().englishTesting()[prop] = false;
- }
- }
- for (var prop in self.user().frenchTesting()) {
- if (self.mFrenchSkills().indexOf(prop) != -1) {
- self.user().frenchTesting()[prop] = true;
- } else {
- self.user().frenchTesting()[prop] = false;
- }
- }
- //RegEx for Start/Finished dates in the Education section (must fit MM/DD/YYYY format)
- var allEducationDates = document.querySelectorAll('.educationDates');
- var allStartDates = document.querySelectorAll('.startDates');
- var allEndDates = document.querySelectorAll('.endDates');
- if (self.user().educationHistory()[0].completed() === undefined) {
- $('.warningTextCompleted').show();
- } else {
- $('.warningTextCompleted').hide();
- }
- if (self.user().educationHistory()[0].schoolName() === undefined) {
- $('.warningTextinstitutionName').show();
- } else {
- $('.warningTextinstitutionName').hide();
- }
- if (self.user().educationHistory()[0].educationLevel() !== undefined && self.user().educationHistory()[0].educationLevel() !== "") {
- var forwardStart = true;
- var forwardEnd = true;
- $.each(allStartDates, function (index, value) {
- var currentVal = $(this).val();
- var currentEle = $(this).context;
- if (self.checkDate(currentVal)) {
- $(currentEle).parent().next('.warningTextDate').hide();
- } else {
- forwardStart = false;
- $(currentEle).parent().next('.warningTextDate').show();
- }
- });
- $.each(allEndDates, function (index, value) {
- var currentVal = $(this).val();
- var currentEle = $(this).context;
- if (self.checkDate(currentVal)) {
- $(currentEle).parent().next('.warningTextDate').hide();
- } else {
- forwardEnd = false;
- $(currentEle).parent().next('.warningTextDate').show();
- }
- });
- if (forwardStart && forwardEnd) {
- self.meta().displayStep5(false);
- self.meta().displayStep6(true);
- $('.warningText').hide();
- $('.step5').removeClass('active');
- $('.step5').addClass('complete');
- $('.step6').addClass('active');
- $("html, body").scrollTop(0);
- }
- } 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 () {
- var allLastWorkedDates = document.querySelectorAll('.lastWorkedDates');
- var yearErrors = [];
- var registrationData = ko.toJSON(self);
- $.each(allLastWorkedDates, function (index, value) {
- var currentVal = $(this).val();
- var currentEle = $(this).context;
- if(currentVal != ""){
- if (self.checkLastYearWorkedInField(currentVal)) {
- $(currentEle).parent().next('.warningTextwhenLastWorkedInField').hide();
- } else {
- yearErrors.push('error');
- $(currentEle).parent().next('.warningTextwhenLastWorkedInField').show();
- }
- }
- });
- if (yearErrors.length > 0) {
- $('.warningText.errors').show();
- $("html, body").scrollTop(0);
- } else {
- 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) {
- var errors = response.Result.errors;
- if (errors.length > 0) {
- $('.warningText.errors').remove();
- $.map(errors, function (error) {
- var output = "<p class='warningText errors'><strong>" + error.message + "</strong></p>";
- $('.wizard-steps').after(output);
- $('.warningText.errors').show();
- $("html, body").scrollTop(0);
- });
- } else {
- document.location.href = $('#hideSuccessPageUrl').val();
- }
- });
- }
- }
- // 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);
- var educationLength = self.user().educationHistory().length;
- if (educationLength == 0) {
- self.user().educationHistory.push(new EducationInfo());
- }
- // 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 () {
- // My Dashboard dropdown on header
- var url = window.location.href;
- if ((url).indexOf('#t1') > -1) {
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#t1').addClass('current');
- $('#navChecklist').addClass('current');
- $('html,body').animate({ scrollTop: 0 }, 100);
- }
- if ((url).indexOf('#t2') > -1) {
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#t2').addClass('current');
- $('#navProfile').addClass('current');
- $('html,body').animate({ scrollTop: 0 }, 100);
- }
- if ((url).indexOf('#t3') > -1) {
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#t3').addClass('current');
- $('#navEmploymentHistory').addClass('current');
- $('html,body').animate({ scrollTop: 0 }, 100);
- }
- if ((url).indexOf('#t4') > -1) {
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#t4').addClass('current');
- $('#navEducation').addClass('current');
- $('html,body').animate({ scrollTop: 0 }, 100);
- }
- if ((url).indexOf('#t5') > -1) {
- var tab_id = $('ul.tabs li').attr('data-tab');
- $('.tab-content').removeClass('current');
- $('.tab-link').removeClass('current');
- $('#t5').addClass('current');
- $('#navAchievements').addClass('current');
- $('html,body').animate({ scrollTop: 0 }, 100);
- }
- //Education Info Constructor
- function EducationInfo(level, name, complete, start, end) {
- var self = this;
- self.educationLevel = ko.observable(level);
- self.schoolName = ko.observable(name);
- self.completed = ko.observable(complete);
- 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, lastyearworkedinfield) {
- 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.lastYearWorkedInField = ko.observable(lastyearworkedinfield);
- };
- //User Constructor
- function User() {
- var self = this;
- self.firstname = ko.observable();
- self.lastname = ko.observable();
- self.preferredName = ko.observable();
- self.email = ko.observable();
- self.skype = ko.observable();
- self.birthday = ko.observable();
- self.preferredLanguage = ko.observable();
- self.motherTongue = ko.observable('--');
- self.otherLang = ko.observable('--');
- self.specialCircumstances = 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.referral = ko.observable();
- self.username = ko.observable();
- self.password = ko.observable();
- self.uciNumber = ko.observable();
- self.gender = ko.observable();
- self.immigrationStatus = ko.observable();
- self.immigrationClass = ko.observable();
- self.preferredDestination = ko.observable('--');
- self.consentResearch = ko.observable();
- self.driversLicense = ko.observable();
- self.englishTesting = ko.observable({});
- self.frenchTesting = ko.observable();
- self.englishLanguageLevel = ko.observable('--');
- self.frenchLanguageLevel = ko.observable('--');
- self.workTesting = ko.observable(new WorkTesting());
- self.maritalStatus = ko.observable('--');
- //self.newJobTitle = ko.observable();
- //self.newCompanyName = ko.observable();
- //self.newTypeOfWork = ko.observableArray([]);
- //self.newYearsExp = ko.observable();
- //self.newCountryEmployment = ko.observable();
- 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);
- self.newJobTitle = ko.observable();
- self.newCompanyName = ko.observable();
- self.newTypeOfWork = ko.observableArray([]); //'d6bae28a-ea86-4c01-8254-e91312c39a13'
- self.newYearsExp = ko.observable();
- self.newCountryEmployment = ko.observable();
- self.newWorkedInField = ko.observable();
- self.newEduLevel = ko.observable();
- self.newSchoolName = ko.observable();
- self.newComplete = ko.observable();
- self.newStart = ko.observable();
- self.newEnd = ko.observable();
- //Create User object on the View Model to track all changes
- self.user = ko.observable(new 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);
- if(self.user().workTesting.jobOffer() == true){
- $('.jobOfferYes').show();
- $('.jobOfferNo').hide();
- } else {
- $('.jobOfferYes').hide();
- $('.jobOfferNo').show();
- }
- // custom select styles
- $('.select-item select').customSelect();
- };
- self.editEducationHistory = function (id) {
- self.overview(id());
- self.editingEducationHistory(true);
- // custom select styles
- $('.select-item select').customSelect();
- };
- self.editWorkHistory = function (id) {
- self.overview(id());
- self.editingWorkHistory(true);
- // custom select styles
- $('.select-item select').customSelect();
- };
- self.newWorkElement = function () {
- self.newJobTitle('');
- self.newCompanyName('');
- self.newTypeOfWork([]);
- self.newYearsExp();
- self.newCountryEmployment('');
- self.newWorkedInField('');
- self.addingWork(true);
- // custom select styles
- $('.select-item select').customSelect();
- $('.popup-modal-removeEducationHistory').magnificPopup();
- $('.popup-modal-removeWorkHistory').magnificPopup();
- };
- self.newEducationElement = function () {
- self.newEduLevel();
- self.newSchoolName('');
- self.newComplete();
- self.newStart('');
- self.newEnd('');
- self.addingEducation(true);
- // custom select styles
- $('.select-item select').customSelect();
- $('.popup-modal-removeEducationHistory').magnificPopup();
- $('.popup-modal-removeWorkHistory').magnificPopup();
- };
- // check year has to be 4 digits and between 1950 and current year
- self.checkLastYearWorkedInField = function (input) {
- var reg = /^\d{4}$/;
- if (!reg.test(input)) {
- return false;
- }
- var year = Number(input);
- if (year >= 1950 && year <= currentYear) {
- return true;
- } else {
- return false;
- }
- }
- self.saveNewWork = function () {
- if (self.newJobTitle() == undefined || self.newJobTitle() == "") {
- self.newJobTitle('--');
- }
- if (self.newCompanyName() == undefined || self.newCompanyName() == "") {
- self.newCompanyName('--');
- }
- if (self.newCountryEmployment() == undefined || self.newCountryEmployment() == "") {
- self.newCountryEmployment('--');
- }
- var title = self.newJobTitle();
- var company = self.newCompanyName();
- var type = self.newTypeOfWork();
- var yearsExp = self.newYearsExp();
- var country = self.newCountryEmployment();
- var workedinfield = self.newWorkedInField();
- if (title == "" && company == "" && yearsExp == undefined && country == "" && type.length == 0 || self.checkLastYearWorkedInField(workedinfield) == false) {
- $('.warningText.errors').remove();
- $('.employmentHistory-header').after('<p class="warningText errors" style="display: block"><strong>Please enter some valid employment history information</strong></p>');
- } else {
- self.user().workHistory.push(new WorkInfo(title, company, type, yearsExp, country, workedinfield));
- var registrationData = ko.toJSON(self.user());
- var settings = {
- "async": true,
- "crossDomain": true,
- "url": "/api/ClientUser/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) {
- var errors = response.Result.errors;
- if (errors.length > 0) {
- self.user().workHistory.pop();
- $('.warningText.errors').remove();
- $.map(errors, function (error) {
- var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
- $('.employmentHistory-header').after(output);
- });
- } else {
- $('.warningText.errors').remove();
- self.overview(null);
- self.editingWorkHistory(false);
- self.editingEducationHistory(false);
- self.addingWork(false);
- self.addingEducation(false);
- $('.popup-modal-removeWorkHistory').magnificPopup();
- }
- });
- }
- };
- self.saveNewEducation = function () {
- if (self.newSchoolName() == undefined || self.newSchoolName() == "") {
- self.newSchoolName('--');
- }
- var level = self.newEduLevel();
- var name = self.newSchoolName();
- var complete = self.newComplete();
- var start = self.newStart();
- var end = self.newEnd();
- if(level != undefined || name != "" || start != "" || end != "") {
- self.user().educationHistory.push(new EducationInfo(level, name, complete, start, end));
- var registrationData = ko.toJSON(self.user());
- var settings = {
- "async": true,
- "crossDomain": true,
- "url": "/api/ClientUser/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) {
- var errors = response.Result.errors;
- if (errors.length > 0) {
- $('.warningText.errors').remove();
- self.user().educationHistory.pop();
- $.map(errors, function (error) {
- var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
- $('.education-header').after(output);
- });
- $('html,body').animate({ scrollTop: 0 }, 100);
- } else {
- $('.warningText.errors').remove();
- self.overview(null);
- self.editingWorkHistory(false);
- self.editingEducationHistory(false);
- self.addingWork(false);
- self.addingEducation(false);
- $('.popup-modal-removeEducationHistory').magnificPopup();
- }
- });
- } else {
- $('.warningText.errors').remove();
- $('.education-header').after('<p class="warningText errors" style="display: block"><strong>Please enter some valid education history information</strong></p>');
- }
- };
- self.saveChange = function () {
- self.overview(null);
- self.editingWorkHistory(false);
- self.editingEducationHistory(false);
- self.addingWork(false);
- self.addingEducation(false);
- $('.popup-modal-removeEducationHistory').magnificPopup();
- $('.popup-modal-removeWorkHistory').magnificPopup();
- };
- self.saveWorkElement = function () {
- if (this.workTitle() == undefined || this.workTitle() == "") {
- this.workTitle('--');
- }
- if (this.workName() == undefined || this.workName() == "") {
- this.workName('--');
- }
- if (this.countryOfEmployment() == undefined || this.countryOfEmployment() == "") {
- this.countryOfEmployment('--');
- }
- var title = this.workTitle();
- var company = this.workName();
- var type = this.typeOfWork();
- var yearsExp = this.yearsExp();
- var country = this.countryOfEmployment();
- var workedinfield = this.lastYearWorkedInField();
- if (title == "" && company == "" && yearsExp == undefined && country == "" && type.length == 0 || self.checkLastYearWorkedInField(workedinfield) == false) {
- $('.warningText.errors').remove();
- $('.employmentHistory-header').after('<p class="warningText errors" style="display: block"><strong>Please enter some valid employment history information</strong></p>');
- } else {
- $('.warningText.errors').remove();
- var registrationData = ko.toJSON(self.user());
- var settings = {
- "async": true,
- "crossDomain": true,
- "url": "/api/ClientUser/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) {
- var errors = response.Result.errors;
- if (errors.length > 0) {
- $('.warningText.errors').remove();
- $.map(errors, function (error) {
- var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
- $('.employmentHistory-header').after(output);
- });
- } else {
- self.overview(null);
- self.editingWorkHistory(false);
- self.editingEducationHistory(false);
- self.addingWork(false);
- self.addingEducation(false);
- $('.popup-modal-removeWorkHistory').magnificPopup();
- }
- });
- }
- };
- self.saveEducationElement = function () {
- var registrationData = ko.toJSON(self.user());
- var settings = {
- "async": true,
- "crossDomain": true,
- "url": "/api/ClientUser/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) {
- var errors = response.Result.errors;
- if (errors.length > 0) {
- $('.warningText.errors').remove();
- $.map(errors, function (error) {
- var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
- $('.education-header').after(output);
- });
- } else {
- self.overview(null);
- self.editingWorkHistory(false);
- self.editingEducationHistory(false);
- self.addingWork(false);
- self.addingEducation(false);
- $('.popup-modal-removeEducationHistory').magnificPopup();
- }
- });
- };
- self.saveProfile = function ($index) {
- var registrationData = ko.toJSON(self.user());
- var settings = {
- "async": true,
- "crossDomain": true,
- "url": "/api/ClientUser/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) {
- var errors = response.Result.errors;
- if (errors.length > 0) {
- $('.warningText.errors').remove();
- $.map(errors, function (error) {
- var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
- $('.profile-header').after(output);
- });
- if(self.user().workTesting.jobOffer() == true){
- $('.jobOfferYes').show();
- $('.jobOfferNo').hide();
- } else {
- $('.jobOfferYes').hide();
- $('.jobOfferNo').show();
- }
- $('html,body').animate({ scrollTop: 0 }, 100);
- } else {
- if (self.user().motherTongue() == '') {
- self.user().motherTongue('--');
- }
- if (self.user().otherLang() == '') {
- self.user().otherLang('--');
- }
- if (self.user().specialCircumstances() == '') {
- self.user().specialCircumstances('--');
- }
- if (self.user().preferredName() == '') {
- self.user().preferredName('--');
- }
- if (self.user().skype() == '') {
- self.user().skype('--');
- }
- if (self.user().maritalStatus() == emptyGuid) {
- self.user().maritalStatus('--');
- }
- if (self.user().preferredDestination() == emptyGuid) {
- self.user().preferredDestination('--');
- }
- if (self.user().englishLanguageLevel() == emptyGuid) {
- self.user().englishLanguageLevel('--');
- }
- if (self.user().frenchLanguageLevel() == emptyGuid) {
- self.user().frenchLanguageLevel('--');
- }
- if (self.user().immigrationClass() == emptyGuid) {
- self.user().immigrationClass('--');
- }
- if(self.user().workTesting.jobOffer() == true){
- $('.jobOfferYes').show();
- $('.jobOfferNo').hide();
- } else {
- $('.jobOfferYes').hide();
- $('.jobOfferNo').show();
- }
- $('.warningText.errors').remove();
- self.editingProfile(false);
- if(self.user().workTesting.jobOffer() == true){
- $('.jobOfferYes').show();
- $('.jobOfferNo').hide();
- } else {
- $('.jobOfferYes').hide();
- $('.jobOfferNo').show();
- }
- }
- if(self.user().workTesting.jobOffer() == true){
- $('.jobOfferYes').show();
- $('.jobOfferNo').hide();
- } else {
- $('.jobOfferYes').hide();
- $('.jobOfferNo').show();
- }
- });
- if(self.user().workTesting.jobOffer() == true){
- $('.jobOfferYes').show();
- $('.jobOfferNo').hide();
- } else {
- $('.jobOfferYes').hide();
- $('.jobOfferNo').show();
- }
- };
- self.cancelChange = function () {
- 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) {
- //Updating Profile Info
- var aUser = ko.mapping.fromJS(data.Result);
- self.user(ko.mapping.fromJS(data.Result));
- //Change First Title on Education Dashboard
- $('.education-title').first().text('Highest Education Level');
- $('.popup-modal-removeWorkHistory').magnificPopup();
- $('.popup-modal-removeEducationHistory').magnificPopup();
- if (self.user().motherTongue() == '') {
- self.user().motherTongue('--');
- }
- if (self.user().otherLang() == '') {
- self.user().otherLang('--');
- }
- if (self.user().specialCircumstances() == '') {
- self.user().specialCircumstances('--');
- }
- if (self.user().preferredName() == '') {
- self.user().preferredName('--');
- }
- if (self.user().skype() == '') {
- self.user().skype('--');
- }
- if (self.user().maritalStatus() == emptyGuid) {
- self.user().maritalStatus('--');
- }
- if (self.user().preferredDestination() == emptyGuid) {
- self.user().preferredDestination('--');
- }
- if (self.user().englishLanguageLevel() == emptyGuid) {
- self.user().englishLanguageLevel('--');
- }
- if (self.user().frenchLanguageLevel() == emptyGuid) {
- self.user().frenchLanguageLevel('--');
- }
- if (self.user().immigrationClass() == emptyGuid) {
- self.user().immigrationClass('--');
- }
- if(self.user().workTesting.jobOffer() == true){
- $('.jobOfferYes').show();
- $('.jobOfferNo').hide();
- }
- if(self.user().workTesting.jobOffer() == false){
- $('.jobOfferNo').show();
- $('.jobOfferYes').hide();
- }
- });
- if(self.user().workTesting.jobOffer() == true){
- $('.jobOfferYes').show();
- $('.jobOfferNo').hide();
- } else {
- $('.jobOfferYes').hide();
- $('.jobOfferNo').show();
- }
- self.overview(null);
- self.editingProfile(false);
- self.editingWorkHistory(false);
- self.editingEducationHistory(false);
- self.addingWork(false);
- self.addingEducation(false);
- $('.warningText.errors').remove();
- };
- self.removeWork = function ($index) {
- self.user().workHistory.remove(this);
- var registrationData = ko.toJSON(self.user());
- var settings = {
- "async": true,
- "crossDomain": true,
- "url": "/api/ClientUser/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) {
- $('.popup-modal-removeEducationHistory').magnificPopup();
- $('.popup-modal-removeWorkHistory').magnificPopup();
- var errors = response.Result.errors;
- if (errors.length > 0) {
- $.map(errors, function (error) {
- var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
- $('.employmentHistory-header').after(output);
- });
- }
- });
- };
- self.removeEducation = function ($index) {
- self.user().educationHistory.remove(this);
- var registrationData = ko.toJSON(self.user());
- var settings = {
- "async": true,
- "crossDomain": true,
- "url": "/api/ClientUser/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) {
- $('.popup-modal-removeEducationHistory').magnificPopup();
- $('.popup-modal-removeWorkHistory').magnificPopup();
- var errors = response.Result.errors;
- if (errors.length > 0) {
- $.map(errors, function (error) {
- var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
- $('.education-header').after(output);
- });
- }
- });
- };
- //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.immigrationClassLookup(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 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) {
- //Updating Profile Info
- var aUser = ko.mapping.fromJS(data.Result);
- self.user(ko.mapping.fromJS(data.Result));
- //Change First Title on Education Dashboard
- $('.education-title').first().text('Highest Education Level');
- $('.popup-modal-removeWorkHistory').magnificPopup();
- $('.popup-modal-removeEducationHistory').magnificPopup();
- if (self.user().motherTongue() == '') {
- self.user().motherTongue('--');
- }
- if (self.user().otherLang() == '') {
- self.user().otherLang('--');
- }
- if (self.user().specialCircumstances() == '') {
- self.user().specialCircumstances('--');
- }
- if (self.user().preferredName() == '') {
- self.user().preferredName('--');
- }
- if (self.user().skype() == '') {
- self.user().skype('--');
- }
- if (self.user().maritalStatus() == emptyGuid) {
- self.user().maritalStatus('--');
- }
- if (self.user().preferredDestination() == emptyGuid) {
- self.user().preferredDestination('--');
- }
- if (self.user().englishLanguageLevel() == emptyGuid) {
- self.user().englishLanguageLevel('--');
- }
- if (self.user().frenchLanguageLevel() == emptyGuid) {
- self.user().frenchLanguageLevel('--');
- }
- if (self.user().immigrationClass() == emptyGuid) {
- self.user().immigrationClass('--');
- }
- if(self.user().workTesting.jobOffer() == true){
- $('.jobOfferYes').show();
- $('.jobOfferNo').hide();
- }
- if(self.user().workTesting.jobOffer() == false){
- $('.jobOfferNo').show();
- $('.jobOfferYes').hide();
- }
- });
- }
- var viewModel = new ProfileViewModel();
- ko.applyBindings(viewModel, document.getElementById("dashboard-home"));
- };
- if ($('.user-mydashboard').html() != undefined) {
- buildON.myDashboard();
- }
- //Add/Edit Workshop
- buildON.addEditWorkshop = function() {
- var workshopViewModle = function (moduleLookup) {
- var self = this;
- // variables
- var isReady = false;
- var mediasNum = 0;
- var hidWorkshopGuid = $('#hidWorkshopGuid') != undefined ? $('#hidWorkshopGuid').val() : "";
- var addAnotherUrl = $('#hidAddEditUrl') != undefined ? $('#hidAddEditUrl').val() : "";
- var workshopDetailsUrl = $('#hidWorkshopDetailsUrl') != undefined ? $('#hidWorkshopDetailsUrl').val() : "";
- // Workshop Video
- function WorkshopVideo(workshopguid, titleen, titlefr, urlen, urlfr, sortorder, type) {
- var self = this;
- // View Model Object variables
- self.workshopguid = ko.observable(workshopguid);
- self.titleen = ko.observable(titleen);
- self.titlefr = ko.observable(titlefr);
- self.urlen = ko.observable(urlen);
- self.urlfr = ko.observable(urlfr);
- self.sortorder = ko.observable(sortorder);
- self.type = ko.observable(type);
- }
- // Workshop Document
- function WorkshopDocument(workshopguid, fileen, filetitleen, filefr, filetitlefr, sortorder, type) {
- var self = this;
- // View Model Object variables
- self.workshopguid = ko.observable(workshopguid);
- self.fileen = ko.observable(fileen);
- self.filetitleen = ko.observable(filetitleen);
- self.filefr = ko.observable(filefr);
- self.filetitlefr = ko.observable(filetitlefr);
- self.sortorder = ko.observable(sortorder);
- self.type = ko.observable(type);
- }
- //Workshop media (video + document) object
- function WorkshopMedia(workshopguid, titleen, titlefr, urlen, urlfr, fileen, filefr, filetitleen, filetitlefr, sortorder, type) {
- var self = this;
- self.workshopguid = ko.observable(workshopguid);
- self.titleen = ko.observable(titleen);
- self.titlefr = ko.observable(titlefr);
- self.urlen = ko.observable(urlen);
- self.urlfr = ko.observable(urlfr);
- self.fileen = ko.observable(fileen);
- self.filetitleen = ko.observable(filetitleen);
- self.filefr = ko.observable(filefr);
- self.filetitlefr = ko.observable(filetitlefr);
- self.sortorder = ko.observable(sortorder);
- self.type = ko.observable(type);
- }
- self.isNew = ko.observable(false);
- self.hasError = ko.observable(false);
- self.moduleLookup = ko.observableArray(moduleLookup);
- // Workshop media observable variable to store all videos and documents, and it is used for getting the right sort order of these items too
- self.workshopMedias = ko.observableArray([]);
- // Initialize workshpVO with MAPPING
- self.workshopVO = ko.mapping.fromJS([]);
- $.ajax({
- type: 'GET',
- contentType: 'application/json',
- url: "/api/Workshop?guid=" + hidWorkshopGuid,
- async: false,
- success: function(data) {
- if (data.Success && data.Result != null) {
- self.workshopVO = ko.mapping.fromJS(data.Result);
- mediasNum = self.workshopVO.workshopvideos().length + self.workshopVO.workshopdocuments().length;
- for (var i = 0; i < self.workshopVO.workshopvideos().length; i++) {
- var newVideo = new WorkshopMedia(hidWorkshopGuid, self.workshopVO.workshopvideos()[i].titleen(), self.workshopVO.workshopvideos()[i].titlefr(), self.workshopVO.workshopvideos()[i].urlen(), self.workshopVO.workshopvideos()[i].urlfr(), "", "", "", "", self.workshopVO.workshopvideos()[i].sortorder(), 'video');
- self.workshopMedias.push(newVideo);
- }
- for (var i = 0; i < self.workshopVO.workshopdocuments().length; i++) {
- var newDoc = new WorkshopMedia(hidWorkshopGuid, "", "", "", "", self.workshopVO.workshopdocuments()[i].fileen(), self.workshopVO.workshopdocuments()[i].filefr(), self.workshopVO.workshopdocuments()[i].filetitleen(), self.workshopVO.workshopdocuments()[i].filetitlefr(), self.workshopVO.workshopdocuments()[i].sortorder(), 'document');
- self.workshopMedias.push(newDoc);
- }
- // Order the workshopMEdias by SortOrder coming from database
- self.workshopMedias.sort(function(a, b) {
- var aID = a.sortorder();
- var bID = b.sortorder();
- return (aID == bID) ? 0 : (aID > bID) ? 1 : -1;
- });
- // Reset the order just in case the data was not correct in DB
- SetOrder();
- isReady = (self.workshopVO != undefined ? true : false);
- self.isNew(self.workshopVO != undefined && self.workshopVO.id() == 0 ? true : false);
- } else {
- // TODO redirect to Error page
- }
- },
- error: function() {
- //TODO error handler?
- }
- });
- // Add Video
- self.videotitleen = ko.observable("");
- self.videotitlefr = ko.observable("");
- self.videourlen = ko.observable("");
- self.videourlfr = ko.observable("");
- self.addVideo = function() {
- $('#popup-modal-saveWorkshop').magnificPopup();
- $('#popup-modal-saveWorkshopAgain').magnificPopup();
- if (self.videourlfr() != "" && self.videourlfr() != undefined && self.videotitlefr() != "" && self.videotitlefr() != undefined && self.videourlen() != "" && self.videourlen() != undefined && self.videotitleen() != "" && self.videotitleen() != undefined) {
- $('.warningTextAddedFiles').hide();
- mediasNum++;
- var newVideo = (new WorkshopVideo(hidWorkshopGuid));
- newVideo.id = 0;
- newVideo.guid = "";
- newVideo.titleen(self.videotitleen());
- newVideo.titlefr(self.videotitlefr());
- newVideo.urlen(self.videourlen());
- newVideo.urlfr(self.videourlfr());
- newVideo.sortorder(mediasNum);
- // Add Video to WorkshopVideos arrary
- self.workshopVO.workshopvideos().push(newVideo);
- var newMedia = new WorkshopMedia(hidWorkshopGuid, self.videotitleen(), self.videotitlefr(), self.videourlen(), self.videourlfr(), "", "", "", "", mediasNum, "video");
- // Add Video to WorkshopMedias arrary
- self.workshopMedias.push(newMedia);
- // Reset the "Add Associated Videos" section observable variables
- self.videotitleen("");
- self.videotitlefr("");
- self.videourlen("");
- self.videourlfr("");
- //Hide any potential error messages
- $('.warningTextVidTitleEn').hide();
- $('.warningTextVidTitleFr').hide();
- $('.warningTextVidUrlFr').hide();
- $('.warningTextVidUrlEn').hide();
- } else {
- //Check to make sure video title has been set
- if (self.videotitleen() == "" || self.videotitleen() == undefined) {
- $('.warningTextVidTitleEn').show();
- } else {
- $('.warningTextVidTitleEn').hide();
- }
- //Check to make sure video title has been set
- if (self.videotitlefr() == "" || self.videotitlefr() == undefined) {
- $('.warningTextVidTitleFr').show();
- } else {
- $('.warningTextVidTitleFr').hide();
- }
- //Check to make sure video URL has been set
- if (self.videourlen() == "" || self.videourlen() == undefined) {
- $('.warningTextVidUrlEn').show();
- } else {
- $('.warningTextVidUrlEn').hide();
- }
- //Check to make sure video URL has been set
- if (self.videourlfr() == "" || self.videourlfr() == undefined) {
- $('.warningTextVidUrlFr').show();
- } else {
- $('.warningTextVidUrlFr').hide();
- }
- }
- }
- // Add Document
- self.documentfileen = ko.observable("");
- self.documenttitleen = ko.observable("");
- self.documentfilefr = ko.observable("");
- self.documenttitlefr = ko.observable("");
- self.addDocument = function() {
- //Getting the value for the Document PDF Fields-if they're set we need to check the Title field later
- var workshopPDFen = $('.document-en .MediaSelector .EditingFormMediaPathTextBox').val();
- var workshopPDFfr = $('.document-fr .MediaSelector .EditingFormMediaPathTextBox').val();
- $('.warningTextPdfEn').show();
- $('.warningTextPdfFr').show();
- $('.warningTextDocTitleFr').show();
- $('.warningTextDocTitleEn').show();
- if (self.documenttitlefr() == undefined || self.documenttitlefr() == "") {
- $('.warningTextDocTitleFr').show();
- } else {
- $('.warningTextDocTitleFr').hide();
- }
- if (self.documenttitleen() == undefined || self.documenttitleen() == "") {
- $('.warningTextDocTitleEn').show();
- } else {
- $('.warningTextDocTitleEn').hide();
- }
- //If English or French PDFs have been uploaded, check to make sure they have a title set
- if (workshopPDFfr != "") {
- $('.warningTextPdfFr').hide();
- if (workshopPDFen == "") {
- $('.warningTextPdfEn').show();
- } else {
- $('.warningTextPdfEn').hide();
- }
- if (self.documenttitlefr() == undefined || self.documenttitlefr() == "") {
- $('.warningTextDocTitleFr').show();
- } else {
- $('.warningTextDocTitleFr').hide();
- }
- }
- if (workshopPDFen != "") {
- $('.warningTextPdfEn').hide();
- if (workshopPDFfr == "") {
- $('.warningTextPdfFr').show();
- } else {
- $('.warningTextPdfFr').hide();
- }
- if (self.documenttitleen() == undefined || self.documenttitleen() == "") {
- $('.warningTextDocTitleEn').show();
- } else {
- $('.warningTextDocTitleEn').hide();
- }
- }
- if (workshopPDFen != "" && workshopPDFfr != "") {
- if (self.documenttitleen() == undefined || self.documenttitleen() == "") {
- $('.warningTextDocTitleEn').show();
- }
- if (self.documenttitlefr() == undefined || self.documenttitlefr() == "") {
- $('.warningTextDocTitleFr').show();
- } else if (self.documenttitlefr() != "" && self.documenttitleen() != "") {
- $('.warningTextDocTitleEn').hide();
- $('.warningTextDocTitleFr').hide();
- mediasNum++;
- // Due to Media Selector form control, we need to set the file name to observable variables
- var enFileName = $('.document-en .MediaSelector .EditingFormMediaPathTextBox').val();
- self.documentfileen(enFileName);
- var frFileName = $('.document-fr .MediaSelector .EditingFormMediaPathTextBox').val();
- self.documentfilefr(frFileName);
- var newDocument = (new WorkshopDocument(hidWorkshopGuid, self.documentfileen(), self.documenttitleen(), self.documentfilefr(), self.documenttitlefr(), mediasNum, 'document'));
- newDocument.id = 0;
- newDocument.guid = "";
- // Add Document to WorkshopDocuments arrary
- self.workshopVO.workshopdocuments.push(newDocument);
- // Add Document to workshopMedias arrary
- self.workshopMedias.push(new WorkshopMedia(hidWorkshopGuid, "", "", "", "", newDocument.fileen(), newDocument.filefr(), newDocument.filetitleen(), newDocument.filetitlefr(), mediasNum, 'document'));
- // Reset the "Add Associated Documents" section observable variables
- self.documentfileen("");
- self.documenttitleen("");
- self.documentfilefr("");
- self.documenttitlefr("");
- }
- }
- }
- // Remove workshop media
- self.removeItem = function(item) {
- if (confirm("Are you sure you want to remove this item?")) {
- var type = item.type();
- self.workshopMedias.remove(item);
- // remove item from self.workshopVO video or document
- if (type != undefined && type.toLowerCase() === "video") {
- var newVideos = self.workshopVO.workshopvideos()
- .filter(function(el) {
- return el.titleen() !== item.titleen() && el.titlefr() !== item.titlefr();
- }
- );
- self.workshopVO.workshopvideos([]);
- self.workshopVO.workshopvideos(newVideos);
- } else if (type != undefined && type.toLowerCase() === "document") {
- var newDocuments = self.workshopVO.workshopdocuments()
- .filter(function(el) {
- return el.fileen() !== item.fileen() && el.filetitleen() !== item.filetitleen();
- }
- );
- self.workshopVO.workshopdocuments([]);
- self.workshopVO.workshopdocuments(newDocuments);
- }
- }
- };
- // Move workshop media up
- self.moveUp = function(itemIndex) {
- var i = self.workshopMedias.indexOf(itemIndex);
- if (i >= 1) {
- var array = self.workshopMedias();
- self.workshopMedias.splice(i - 1, 2, array[i], array[i - 1]);
- SetOrder();
- }
- };
- // Move workshop media down
- self.moveDown = function(itemIndex) {
- var i = self.workshopMedias.indexOf(itemIndex);
- var array = self.workshopMedias();
- if (i < array.length - 1) {
- self.workshopMedias.splice(i, 2, array[i + 1], array[i]);
- SetOrder();
- }
- };
- // Save workshop
- function ValidateForm() {
- if (self.workshopMedias().length == 0) {
- $('.warningTextAddedFiles').show();
- } else {
- $('.warningTextAddedFiles').hide();
- }
- //Check to make sure a module has been selected
- if (self.workshopVO.moduleguid() == undefined) {
- $('.warningTextModule').show();
- } else {
- $('.warningTextModule').hide();
- }
- //Check to make sure an image title has been added
- if (self.workshopVO.titleen() == "") {
- $('.warningTextTitleEn').show();
- } else {
- $('.warningTextTitleEn').hide();
- }
- //Check to make sure an image title has been added
- if (self.workshopVO.titlefr() == "") {
- $('.warningTextTitleFr').show();
- } else {
- $('.warningTextTitleFr').hide();
- }
- //Check to make sure a short description has been added
- if (self.workshopVO.summaryen() == "") {
- $('.warningTextSummaryEn').show();
- } else {
- $('.warningTextSummaryEn').hide();
- }
- //Check to make sure a short description has been added
- if (self.workshopVO.summaryfr() == "") {
- $('.warningTextSummaryFr').show();
- } else {
- $('.warningTextSummaryFr').hide();
- }
- //Check all values together to make sure they're valid
- if (self.workshopVO.moduleguid() != undefined && self.workshopVO.summaryen() != "" && self.workshopVO.summaryfr() != "" && self.workshopVO.titleen() != "" && self.workshopVO.titlefr() != "" && self.workshopMedias().length > 0) {
- $('#popup-modal-saveWorkshop').attr('href', '#saveWorkshop-modal');
- $('#popup-modal-saveWorkshopAgain').attr('href', '#saveWorkshopAgain-modal');
- self.hasError(false);
- } else {
- $('#popup-modal-saveWorkshop').attr('href', '');
- $('#popup-modal-saveWorkshopAgain').attr('href', '');
- self.hasError(true);
- }
- }
- self.saveWorkshop = function() {
- // Due to Media Selector form control, we need to set the worshop image to observable variables
- var workshopImage = $('.workshop-image .MediaSelector .EditingFormMediaPathTextBox').val();
- self.workshopVO.image(workshopImage);
- //Check to make sure an image alt text has been added if workshop image is selected
- if (self.workshopVO.image() != "") {
- if (self.workshopVO.imagealten() == "") {
- $('.warningAltTextEn').show();
- } else {
- $('.warningAltTextEn').hide();
- }
- if (self.workshopVO.imagealtfr() == "") {
- $('.warningAltTextFr').show();
- } else {
- $('.warningAltTextFr').hide();
- }
- }
- // Validate form
- ValidateForm();
- if (!self.hasError()) {
- submit(false);
- }
- };
- self.saveAndReset = function() {
- ValidateForm();
- if (!self.hasError()) {
- submit(true);
- }
- }; // prevent user from leaving page on unsaved mode
- self.displayMode = function(type) {
- // Initially "Kari" uses the "active" template, while the others use "inactive"
- return type === "video" ? "videoTemplate" : "documentTemplate";
- }
- // Set the workshopMedias observable array sort order
- function SetOrder() {
- var order = 0;
- for (var media in self.workshopMedias()) {
- order++;
- self.workshopMedias()[media].sortorder(order);
- var type = self.workshopMedias()[media].type();
- // reset self.workshopVO video and document sort order as well
- if (type === "video") {
- for (var video in self.workshopVO.workshopvideos()) {
- if (self.workshopVO.workshopvideos()[video].titleen() === self.workshopMedias()[media].titleen()) {
- self.workshopVO.workshopvideos()[video].sortorder(order);
- }
- }
- }
- if (type === "document") {
- for (var document in self.workshopVO.workshopdocuments()) {
- if (self.workshopVO.workshopdocuments()[document].filetitleen() === self.workshopMedias()[media].filetitleen()) {
- self.workshopVO.workshopdocuments()[document].sortorder(order);
- }
- }
- }
- }
- }
- function submit(reload) {
- var workshopData = ko.toJSON(self.workshopVO);
- // ajax call API to save asset
- $.ajax({
- url: "/api/workshop/",
- type: "POST",
- data: workshopData,
- contentType: 'application/json',
- cache: false,
- processData: false,
- success: function(data) {
- //ko.mapping.fromJS(data.Result, viewModel);
- if (data.Success) {
- //viewModel.errors.showAllMessages(false);
- if (reload) {
- if (addAnotherUrl != "") {
- $('#hrefReasonBtmAgain').attr('href', addAnotherUrl);
- }
- } else {
- // Save and redirect to the web part setting for SaveURL property
- if (workshopDetailsUrl != "") {
- var url = workshopDetailsUrl + "?guid=" + hidWorkshopGuid;
- //location.href = url;
- $('#hrefReasonBtm').attr('href', url);
- }
- }
- } else {
- if (data.Result.errors.length != null && data.Result.errors.length > 0) {
- var errors = data.Result.errors;
- $('.warningText.errors').remove();
- $.map(errors, function(error) {
- var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
- $('#page-header').after(output);
- $('.warningText.errors').show();
- $("html, body").scrollTop(0);
- });
- //var url = workshopDetailsUrl + "?guid=" + hidWorkshopGuid;
- //$('#hrefReasonBtm').attr('href', url);
- // TODO Showing Fail to store the data message in the model?
- }
- }
- }, //IF PROBLEM WITH AJAX CALL
- error: function(data) {
- // TODO Shwoing Generic System error message in the model.
- }
- });
- }
- };
- //Initialize ModuleLookup for dropdown, call back will do viewmodel binding
- $.ajax({
- type: 'GET',
- contentType: 'application/json',
- url: "/api/lookupdata?culture=" + lang + "&classname=BuildON.WorkshopModule",
- async: false,
- success: function (data) {
- if (data.Success && data.Result != null) {
- // VieModel Binding
- var moduleLookup = data.Result;
- var viewModel = new workshopViewModle(moduleLookup);
- ko.applyBindings(viewModel);
- $('#popup-modal-saveWorkshop').magnificPopup();
- $('#popup-modal-saveWorkshopAgain').magnificPopup();
- }
- },
- error: function () {
- //TODO error handler?
- }
- });
- };
- if ($('.addEditWorkshops').html() != undefined) { buildON.addEditWorkshop(); }
- //Co-ordinator Unassigned cases
- buildON.coordinatorUnassignedCases = function () {
- var casesViewModel = function() {
- var self = this;
- self.preferLangLookup = ko.observableArray([]);
- self.countriesLookup = ko.observableArray([]);
- self.immigrationStatusLookup = ko.observableArray([]);
- var overviewUrl = $('#hidCaseUserDetailsUrl').val();
- self.caseoverview = ko.observable(overviewUrl);
- // initial look up table
- $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
- if (data.Result != null) {
- var countryItem = FindItemByKey("BuildON.OriginCountry", data.Result);
- if (countryItem != undefined && countryItem != null) {
- self.countriesLookup(countryItem[0].Data);
- }
- var statusItem = FindItemByKey("BuildON.ImmigrationStatus", data.Result);
- if (statusItem != undefined && statusItem != null) {
- self.immigrationStatusLookup(statusItem[0].Data);
- }
- var preferLangItem = FindItemByKey("BuildON.PreferredLanguage", data.Result);
- if (preferLangItem != undefined && preferLangItem != null) {
- self.preferLangLookup(preferLangItem[0].Data);
- }
- }
- $('.popup-modal-assignCase').magnificPopup();
- });
- self.cases = ko.observableArray([]);
- self.isReady = ko.observable(false);
- self.assignedCounciler = ko.observable();
- self.GetImmigrationStatus = function (guid) {
- return FindItemByGuid(guid, self.immigrationStatusLookup());
- };
- self.GetLanguage = function (guid) {
- return FindItemByGuid(guid, self.preferLangLookup());
- };
- self.GetOriginCountry = function (guid) {
- return FindItemByGuid(guid, self.countriesLookup());
- };
- //Initialize
- $.ajax({
- type: 'GET',
- contentType: 'application/json',
- url: "/api/ClientUserCases?assigned=false",
- async: false,
- success: function(data) {
- $('.popup-modal-assignCase').magnificPopup();
- if (data.Success && data.Result != null) {
- ko.utils.arrayForEach(data.Result, function(entry) {
- self.cases.push(entry);
- });
- self.isReady(true);
- }
- },
- error: function() {
- //TODO error handler?
- }
- });
- self.dismissModal = function() {
- setTimeout(function(){ location.reload(); }, 300);
- };
- // TODO implement method for Assign Case
- self.AssignCase = function(id, ecid) {
- // API url for assign: /api/clientusercases?id=17&ecid=70
- var selectedId = this.id;
- $.ajax({
- type: 'GET',
- contentType: 'application/json',
- url: "/api/clientusercases?clientUserId=" + selectedId + "&ecid=" + self.assignedCounciler(),
- async: false,
- success: function(data) {
- if (data.Success && data.Result != null) {
- // Get the id, then check the self.case to remove the case
- $.each(self.cases(), function(index, obj){
- if(this['id'] == data.Result.id){
- self.cases().splice(index, 1);
- $('.popup-modal-assignCase').magnificPopup('open');
- //setTimeout(function(){ location.reload(); }, 500);
- }
- });
- }
- },
- error: function() {
- //TODO error handler?
- var errors = data.Result.errors;
- $('.warningText.errors').remove();
- $.map(errors, function (error) {
- var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
- $('.case-title').after(output);
- });
- }
- });
- }
- self.assignedCounciler.subscribe(function(newValue) {
- // API url for assign: /api/clientusercases?id=17&ecid=70
- self.assignedCounciler(newValue);
- });
- };
- // VieModel Binding
- var viewModel = new casesViewModel();
- ko.applyBindings(viewModel);
- };
- if ($('#Coordinator-Unassigned-Cases').html() != undefined) {
- buildON.coordinatorUnassignedCases();
- }
- buildON.coordinatorAssignedCases = function () {
- var casesViewModel = function () {
- var self = this;
- self.preferLangLookup = ko.observableArray([]);
- self.countriesLookup = ko.observableArray([]);
- self.immigrationStatusLookup = ko.observableArray([]);
- var overviewUrl = $('#hidCaseUserDetailsUrl').val();
- self.caseoverview = ko.observable(overviewUrl);
- // initial look up table
- $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
- if (data.Result != null) {
- var countryItem = FindItemByKey("BuildON.OriginCountry", data.Result);
- if (countryItem != undefined && countryItem != null) {
- self.countriesLookup(countryItem[0].Data);
- }
- var statusItem = FindItemByKey("BuildON.ImmigrationStatus", data.Result);
- if (statusItem != undefined && statusItem != null) {
- self.immigrationStatusLookup(statusItem[0].Data);
- }
- var preferLangItem = FindItemByKey("BuildON.PreferredLanguage", data.Result);
- if (preferLangItem != undefined && preferLangItem != null) {
- self.preferLangLookup(preferLangItem[0].Data);
- }
- }
- $('.popup-modal-unassignCase').magnificPopup();
- $('.popup-modal-assignCase').magnificPopup();
- });
- self.cases = ko.observableArray([]);
- self.isReady = ko.observable(false);
- self.assignedCounciler = ko.observable();
- self.GetImmigrationStatus = function (guid) {
- return FindItemByGuid(guid, self.immigrationStatusLookup());
- };
- self.GetLanguage = function (guid) {
- return FindItemByGuid(guid, self.preferLangLookup());
- };
- self.GetOriginCountry = function (guid) {
- return FindItemByGuid(guid, self.countriesLookup());
- };
- //Initialize
- $.ajax({
- type: 'GET',
- contentType: 'application/json',
- url: "/api/ClientUserCases?assigned=true",
- async: false,
- success: function (data) {
- if (data.Success && data.Result != null) {
- ko.utils.arrayForEach(data.Result, function (entry) {
- self.cases.push(entry);
- });
- $('.popup-modal-unassignCase').magnificPopup();
- $('.popup-modal-assignCase').magnificPopup();
- self.isReady(true);
- }
- $('.popup-modal-unassignCase').magnificPopup();
- $('.popup-modal-assignCase').magnificPopup();
- },
- error: function () {
- //TODO error handler?
- }
- });
- self.dismissModal = function() {
- setTimeout(function(){ location.reload(); }, 300);
- };
- self.unassignCase = function(id, ecid){
- var selectedId = this.id;
- $.ajax({
- type: 'GET',
- contentType: 'application/json',
- url: "/api/clientusercases?clientUserId=" + selectedId + "&ecid=0",
- async: false,
- success: function(data) {
- if (data.Success && data.Result != null) {
- $('.popup-modal-unassignCase').attr('href', '#unassignCase-modal');
- $('.popup-modal-unassignCase').magnificPopup('open');
- }
- },
- error: function() {
- //TODO error handler?
- var errors = data.Result.errors;
- $('.warningText.errors').remove();
- $.map(errors, function (error) {
- var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
- $('.case-title').after(output);
- });
- }
- });
- };
- // TODO implement method for Assign Case
- self.AssignCase = function(id, ecid) {
- // API url for assign: /api/clientusercases?id=17&ecid=70
- var selectedId = this.id;
- $.ajax({
- type: 'GET',
- contentType: 'application/json',
- url: "/api/clientusercases?clientUserId=" + selectedId + "&ecid=" + self.assignedCounciler(),
- async: false,
- success: function(data) {
- if (data.Success && data.Result != null) {
- $('.popup-modal-assignCase').magnificPopup('open');
- }
- },
- error: function() {
- //TODO error handler?
- var errors = data.Result.errors;
- $('.warningText.errors').remove();
- $.map(errors, function (error) {
- var output = "<p class='warningText errors' style='display: block'><strong>" + error.message + "</strong></p>";
- $('.case-title').after(output);
- });
- }
- });
- };
- self.assignedCounciler.subscribe(function(newValue) {
- // API url for assign: /api/clientusercases?id=17&ecid=70
- self.assignedCounciler(newValue);
- });
- };
- // VieModel Binding
- var viewModel = new casesViewModel();
- ko.applyBindings(viewModel);
- };
- if ($('#Coordinator-Assigned-Cases').html() != undefined) {
- buildON.coordinatorAssignedCases();
- $('.popup-modal-unassignCase').magnificPopup();
- $('.popup-modal-assignCase').magnificPopup();
- }
- // Workshop library
- buildON.workshopLibrary = function () {
- $('.workshop-tile').click(function () {
- var isMobile = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/);
- if (isMobile != null) {
- // TODO: if markup changes, this functionality needs to be updated
- window.location = this.children[2].children[2].children[0].href;
- } else {
- return;
- }
- });
- };
- buildON.workshopLibrary();
- // Workshop details
- buildON.workshopDetails = function () {
- var workshopViewModel = function () {
- var self = this;
- var deleteRedirectUrl = $('#hidDeleteUrl') != undefined ? $('#hidDeleteUrl').val() : "";
- var workshopGuid = $('#hidWorkshopGuid') != undefined ? $('#hidWorkshopGuid').val() : "";
- // Initialize workshopVO with MAPPING - will be used for workshop elements data-bind
- var isReady = false;
- self.workshopVO = ko.mapping.fromJS([]);
- var getUrl = "/api/Workshop?guid=" + workshopGuid;
- $.ajax({
- type: 'GET',
- contentType: 'application/json',
- url: getUrl,
- async: false,
- success: function (data) {
- if (data.Success && data.Result != null) {
- if (data.Result.id == 0) {
- //location.href = errorUrl;
- } else {
- self.workshopVO = ko.mapping.fromJS(data.Result);
- isReady = self.workshopVO != undefined ? true : false;
- }
- } else {
- // redirect to Error page
- //location.href = errorUrl;
- }
- },
- error: function () {
- //
- }
- });
- // Delete Workshop
- self.showDeleteConfirmation = ko.observable(true);
- self.showDeleteSuccess = ko.observable(false);
- self.showDeleteFail = ko.observable(false);
- self.deleteWorkshop = function() {
- var strDeleteUrl = "/api/Workshop?GUID=" + workshopGuid;
- $.ajax({
- url: strDeleteUrl,
- type: 'DELETE',
- success: function(data) {
- // Do something after successful delete
- self.showDeleteSuccess(true);
- if (data.Success) {
- self.showDeleteSuccess(true);
- $('.hrefReasonBtm').attr('href', deleteRedirectUrl);
- } else {
- // Fail to delete
- self.showDeleteSuccess(false);
- }
- },
- error: function(data) {
- self.showDeleteSuccess(false);
- },
- });
- };
- };
- // VieModel Binding
- var viewModel = new workshopViewModel();
- ko.applyBindings(viewModel);
- };
- if ($('#workshop-details').html() != undefined) { buildON.workshopDetails(); }
- $('#popup-modal-removeWorkshop').magnificPopup();
- // My Cases
- buildON.myCases = function () {
- var myCasesViewModel = function () {
- var self = this;
- var overviewUrl = $('#hidCaseUserDetailsUrl').val();
- self.caseoverview = ko.observable(overviewUrl);
- self.preferLangLookup = ko.observableArray([]);
- self.countriesLookup = ko.observableArray([]);
- self.immigrationStatusLookup = ko.observableArray([]);
- // initial look up table
- $.getJSON("/api/lookupdata?culture=" + lang, function (data) {
- if (data.Result != null) {
- var countryItem = FindItemByKey("BuildON.OriginCountry", data.Result);
- if (countryItem != undefined && countryItem != null) {
- self.countriesLookup(countryItem[0].Data);
- }
- var statusItem = FindItemByKey("BuildON.ImmigrationStatus", data.Result);
- if (statusItem != undefined && statusItem != null) {
- self.immigrationStatusLookup(statusItem[0].Data);
- }
- var preferLangItem = FindItemByKey("BuildON.PreferredLanguage", data.Result);
- if (preferLangItem != undefined && preferLangItem != null) {
- self.preferLangLookup(preferLangItem[0].Data);
- }
- }
- });
- self.cases = ko.observableArray([]);
- self.GetImmigrationStatus = function (guid) {
- return FindItemByGuid(guid, self.immigrationStatusLookup());
- };
- self.GetLanguage = function (guid) {
- return FindItemByGuid(guid, self.preferLangLookup());
- };
- self.GetOriginCountry = function (guid) {
- return FindItemByGuid(guid, self.countriesLookup());
- };
- //Initialize
- $.ajax({
- type: 'GET',
- contentType: 'application/json',
- url: "/api/ClientUserCases/GetMyCase?id=" + userid,
- async: false,
- success: function (data) {
- if (data.Success && data.Result != null) {
- ko.utils.arrayForEach(data.Result, function (entry) {
- self.cases.push(entry);
- });
- }
- },
- error: function () {
- //TODO error handler?
- }
- });
- };
- // VieModel Binding
- var viewModel = new myCasesViewModel();
- ko.applyBindings(viewModel);
- };
- if ($('#my-cases').html() != undefined) { buildON.myCases(); }
- }(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