(function(e){"use strict";var t="History";u8.Base.History=function(e){$.extend(this,u8.Base.History.defaults,e);this.id=this.id||"history";this._items=new u8.Base.ObservableList([]);this._isLoaded=false;this._displayMode=null;this._element=null;this.bind(e);var t=u8.services.events;t.bind("u8.services.settings.onPreSave",this._onSettingsPreSave.bind(this),this.id);t.bind("u8.session.onLogin",this._onLogin.bind(this),this.id);t.bind("u8.session.onLogout",this._onLogout.bind(this),this.id);if(u8.session.isLogin){this._onLogin()}};u8.Base.History.defaults={maxItems:10,persist:true,linkSeperator:" / "};$.extend(u8.Base.History.prototype,{dispose:function(){if(this._isDisposed){return}this.unbind();u8.services.events.unbind("u8.services.settings.onPreSave",this.id).unbind("u8.session.onLogin",this.id).unbind("u8.session.onLogout",this.id);this._isDisposed=true},addPage:function(e){$assert(e,"Missing or invalid argument 'o' in a call to 'History.addPage'.");var t=u8.create("Uri",e.url);var i=u8.services.browserHistory.parseHistoryIdFromUrl(t);if(i=="none"){return undefined}if(i>=0){i=i.toString()}else{var s=$p("work");i=s&&s.getHistory().id;if(!i){return undefined}}var n;var r=Date.now();var o=this.indexOfKey(i);if(o<0){n=$.extend({type:"Page",key:i,time:r},e);this._items.unshift(n)}else{n=this._items.at(o);$.extend(n,{time:r},e);if(o>0){this._items.removeAt(o);this._items.unshift(n)}}this._onAddPage(n);return i},find:function(e){return this.getItems().find(e)},findByKey:function(e){var t=this.indexOfKey(e);if(t<0){return null}return this._items.at(t)||null},indexOfKey:function(t){return this.getItems().indexWhere(e.eq("key",t))},getItems:function(){return this._items},update:function(e,t){var i=this.indexOfKey(e);if(i<0){return}var s=this._items.at(i);if(!s){return}u8.tools.extendOwn(s,t);this._onUpdate("update",s)},clear:function(e){if(typeof e==="undefined"){this._items.attach([]);this.raise("Update",{reason:"clear"})}else{this._items.iterate(function(){if(this.value.type==e){this.remove()}});this.raise("Update",{reason:"clear",type:e})}},execute:function(e,t){var i=this.findByKey(e);if(!i){return undefined}var s=this["execute."+i.type];if(!s){u8.log.warn("Ignoring attempt to execute unsupported history item type '{0}'".format(i.type));return undefined}return s.apply(this,[i,t])},"execute.Page":function(e,t){if(!e){return}if(t&&t.elEvent.ctrlKey){t.createNewTab=true}u8.services.navigation.navigateToUrl(e.url,t)},_create:function(){var e=this;u8.using({texts:["net_history_text"]},function(){e._isLoaded=true})},_setItems:function(e){if(!e){e=[]}var t=[];for(var i=0;i<e.length;i++){t.push(e[i]);if(t.length>=this.maxItems){break}}this._items.attach(t)},_complementPage:function(e){if(!e.label&&e.page){e.label=e.page}if(e.label){e.label=e.label.format()}},_updateFromWebConfigValues:function(){this.maxItems=u8.session.webConfigValues.getInt("History.MaxEntries",this.maxItems);this.persist=u8.session.webConfigValues.getBoolean("History.Persist")},_load:function(){if(!this.persist){return}var e=u8.services.settings.get(t);if(!e){return}if(e.version!=1){return}this._setItems(e.items)},_save:function(){var e={version:1,items:[]};var i=this._items,s=i.size();for(var n=0;n<s;n++){var r=i.at(n);e.items.push($.extend({},r))}u8.services.settings.set(t,e)},_onAddPage:function(e){if(!e){return}var t=this;u8.using({texts:"net_history_text"},function(){t._complementPage(e);t._onUpdate("add",e)})},_onUpdate:function(e,t){var i=[];if(this._items.size()>this.maxItems){while(this._items.size()>this.maxItems){i.push(this._items.pop())}}this.raise("Update",{reason:e,item:t,removed:i})},_onLogin:function(){this._updateFromWebConfigValues();if(this.persist){this._load()}},_onLogout:function(){this.clear()},_onSettingsPreSave:function(){if(this.persist){this._save()}}});u8.Base.History.makeClass({name:"History",events:[{name:"Update",globalName:"u8.services.history.onChange"}]});u8.services.add({name:"history",ctor:u8.Base.History})})(u8._);