--- /dev/null
+(function() {
+ "use strict";
+ angular.module("nero.app.cdt")
+ .controller("VisaDetailsController", VisaDetailsController);
+
+ VisaDetailsController.$inject = ["$uibModalInstance", "teacherService", "visaService", "selectedTeacher",
+ "startDateSchool", "endDateSchool", "startDayTime", "endDayTime", "toastr", "$filter", "$uibModal"];
+
+ function VisaDetailsController($uibModalInstance, teacherService, visaService, selectedTeacher,
+ startDateSchool, endDateSchool, startDayTime, endDayTime, toastr, $filter, $uibModal) {
+ var vm = this;
+ vm.visas = [];
+
+ vm.sortOptions = {
+ field: "teacher",
+ reverse: false,
+ isTeacher: true,
+ isFromDate: false,
+ isToDate: false
+ }
+
+ vm.onChangeSort = onChangeSort;
+ vm.sortData = sortData;
+ vm.onDeleteVisa = onDeleteVisa;
+ vm.displayAddVisaWindow = displayAddVisaWindow;
+ vm.ok = ok;
+
+ visaService.getVisa()
+ .then(function(data) {
+ var index, visa, fromDate, toDate;
+ for (index = 0 ; index < data.visas.length ; ++index) {
+ visa = data.visas[index];
+ fromDate = moment(visa.fromDate, "DD/MM/YYYY HH:mm");
+ toDate = moment(visa.toDate, "DD/MM/YYYY HH:mm");
+ visa.fromDate = fromDate.format("DD/MM/YYYY");
+ visa.toDate = toDate.format("DD/MM/YYYY");
+ visa.sortFromDate = fromDate.format("YYYY-MM-DD");
+ visa.sortToDate = toDate.format("YYYY-MM-DD");
+
+ vm.visas.push(visa);
+ }
+ });
+
+ /*
+ Sort column on header click
+ */
+ function onChangeSort(column) {
+ if (vm.sortOptions.field == column) {
+ vm.sortOptions.reverse = !vm.sortOptions.reverse;
+ }
+ else {
+ vm.sortOptions.isTeacher = false;
+ vm.sortOptions.isFromDate = false;
+ vm.sortOptions.isToDate = false;
+ if (column == "sortFromDate") {
+ vm.sortOptions.isFromDate = true;
+ }
+ else if (column == "sortToDate") {
+ vm.sortOptions.isToDate = true;
+ }
+ else {
+ vm.sortOptions.isTeacher = true;
+ }
+ vm.sortOptions.field = column;
+ vm.sortOptions.reverse = false;
+ }
+ }
+
+ function sortData(visa) {
+ if (vm.sortOptions.field != "teacher") {
+ return visa[vm.sortOptions.field];
+ }
+ else {
+ return [visa.teacher.lastName, visa.teacher.firstName];
+ }
+ }
+
+ /*
+ Call delete visa service and display toastr
+ */
+ function onDeleteVisa(visa) {
+ vm.myPromise = visaService.deleteVisa(visa)
+ .then(function(data) {
+ vm.visas.splice(vm.visas.indexOf(visa), 1);
+ toastr.success(data.message);
+ })
+ ["catch"](function(message) {
+ toastr.error(message);
+ });
+ }
+
+ /*
+ Display add visa window
+ */
+ function displayAddVisaWindow() {
+ var modalInstance = $uibModal.open({
+ templateUrl: contextPath + "/js/add-visa/add-visa.html?t="+cdtTimestamp,
+ controller: "AddVisaController",
+ controllerAs: "AddVisaCtrl",
+ resolve: {
+ selectedTeacher: function() {
+ return selectedTeacher;
+ },
+ startDateSchool: function() {
+ return startDateSchool;
+ },
+ endDateSchool: function() {
+ return endDateSchool;
+ },
+ startDayTime: function() {
+ return startDayTime;
+ },
+ endDayTime: function() {
+ return endDayTime;
+ }
+ }
+ });
+
+ modalInstance.result.then(function(visa) {
+ var fromDate = moment(visa.fromDate, "DD/MM/YYYY HH:mm");
+ var toDate = moment(visa.toDate, "DD/MM/YYYY HH:mm");
+ visa.fromDate = fromDate.format("DD/MM/YYYY");
+ visa.toDate = toDate.format("DD/MM/YYYY");
+ visa.sortFromDate = fromDate.format("YYYY-MM-DD");
+ visa.sortToDate = toDate.format("YYYY-MM-DD");
+
+ vm.visas.push(visa);
+ }, function() {
+ //Cancel paste so don't do anything
+ });
+ }
+
+ function ok() {
+ $uibModalInstance.close();
+ };
+
+ }
+})();