123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- app.controller('AppCtrl', [ '$rootScope', '$scope', '$http', '$localStorage', '$location', '$modal', '$ocLazyLoad', '$q', 'toaster', function($rootScope, $scope, $http, $localStorage, $location, $modal, $ocLazyLoad, $q, toaster) {
- $rootScope.frame = {
- CompanyName : '',
- FrameVersion : '1.0.0',
- WaitWindow : false,
- // for chart colors
- color : {
- primary : '#7266ba',
- info : '#23b7e5',
- success : '#27c24c',
- warning : '#fad733',
- danger : '#f05050',
- light : '#e8eff0',
- dark : '#3a3f51',
- black : '#1c2b36'
- },
- colors : [ '#23b7e5', '#27c24c', '#7266ba', '#FFB6C1', '#87CEFA', '#DB7093', '#7FFF00', '#9932CC', '#6A5ACD' ],
- texts : [ 'text-info', 'text-success', 'text-primary', 'text-gold', 'text-lime', 'text-aliceblue', 'text-indianred', 'text-palevioletred', 'text-darkslategray' ],
- settings : {
- themeID : 1,
- navbarHeaderColor : 'bg-black',
- navbarCollapseColor : 'bg-white-only',
- asideColor : 'bg-black',
- headerFixed : true,
- asideFixed : true,
- asideFolded : false,
- asideDock : false,
- container : false
- }
- }
- $.ajax({
- url : 'frame/optr/init.htm',
- async : false,
- type : "POST",
- dataType : "json",
- success : function(data) {
- if (data.success == false) {
- window.location = "logout.html";
- return;
- } else
- angular.extend($rootScope.frame, data.map);
- // param
- $rootScope.frame.FrameParam = {};
- angular.forEach(data.map.FrameParamArray, function(param, key) {
- $rootScope.frame.FrameParam[param.param_name] = param.param_value;
- });
- document.title = $rootScope.frame.FrameParam.FrameTitle;
- // config
- $rootScope.frame.configMap = {}, $rootScope.frame.configArray = {};
- angular.forEach(data.map.FrameConfigArray, function(config, key) {
- $rootScope.frame.configMap[config.config_name + "_" + config.config_value] = config;
- if ($rootScope.frame.configArray[config.config_name] == undefined)
- $rootScope.frame.configArray[config.config_name] = [];
- $rootScope.frame.configArray[config.config_name].push(config);
- });
- // role
- $rootScope.frame.FrameOptr.roleMap = {};
- angular.forEach(data.map.FrameOptr.resMap, function(role, key) {
- $rootScope.frame.FrameOptr.roleMap['Role' + role] = role;
- });
- }
- });
- $rootScope.getConfigText = function(config_name, config_value) {
- var config = $rootScope.frame.configMap[config_name + "_" + config_value];
- if (config) {
- return config.config_text;
- }
- return config_value;
- };
- // 获取配置
- $rootScope.getConfigArray = function(config_name) {
- return $rootScope.frame.configArray[config_name];
- };
- // 鉴权
- $rootScope.authOptrRole = function(role_id) {
- return !!$rootScope.frame.FrameOptr.roleMap['Role' + role_id];
- };
- // 获取图标css
- $rootScope.getIconCss = function(css) {
- css = $.trim(css);
- if (css != undefined && css.length > 0) {
- if (css.indexOf('icon') == 0)
- return 'glyphicon icon ' + css + ' ';
- if (css.indexOf('fa') == 0)
- return 'glyphicon fa ' + css + ' ';
- if (css.indexOf('glyphicon') == 0)
- return 'glyphicon ' + css + ' ';
- return 'glyphicon ' + css + ' ';
- } else
- return 'glyphicon glyphicon-cog text-info-lter ';
- };
- // 计算文件大小:tostring
- $rootScope.getFileSize = function(size) {
- if (size == null || size == undefined || isNaN(size))
- return;
- if (size < 1024)
- return size + ' Byte'
- if (size < 1024 * 1024)
- return Math.round(size / 1024 * 100) / 100 + ' KB';
- return Math.round(size / (1024 * 1024) * 100) / 100 + ' MB';
- }
- // 对话框
- $rootScope.dialog = function(params) {
- $modal.open({
- templateUrl : 'frame/dialog/confirm.html',
- controller : 'FrameConfirmCtrl',
- backdrop : 'static',
- size : 's4',
- keyboard : false,
- windowClass : 'dialog',
- // scope : true,
- resolve : {
- params : function() {
- return angular.copy(params);
- }
- }
- });
- }
- // 对话框
- $rootScope.msg = function(params) {
- $modal.open({
- templateUrl : 'frame/dialog/alert.html',
- controller : 'FrameAlertCtrl',
- backdrop : 'static',
- size : 's4',
- keyboard : false,
- windowClass : 'dialog',
- // scope : scope,
- resolve : {
- params : function() {
- return angular.copy(params);
- }
- }
- });
- }
- // 等待
- $rootScope.wait = function(params) {
- $modal.open({
- templateUrl : 'frame/dialog/wait.html',
- controller : 'FrameWaitCtrl',
- backdrop : 'static',
- size : 's4',
- keyboard : false,
- windowClass : 'dialog',
- // scope : true,
- resolve : {
- params : function() {
- return angular.copy(params);
- }
- }
- });
- }
- // 显示等待层
- $rootScope.showWaitWindow = function(wait) {
- // 已经打开了等待框
- if ($rootScope.frame.WaitWindow == true)
- return;
- $rootScope.frame.WaitWindow = true;
- $rootScope.wait({
- seconds : wait
- });
- }
- // 通用弹出层
- $rootScope.showModal = function(params) {
- var js = params.js || '';
- if (js.length != 0) {
- $ocLazyLoad.load([ js ]).then(function() {
- $modal.open(params)
- });
- } else
- $modal.open(params);
- }
- // 通用上传文件框
- $rootScope.showUpload = function(url, params, fn) {
- $ocLazyLoad.load([ 'angularFileUpload' ]).then(function() {
- $modal.open({
- templateUrl : 'frame/dialog/upload.html',
- controller : 'FrameUploadCtrl',
- backdrop : 'static',
- size : 'lg',
- keyboard : false,
- windowClass : 'dialog',
- // scope : true,
- resolve : {
- url : function() {
- return angular.copy(url);
- },
- params : function() {
- return angular.copy(params);
- },
- fn : function() {
- return angular.copy(fn);
- },
- }
- });
- });
- }
- // 通用状态颜色
- $rootScope.getStatusColor = function(status) {
- if (status == 'Active')
- return {
- color : 'green'
- };
- return {
- color : '#ADADAD'
- }
- }
- // 通用编辑窗口
- $rootScope.editEntity = function(scope, url, contorl, entity, size, js, keyboard) {
- js = js || (url.substring(0, url.length - 4) + 'js');
- $rootScope.showModal({
- templateUrl : url,
- controller : contorl,
- keyboard : keyboard == undefined ? true : keyboard,
- js : js,
- backdrop : 'static',
- size : size,
- scope : scope,
- resolve : {
- entity : function() {
- return angular.copy(entity);
- }
- }
- });
- }
- $rootScope.jAjax = function(params) {
- var aParam = angular.extend({
- async : false,
- type : "POST",
- dataType : "json"
- }, params)
- if (params.success) {
- aParam.success = function(data) {
- if (data.success == false) {
- if (data.login == false) {
- window.location = "logout.html";
- return;
- }
- toaster.error(data.errorMsg);
- return;
- }
- params.success.call(this, data);
- }
- }
- $.ajax(aParam);
- }
- $rootScope.shortDateString = function(date) {
- if (date == undefined)
- return "";
- if (angular.isDate(date))
- date = date.toJSON();
- if (date.length > 10)
- return date.substr(0, 10);
- return date;
- }
- $rootScope.shortTimeString = function(date) {
- if (date == undefined)
- return "";
- if (angular.isDate(date))
- date = date.toJSON();
- if (date.length > 10)
- return date.substr(11);
- return date;
- }
- $rootScope.parseShortString = function(date) {
- if(date == undefined)
- date = new Date();
- var str = $rootScope.shortDateString(date);
- return new Date(Date.parse(str.replace(/-/g, "/")));
- }
- $rootScope.parseLongString = function(date) {
- if (angular.isDate(date))
- return date;
- if (date == undefined || date.length != 19)
- return undefined;
- return new Date(Date.parse(date.replace(/-/g, "/")));
- }
- $rootScope.shortDateOptions = {
- formatYear : 'yyyy',
- startingDay : 1,
- class : 'datepicker',
- };
- $rootScope.openDatepicker = function(scope, $event, value) {
- $event.preventDefault();
- $event.stopPropagation();
- scope[value] = true;
- };
- $rootScope.openNewWindow = function(url) {
- window.open(url);
- };
- $rootScope.removeFirstElement = function(array) {
- var ar = new Array();
- if (array == undefined)
- return;
- for (var i = 1; i < array.length; i++)
- ar.push(array[i]);
- return ar;
- };
- $rootScope.optrSingleRecord = function(url, key, fn, dialog_msg, toaster_msg) {
- var ajax = function() {
- $http({
- url : url,
- method : 'post',
- data : {
- key : key
- }
- }).success(function(data) {
- if (fn)
- fn.call(this, data);
- if (toaster_msg == false)
- return;
- toaster.success('', toaster_msg || '操作成功');
- });
- };
- if (dialog_msg == undefined || dialog_msg.length == 0) {
- ajax();
- } else {
- // 提交
- $rootScope.dialog({
- success : ajax,
- msg : dialog_msg
- });
- }
- }
-
- $rootScope.optrRecord = function(url, entity, fn, dialog_msg, toaster_msg) {
- var ajax = function() {
- $http({
- url : url,
- method : 'post',
- data : entity
- }).success(function(data) {
- if (fn)
- fn.call(this, data);
- if (toaster_msg == false)
- return;
- toaster.success('', toaster_msg || '操作成功');
- });
- };
- if (dialog_msg == undefined || dialog_msg.length == 0) {
- ajax();
- } else {
- // 提交
- $rootScope.dialog({
- success : ajax,
- msg : dialog_msg
- });
- }
- }
- $rootScope.totalValues = function(array, field) {
- var value = 0;
- angular.forEach(array, function(dr) {
- if (dr[field])
- value += dr[field];
- })
- return value;
- }
- $scope.logout = function() {
- $rootScope.dialog({
- success : function() {
- $http({
- url : 'frame/optr/logout.htm',
- }).success(function() {
- window.location = "./login/login.jsp"
- });
- },
- title : '退出系统提示',
- msg : '请问您确定要退出系统吗?'
- });
- }
- // save settings to local storage
- if (angular.isDefined($localStorage.settings)) {
- $scope.frame.settings = $localStorage.settings;
- } else {
- $localStorage.settings = $scope.frame.settings;
- }
- $scope.$watch('frame.settings', function() {
- if ($scope.frame.settings.asideDock && $scope.frame.settings.asideFixed) {
- $scope.frame.settings.headerFixed = true;
- }
- $localStorage.settings = $scope.frame.settings;
- }, true);
- } ]);
|