(function(angular) { 'use strict'; angular.module('ngOSS', ['ngRoute', 'ngCookies', 'ngDialog', 'flow']) .constant('serviceURL', "https://mis-service.fastel.ph/index.php") .constant('pageURL', "https://mis-tech.fastel.ph/") .config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) { $routeProvider .when('/', { templateUrl: 'views/main.html', controller: 'MainCtrl', controllerAs: 'Reports' }) .when('/login', { templateUrl: 'views/login.html', controller: 'LoginCtrl', controllerAs: 'login' }) .when('/logout', { templateUrl: 'views/logout.html', controller: 'LogoutCtrl', controllerAs: 'logout' }) //$locationProvider.html5Mode(true); } ]) .filter('ceil', function() { return function(input) { return Math.ceil(input); }; }) .filter('startFrom', function() { return function(input, start) { start = +start; //parse to int return input.slice(start); } }) .filter('numberFixedLen', function () { return function (n, len) { var num = parseInt(n, 10); len = parseInt(len, 10); if (isNaN(num) || isNaN(len)) { return n; } num = ''+num; while (num.length < len) { num = '0'+num; } return num; }; }) .filter('htmlToPlaintext', function() { return function(text) { return text ? String(text).replace(/<[^>]+>/gm, ' ') : ''; }; }) .directive('numInput', function () { return { require: 'ngModel', link: function (scope, element, attrs, ngModelCtrl) { scope.$watch(attrs.ngModel, function (newVal) { if (newVal !== undefined && newVal !== null) { ngModelCtrl.$setViewValue(String(newVal).replace(/[^0-9]+/, '')); element.val(String(newVal).replace(/[^0-9]+/, '')); } }) } } }) .directive('alphaInput', function () { return { require: 'ngModel', link: function (scope, element, attrs, ngModelCtrl) { scope.$watch(attrs.ngModel, function (newVal) { if (newVal !== undefined && newVal !== null) { ngModelCtrl.$setViewValue(String(newVal).replace(/[^a-zA-Z ]+/, '')); element.val(String(newVal).replace(/[^a-zA-Z ]+/, '')); } }) } } }) .directive('alphaNumInput', function () { return { require: 'ngModel', link: function (scope, element, attrs, ngModelCtrl) { scope.$watch(attrs.ngModel, function (newVal) { if (newVal !== undefined && newVal !== null) { ngModelCtrl.$setViewValue(String(newVal).replace(/[^a-zA-Z0-9\- ]+/, '')); element.val(String(newVal).replace(/[^a-zA-Z0-9\- ]+/, '')); } }) } } }) .directive('fileInput', ['$parse', function($parse){ return { restrict: 'A', link: function (scope, elm, attrs) { elm.bind('change', function () { $parse(attrs.fileInput).assign(scope, elm[0].files); scope.$apply(); }); } }; }]) .directive('ajsdatepickerfrom', function () { return { restrict: 'A', require: 'ngModel', link: function (scope, element, attrs, ngModelCtrl) { element.datepicker({ dateFormat: 'yy-mm-dd', onSelect: function (date) { scope.datefrom = date; scope.$apply(); } }); } }; }) .directive('ajsdatepickerto', function () { return { restrict: 'A', require: 'ngModel', link: function (scope, element, attrs, ngModelCtrl) { element.datepicker({ dateFormat: 'yy-mm-dd', onSelect: function (date) { scope.dateto = date; scope.$apply(); } }); } }; }) .controller('MainCtrl', ['$http', '$window', '$scope', '$route', '$routeParams', '$location', "$cookies", "$cookieStore", "pageURL", "serviceURL", function MainCtrl($http, $window, $scope, $route, $routeParams, $location, $cookies, $cookieStore, pageURL, serviceURL) { this.title = 'ASSIGNED JO'; this.params = $routeParams; $scope.jotype = $routeParams.jotype; $scope.pageIdent = 'joborder_fields'; if($window.localStorage.getItem("token") === null) $window.location.href = pageURL + '#!/login'; $scope.notificationMessage = false; $scope.token = $cookies.get('token'); $scope.token = $window.localStorage.getItem('token'); console.log($scope.token); $scope.notificationMessage = false; $scope.id = 0; $scope.type = "DAILY"; $scope.required = "0"; $scope.name = ""; $scope.description = ""; $scope.etechnician1 = "0"; $scope.etechnician2 = "0"; $scope.etechnician3 = "0"; $scope.processstatus = "COMPLETED"; $scope.processremarks = ""; $scope.package = "B1"; $scope.cafac = ""; $scope.proioo = ""; $scope.proojb = ""; $scope.pronap = ""; $scope.displayView = "list"; $scope.itemList = []; $scope.errormessages = []; $scope.successmessages = []; $scope.displayList = false; var today = new Date(); $scope.dd = today.getDate(); $scope.mm = today.getMonth()+1; //January is 0! $scope.yyyy = today.getFullYear(); $scope.hour = today.getHours(); $scope.minu = today.getMinutes(); $scope.secs = today.getSeconds(); var hostURL = pageURL; var serviceURL = serviceURL; $scope.serviceURL = serviceURL; var serviceheaders = {'Content-Type': 'application/x-www-form-urlencoded', 'token': $scope.token}; $scope.statusUpdateIdent = ""; $scope.statusupdate = function(id){ $scope.id = id; $scope.displayView = "statusupdate"; } $scope.uploadimage = function(obj){ $scope.selectedDispatch = obj; $scope.displayView = "uploadimage"; $('#loadingicon').show(); $http({ method:"POST", url: serviceURL + "/ct-ticketsearch/getmobileformdetail", headers: serviceheaders, data: { id: obj.technical_info } }).then(function (response){ $('#loadingicon').hide(); console.log(response.data); if(response){ $scope.dispatchImages = response.data; } },function (error){ $('#loadingicon').hide(); $scope.notificationMessage = "Network connection problem. Try again"; }); } $scope.updatestatus = ""; $scope.selectedDispatch = ""; $scope.showreceivedform = function(obj){ $scope.id = obj.id; $scope.selectedDispatch = obj; $scope.displayView = "received"; $scope.adate = $scope.mm + "/" + $scope.dd + "/" + $scope.yyyy; } $scope.showParkForm = function(obj){ $scope.id = obj.id; $scope.selectedDispatch = obj; $scope.displayView = "park"; $scope.updatestatus = "PARKED"; $scope.adate = $scope.mm + "/" + $scope.dd + "/" + $scope.yyyy; } $scope.showResumeForm = function(obj){ $scope.id = obj.id; $scope.selectedDispatch = obj; $scope.displayView = "resume"; $scope.updatestatus = "ON GOING"; $scope.adate = $scope.mm + "/" + $scope.dd + "/" + $scope.yyyy; } $scope.showupdateform = function(obj){ $scope.id = obj.id; $scope.selectedDispatch = obj; $scope.displayView = "statusupdate"; $scope.adate = $scope.mm + "/" + $scope.dd + "/" + $scope.yyyy; } $scope.selectedDelivery = ""; $scope.showdeliveryform = function(obj){ $scope.id = obj.id; $scope.selectedDispatch = obj; $scope.displayView = "delivery"; $scope.adate = $scope.mm + "/" + $scope.dd + "/" + $scope.yyyy; } $scope.areas = []; $scope.statuses = []; $scope.tickettypes = []; $scope.teams = []; $scope.materials = []; $scope.getdropdown = function(){ $('#myModalLoading').show(); var request = $http({ method: "POST", url: serviceURL + "/ct-ticketsearch/getdropdown", headers: {'Content-Type': 'application/x-www-form-urlencoded', 'token': $scope.token} }) .then(function (response){ $('#loadingicon').hide(); console.log(response.data); if(response){ $('#myModalLoading').hide(); $scope.areas = response.data.areas; $scope.statuses = response.data.ticketstatuses; $scope.teams = response.data.teams; $scope.tickettypes = response.data.tickettypes; $scope.materials = response.data.materials; } }); } $scope.getdropdown(); $scope.sono = ""; $scope.status = ""; $scope.datefrom = ""; $scope.dateto = ""; $scope.tech = ""; $scope.getList = function(){ $scope.displayView = "list"; var URL = serviceURL + "/ct-ticketsearch/techtickets"; $('#loadingicon').show(); $http({ method: "POST", url: URL, headers: serviceheaders }).then(function (response){ $('#loadingicon').hide(); console.log(response.data); if(response){ $scope.itemList = response.data; } },function (error){ $('#loadingicon').hide(); $scope.notificationMessage = "Network connection problem. Try again"; }); } $scope.getList(); $scope.currentPage = 0; $scope.pageSize = 25; $scope.numberOfPages = function(){ return Math.ceil($scope.itemList.length/$scope.pageSize); } $scope.deliveredDispatchDetails = []; $scope.ticketDetails = []; $scope.getDispatchedDeliveredDetails = function(obj){ $scope.displayView = "delivered_details"; $scope.ticketDetails = obj; $('#loadingicon').show(); $http({ method:"POST", url: serviceURL + "/ct-ticketsearch/getmobileformdetail", headers: serviceheaders, data: { id: obj.technical_info } }).then(function (response){ $('#loadingicon').hide(); console.log(response.data); if(response){ $scope.deliveredDispatchDetails = response.data; } },function (error){ $('#loadingicon').hide(); $scope.notificationMessage = "Network connection problem. Try again"; }); } $scope.receivingDispatchDetails = []; $scope.getDispatchedReceivedDetails = function(obj){ $scope.displayView = "receiving_details"; $('#loadingicon').show(); $http({ method:"POST", url: serviceURL + "/appkotlin/getdispatchreceiving", headers: serviceheaders, data: { id: obj.dispatch_id } }).then(function (response){ $('#loadingicon').hide(); console.log(response.data); if(response){ $scope.receivingDispatchDetails = response.data; } },function (error){ $('#loadingicon').hide(); $scope.notificationMessage = "Network connection problem. Try again"; }); } // start get job order images $scope.dispatchImages = []; $scope.getImages = function(dispatch_id){ $scope.displayView = "images"; $('#loadingicon').show(); $http({ method:"POST", url: serviceURL + "/ct-ticket/getticketimages", headers: serviceheaders, data: { id: dispatch_id } }).then(function (response){ $('#loadingicon').hide(); console.log(response.data); if(response){ $scope.dispatchImages = response.data; } },function (error){ $('#loadingicon').hide(); $scope.notificationMessage = "Network connection problem. Try again"; }); } // end get job order images // start functions for uploading images $scope.savePictures = function(){ $('#loadingicon').show(); //var url = serviceURL + '/appkotlin/saveimage'; var url = serviceURL + '/ct-ticket/uploadimage'; var payload = new FormData(); angular.forEach($scope.files, function(eachItem){ payload.append('file', eachItem); }); //console.log($scope.selectedDispatch); payload.append('data', JSON.stringify($scope.selectedDispatch)); //payload.append("title", "Image Upload"); var serviceheadersUpload = {'Content-Type': undefined, 'token': $scope.token}; $http.post(url, payload, { transformRequest: angular.identity, headers: serviceheadersUpload }) .then(function (response){ $('#loadingicon').hide(); $scope.uploadimage($scope.selectedDispatch); //$scope.getList(); },function (error){ $('#loadingicon').hide(); $scope.displayView = "list"; $scope.statusUpdateIdent = ""; $scope.notificationMessage = "Network connection problem. Try again"; }); } // end functions for uploading images $scope.logout = function(){ $window.localStorage.clear(); $window.location.href = pageURL + '#!/login'; } // start park ticket $scope.processParkForm = function(){ $('#myModalLoading').show(); $http({ method:"POST", url: serviceURL + "/ct-ticket/mobileform", headers: serviceheaders, data: { "action": "PARKED", "aremarks": $scope.aremarks, "ticket": $scope.selectedDispatch } }) .then(function (html){ alert("Ticket remarks has been saved"); $scope.aremarks = ""; $scope.getList(); $('#myModalLoading').hide(); },function (error){ $('#loadingicon').hide(); $scope.notificationMessage = "Network connection problem. Try again"; }); } // end park ticket // start resume ticket $scope.processResumeForm = function(){ $('#myModalLoading').show(); $http({ method:"POST", url: serviceURL + "/ct-ticket/mobileform", headers: serviceheaders, data: { "action": "ON GOING", "aremarks": $scope.aremarks, "ticket": $scope.selectedDispatch } }) .then(function (html){ alert("Ticket remarks has been saved"); $scope.aremarks = ""; $scope.getList(); $('#myModalLoading').hide(); },function (error){ $('#loadingicon').hide(); $scope.notificationMessage = "Network connection problem. Try again"; }); } // end resume ticket // Start update process $scope.processUpdate = function(obj){ $('#myModalLoading').show(); console.log(obj); $http({ method:"POST", url: serviceURL + "/ct-ticket/mobileform", headers: serviceheaders, data: { "action": "UPDATE", "aremarks": $scope.aremarks, "ticket": $scope.selectedDispatch } }) .then(function (html){ alert("Ticket remarks has been saved"); $scope.aremarks = ""; $scope.getList(); $('#myModalLoading').hide(); },function (error){ $('#loadingicon').hide(); $scope.notificationMessage = "Network connection problem. Try again"; }); } // End update process // Start completion process $scope.processDelivery = function(obj){ $('#myModalLoading').show(); console.log(obj); $http({ method:"POST", url: serviceURL + "/ct-ticket/mobileform", headers: serviceheaders, data: { "action": "COMPLETED - FOR VERIFICATION", "aremarks": $scope.aremarks, "ticket": $scope.selectedDispatch, "materials": $scope.materials, "otdr_result": $scope.otdr_result, "speed_result": $scope.speed_result } }) .then(function (html){ alert("Ticket has been updated to Completed"); $scope.getList(); $scope.aremarks = ""; $('#myModalLoading').hide(); },function (error){ $('#loadingicon').hide(); $scope.notificationMessage = "Network connection problem. Try again"; }); } // End completion process // Start completion process $scope.processReceiving = function(obj){ $('#myModalLoading').show(); console.log(obj); $http({ method:"POST", url: serviceURL + "/ct-ticket/mobileform", headers: serviceheaders, data: { "action": "ON GOING", "aremarks": $scope.aremarks, "ticket": $scope.selectedDispatch } }) .then(function (html){ alert("Ticket has been updated to On Going"); $scope.aremarks = ""; $scope.getList(); $('#myModalLoading').hide(); },function (error){ $('#loadingicon').hide(); $scope.notificationMessage = "Network connection problem. Try again"; }); } // End completion process } ]) .controller('LogoutCtrl', ['$window', '$scope', '$http', '$route', '$routeParams', '$location', 'pageURL', 'serviceURL', '$cookies', function LogoutCtrl($window, $scope, $http, $route, $routeParams, $location, pageURL, serviceURL, $cookies) { $window.localStorage.clear(); $window.location.href = pageURL + '#!/login'; } ]) .controller('LoginCtrl', ['$http', '$window', '$scope', '$route', '$routeParams', '$location', "$cookies", "$cookieStore", "pageURL", "serviceURL", function LoginCtrl($http, $window, $scope, $route, $routeParams, $location, $cookies, $cookieStore, pageURL, serviceURL) { var hostURL = pageURL; this.$route = $route; this.$location = $location; this.$routeParams = $routeParams; $scope.lon = null; $scope.lat = null; function showPosition(position) { $scope.lon = position.coords.latitude; $scope.lat = position.coords.longitude; } $scope.userlogin = function(){ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } var saveData = { "username": $scope.email, "pass": $scope.password } var URL = serviceURL + "/ct-user/user/authentication"; $('#loadingicon').show(); $http({ method: "POST", url: URL, data: saveData }).then(function (response){ $('#loadingicon').hide(); console.log(response.data); if(response){ $window.localStorage.setItem("token", response.data.token); $window.localStorage.setItem("email", response.data.email); $window.localStorage.setItem("lname", response.data.lname); $window.localStorage.setItem("fname", response.data.fname); $('#confirmationModal').modal('hide'); if(response.data.token) $window.location.href = hostURL + '/index.html'; } },function (error){ $('#loadingicon').hide(); $scope.notificationMessage = "Network connection problem. Try again"; }); } } ]) .controller('MenuController', ['$window', '$scope', '$route', '$routeParams', '$location', 'ngDialog', "$http", "$cookies", "pageURL", "serviceURL", function MenuController($window, $scope, $route, $routeParams, $location, ngDialog, $http, $cookies, pageURL, serviceURL) { this.$route = $route; this.$location = $location; this.$routeParams = $routeParams; $scope.token = $cookies.get('token'); $scope.token = $window.localStorage.getItem('token'); $scope.userPermissions = JSON.parse($window.localStorage.getItem("permissions")); } ]) .controller('ConfirmationModalCtrl', ['$window', '$scope', '$route', '$routeParams', '$location', 'ngDialog', "$http", "$cookies", "pageURL", "serviceURL", function ConfirmationModalCtrl($window, $scope, $route, $routeParams, $location, ngDialog, $http, $cookies, pageURL, serviceURL) { this.$route = $route; this.$location = $location; this.$routeParams = $routeParams; $scope.notificationMessage = false; $scope.token = $cookies.get('acc-token'); $scope.processConfirm = function (){ var returnValue = true; ngDialog.close('confirmationDialog', returnValue); }; $scope.closeDialog = function (){ var returnValue = false; ngDialog.close('confirmationDialog', returnValue); }; } ]) ; })(window.angular); /* Copyright 2016 Google Inc. All Rights Reserved. Use of this source code is governed by an MIT-style license that can be found in the LICENSE file at http://angular.io/license */