// 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() { // $templateCache.removeAll(); // $scope.$apply(); // $location.url('/login').replace(); // mainPostFactory.doCheckLogin() // .success( // function (data) { // alert("session >>" + data); // // alert("data1 >> " + (data[0].replace('-',''))); // // alert("data2 >> " + data[1]); // var url = "/#/ENDR001" + "/" + (data[0].replace('-', '')); // // $location.path(url); // } // ); $("#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; } } }; });