// create the controller and inject Angular's $scope //scotchApp.registerCtrl('ENDR200Controller', // create a message to display in our view function ENDR400Controller($scope, $log, $location, commonFactory) { init(); function init() { $scope.openInsertPanel = false; $scope.searchFlag = '0'; $scope.onSearch = false; $scope.insertFlag = 0; //page $scope.perPages = 20; $scope.maxSize = 10; // end page $scope.schForm = {}; //$scope.schForm.team = ""; $scope.pntForm = {}; $scope.userLst = []; $scope.endrProvincialList = []; $scope.endrPrintServerList = []; $scope.endrProvincialPrintList = []; $scope.dataNotFound = ""; $scope.$apply(); //////////////////////////////////////////////////////////////////// try { var actLoadData = $.ajax(doGetPath('/json/ENDR400LoadData.json'), { ajax: true, dataType: 'json', type: "POST" }).error( function (data) { // alert("Session Time Out!!!"); // $location.path("/"); // $scope.$apply(); }); actLoadData.success( function (data) { var dbError = data[0]; if (dbError.errorFlag == 1) { $scope.userLst = data[1]; //$scope.printerLst = data[2]; $scope.$apply(); } else { $scope.userLst = data[1]; $scope.endrProvincialList = data[2]; $scope.endrPrintServerList = data[3]; // console.log("EndrProvincialList >>>" + JSON.stringify($scope.endrProvincialList)); // console.log("EndrPrintServerList >>>" + JSON.stringify($scope.endrPrintServerList)); //$scope.printerLst = data[2]; $scope.$apply(); } $scope.$apply(); } ); } catch (e) { // } } $scope.doSearch = function searchData() { $scope.searchFlag = '1'; $scope.onSearch = true; try { var actLoadData = $.ajax(doGetPath('/json/ENDR400SchData.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) { var dbError = data[0]; if (dbError.errorFlag == 1) { $scope.endrLst = data[1]; if ($scope.endrLst.length == 0) { $scope.dataNotFound = "No data found"; $scope.$apply(); } // page setPaging($scope.endrLst); $scope.$apply(); $scope.onSearch = false; ////////////////////////////////////////////////// // var retDialog1 = commonFactory.doOpenMsg(dbError); retDialog1.then((function (returnData) { //alert("1"); }), function () { //dismissed }); } else { // console.log("Search result >>>" + JSON.stringify(data[1])); $scope.endrProvincialPrintList = data[1]; // console.log("endrProvincialPrintList >>" + JSON.stringify($scope.endrProvincialPrintList)); setPaging($scope.endrProvincialPrintList); $scope.$apply(); $scope.onSearch = false; } $scope.$apply(); } ); } catch (e) { // } } $scope.doClearSch = function () { $scope.schForm = {}; $scope.$apply(); }; function setPaging(dataLst) { if (dataLst != null) { $scope.totalItems1 = dataLst.length; $scope.currentPage1 = 1; $scope.numPages1 = Math.ceil($scope.totalItems1 / $scope.perPages); $scope.$apply(); } } $scope.doDelete = function (deleteData) { console.log("Delete >>> " + JSON.stringify(deleteData)); if (deleteData.printerStatus == 1) { var dataForm = {msgHeader: "Warning!!", msg: 'ไม่สามารถลบเครื่องพิมพ์นี้ได้ เนื่องจากอยู่ในสถานะใช้งาน'}; var retDialog1 = commonFactory.doOpenMsgWarning(dataForm); return; } var confirmDialog = commonFactory.doOpenConfirmDelete(); confirmDialog.then((function (returnData) { if (true == returnData) { // alert("Delete"); try { var actLoadData = $.ajax(doGetPath('/json/ENDR400DeleteData.json'), { ajax: true, dataType: 'json', type: "POST", data: { deleteFormParam: JSON.stringify(deleteData) } }); actLoadData.success( function (data) { var dbError = data[0]; if (dbError.errorFlag == 1) { ////////////////////////////////////////////////// var retDialog1 = commonFactory.doOpenMsg(dbError); retDialog1.then((function (returnData) { //alert("1"); }), function () { //dismissed }); } else { console.log("result After delete >>>" + JSON.stringify(data[1])); $scope.endrProvincialPrintList = data[1]; setPaging($scope.endrProvincialPrintList); $scope.$apply(); } $scope.$apply(); } ); } catch (e) { // } } }), function () { //dismissed }); }; $scope.doSavePrinter = function () { $scope.insertFlag = 1; if ($scope.insertEndrProvincialPrintForm.$valid) { try { var actLoadData = $.ajax(doGetPath('/json/ENDR400InsertData.json'), { ajax: true, dataType: 'json', type: "POST", data: { insertFormParam: JSON.stringify($scope.insertForm) } }).error( function (data) { // alert("Session Time Out!!!"); // $location.path("/"); // $scope.$apply(); }); actLoadData.success( function (data) { var dbError = data[0]; if (dbError.errorFlag == 1) { ////////////////////////////////////////////////// var retDialog1 = commonFactory.doOpenMsg(dbError); retDialog1.then((function (returnData) { //alert("1"); }), function () { //dismissed }); } else { // console.log("After Insert result>>>" + JSON.stringify(data[1])); $scope.endrProvincialPrintList = data[1]; setPaging($scope.endrProvincialPrintList); $scope.insertForm = {}; $scope.schForm = {}; $scope.$apply(); var retDialog1 = commonFactory.doOpenMsgSaveSuccess("บันทึกข้อมูลสำเร็จ"); $('html,body').animate({scrollTop: angular.element("#result").offset().top}, "fast");//GotoTop } $scope.$apply(); } ); } catch (e) { // } $scope.insertFlag = 0; } }; $scope.setInsertEndrProvincialPrintForm = function (form) { $scope.insertEndrProvincialPrintForm = form; }; $scope.doClearInsertForm = function () { $scope.insertForm = {}; }; //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.doCloseInsertPanel = function () { $scope.openInsertPanel = false; $scope.insertForm = {}; $scope.$apply(); }; $scope.doOpenInsertPanel = function () { $scope.openInsertPanel = true; }; }