var MetronicApp = angular.module('MetronicApp', [ 'ui.router', 'ui.bootstrap', 'ui.select', // https://angular-ui.github.io/ui-select/ 'ui.validate', // https://github.com/angular-ui/ui-validate 'ui.date', // https://github.com/angular-ui/ui-date 'ngSanitize', 'ngAnimate', 'ngCookies', 'ui.sortable', // https://github.com/angular-ui/ui-sortable 'ngStorage', // https://github.com/gsklee/ngStorage 'oc.lazyLoad', // https://github.com/ocombe/ocLazyLoad 'angular-growl', // http://janstevens.github.io/angular-growl-2 'angularSpinner', // https://github.com/urish/angular-spinner 'ngFileUpload', // https://github.com/danialfarid/ng-file-upload 'mwl.calendar' // https://github.com/mattlewis92/angular-bootstrap-calendar ]); MetronicApp.constant("appConfig", { apiBaseUrl: "", pageYOffset: 50, spinner: { color: '#cccccc' } }) /* Configure ocLazyLoader(refer: https://github.com/ocombe/ocLazyLoad) */ MetronicApp.config(['$ocLazyLoadProvider', function ($ocLazyLoadProvider) { $ocLazyLoadProvider.config({ // global configs go here }); }]); MetronicApp.config(['growlProvider', function (growlProvider) { growlProvider.globalTimeToLive({ success: 1500, error: 20000, warning: -1, info: 10000 }); growlProvider.globalDisableCountDown(true); growlProvider.globalPosition('top-center'); }]); /* Setup global settings */ MetronicApp.factory('settings', ['$rootScope', function($rootScope) { // supported languages var settings = { layout: { pageSidebarClosed: false, // sidebar menu state pageBodySolid: false // solid body color state //pageAutoScrollOnLoad: 1000 // auto scroll to top on page load }, layoutImgPath: Metronic.getAssetsPath() + 'admin/layout/img/', layoutCssPath: Metronic.getAssetsPath() + 'admin/layout/css/' }; $rootScope.settings = settings; return settings; }]); MetronicApp.factory('pageCache', ['$rootScope', function ($rootScope) { return { wdr_List: null }; }]); /* Setup App Main Controller */ /* MetronicApp.controller('AppController', ['$scope', '$rootScope', function($scope, $rootScope) { $scope.$on('$viewContentLoaded', function() { Metronic.initComponents(); // init core components //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 }); }]); */ /*** Layout Partials. 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 initialization can be disabled and Layout.init() should be called on page load complete as explained above. ***/ /* Setup Layout Part - Header */ MetronicApp.controller('HeaderController', ['$scope', '$http', '$log', 'appConfig', function ($scope, $http, $log, appConfig) { $scope.appConfig = appConfig; $scope.$on('$includeContentLoaded', function() { Layout.initHeader(); // init header }); $scope.errors = []; $scope.data = []; $scope.init = function () { $scope.errors = []; $http .get($scope.appConfig.apiBaseUrl + "/api/ActionUser/Info/", { params: { withs: 'CompanyShortInfo' } }) .success(function (result) { $scope.data.ActionUser = result; }) .error(function (error) { $log.error('Error loading action user info.'); $scope.errors.push(error); }) } $scope.init(); }]); /* Setup Layout Part - Sidebar */ MetronicApp.controller('SidebarController', ['$q', '$scope', 'appConfig', '$http', '$log', function ($q, $scope, appConfig, $http, $log) { $scope.$on('$includeContentLoaded', function() { Layout.initSidebar(); // init sidebar }); $scope.appConfig = appConfig; $scope.errors = []; $scope.data = { company: null, genericDocumentTypeList: [], numberOfActiveNotifications: 0 }; $scope.init = function () { $scope.errors = []; var reqs1 = []; $.merge(reqs1, $scope.initCompany()); $.merge(reqs1, $scope.initGenericDocumentTypeList()); $scope.event_Notification_OnItemCountChanged(); $q.all(reqs1) .finally(function () { if ($scope.errors.length > 0) { $log.error('Error loading side bar info.'); $scope.errors.push(error); } }); } $scope.$on('Notification_OnItemCountChanged', function (event, data) { $scope.data.numberOfActiveNotifications = data.ItemCount; }); $scope.initCompany = function () { return [$http.get($scope.appConfig.apiBaseUrl + "/Api/Company/Current/", { params: {} }) .success(function (result) { $scope.data.company = result; }) .error(function (error) { $log.error('Error loading company info.'); $scope.errors.push(error); })]; }; $scope.initGenericDocumentTypeList = function () { return [$http.get($scope.appConfig.apiBaseUrl + "/Api/Document/DocumentType/List", { params: {} }) .success(function (result) { $scope.data.genericDocumentTypeList = result; }) .error(function (error) { $log.error('Error loading document type list.'); $scope.errors.push(error); })]; }; $scope.$on('CompanyLogoChanged', function (event, data) { $scope.data.company.HasLogo = data.HasLogo; // The secure-image directive will automatically handle logo updates // No need to manually set image src anymore }); $scope.init(); }]); /* Setup Layout Part - Quick Sidebar */ MetronicApp.controller('QuickSidebarController', ['$scope', function($scope) { $scope.$on('$includeContentLoaded', function() { setTimeout(function(){ QuickSidebar.init(); // init quick sidebar }, 2000) }); }]); /* Setup Layout Part - Theme Panel */ MetronicApp.controller('ThemePanelController', ['$scope', function($scope) { $scope.$on('$includeContentLoaded', function() { Demo.init(); // init theme panel }); }]); /* Setup Layout Part - Footer */ MetronicApp.controller('FooterController', ['$scope', function($scope) { $scope.$on('$includeContentLoaded', function() { Layout.initFooter(); // init footer }); }]); MetronicApp.factory('pathInterceptor', ['$location', '$cookies', function ($location, $cookies) { var path = { request: function (config) { var token = $cookies.get('SessionToken'); config.headers['Authorization'] = 'bearer ' + token return config; }, response: function (response) { return response; } }; return path; }]); /* Setup Rounting */ MetronicApp.config(['appConfig', '$stateProvider', '$urlRouterProvider', '$locationProvider', '$urlMatcherFactoryProvider', '$httpProvider', function (appConfig, $stateProvider, $urlRouterProvider, $locationProvider, $urlMatcherFactoryProvider, $httpProvider) { $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; $httpProvider.defaults.headers.common['X-XSRF-Token'] = $('input[name="__RequestVerificationToken"]').val(); $httpProvider.interceptors.push('pathInterceptor'); $locationProvider.html5Mode(true); // Pretty URL with no hash (#) $urlMatcherFactoryProvider.caseInsensitive(true); // Allow case-insensitive URL. $urlMatcherFactoryProvider.strictMode(false); // Ignore trailing slash (/) in the URL (Ex: '/test/' is the same as '/test'). $urlRouterProvider.otherwise(function ($injector, $location) { // If URL does not match the route, navigate to that URL directly with full page load. // This is to allow exiting the app in this area and navigate to other areas of the site. var sections = [ '/wdr', '/part', '/labor', '/customer', '/setting', '/document', '/report', '/notification', '/help' ]; var url = $location.url().toLowerCase(); var matchSection = false; for (var i = 0; i < sections.length; i++) { var header = sections[i].toLowerCase(); if (url.indexOf(header) == 0) { matchSection = true; break; } } if (matchSection != true) { window.location.href = url; } }); $urlRouterProvider.when('', '/dashboard'); $stateProvider .state('Dashboard', { url: '/dashboard', templateUrl: "/app/shared/views/dashboard.html", controller: "Dashboard", resolve: { deps: ['$ocLazyLoad', function($ocLazyLoad) { return $ocLazyLoad.load({ name: 'MetronicApp', 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 files: [ '/app/shared/controllers/Dashboard.js' ] }); }] } }) }]); /* Init global settings and run the app */ MetronicApp.run(["$rootScope", "settings", "$state", function($rootScope, settings, $state) { $rootScope.$state = $state; // state to be accessed from view }]);