ENDRPrint/.svn/pristine/95/955d4432a7f443fed414c97d35612689a3cf5f31.svn-base

99 lines
4.2 KiB
Plaintext
Raw Permalink Normal View History

2024-08-14 10:33:27 +07:00
// create the controller and inject AngularJs $scope
scotchApp.controller('loginController',
// create a message to display in our view
function($scope ,$modal ,$log ,$window ,$route ,$location ,$templateCache,commonService,mainPostFactory) {
//$templateCache.removeAll();
/////////////////////////////////
init();
function init(){
$("#userId" ).focus();
$scope.logIn = {};
$scope.logInFlag = false;
$scope.user = {
userId : '', //anupong
userPassword : '', //anupong_h
errorMsg : ''
};
}
//cursor_clear();
//
$scope.doLogin = function(form){
//alert("doLogin");
if( !form.$valid ){
$scope.user.errorMsg = 'กรุณากรอก ชื่อผู้ใช้งาน และ รหัสผ่าน';
$scope.$apply();
}else{
//alert("doGetPath('/LoginJsonController.json");
//alert(doGetPath('/LoginJsonController.json'));
$scope.logInFlag = true;
try{
//alert("11");
// var jsLogin = $.ajax(doGetPath('/LoginJsonController.json'),
// {
// ajax: true,
// dataType: 'json',
// type: "POST",
// data:{
// user: JSON.stringify( $scope.user )
// }
// });
// jsLogin.success(
var data = {user: JSON.stringify( $scope.user )};
mainPostFactory.doAjaxPost('/LoginJsonController.json',data).success(
function(data){
//alert(data);
if( data != null ){
//var datas = data[0];
//alert(data[0].flagLogin);
if('1' == data[0].flagLogin ){
//$window.location.href = "index.jsp";
//$window.location.href = "endr_print.jsp";
commonService.setUrlPath("/ENDR001/"+new Date().getTime());
commonService.setDv(data[1]);
$location.path("/ENDR001/"+new Date().getTime());
$scope.logInFlag = false;
}else if('-1' == data[0].flagLogin){
$scope.user.errorMsg = 'กรุณาติดต่อผู้ดูแลระบบ สำหรับตั้งค่าการใช้งาน';
$scope.user.userId = '';
$scope.user.userPassword = '';
$scope.logInFlag = false;
$("#userId" ).focus();
}else{
$scope.user.errorMsg = 'Username or password ไม่ถูกต้อง';
$scope.user.userId = '';
$scope.user.userPassword = '';
$scope.logInFlag = false;
//$window.location.href = "login.jsp";
$("#userId" ).focus();
}
}else{
$scope.user.errorMsg = 'Username or password ไม่ถูกต้อง';
$scope.user.userId = '';
$scope.user.userPassword = '';
$scope.logInFlag = false;
$("#userId" ).focus();
}
$scope.$apply();
}
);
}catch (ex){
//
$scope.logInFlag = false;
}
}
};
});