zupit.service('Zupit.Core.AppService', ['Zupit.Core.HttpClient', 'Zupit.Core.NotificationService', 'config', '$translate','$rootScope','$q','Zupit.Core.SignalR', function ($http, notify, config, $translate, $rootScope, $q, sr) { kendo.culture(config.kendoCulture); moment.locale(config.momentCulture); var culture = kendo.culture(); culture.numberFormat.currency.symbol = config.currencySymbol; if (config.timeZone!==undefined && config.timeZone!==null && config.timeZone!=='') $rootScope.timezone = moment.tz(config.timeZone); if ($rootScope.timezone === undefined) $rootScope.timezone = moment.tz(moment.tz.guess()); return { culture: config.lang, currency:config.currency, init:function() { $translate.use(this.culture); }, currentForm: null, canLeave: true, canILeaveThePage: function () { return this.canLeave && (this.currentForm===null || (this.currentForm !== null && !this.currentForm.$isDirty())); }, menu: null, user: null, currentPlant:null, isInRole: function (role) { if (this.user != null && this.user.roles != undefined) { return _.contains(this.user.roles, role); } return false; }, isAdmin: function() { return this.isInRole('Administrator') || this.isInRole('Developer'); }, fetchMenu: function () { var that = this; $http.get('api/admin/usermenu').then(function (ret) { that.menu = ret; $rootScope.$broadcast('MENU.CHANGE', ret); }); }, Loading: { state: { }, show:function(ui) { ui = ui || '_'; if (!this.state.hasOwnProperty(ui)) this.state[ui] = 1; var options = { baseZ: '100000', message: '', overlayCSS: { backgroundColor: '#1b2024', opacity: 0.8, zIndex: 1200, cursor: 'wait' }, css: { border: 0, color: '#fff', padding: 0, zIndex: 1201, backgroundColor: 'transparent' } }; if (ui === '_') $.blockUI(options); else $(ui).block(options); }, hide: function (ui) { ui = ui || '_'; if (!this.state.hasOwnProperty(ui)) return; this.state[ui]--; if (this.state[ui] < 0) this.state[ui] = 0; if (this.state[ui] === 0) { if (ui === '_') $.unblockUI(); else $(ui).unblock(); } } } }; } ]);