var app = angular.module('indexApp', ['ui.bootstrap', 'ngSanitize', 'angular.filter']); app.controller('indexCtrl', ["$http", "$location", "$sce", function ($http, $location, $sce) { var self = this; self.filterresponseneeded = function (slot) { return slot.workflowstatus === 'told' || slot.workflowstatus === 'reminded'; }; self.initialise = function () { self.screenname = 'landing'; self.datepickeroptions = { showWeeks: false }; self.url = $location.absUrl(); //parse the URL for the correct personid if (self.url.indexOf("?personid=") != -1) { self.personid = $location.search().personid; } else { self.personid = self.url.substr(self.url.lastIndexOf("?") + 1); } self.myprofileget(); self.daynames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; }; self.myprofileget = function () { self.myprofile = null; //get the user's profile $http.get("https://1i3enbgfb1.execute-api.eu-west-2.amazonaws.com/Prod/myprofile/" + self.personid) .then(function onSuccess(response) { self.myprofile = response.data.myprofile; localStorage.setItem(self.myprofile.organisationid, self.myprofile.personid); if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { if (self.pageopenedforfirsttime) { self.pageopenedforfirsttime = false; gtag('set', { 'user_id': self.personid }); gtag('config', 'UA-87045807-1', { 'link_attribution': true, 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); gtag('event', 'view_myprofile', { 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); } } self.responsesdue = 0; for (var i = 0; i < self.myprofile.slots.length; i++) { self.myprofile.slots[i].isinswapmode = false; if (self.myprofile.slots[i].swaps.length > 0 && self.myprofile.slots[i].swaps[0].status == 'created') { //TODO: check that it is correct that this only examines the zeroth element of the swaps array to see if its status is 'created' self.myprofile.slots[i].isinswapmode = true; } if (self.myprofile.slots[i].workflowstatus == 'told' || self.myprofile.slots[i].workflowstatus == 'reminded') { self.responsesdue++; } } //if it is a FREE tier customer then get the all the details of all the volunteer rotas including all the avaiable slots self.rota = null; $http.get("https://1i3enbgfb1.execute-api.eu-west-2.amazonaws.com/Prod/volunteerrotas/" + self.personid) .then(function onSuccess(response) { self.volunteerrotas = response.data.volunteerrotas; self.totalavailable = 0; for (rotaindex = 0; rotaindex < self.volunteerrotas.rotas.length; rotaindex++) { self.volunteerrotas.rotas[rotaindex].vacancies = 0; for (e = 0; e < self.volunteerrotas.rotas[rotaindex].events.length; e++) { var earliestshift = ""; for (r = 0; r < self.volunteerrotas.rotas[rotaindex].events[e].roles.length; r++) { for (s = 0; s < self.volunteerrotas.rotas[rotaindex].events[e].roles[r].slots.length; s++) { self.volunteerrotas.rotas[rotaindex].events[e].roles[r].slots[s].selected = false; if (self.volunteerrotas.rotas[rotaindex].events[e].roles[r].slots[s].got == self.volunteerrotas.rotas[rotaindex].events[e].roles[r].slots[s].needed) { self.volunteerrotas.rotas[rotaindex].events[e].roles[r].slots[s].disabled = true; } else { self.volunteerrotas.rotas[rotaindex].events[e].roles[r].slots[s].disabled = false; self.volunteerrotas.rotas[rotaindex].vacancies++; self.totalavailable++ } if (earliestshift == "" || self.volunteerrotas.rotas[rotaindex].events[e].roles[r].slots[s].start < earliestshift) { earliestshift = self.volunteerrotas.rotas[rotaindex].events[e].roles[r].slots[s].start; } } } self.volunteerrotas.rotas[rotaindex].events[e].earliestshift = earliestshift; } } self.totalselected = 0; }); }); }; self.viewallocatedshifts = function () { if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('config', 'UA-87045807-1', { 'link_attribution': true, 'dimension1': 'member', 'dimension2': self.volunteerrotas.organisationid }); gtag('event', 'view_my_current_shifts', { 'dimension1': 'member', 'dimension2': self.volunteerrotas.organisationid }); } self.screenname = "shifts"; } self.findmoreshiftsopen = function () { if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('config', 'UA-87045807-1', { 'link_attribution': true, 'dimension1': 'member', 'dimension2': self.volunteerrotas.organisationid }); gtag('event', 'view_volunteering', { 'dimension1': 'member', 'dimension2': self.volunteerrotas.organisationid }); } if (self.volunteerrotas.rotas.length == 1) { self.rota = self.volunteerrotas.rotas[0]; self.rotaid = self.volunteerrotas.rotas[0].rotaid; } else { self.rota = null; self.rotaid = null; } self.screenname = 'findmoreshifts'; } self.chooserota = function (rotaid) { self.rotaid = rotaid; for (rotaindex = 0; rotaindex < self.volunteerrotas.rotas.length; rotaindex++) { if (self.volunteerrotas.rotas[rotaindex].rotaid == rotaid) { self.rotaname = self.volunteerrotas.rotas[rotaindex].name; self.rota = self.volunteerrotas.rotas[rotaindex]; break; } } } self.slottoggle = function (slot) { if (slot.needed > slot.got || slot.selected) { slot.selected = !slot.selected; if (slot.selected) { slot.got++; self.totalselected++; } else { self.totalselected--; slot.got--; } } }; self.submitchoices = function () { self.selections = []; for (rotaindex = 0; rotaindex < self.volunteerrotas.rotas.length; rotaindex++) { for (eventindex = 0; eventindex < self.volunteerrotas.rotas[rotaindex].events.length; eventindex++) { for (roleindex = 0; roleindex < self.volunteerrotas.rotas[rotaindex].events[eventindex].roles.length; roleindex++) { for (slotindex = 0; slotindex < self.volunteerrotas.rotas[rotaindex].events[eventindex].roles[roleindex].slots.length; slotindex++) { if (self.volunteerrotas.rotas[rotaindex].events[eventindex].roles[roleindex].slots[slotindex].selected) { self.selections.push( { rotaid: self.volunteerrotas.rotas[rotaindex].rotaid, rotaname: self.volunteerrotas.rotas[rotaindex].name, role: self.volunteerrotas.rotas[rotaindex].events[eventindex].roles[roleindex].name, eventid: self.volunteerrotas.rotas[rotaindex].events[eventindex].eventid, event: self.volunteerrotas.rotas[rotaindex].events[eventindex].name, date: self.volunteerrotas.rotas[rotaindex].events[eventindex].date, slotid: self.volunteerrotas.rotas[rotaindex].events[eventindex].roles[roleindex].slots[slotindex].slotid, start: self.volunteerrotas.rotas[rotaindex].events[eventindex].roles[roleindex].slots[slotindex].start, finish: self.volunteerrotas.rotas[rotaindex].events[eventindex].roles[roleindex].slots[slotindex].finish, location: "", note: "" } ); } } } } } self.screenname = "submitchoices"; }; self.confirmednewshifts = function () { //only proceed if this function hasn't already been called if (!self.confirmingsignups) { self.confirmingsignups = true; var slots = []; for (i = 0; i < self.selections.length; i++) { slots.push( { slotid: self.selections[i].slotid, note: self.selections[i].note, rotaid: self.selections[i].rotaid, rotaname: self.selections[i].rotaname, eventname: self.selections[i].event, date: self.selections[i].date, rolename: self.selections[i].role, start: self.selections[i].start, finish: self.selections[i].finish, location: "" } ); } var params = { personid: self.myprofile.personid, slots: JSON.stringify(slots) }; $http({ method: 'POST', url: '/restapi/volunteerconfirm.aspx', data: $.param(params), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then(function onSuccess(response) { console.log("slots saved"); if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('event', 'volunteer', { 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); } self.totalselected = 0; delete self.selections; self.myprofileget(); self.screenname = "thankyou"; self.confirmingsignups = false; }, function onError(response) { console.log("slot save failed"); }); } }; self.slotactionsget = function (slot) { if (typeof slot.slotactions == 'undefined') { $http.get("https://1i3enbgfb1.execute-api.eu-west-2.amazonaws.com/Prod/slotactions/" + slot.slotid) .then(function onSuccess(response) { var data = response.data; slot.slotactions = data.slotactions; if (slot.slotactions.valid == true) { //this email can be responded to, so set up the screen slot.valid = true; slot.message = ""; if (slot.workflowstatus == 'told') { slot.labelyes = 'Accept'; slot.labelno = 'Reject'; } else { slot.labelyes = 'Confirm'; slot.labelno = 'Cancel'; } //decide which sections to display slot.displayaccept = (!slot.isinswapmode && (slot.workflowstatus == 'told' || slot.workflowstatus == 'reminded')); var tempdate = new Date(); tempdate.setDate(tempdate.getDate() + slot.mincancellingnotice); slot.displayreject = (slot.slotactions.swapstyle == 'emptyonly' && (!slot.slotactions.alternatives.length > 0) && slot.workflowstatus == 'told') || (slot.mincancellingnotice >= 0 && tempdate <= Date.parse(slot.date)); slot.displayswapempty = (slot.slotactions.swapstyle == 'emptyonly' && (slot.slotactions.alternatives.length > 0) && (slot.workflowstatus == 'told' || slot.workflowstatus == 'reminded')); slot.displayswapfull = (slot.isinswapmode) || (slot.slotactions.swapstyle == 'fullonly') && (slot.slotactions.alternatives.length > 0); slot.displaybuttonformorealternatives = false; slot.numberofalternativestoshow = 5; slot.numberofalternativesselected = 0; //if we are using the fullonly swapstyle then add a selected flag to each alternative slot if (slot.slotactions.swapstyle == 'fullonly') { for (var i = 0; i < slot.slotactions.alternatives.length; i++) { slot.slotactions.alternatives[i].selected = false; slot.slotactions.alternatives[i].display = (i < slot.numberofalternativestoshow); //only display the first 5 alternatives } if (slot.slotactions.alternatives.length > slot.numberofalternativestoshow) { slot.displaybuttonformorealternatives = true; } } } else { //this slot is out of date or no longer valid in some way. Display a message slot.valid = false; } }); } } self.displaymorealternatives = function (slot) { slot.numberofalternativestoshow += 5; for (var i = 0; i < slot.slotactions.alternatives.length; i++) { slot.slotactions.alternatives[i].display = (i < slot.numberofalternativestoshow); } if (slot.numberofalternativestoshow >= slot.slotactions.alternatives.length) { slot.displaybuttonformorealternatives = false; } }; self.toggleswapoption = function (slot, alternative) { alternative.selected = !alternative.selected; if (alternative.selected) { slot.numberofalternativesselected++; } else { slot.numberofalternativesselected--; } }; self.areyousure = function (action, slot, alternativeslotid) { self.action = action; self.slot = slot; self.alternativeslotid = alternativeslotid; $("#areyousuremodal").modal("show"); }; self.confirmedsure = function () { $("#areyousuremodal").modal("hide"); switch (self.action) { case "accept": self.responseaccept(); break; case "reject": self.responsereject(self.alternativeslotid); break; case "swaprequest": self.responseswaprequest(); break; case "message": self.responsemessage(); break; case "cancelswaprequest": self.responsecancelswaprequest(); break; } }; self.responseaccept = function () { $http.get("https://1i3enbgfb1.execute-api.eu-west-2.amazonaws.com/Prod/confirmationaccept/" + self.slot.slotid) .then(function onSuccess(response) { console.log("acceptance processed"); if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('event', 'accept', { 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); } $("#acknowledgementmodal").modal("show"); self.myprofileget(); }, function onError(response) { console.log("acceptance processing failed"); }); }; self.responsecancelswaprequest = function () { var params = { "slotid": self.slot.slotid }; $http({ method: 'POST', url: '/restapi/confirmationcancelswaprequest.aspx', data: $.param(params), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then(function onSuccess() { console.log("swap request cancellation processed"); if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('event', 'cancel_swap_request', { 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); } $("#acknowledgementmodal").modal("show"); self.myprofileget(); }, function onError() { console.log("swap request cancellation processing failed"); }); }; self.responsereject = function () { $http({ method: 'POST', url: "/restapi/confirmationreject.aspx", data: $.param({ "slotid": self.slot.slotid }), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then(function onSuccess(response) { var data = response.data; console.log("rejection processed"); if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('event', "reject", { 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); } $("#acknowledgementmodal").modal("show"); self.myprofileget(); }, function onError(response) { console.log("rejection processing failed"); }); }; self.responsereject = function (alternativeslotid) { $http({ method: 'POST', url: "https://1i3enbgfb1.execute-api.eu-west-2.amazonaws.com/Prod/confirmationrejectandreplace" + "?slotid=" + self.slot.slotid + "&alternativeslotid=" + alternativeslotid, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then(function onSuccess(response) { var data = response.data; console.log("swap processed"); if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('event', "swap", { 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); } $("#acknowledgementmodal").modal("show"); self.myprofileget(); }, function onError(response) { console.log("swap processing failed"); }); }; self.responseswaprequest = function () { var alternatives = []; for (var i = 0; i < self.slot.slotactions.alternatives.length; i++) { if (self.slot.slotactions.alternatives[i].selected) { alternatives.push( { "ID": self.slot.slotactions.alternatives[i].slotid } ); } } var params = { "slotid": self.slot.slotid, "alternatives": JSON.stringify(alternatives) }; $http({ method: 'POST', url: "/restapi/confirmationswaprequest.aspx", data: $.param(params), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then(function onSuccess(response) { var data = response.data; console.log("swap request processed"); if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('event', 'request_swap', { 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); } $("#acknowledgementmodal").modal("show"); self.myprofileget(); }, function onError(response) { console.log("swap request processing failed"); }); }; self.responsemessage = function () { var params = { "slotid": self.slot.slotid, "personid": self.personid, "message": self.slot.message }; $http({ method: 'POST', url: '/restapi/confirmationmessage.aspx', params: params, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then(function onSuccess(response) { var data = response.data; console.log("message processed"); if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('event', 'sendmessage', { 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); } $("#acknowledgementmodal").modal("show"); self.myprofileget(); }, function onError(response) { console.log("message processing failed"); }); }; self.timetoavoidmodalopen = function (timetoavoid) { self.timetoavoiderror = false; if (timetoavoid == null) { self.timetoavoid = {}; self.timetoavoid.dayofweek = 1; self.timetoavoid.start = new Date(1970, 0, 1, 0, 0, 0, 0); self.timetoavoid.finish = new Date(1970, 0, 1, 23, 59, 0, 0); } else { self.timetoavoid = {}; self.timetoavoid.timetoavoidid = timetoavoid.timetoavoidid; self.timetoavoid.dayofweek = timetoavoid.dayofweek; self.timetoavoid.start = new Date(1970, 0, 1, timetoavoid.start.substring(0, 2), timetoavoid.start.substring(3, 6), 0, 0); self.timetoavoid.finish = new Date(1970, 0, 1, timetoavoid.finish.substring(0, 2), timetoavoid.finish.substring(3, 6), 0, 0); } $("#timetoavoidmodal").modal("show"); }; self.timetoavoidmodalsubmit = function () { self.validatetimetoavoid(); if (self.timetoavoiderror == false) { var params = { "personid": self.personid, "day": self.timetoavoid.dayofweek, "start": self.timetoavoid.start.getHours() + ":" + self.timetoavoid.start.getMinutes(), "finish": self.timetoavoid.finish.getHours() + ":" + self.timetoavoid.finish.getMinutes(), "changedbyparticipant": true }; if (self.timetoavoid.timetoavoidid != null) { params.timetoavoidid = self.timetoavoid.timetoavoidid; } $http({ method: 'POST', url: '/restapi/timetoavoidsave.aspx', data: $.param(params), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then(function onSuccess(response) { var data = response.data; if (self.timetoavoid.timetoavoidid == null) { var thenewtimetoavoid = {}; thenewtimetoavoid.timetoavoidid = data.timetoavoidid; thenewtimetoavoid.dayofweek = parseInt(self.timetoavoid.dayofweek); thenewtimetoavoid.start = self.timetoavoid.start; thenewtimetoavoid.start = padtwodigits(self.timetoavoid.start.getHours()) + ":" + padtwodigits(self.timetoavoid.start.getMinutes()); thenewtimetoavoid.finish = padtwodigits(self.timetoavoid.finish.getHours()) + ":" + padtwodigits(self.timetoavoid.finish.getMinutes()); self.myprofile.timestoavoid.push(thenewtimetoavoid); } else { for (var i = 0; i < self.myprofile.timestoavoid.length; i++) { if (self.myprofile.timestoavoid[i].timetoavoidid == self.timetoavoid.timetoavoidid) { self.myprofile.timestoavoid[i].dayofweek = parseInt(self.timetoavoid.dayofweek); self.myprofile.timestoavoid[i].start = padtwodigits(self.timetoavoid.start.getHours()) + ":" + padtwodigits(self.timetoavoid.start.getMinutes()); self.myprofile.timestoavoid[i].finish = padtwodigits(self.timetoavoid.finish.getHours()) + ":" + padtwodigits(self.timetoavoid.finish.getMinutes()); break; } } } $("#timetoavoidmodal").modal("hide"); if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('event', 'time_to_avoid_saved', { 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); } console.log("saving timetovoid succeeded"); }, function onError(response) { console.log("saving timetoavoid failed"); }); } }; self.timetoavoiddelete = function (timetoavoid, $event) { $event.stopPropagation(); var params = { "timetoavoidid": timetoavoid.timetoavoidid }; $http({ method: 'POST', url: '/restapi/timetoavoiddelete.aspx', data: $.param(params), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then(function onSuccess(response) { for (var i = 0; i < self.myprofile.timestoavoid.length; i++) { if (self.myprofile.timestoavoid[i].timetoavoidid == timetoavoid.timetoavoidid) { self.myprofile.timestoavoid.splice(i, 1); break; } } console.log("timetoavoid delete succeeded"); if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('event', 'time_to_avoid_deleted', { 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); } }, function onError(response) { console.log("timetoavoid deletion failed"); }); }; function padtwodigits(num) { var n = num.toString(); if (n.length == 1) return "0" + n; else return n; } self.unavailabilityperiodmodalopen = function (unavailabilityperiod) { self.unavailabilitystartdatepickeropened = false; self.unavailabilityfinishdatepickeropened = false; self.unavailabilityperioderror = false; if (unavailabilityperiod == null) { self.unavailabilityperiod = {}; self.unavailabilityperiod.start = Date.now(); self.unavailabilityperiod.finish = Date.now(); } else { self.unavailabilityperiod = {}; self.unavailabilityperiod.unavailabilityperiodid = unavailabilityperiod.unavailabilityperiodid; self.unavailabilityperiod.start = (new Date(unavailabilityperiod.start)).getTime(); self.unavailabilityperiod.finish = (new Date(unavailabilityperiod.finish)).getTime(); } $("#unavailabilityperiodmodal").modal("show"); }; self.validatetimetoavoid = function () { //default variables to record no error self.timetoavoiderrormessage = ""; self.timetoavoiderror = false; if (self.timetoavoid.start >= self.timetoavoid.finish) { self.timetoavoiderrormessage = "The start time must be before the finish time."; self.timetoavoiderror = true; } else { for (var i = 0; i < self.myprofile.unavailabilitysettings.timestoavoidrestrictions.length; i++) { var therestriction = self.myprofile.unavailabilitysettings.timestoavoidrestrictions[i]; if (self.restrictionhasbeenbreached(therestriction)) { self.timetoavoiderrormessage = therestriction.message; self.timetoavoiderror = true; } } } }; self.convertstringtominutevalue = function (timestring) { //convert a time string such as "11:30" into a number of minutes eg 11*60+30 = return parseInt(timestring.substring(0, 2)) * 60 + parseInt(timestring.substring(3, 5)); } self.converttimetominutevalue = function (thetime) { return thetime.getHours() * 60 + thetime.getMinutes(); //convert a time string such as "11:30" into a number of minutes eg 11*60+30 = //return parseInt(timestring.substring(0, 2)) * 60 + parseInt(timestring.substring(3, 5)); } self.restrictionhasbeenbreached = function (therestriction) { var matchcount = 0; //count the matching Times To Avoid already present in the profile for (var i = 0; i < self.myprofile.timestoavoid.length; i++) { var thetimetoavoid = self.myprofile.timestoavoid[i]; var avoidstart = self.convertstringtominutevalue(thetimetoavoid.start); var avoidfinish = self.convertstringtominutevalue(thetimetoavoid.finish); var reststart = self.convertstringtominutevalue(therestriction.start); var restfinish = self.convertstringtominutevalue(therestriction.finish); if ((therestriction.day == 0 || therestriction.day == thetimetoavoid.dayofweek) && ((avoidstart < restfinish && avoidfinish >= reststart) || (avoidfinish >= restfinish && avoidstart <= restfinish))) { matchcount++; } } //evaluate the Time To Avoid currently being added var thetimetoavoid = self.timetoavoid; var avoidstart = self.converttimetominutevalue(self.timetoavoid.start); var avoidfinish = self.converttimetominutevalue(self.timetoavoid.finish); var reststart = self.convertstringtominutevalue(therestriction.start); var restfinish = self.convertstringtominutevalue(therestriction.finish); if ((therestriction.day == 0 || therestriction.day == self.timetoavoid.dayofweek) && ((avoidstart < restfinish && avoidfinish >= reststart) || (avoidfinish >= restfinish && avoidstart <= restfinish))) { matchcount++; } //return true if the matchcount exceeds the maximum allowed by the rule return matchcount > therestriction.max; }; self.unavailabilitystartdatevaluechanged = function () { self.unavailabilitystartdatepickeropened = false; if (self.unavailabilityperiod.start > self.unavailabilityperiod.finish) { self.unavailabilityperiod.finish = new Date(self.unavailabilityperiod.start.getTime()); } }; self.validateunavailabilityperiod = function () { self.unavailabilityperioderror = (self.unavailabilityperiod.start > self.unavailabilityperiod.finish); }; self.unavailabilityperiodmodalsubmit = function () { self.validateunavailabilityperiod(); if (self.unavailabilityperioderror == false) { var start = new Date(self.unavailabilityperiod.start); var finish = new Date(self.unavailabilityperiod.finish); var params = { "personid": self.personid, "start": start.getDate() + "/" + (start.getMonth() + 1) + "/" + start.getFullYear(), "finish": finish.getDate() + "/" + (finish.getMonth() + 1) + "/" + finish.getFullYear(), "changedbyparticipant": true }; if (self.unavailabilityperiod.unavailabilityperiodid != null) { params.unavailabilityperiodid = self.unavailabilityperiod.unavailabilityperiodid; } $http({ method: 'POST', url: '/restapi/unavailabilityperiodsave.aspx', data: $.param(params), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then(function onSuccess(response) { var data = response.data; if (self.unavailabilityperiod.unavailabilityperiodid == null) { var thenewunavailabilityperiod = {}; thenewunavailabilityperiod.unavailabilityperiodid = data.unavailabilityperiodid; thenewunavailabilityperiod.start = new Date(self.unavailabilityperiod.start); thenewunavailabilityperiod.finish = new Date(self.unavailabilityperiod.finish); self.myprofile.unavailabilityperiods.push(thenewunavailabilityperiod); } else { for (var i = 0; i < self.myprofile.unavailabilityperiods.length; i++) { if (self.myprofile.unavailabilityperiods[i].unavailabilityperiodid == self.unavailabilityperiod.unavailabilityperiodid) { self.myprofile.unavailabilityperiods[i].start = self.unavailabilityperiod.start; self.myprofile.unavailabilityperiods[i].finish = self.unavailabilityperiod.finish; break; } } } console.log("saving unavailability period succeeded"); if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('event', 'unavailbility_period_saved', { 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); } $("#unavailabilityperiodmodal").modal("hide"); }, function onError(response) { console.log("saving unavailability period failed"); }); } }; self.unavailabilityperioddelete = function (unavailabilityperiod, $event) { $event.stopPropagation(); var params = { "unavailabilityperiodid": unavailabilityperiod.unavailabilityperiodid }; $http({ method: 'POST', url: '/restapi/unavailabilityperioddelete.aspx', data: $.param(params), headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then(function onSuccess(response) { for (var i = 0; i < self.myprofile.unavailabilityperiods.length; i++) { if (self.myprofile.unavailabilityperiods[i].unavailabilityperiodid == unavailabilityperiod.unavailabilityperiodid) { self.myprofile.unavailabilityperiods.splice(i, 1); break; } } console.log("unavailabilityperiod delete succeeded"); if ((window.location.href.split("//")[1]).split("/")[0] == 'app.rotacentral.com') { gtag('event', 'unavailbility_period_deleted', { 'dimension1': 'member', 'dimension2': self.myprofile.organisationid }); } }, function onError(response) { console.log("unavailabilityperiod deletion failed"); }); }; self.privacypolicyshow = function () { $http({ method: 'GET', url: '/restapi/privacypolicyget.aspx', headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then(function onSuccess(response) { self.privacypolicyhtml = response.data.privacypolicyhtml; $("#privacymodal").modal("show"); }); }; //initialise the screen self.pageopenedforfirsttime = true; self.vacanciesonly = true; self.confirmingsignups = false; self.initialise(); }]); app.config(['$locationProvider', function ($locationProvider) { $locationProvider.hashPrefix(''); }]);