From 7e86f1d568d5add24100ee7fb2d7f705089bce2f Mon Sep 17 00:00:00 2001 From: gandhimathi Date: Tue, 26 Dec 2017 18:42:21 +0530 Subject: [PATCH] course details changes done --- .../js/controllers/dayBookMasterCtrl.js | 208 ++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 Apollo/assets/js/controllers/dayBookMasterCtrl.js diff --git a/Apollo/assets/js/controllers/dayBookMasterCtrl.js b/Apollo/assets/js/controllers/dayBookMasterCtrl.js new file mode 100644 index 00000000..b0da3021 --- /dev/null +++ b/Apollo/assets/js/controllers/dayBookMasterCtrl.js @@ -0,0 +1,208 @@ +'use strict'; +/** + * controllers for ng-table + * Simple table with sorting and filtering on AngularJS + */ +// var helloApp = angular.module("helloApp", []); +app.controller("dayBookMasterCtrl", ["$scope", "toaster", "$filter", "API_POINTS", "$localStorage", "$http", "$state", function ($scope, toaster, $filter, apiPoint, $localStorage, $http, $state) { + + $scope.myModel = { + "name": "", + "type": "", + "switchsetting": true + + }; + /* + * edit status details + * created by Surendiran + * */ + $scope.editId = -1; + $scope.setEditId = function (pid) { + $scope.editId = pid; + $scope.viewId = -1; + }; + + /* + * cancel edit div + * created by Surendiran + * */ + $scope.cancel = function () { + $scope.init(); + $scope.editId = -1; + + }; + + // sorting function for table params + $scope.sort = function(keyname){ + $scope.sortKey = keyname; //set the sortKey to the param passed + $scope.reverse = !$scope.reverse; //if true make it false and vice versa + } + + + $scope.dayForm = { + + submit: function (form, myModel,loading) { + + var firstError = null; + if (form.$invalid) { + var field = null, firstError = null; + for (field in form) { + if (field[0] != '$') { + if (firstError === null && !form[field].$valid) { + firstError = form[field].$name; + } + if (form[field].$pristine) { + form[field].$dirty = true; + } + } + } + angular.element('.ng-invalid[name=' + firstError + ']').focus(); + // swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error"); + } else { + + $scope.ldloading1 = {}; + + $scope.ldloading1[loading.replace('-', '_')] = true; + + + var addstatus = { + method: 'POST', + url: apiPoint.url + 'addDaybookMasterDetails/', + headers: { + 'Content-Type': 'application/json' + }, + data: { + name: myModel.name, + type: myModel.type, + status: myModel.switchsetting, + createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID + } + }; + + $http(addstatus).then(function (response) { + if (response.data.status == 200 && response.data.addStatus) { + $scope.ldloading1[loading.replace('-', '_')] = false; + $scope.init(); + swal("Success!", response.data.message, "success"); + $state.go($state.current, {}, { reload: true }); + } else { + $scope.ldloading1[loading.replace('-', '_')] = false; + swal("Failed!", response.data.message, "error"); + } + }); + + + } + }, + + reset: function (form) { + + $scope.myModel = angular.copy($scope.master); + form.$setPristine(true); + $scope.myModel = { + "name": "", + "switchsetting": true, + "type": "" + }; + + } + }; + /* + *get day book details + * */ + + $scope.loader=''; + + $scope.emptyData=''; + + + $scope.init = function () { + + var getdetails = { + method: 'POST', + url: apiPoint.url + 'getDayBookMasterDetails/', + headers: { + 'Content-Type': 'application/json' + }, + data: { + requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID + } + }; + + $http(getdetails).then(function (response) { + $scope.dayBookType = response.data.getDayBooktype; + if (response.data.status==200 && response.data.daybookStatus) { + $scope.emptyData=true; + $scope.loader=true; + + $scope.dayBookInfo = response.data.details; + + } else { + $scope.emptyData=false; + $scope.loader=true; + + $scope.dayBookInfo=''; + + } + }); + }; + + /* + * update the day book details + * */ + $scope.updateDaybook = function (myModel, form, loading) { + + var firstError = null; + if (form.$invalid) { + var field = null, firstError = null; + for (field in form) { + if (field[0] != '$') { + if (firstError === null && !form[field].$valid) { + firstError = form[field].$stop_name; + } + + if (form[field].$pristine) { + form[field].$dirty = true; + } + } + } + angular.element('.ng-invalid[name=' + firstError + ']').focus(); + } else { + $scope.ldloading = {}; + + $scope.ldloading[loading.replace('-', '_')] = true; + + + var update = { + method: 'POST', + url: apiPoint.url + 'updateDayBookMasterDetails/', + headers: { + 'Content-Type': 'application/json' + }, + data: { + ID: myModel.ID, + TypeID: myModel.TypeID, + TypeName: myModel.TypeName, + status: myModel.IsActive, + updatedBy: JSON.parse(localStorage.getItem('localObj')).localUserID + } + }; + $http(update).then(function (response) { + if (response.data.status==200 && response.data.updateStatus) { + $scope.ldloading[loading.replace('-', '_')] = false; + swal("Success!", response.data.message, "success"); + $scope.editId = -1; + $scope.init(); + + } else { + $scope.ldloading[loading.replace('-', '_')] = false; + swal("Failed!", response.data.message, "error"); + } + }); + + } + }; + + + +}]); \ No newline at end of file