Advertisement
Guest User

main

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