(function(){"use strict";u8.Base.Session=function(e){$.extend(this,u8.Base.Session.defaults,e);this.isLogin=false;if(u8.session){$error("Duplicate session! The session is a singleton. Only one instance can be created at any given time!")}u8.session=this;this.parent=u8.application;this._init()};$.extend(u8.Base.Session.prototype,{dispose:function(){if(this._isDisposed){return}this._isDisposed=true;if(this.isLogin){u8.services.leaveScope("Login")}u8.services.leaveScope("Session");delete u8.session},login:function(e,t){delete this.aborted;var i=this;var n=u8.application.getMainWindow();e=$.extend({elWindow:n,autoLogin:true},e);if(!u8.services.authentication){return s(this,{})}u8.services.authentication.login(e,s);function s(e,n){if(n.error){if(t){t(i,n)}return}i._onLogin(n,o)}function o(e,n){n=n||{};i.isLogin=true;u8.services.enterScope("Login");u8.services.events.raise("u8.session.onLogin",i,n);if(t){t(i,n)}}},logout:function(e,t){$assert(this.isLogin,"Invalid call to logout()! logout() was called without a matching call to login().");var i=this,n={cancel:false,aborted:this.aborted};e=$.extend({},e);u8.services.events.raiseAsync("u8.session.onPreLogout",this,n,s);function s(){if(i.aborted){o();return undefined}if(n.cancel){return false}if(u8.services.settings){u8.services.settings.save(o)}else{o()}}function o(){if(e.skipLogout){return r()}var t=u8.services.authentication;if(t){t.logout(e,function(e,t){if(t.error){return}r()})}else{r()}}function r(){i._onLogout(u)}function u(){i.isLogin=false;delete i.identity;u8.services.events.raise("u8.session.onLogout",i,{});if(t){t(i,{})}}return n.cancel},abort:function(e){if(this.aborted){return}this.aborted=true;var t={};var i=e&&e.error;if(i){var n="AccessDeniedException"==i.type&&i.errorUid&&i.errorUid.indexOf("/Error/4/")>=0;if(n){t.skipLogout=true}}if(this.isLogin){this.logout(t)}},refresh:function(e,t){if(!e){e={}}u8.services.each(function(i){if(i&&typeof i.refresh=="function"&&(!t||t(i))){i.refresh(e)}},"Session");u8.services.events.raise("u8.session.onRefresh",this,e)},isAuthenticated:function(e){var t=this.identity&&this.identity.userName;if(!t){return undefined}return t==e},_init:function(){u8.services.enterScope("Session");this._onInit()},_onInit:function(){},_onLogin:function(e,t){var i=this;var n=u8.services.settings;if(n&&n.load){n.load(function(){if(t){t(i,{})}})}else if(t){t(i,{})}},_onLogout:function(e){u8.services.leaveScope("Login");if(u8.services.settings){u8.services.settings.clear()}if(e){e(self,{})}}});u8.Base.ConfigValues=function(){};$.extend(u8.Base.ConfigValues.prototype,{getBoolean:function(e,t){return u8.Base.ConfigValues.toBoolean(this.get(e,t?"1":"0"))},getInt:function(e,t){return u8.Base.ConfigValues.toInt(this.get(e,t),t)},getStringArray:function(e,t){return u8.Base.ConfigValues.toStringArray(this.get(e),t)},getIntArray:function(e,t){return u8.Base.ConfigValues.toIntArray(this.getStringArray(e),t)},getOptions:function(e,t){return u8.Base.ConfigValues.toOptions(this.get(e,t))},get:function(e,t){if(!e){return t}var i;if(u8.tools.isArray(e)){for(var n=0;n<e.length;n++){i=this.get(e[n]);if(typeof i!="undefined"){return i}}}else{i=this[e]}if("undefined"==typeof i){return t}return i}});$.extend(u8.Base.ConfigValues,{toBoolean:function(e,t){if(typeof e=="undefined"){return t}if(typeof e!="string"){e=e.toString()}return e==="1"||e.toLowerCase()==="true"?true:false},toInt:function(e,t){if("undefined"==typeof e){return e}else if("number"==typeof e){return e}e=parseInt(e);if(isNaN(e)){return t}return e},toStringArray:function(e,t){if(typeof e!="string"){return t}e=e.trim();if(e.length==0){return t}e=e.split(",");for(var i=0;i<e.length;i++){e[i]=e[i].trim()}return e},toIntArray:function(e,t){if(typeof e!="string"&&!u8.tools.isArray(e)){return t}if(u8.tools.isArray(e)){return e.map(function(e){return parseInt(e,10)})}e=e.trim();if(e.length==0){return t}e=e.split(",");for(var i=0;i<e.length;i++){e[i]=parseInt(e[i].trim(),10)}return e},toOptions:function(e,t){return new u8.Base.Options(e!==undefined?e:t)}});u8.Base.Session.defaults={environment:{imageUri:"~/images/update/"},images:{},commonTexts:{loading:"Loading...",accessDenied:"(Access denied)",accessDeniedTip:"You are not allowed to view this field",showHide:"Show/Hide",tipMustField:"You must enter a value for this field!",tipNoDeleteField:"You are not allowed to delete the value of this field!",mustFieldMarker:"*",noDeleteFieldMarker:"!",headerFromTo:"{1} - {2}",headerFromToOf:"{1} - {2} of {3}",noValue:"no value",closeButtonText:"Close",backButtonText:"Back",applyButtonText:"Apply",cancelButtonText:"Cancel",hotkeyShift:"Shift",hotkeyCtrl:"Ctrl",hotkeyAlt:"Alt"},localeSettings:{},webConfigValues:$.extend({},u8.Base.ConfigValues.prototype)};u8.Base.Session.makeClass({name:"Session",virtual:["_onInit","_onLogin","_onLogout","dispose","refresh"]})})();