ENDRPrint/web/js/ctrl/ENDR300Controller.js

191 lines
6.4 KiB
JavaScript
Raw Permalink Normal View History

2024-08-14 10:33:27 +07:00
// create the controller and inject Angular's $scope
//scotchApp.registerCtrl('ENDR200Controller',
// create a message to display in our view
function ENDR300Controller($scope, $log, $location, commonFactory) {
init();
// function 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.endrPrintServerList = [];
$scope.$apply();
}
$scope.doSearch = function () {
$scope.searchFlag = '1';
$scope.onSearch = true;
try {
var actLoadData = $.ajax(doGetPath('/json/ENDR300SchData.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 {
console.log(JSON.stringify(data));
angular.copy(data[1], $scope.endrPrintServerList);
// console.log("endrPrintServerList >>> " + JSON.stringify(data[1]));
// page
setPaging($scope.endrPrintServerList);
$scope.$apply();
$scope.onSearch = false;
}
$scope.$apply();
}
);
} catch (e) {
//
}
};
$scope.doEdit = function (data) {
$scope.insertForm = data;
$scope.openInsertPanel = true;
$('html, body').animate({scrollTop: 0}, 'fast');
};
$scope.doClearSch = function () {
$scope.schForm = {};
$scope.$apply();
};
$scope.doClearInsert = function () {
$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.doSavePrinter = function () {
$scope.insertFlag = 1;
if ($scope.insertEndrPrintServerForm.$valid) {
// alert("OK");
try {
var actLoadData = $.ajax(doGetPath('/json/ENDR300doSaveData.json'),
{
ajax: true,
dataType: 'json',
type: "POST",
data: {
saveFormParam: JSON.stringify($scope.insertForm)
}
}).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);
//////////////////////////////////////////////////
var retDialog1 = commonFactory.doOpenMsg(dbError);
retDialog1.then((function (returnData) {
//alert("1");
}), function () {
//dismissed
});
} else {
// alert("ok");
$scope.insertForm = {};
$scope.schForm = {};
// console.log(" After Insert >>" + JSON.stringify(data[1]));
angular.copy(data[1], $scope.endrPrintServerList);
setPaging($scope.endrPrintServerList);
var retDialog1 = commonFactory.doOpenMsgSaveSuccess("บันทึกข้อมูลสำเร็จ");
$('html,body').animate({scrollTop: angular.element("#result").offset().top}, "fast");
}
$scope.$apply();
}
);
} catch (e) {
//
}
$scope.insertFlag = 0;
}
};
$scope.setInsertEndrPrintServerForm = function (form) {
$scope.insertEndrPrintServerForm = 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.openInsertPanel = false;
$scope.insertForm = {};
$scope.$apply();
}
}