// create the controller and inject Angular's $scope //scotchApp.registerCtrl('ENDR200Controller', // create a message to display in our view function ENDR800Controller($scope, $log, $location, commonFactory) { init(); function init() { $scope.openInsertPanel = false; $scope.insertFlag = 0; $scope.onSearch = false; $scope.searchFlag = '0'; //page $scope.perPages = 20; $scope.maxSize = 10; // end page $scope.insertFrom = {}; $scope.schForm = {}; $scope.endrProvincialList = []; $scope.endrProvincialTeamList = []; $scope.isEditMode = false; $scope.oldData = {}; try { var actLoadData = $.ajax(doGetPath('/json/ENDR800LoadData.json'), { ajax: true, dataType: 'json', type: "POST" }).error( function (data) { alert("Session Time Out!!!"); // $location.path("/"); $scope.$apply(); }); actLoadData.success( function (data) { // console.log(JSON.stringify(data)); var dbError = data[0]; if (dbError.errorFlag == 1) { $scope.onSearch = false; var retDialog1 = commonFactory.doOpenMsg(dbError); retDialog1.then((function (returnData) { //alert("1"); }), function () { //dismissed }); } else { angular.copy(data[1], $scope.endrProvincialList); // page $scope.onSearch = false; } $scope.$apply(); } ); } catch (e) { // } $scope.$apply(); } $scope.doSearch = function () { $scope.searchFlag = '1'; $scope.onSearch = true; try { var actLoadData = $.ajax(doGetPath('/json/ENDR800SchData.json'), { ajax: true, dataType: 'json', type: "POST", data: { schFormParam: JSON.stringify($scope.schForm) } }).error( function (data) { alert("Session Time Out!!!"); // $location.path("/"); $scope.$apply(); }); actLoadData.success( function (data) { // console.log(JSON.stringify(data)); var dbError = data[0]; if (dbError.errorFlag == 1) { $scope.onSearch = false; var retDialog1 = commonFactory.doOpenMsg(dbError); retDialog1.then((function (returnData) { //alert("1"); }), function () { //dismissed }); } else { angular.copy(data[1], $scope.endrProvincialTeamList); // page setPaging($scope.endrProvincialTeamList); $scope.onSearch = false; } $scope.$apply(); } ); } catch (e) { // } }; $scope.doEdit = function (data) { angular.copy(data, $scope.oldData); $scope.insertForm = {}; angular.copy(data, $scope.insertForm); // $scope.insertForm = data; $scope.isEditMode = true; $scope.openInsertPanel = true; $('html, body').animate({scrollTop: 0}, 'fast'); }; $scope.doClearSch = function () { $scope.schForm = {}; $scope.$apply(); }; $scope.doClearInsert = function () { $scope.isEditMode = false; $scope.insertForm = {}; $scope.$apply(); } function setPaging(dataLst) { $scope.totalItems1 = dataLst.length; $scope.currentPage1 = 1; $scope.numPages1 = Math.ceil($scope.totalItems1 / $scope.perPages); $scope.$apply(); } $scope.doSaveEndrProvincialTeamTab = function () { $scope.insertFlag = 1; if ($scope.insertEndrProvincialTeamForm.$valid) { try { var actLoadData = $.ajax(doGetPath('/json/ENDR800SaveData.json'), { ajax: true, dataType: 'json', type: "POST", data: { saveFormParams: JSON.stringify($scope.insertForm), saveFormParams_OldData: JSON.stringify($scope.oldData), saveFlag: $scope.isEditMode ? 'E' : 'I' } }).error( function (data) { alert("Session Time Out!!!"); // $location.path("/"); $scope.$apply(); }); actLoadData.success( function (data) { var dbError = data; if (dbError.errorFlag == 1) { var retDialog1 = commonFactory.doOpenMsg(dbError); retDialog1.then((function (returnData) { //alert("1"); }), function () { //dismissed }); } else { $scope.insertForm = {}; $scope.schForm = {}; var retDialog1 = commonFactory.doOpenMsgSaveSuccess("บันทึกข้อมูลสำเร็จ"); $('html,body').animate({scrollTop: angular.element("#result").offset().top}, "fast"); $scope.isEditMode = false; $scope.doSearch(); } $scope.$apply(); } ); } catch (e) { // } $scope.insertFlag = 0; } }; $scope.setInsertEndrProvincialTeamForm = function (form) { $scope.insertEndrProvincialTeamForm = form; }; //for show & hide Insert Panel $scope.hidePanelStyle = { "max-height": "0px", "-webkit-transition": "max-height 0.5s ease-in-out", "-o-transition": "max-height 0.5s ease-in-out", "-ms-transition": "max-height 0.5s ease-in-out", "transition": "max-height 0.5s ease-in-out" }; $scope.showPanelStyle = { "max-height": "1000px", "-webkit-transition": "max-height 0.5s ease-in-out", "-o-transition": "max-height 0.5s ease-in-out", "-ms-transition": "max-height 0.5s ease-in-out", "transition": "max-height 0.5s ease-in-out" }; $scope.doOpenInsertPanel = function () { $scope.openInsertPanel = true; }; $scope.doCloseInsertPanel = function () { $scope.isEditMode = false; $scope.openInsertPanel = false; $scope.insertForm = {}; $scope.$apply(); }; $scope.getProvincialDesc = function (id) { for (var i = 0; i < $scope.endrProvincialList.length; i++) { if ($scope.endrProvincialList[i].provincialId == id) { return $scope.endrProvincialList[i].provincialId + " : " + $scope.endrProvincialList[i].provincialDesc; } } } $scope.doDelete = function (deleteData) { try { var actLoadData = $.ajax(doGetPath('/json/ENDR800DeleteData.json'), { ajax: true, dataType: 'json', type: "POST", data: { deleteFormParams: JSON.stringify(deleteData), } }).error( function (data) { alert("Session Time Out!!!"); // $location.path("/"); $scope.$apply(); }); actLoadData.success( function (data) { var dbError = data[0]; if (dbError != null && dbError.errorFlag == 1) { var retDialog1 = commonFactory.doOpenMsg(dbError); retDialog1.then((function (returnData) { //alert("1"); }), function () { //dismissed }); } else { $scope.insertForm = {}; $scope.schForm = {}; var retDialog1 = commonFactory.doOpenMsgSaveSuccess("บันทึกข้อมูลสำเร็จ"); $('html,body').animate({scrollTop: angular.element("#result").offset().top}, "fast"); $scope.isEditMode = false; $scope.doSearch(); } $scope.$apply(); } ); } catch (e) { // } }; }