(function(){"use strict";u8.Crm.FavoritesHistory=function(e){$.extend(this,u8.Crm.FavoritesHistory.defaults,e);this.bind(e);this.maxRows=u8.session.webConfigValues.getInt("History.MaxPopupEntries",this.maxRows);u8.using({texts:["ui_common"]},this._create.bind(this))};u8.Crm.FavoritesHistory.makeClass({name:"FavoritesHistory",events:["Create"]});u8.Crm.FavoritesHistory.defaults={maxRows:10};$.extend(u8.Crm.FavoritesHistory,{register:function(){return new u8.Crm.FavoritesHistory({onCreate:function(e){u8.services.menus.registerMenuItemHandler(function(e){return!!e.quickLinkContext},{create:e.build.bind(e),needsUpdateOnShow:true})}})}});$.extend(u8.Crm.FavoritesHistory.prototype,{build:function(e,t){var i=t.menuItem,a=i.quickLinkContext;var n={infoAreaId:a,menuItem:i,items:[]};Function.chain(this._loadFavorites.curry(n),this._loadHistory.curry(n),this._buildMenu.curry(n)).call(this)},_create:function(){this._isCreated=true;this.raise("Create",{})},_loadFavorites:function(e,t){var i=this,a={infoAreaId:e.infoAreaId,tableCaptionName:e.infoAreaId+"QuickLinks",alternativeTableCaptionNames:[e.infoAreaId+".QuickLinks",e.infoAreaId],firstRows:this.maxRows+1};u8.services.favorites.readTableCaptions(a,n);function n(a,n){if(n.tableCaptions){var s=n.tableCaptions;for(var o=0;o<Math.min(i.maxRows,s.length);o++){var r=s[o];e.items.push({label:r.text,image:"u8-img-popup-fav-xs",action:u8.Base.Action.createDefaultAction(r.uid)})}if(s.length>i.maxRows){e.items.push({label:$t("TXT_ui_common_7"),action:u8.Base.Action.createCommandAction("System/Favorites",{})})}}t()}},_loadHistory:function(e,t){var i={infoAreaId:e.infoAreaId,includeVirtual:true,tableCaptionName:e.infoAreaId+"QuickLinks",alternativeTableCaptionNames:[e.infoAreaId+".QuickLinks",e.infoAreaId],maxRows:this.maxRows};u8.services.history.readTableCaptions(i,a);function a(i,a){if(a.tableCaptions){var n=a.tableCaptions;if(n.length>0&&e.items.length>0){e.items.push({})}for(var s=0;s<n.length;s++){var o=n[s];e.items.push({label:o.text,action:u8.Base.Action.createDefaultAction(o.uid)})}if(a.moreItemsExist){e.items.push({label:$t("TXT_ui_common_8"),action:u8.Base.Action.createCommandAction("System/History",{})})}}t()}},_buildMenu:function(e,t){e.menuItem.removeAllChildren();e.items.forEach(e.menuItem.add.bind(e.menuItem));e.menuItem.update();t()}});u8.Crm.FavoritesHistory.register()})();