1/*** 2 Metronic AngularJS App Main Script 3 ***/ 4 5/* Metronic App */ 6var MetronicApp = angular.module("MetronicApp", [ 7 "ui.router", 8 "ui.bootstrap", 9 "oc.lazyLoad", 10 "ngSanitize", 11 'wemsFactory', 'amplifyFactory', 'storeFactory', 12 'toastr', 13]); 14 15/* Configure ocLazyLoader(refer: https://github.com/ocombe/ocLazyLoad) */ 16MetronicApp.config(['$ocLazyLoadProvider', function ($ocLazyLoadProvider) { 17 $ocLazyLoadProvider.config({ 18 // global configs go here 19 }); 20}]); 21 22//AngularJS v1.3.x workaround for old style controller declarition in HTML 23MetronicApp.config(['$controllerProvider', function ($controllerProvider) { 24 // this option might be handy for migrating old apps, but please don't use it 25 // in new ones! 26 $controllerProvider.allowGlobals(); 27}]); 28 29MetronicApp.config(['$httpProvider', function ($httpProvider) { 30 31 $httpProvider.interceptors.push(['settings', function (settings) { 32 return { 33 'request': function (config) { 34 //console.log('test httpProvider config.headers.Authorization '); 35 //console.log(settings); 36 var token = settings.Token; 37 if (token) { 38 config.headers = config.headers || {}; 39 config.headers.Authorization = token; 40 } 41 return config; 42 } 43 }; 44 }]); 45}]); 46 47/******************************************** 48 END: BREAKING CHANGE in AngularJS v1.3.x: 49 *********************************************/ 50 51/* Setup global settings */ 52MetronicApp.factory('settings', ['$rootScope', function ($rootScope) { 53 // supported languages 54 var settings = { 55 layout: { 56 pageSidebarClosed: false, // sidebar menu state 57 pageContentWhite: true, // set page content layout 58 pageBodySolid: false, // solid body color state 59 pageAutoScrollOnLoad: 1000 // auto scroll to top on page load 60 }, 61 assetsPath: '../assets', 62 globalPath: '../assets/global', 63 layoutPath: '../assets/layouts/layout', 64 65 sarunrdPath: 'js/sarunrd/', 66 67 Token: '', 68 PrivateKey: UUID.generate(), // actas UUID must have priv-key when after login or not ? 69 crypto_password: 'sarun.rd', 70 71 User_Idx: 0, 72 UserLogin: '', 73 UserFullName: '', 74 Icon: 'assets/layouts/layout4/img/avatar9.jpg', 75 76 signout: function () { 77 this.Token = ''; 78 this.User_Idx = 0; 79 this.UserLogin = ''; 80 this.UserFullName = ''; 81 }, 82 83 tempObj: {}, 84 }; 85 86 $rootScope.settings = settings; 87 88 return settings; 89}]); 90 91/* Setup App Main Controller */ 92MetronicApp.controller('AppController', ['$scope', '$rootScope', function ($scope, $rootScope) { 93 $scope.$on('$viewContentLoaded', function () { 94 //App.initComponents(); // init core components 95 //Layout.init(); // Init entire layout(header, footer, sidebar, etc) on page load if the partials included in server side instead of loading with ng-include directive 96 }); 97}]); 98 99/*** 100 Layout Partials. 101 By default the partials are loaded through AngularJS ng-include directive. In case they loaded in server side(e.g: PHP include function) then below partial 102 initialization can be disabled and Layout.init() should be called on page load complete as explained above. 103 ***/ 104 105/* Setup Layout Part - Header */ 106MetronicApp.controller('HeaderController', function ($rootScope, $scope, $state, settings, toastr, wemsFactory, storeFactory) { 107 $scope.$on('$includeContentLoaded', function () { 108 Layout.initHeader(); // init header 109 }); 110 111 $scope.IsUserAuthenticated = false; 112 $scope.UserFullName = ''; 113 114 $rootScope.$on('OnSettingsChanged', function (event) { 115 console.log('OnSettingsChanged '); 116 /// refresh image load 117 //$scope.UserLoginPictureUrl = pict + '?timestamp=' + new Date().getTime(); 118 //$scope.$apply(); 119 console.log(settings); 120 $scope.IsUserAuthenticated = false; 121 if (settings.User_Idx > 0) { 122 $scope.IsUserAuthenticated = true; 123 $scope.UserFullName = settings.UserFullName; 124 125 console.log(' set IsUserAuthenticated to TRUE 3........ ') 126 } else $scope.IsUserAuthenticated = false;
127 //$scope.$apply(); 128 }); 129 130 $scope.doneUserLogout = function () { 131 console.log('doneLogin'); 132 console.log('User -> ' + $scope.Password); 133 var params = $.param({ 134 User_Idx: settings.User_Idx, 135 PrivateKey: settings.PrivateKey 136 }); 137 console.log(params); 138 139 var promise = wemsFactory.postActionAjax('/userprofile/logout', params); 140 promise.then( 141 function (value) { 142 var jsonObj = value; 143 console.log(jsonObj); 144 145 $scope.IsAuthenticated = false; 146 147 storeFactory.RemoveLocal('Token'); 148 storeFactory.RemoveLocal('User_Idx'); 149 storeFactory.RemoveLocal('UserFullName'); 150 151 $rootScope.settings.signout(); 152 153 $rootScope.$broadcast('OnSettingsChanged'); 154 155 $stste.go('profile.help'); // go login page 156 157 //toastr.success(value.Message, 'รายà¸à¸²à¸à¸à¸¥'); 158 }, 159 function (reason) { 160 console.log(reason); 161 toastr.error(reason.statusCode + ': ' + reason.error + '<br/>' + reason.message, 'มีà¸à¹à¸à¸à¸´à¸à¸à¸¥à¸²à¸'); 162 }); 163 }; 164}); 165 166/* Setup Layout Part - Sidebar */ 167MetronicApp.controller('SidebarController', ['$state', '$scope', function ($state, $scope) { 168 $scope.$on('$includeContentLoaded', function () { 169 Layout.initSidebar($state); // init sidebar 170 }); 171}]); 172 173/* Setup Layout Part - Quick Sidebar */ 174MetronicApp.controller('QuickSidebarController', ['$scope', function ($scope) { 175 $scope.$on('$includeContentLoaded', function () { 176 setTimeout(function () { 177 QuickSidebar.init(); // init quick sidebar 178 }, 2000) 179 }); 180}]); 181 182/* Setup Layout Part - Theme Panel */ 183MetronicApp.controller('ThemePanelController', ['$scope', function ($scope) { 184 $scope.$on('$includeContentLoaded', function () { 185 Demo.init(); // init theme panel 186 }); 187}]); 188 189/* Setup Layout Part - Footer */ 190MetronicApp.controller('FooterController', ['$scope', function ($scope) { 191 $scope.$on('$includeContentLoaded', function () { 192 Layout.initFooter(); // init footer 193 }); 194}]); 195 196/* Setup Rounting For All Pages */ 197MetronicApp.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) { 198 // Redirect any unmatched url 199 $urlRouterProvider.otherwise("/login"); 200 201 $stateProvider 202 // Login in 203 .state('login', { 204 url: "/login", 205 templateUrl: "views/login.html", 206 data: { 207 pageTitle: 'Login' 208 }, 209 controller: "LoginController", 210 resolve: { 211 deps: ['$ocLazyLoad', function ($ocLazyLoad) { 212 return $ocLazyLoad.load({ 213 name: 'MetronicApp', 214 insertBefore: '#ng_load_plugins_before', // load the above css files before a LINK element with this ID. Dynamic CSS files must be loaded between core and theme css files 215 files: [ 216 '../assets/pages/css/login-5.min.css', 217 '../assets/global/plugins/morris/morris.css', 218 '../assets/global/plugins/morris/morris.min.js', 219 '../assets/global/plugins/morris/raphael-min.js', 220 '../assets/global/plugins/jquery.sparkline.min.js', 221 222 'js/controllers/LoginController.js', 223 ] 224 }); 225 }] 226 } 227 }) 228 // Change Password 229 .state('change_password', { 230 url: "/change_password", 231 templateUrl: "views/change_password.html", 232 data: { 233 pageTitle: 'Change Password Template' 234 }, 235 controller: "ChangePasswordController", 236 resolve: { 237 deps: ['$ocLazyLoad', function ($ocLazyLoad) { 238 return $ocLazyLoad.load({ 239 name: 'MetronicApp', 240 insertBefore: '#ng_load_plugins_before', // load the above css files before a LINK element with this ID. Dynamic CSS files must be loaded between core and theme css files 241 files: [ 242 '../assets/pages/css/lock.min.css', 243 '../assets/pages/scripts/lock.min.js', 244 245 'js/controllers/ChangePasswordController.js', 246 ] 247 }); 248 }] 249 } 250 }) 251 252}]); 253 254//toastr Config 255MetronicApp.config(function(toastrConfig) { 256 angular.extend(toastrConfig, { 257 allowHtml: true, 258 closeButton: true, 259 extendedTimeOut: 1000, 260 progressBar: false, 261 timeOut: 5000, 262 tapToDismiss: false, 263 }); 264}); 265 266/* Init global settings and run the app */ 267MetronicApp.run(function ($rootScope, settings, $window, $location, $state, toastr, wemsFactory, storeFactory) { 268 $rootScope.$state = $state; // state to be accessed from view 269 $rootScope.$settings = settings; // state to be accessed from view 270 271 //settings.client_ip = '127.0.0.1'; 272 if (_.isEmpty(settings.client_ip)) { 273 $.getJSON('//api.ipify.org?format=jsonp&callback=?', function (data) { 274 //console.log(JSON.stringify(data, null, 2)); 275 //console.log(typeof data); 276 //console.log('ipify -> ' + data.ip); 277 settings.client_ip = data.ip; 278 }); 279 } 280 281 $rootScope.$on('$locationChangeStart', function (event, next, current) { 282 //console.log(' ****** MetronicApp.run ==> locationChangeStart'); 283 284 var local_token = storeFactory.GetLocal('Token'); 285 //console.log(' local_token = ' + local_token); 286 //console.log(typeof local_token); 287 //console.log(' ' + settings.userSignin_info.Token); 288 289 if (_.isUndefined(local_token) || local_token.isEmpty()) { 290 //console.log(' if (_.isUndefined(token)) { current: ' + current); 291 //console.log(' if (_.isUndefined(token)) { next: ' + next); 292 /// check token already ? 293 //alert(' ****** MetronicApp.run ==> locationChangeStart'); 294 //$window.location.href = '/index_login.html'; 295 return; 296 } 297 298 if (local_token && local_token !== settings.Token) { 299 //console.log(' if (token && token !== settings.Token) {'); 300 //console.log(' verify token ???????? Oh yes.'); 301 302 //console.log(' if (_.isUndefined(token)) { current: ' + current); 303 //console.log(' if (_.isUndefined(token)) { next: ' + next); 304 305 //console.log(' locationChangeStart check_usersignin_token local_token='
305+ local_token + ']]]]]]'); 306 check_usersignin_token(local_token, function (success) { 307 //console.log('success = ' + success); 308 309 if (!success) { 310 //$window.location.href = '/index_login.html'; 311 //return; 312 } 313 }); 314 return; 315 } 316 317 if (local_token && settings.User_Idx === 0) { 318 //console.log(' if (settings.userSignin_info.User_Idx === 0) { '); 319 /// check token already ? 320 321 //console.log(' if (_.isUndefined(token)) { current: ' + current); 322 //console.log(' if (_.isUndefined(token)) { next: ' + next); 323 //if (next.indexOf('staff-signin') === -1) 324 // $location.path('/staff-signin'); 325 326 return; 327 } 328 }); 329 330 /////////////////////// 331 /// check Token is ok ? 332 var check_usersignin_token = function (token, callback) { 333 //console.log(' var check_token = function (token) { ' + token); 334 var obj = { 335 Token: token 336 }; 337 //console.log(obj); 338 var promise = wemsFactory.postActionJson('/user/check_token', obj); 339 promise.then( 340 function (jsonObj) { 341 //console.log(' /user/check_token jsonObj **********************'); 342 //console.log('jsonObj ' + typeof jsonObj); 343 //console.log(jsonObj); 344 345 if (settings.PrivateKey !== jsonObj.PrivateKey) { 346 //console.log('>> found PrivateKey mismatch <<'); 347 settings.PrivateKey = jsonObj.PrivateKey; 348 storeFactory.SetLocal('PrivateKey', jsonObj.PrivateKey); 349 } 350 351 /// update settings 352 settings.User_Idx = jsonObj.User_Idx; 353 settings.UserLogin = jsonObj.UserLogin; 354 settings.UserFullName = jsonObj.UserFullName; 355 settings.Token = jsonObj.Token; 356 357 storeFactory.SetLocal('Token', jsonObj.Token); 358 359 //var absUrl = $location.absUrl(); 360 //console.log('absUrl = ' + absUrl); 361 //console.log('jsonObj.StartPageUrl = ' + jsonObj.StartPageUrl); 362 363 //toastr.success('รายà¸à¸²à¸à¸à¸¥<br/> ' + 'Welcome ' + jsonObj.UserFullName); 364 return callback(true); 365 }, 366 function (reason) { 367 console.log(reason); 368 toastr.error('มีà¸à¹à¸à¸à¸´à¸à¸à¸¥à¸²à¸<br/> ' + reason.message); 369 ///settings.doUpdate_Signout(); no need to do 370 371 //$window.location.href = '/index_login.html'; 372 return callback(false); 373 }); 374 }; 375});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.