// create the controller and inject Angular's $scope //scotchApp.registerCtrl('ENDR200Controller', // create a message to display in our view function ENDR700Controller($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.teamTabList = []; $scope.isEditMode = false; $scope.oldData = {};//for editmode $scope.$apply(); } $scope.doSearch = function () { $scope.searchFlag = '1'; $scope.onSearch = true; try { var actLoadData = $.ajax(doGetPath('/json/ENDR700SchData.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) { // page // setPaging($scope.endrLst); $scope.onSearch = false; ////////////////////////////////////////////////// var retDialog1 = commonFactory.doOpenMsg(dbError); retDialog1.then((function (returnData) { //alert("1"); }), function () { //dismissed }); } else { angular.copy(data[1], $scope.teamTabList); // page setPaging($scope.teamTabList); $scope.onSearch = false; } $scope.$apply(); } ); } catch (e) { // } }; $scope.doEdit = function (data) { angular.copy(data, $scope.oldData); $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.doSaveTeamTab = function () { $scope.insertFlag = 1; if ($scope.insertTeamTabForm.$valid) { try { var actLoadData = $.ajax(doGetPath('/json/ENDR700SaveData.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.setInsertEndrCodeForm = function (form) { $scope.insertTeamTabForm = 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(); }; }