491 lines
15 KiB
JavaScript
491 lines
15 KiB
JavaScript
|
// create the controller and inject Angular's $scope
|
|||
|
//scotchApp.registerCtrl('ENDR200Controller',
|
|||
|
// create a message to display in our view
|
|||
|
function ENDR200Controller($scope, $log, $location, commonFactory) {
|
|||
|
|
|||
|
init();
|
|||
|
|
|||
|
// function init();
|
|||
|
function init() {
|
|||
|
$scope.endrLst = [];
|
|||
|
$scope.msgErrorSch = '1';
|
|||
|
$scope.msgErrorPrint = '1';
|
|||
|
$scope.selectAll = 0;
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
//page
|
|||
|
$scope.perPages = 20;
|
|||
|
$scope.maxSize = 10;
|
|||
|
// end page
|
|||
|
|
|||
|
$scope.schForm = {};
|
|||
|
//$scope.schForm.team = "";
|
|||
|
|
|||
|
$scope.pntForm = {};
|
|||
|
$scope.userLst = [];
|
|||
|
//$scope.lstSelect = [];
|
|||
|
//$scope.lstDataPrint = [];
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
|
|||
|
//$scope.teamLst = [];
|
|||
|
//$scope.printerLst = [];
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
$scope.dataNotFound = "";
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
////////////////////////////////////////////////////////////////////
|
|||
|
try {
|
|||
|
var actLoadData = $.ajax(doGetPath('/json/ENDR200LoadData.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.printerLst = data[2];
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
);
|
|||
|
} catch (e) {
|
|||
|
//
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
$scope.doSearch = function (form) {
|
|||
|
|
|||
|
//alert("sch");
|
|||
|
$scope.msgErrorSch = '1';
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
try {
|
|||
|
if (form.$valid) {
|
|||
|
|
|||
|
searchData();
|
|||
|
|
|||
|
} else {
|
|||
|
$scope.msgErrorSch = '0';
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
} catch (e) {
|
|||
|
$scope.msgErrorSch = '0';
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
};
|
|||
|
function searchData() {
|
|||
|
try {
|
|||
|
var actLoadData = $.ajax(doGetPath('/json/ENDR200SchData.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];
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
selectAllInit();
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
if ($scope.endrLst.length == 0) {
|
|||
|
$scope.dataNotFound = "No data found";
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
|
|||
|
// page
|
|||
|
setPaging($scope.endrLst);
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
//////////////////////////////////////////////////
|
|||
|
//
|
|||
|
var retDialog1 = commonFactory.doOpenMsg(dbError);
|
|||
|
retDialog1.then((function (returnData) {
|
|||
|
//alert("1");
|
|||
|
}), function () {
|
|||
|
//dismissed
|
|||
|
});
|
|||
|
|
|||
|
} else {
|
|||
|
|
|||
|
$scope.userLst = data[1];
|
|||
|
console.log(JSON.stringify(data[1]));
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
if ($scope.userLst.length == 0) {
|
|||
|
$scope.dataNotFound = "No data found";
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
|
|||
|
selectAllInit();
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
// page
|
|||
|
setPaging($scope.userLst);
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
//////////////////////////////////////////////////
|
|||
|
|
|||
|
//var retDialog2 = commonFactory.doOpenMsg(dbError);
|
|||
|
//retDialog2.then((function (returnData) {
|
|||
|
// //alert("1");
|
|||
|
//}),function(){
|
|||
|
// //dismissed
|
|||
|
//});
|
|||
|
|
|||
|
}
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
);
|
|||
|
} catch (e) {
|
|||
|
//
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
$scope.doClearSch = function () {
|
|||
|
$scope.selectAll = 0;
|
|||
|
$scope.schForm = {};
|
|||
|
$scope.dataNotFound = "";
|
|||
|
$scope.msgErrorSch = '1';
|
|||
|
$scope.endrLst = [];
|
|||
|
$scope.$apply();
|
|||
|
};
|
|||
|
|
|||
|
$scope.doPrint = function (form) {
|
|||
|
|
|||
|
setSelectLst($scope.endrLst);
|
|||
|
//alert("sch");
|
|||
|
$scope.msgErrorPrint = '1';
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
try {
|
|||
|
if (form.$valid) {
|
|||
|
|
|||
|
if ($scope.lstSelect.length <= 0) {
|
|||
|
var errorForm = {};
|
|||
|
errorForm.errorFlag = 1;
|
|||
|
errorForm.errorDesc = "Please ,selected data.";
|
|||
|
var retDialog = commonFactory.doOpenMsg(errorForm);
|
|||
|
retDialog.then((function (returnData) {
|
|||
|
//alert("1");
|
|||
|
}), function () {
|
|||
|
//dismissed
|
|||
|
});
|
|||
|
} else {
|
|||
|
printData();
|
|||
|
}
|
|||
|
|
|||
|
} else {
|
|||
|
$scope.msgErrorPrint = '0';
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
} catch (e) {
|
|||
|
$scope.msgErrorPrint = '0';
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
};
|
|||
|
function printData() {
|
|||
|
try {
|
|||
|
//alert("printData");
|
|||
|
setLstPrint($scope.lstSelect);
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
var actLoadData = $.ajax(doGetPath('/json/ENDR001Print.json'),
|
|||
|
{
|
|||
|
ajax: true,
|
|||
|
dataType: 'json',
|
|||
|
type: "POST",
|
|||
|
data: {
|
|||
|
dataFormParam: JSON.stringify($scope.lstDataPrint),
|
|||
|
dataPrintParam: JSON.stringify($scope.pntForm)
|
|||
|
}
|
|||
|
}).error(
|
|||
|
function (data) {
|
|||
|
// alert("Session Time Out!!!");
|
|||
|
// $location.path("/");
|
|||
|
// $scope.$apply();
|
|||
|
});
|
|||
|
|
|||
|
actLoadData.success(
|
|||
|
function (data) {
|
|||
|
var dbError = data[0];
|
|||
|
if (dbError.errorFlag == 1) {
|
|||
|
|
|||
|
var retDialog = commonFactory.doOpenMsg(dbError);
|
|||
|
retDialog.then((function (returnData) {
|
|||
|
//alert("1");
|
|||
|
}), function () {
|
|||
|
//dismissed
|
|||
|
});
|
|||
|
|
|||
|
} else {
|
|||
|
|
|||
|
var retDialog2 = commonFactory.doOpenMsg(dbError);
|
|||
|
retDialog2.then((function (returnData) {
|
|||
|
//alert("1");
|
|||
|
}), function () {
|
|||
|
//dismissed
|
|||
|
});
|
|||
|
|
|||
|
/////////////////////////////////////////
|
|||
|
searchData();
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
}
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
);
|
|||
|
} catch (e) {
|
|||
|
//
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
$scope.doRejectPrint = function () {
|
|||
|
//alert("doRejectPrint");
|
|||
|
setSelectLst($scope.endrLst);
|
|||
|
//alert("doRejectPrint");
|
|||
|
$scope.msgErrorPrint = '1';
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
try {
|
|||
|
//if(form.$valid){
|
|||
|
if (true) {
|
|||
|
|
|||
|
if ($scope.lstSelect.length <= 0) {
|
|||
|
var errorForm = {};
|
|||
|
errorForm.errorFlag = 1;
|
|||
|
errorForm.errorDesc = "Please ,selected data.";
|
|||
|
var retDialog = commonFactory.doOpenMsg(errorForm);
|
|||
|
retDialog.then((function (returnData) {
|
|||
|
//alert("1");
|
|||
|
}), function () {
|
|||
|
//dismissed
|
|||
|
});
|
|||
|
} else {
|
|||
|
|
|||
|
var errorForm2 = {};
|
|||
|
errorForm2.errorFlag = 2;
|
|||
|
errorForm2.errorDesc = "<22><>ͧ<EFBFBD><CDA7><EFBFBD>¡<EFBFBD><C2A1>ԡ<EFBFBD><D4A1>þ<EFBFBD><C3BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
var retDialog2 = commonFactory.doOpenConfirm(errorForm2);
|
|||
|
retDialog2.then((function (returnData) {
|
|||
|
if (returnData) {
|
|||
|
|
|||
|
rejectData();
|
|||
|
}
|
|||
|
//alert("1");
|
|||
|
}), function () {
|
|||
|
//dismissed
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
} else {
|
|||
|
$scope.msgErrorPrint = '0';
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
} catch (e) {
|
|||
|
$scope.msgErrorPrint = '0';
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
};
|
|||
|
function rejectData() {
|
|||
|
try {
|
|||
|
//alert("printData");
|
|||
|
setLstPrint($scope.lstSelect);
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
var actLoadData = $.ajax(doGetPath('/json/ENDR001RejectPrint.json'),
|
|||
|
{
|
|||
|
ajax: true,
|
|||
|
dataType: 'json',
|
|||
|
type: "POST",
|
|||
|
data: {
|
|||
|
dataFormParam: JSON.stringify($scope.lstDataPrint),
|
|||
|
dataPrintParam: JSON.stringify($scope.pntForm)
|
|||
|
}
|
|||
|
}).error(
|
|||
|
function (data) {
|
|||
|
// alert("Session Time Out!!!");
|
|||
|
// $location.path("/");
|
|||
|
// $scope.$apply();
|
|||
|
});
|
|||
|
|
|||
|
actLoadData.success(
|
|||
|
function (data) {
|
|||
|
var dbError = data[0];
|
|||
|
if (dbError.errorFlag == 1) {
|
|||
|
|
|||
|
var retDialog = commonFactory.doOpenMsg(dbError);
|
|||
|
retDialog.then((function (returnData) {
|
|||
|
//alert("1");
|
|||
|
}), function () {
|
|||
|
//dismissed
|
|||
|
});
|
|||
|
|
|||
|
} else {
|
|||
|
|
|||
|
var retDialog2 = commonFactory.doOpenMsg(dbError);
|
|||
|
retDialog2.then((function (returnData) {
|
|||
|
//alert("1");
|
|||
|
}), function () {
|
|||
|
//dismissed
|
|||
|
});
|
|||
|
|
|||
|
/////////////////////////////////////////
|
|||
|
searchData();
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
}
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
);
|
|||
|
} catch (e) {
|
|||
|
//
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
$scope.doClearPnt = function () {
|
|||
|
$scope.pntForm = {};
|
|||
|
$scope.msgErrorPrint = '1';
|
|||
|
$scope.$apply();
|
|||
|
};
|
|||
|
|
|||
|
function setPaging(dataLst) {
|
|||
|
$scope.totalItems1 = dataLst.length;
|
|||
|
$scope.currentPage1 = 1;
|
|||
|
$scope.numPages1 = Math.ceil($scope.totalItems1 / $scope.perPages);
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
|
|||
|
// Select checkBox
|
|||
|
$scope.doSelectAll = function () {
|
|||
|
|
|||
|
//alert($scope.selectAll);
|
|||
|
if ($scope.selectAll == 0) {
|
|||
|
for (var i = 0; i < $scope.endrLst.length; i++) {
|
|||
|
$scope.endrLst[i].selectFlag = 0;
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
} else {
|
|||
|
for (var j = 0; j < $scope.endrLst.length; j++) {
|
|||
|
$scope.endrLst[j].selectFlag = 1;
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
$scope.$apply();
|
|||
|
};
|
|||
|
|
|||
|
function selectAllInit() {
|
|||
|
$scope.selectAll = 1;
|
|||
|
if ($scope.endrLst.length > 0) {
|
|||
|
for (var j = 0; j < $scope.endrLst.length; j++) {
|
|||
|
$scope.endrLst[j].selectFlag = 1;
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
$scope.toggleSelect = function (data) {
|
|||
|
|
|||
|
for (var k = 0; k < $scope.endrLst.length; k++) {
|
|||
|
if ($scope.endrLst[k].taskId == data) {
|
|||
|
if ($scope.endrLst[k].selectFlag == 1) {
|
|||
|
$scope.endrLst[k].selectFlag = 0;
|
|||
|
$scope.$apply();
|
|||
|
} else {
|
|||
|
$scope.endrLst[k].selectFlag = 1;
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
$scope.$apply();
|
|||
|
};
|
|||
|
|
|||
|
// $scope.setSelectOne = function( data ) {
|
|||
|
//
|
|||
|
// for(var k = 0 ; k < $scope.endrLst.length; k++){
|
|||
|
// if($scope.endrLst[k].taskId==data){
|
|||
|
// if($scope.endrLst[k].selectFlag == 1){
|
|||
|
// $scope.lstSelect.push( data );
|
|||
|
// $scope.$apply();
|
|||
|
// }else{
|
|||
|
// for(var l = 0 ; l < $scope.endrLst.length; l++){
|
|||
|
// if($scope.endrLst[l].taskId==data){
|
|||
|
// $scope.lstSelect.splice(l, 1);
|
|||
|
// $scope.$apply();
|
|||
|
// //break;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
// //break;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// };
|
|||
|
|
|||
|
function setLstPrint(lstData) {
|
|||
|
//alert(lstData.length);
|
|||
|
var lstDataPrintTmp = [];
|
|||
|
for (var i = 0; i < lstData.length; i++) {
|
|||
|
for (var y = 0; y < $scope.endrLst.length; y++) {
|
|||
|
if (lstData[i] == $scope.endrLst[y].taskId) {
|
|||
|
lstDataPrintTmp.push($scope.endrLst[y]);
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
$scope.lstDataPrint = [];
|
|||
|
$scope.$apply();
|
|||
|
angular.copy(lstDataPrintTmp, $scope.lstDataPrint);
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
|
|||
|
function setSelectLst(endrLst) {
|
|||
|
$scope.lstSelect = [];
|
|||
|
$scope.$apply();
|
|||
|
|
|||
|
if (endrLst.length > 0) {
|
|||
|
for (var i = 0; i < endrLst.length; i++) {
|
|||
|
if (endrLst[i].selectFlag == 1) {
|
|||
|
$scope.lstSelect.push(endrLst[i].taskId);
|
|||
|
$scope.$apply();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
//)
|
|||
|
//;
|