(function(){var e={};var n=[];u8.Base.Menus=function(e){$.extend(this,u8.Base.Menus.defaults,e);this.id="menus"};u8.Base.Menus.makeClass("Menus");$.extend(u8.Base.Menus.prototype,{refresh:function(){return this.invalidateCache()},invalidateCache:function(){u8.services.cache.invalidate(/Menu\//);return this},closeAll:function(e){u8.services.popups.autoClose(e);return this},delete_:function(e,n){var r=t(e);u8.request("MenusChannel.DeleteMenu",{menuName:e.menuName},function(e,t){if(!t.error&&r){u8.services.cache.invalidate(r)}return n&&n(this,t)});return this},save:function(e,n){var r=t(e);u8.request("MenusChannel.SaveMenu",{menuName:e.menuName,childMenuNames:e.childMenuNames},function(e,t){if(!t.error&&r){u8.services.cache.invalidate(r)}return n&&n(this,t)});return this},load:function(e,n){if(typeof e=="string"){e={menuName:e}}var r=this,u=u8.services.cache;var i=t(e);var s=e.force!==true&&i&&u.get(i);if(s&&s.menu){var a=c(s.menu);if(n){n(this,a)}}else if(s){s.onReady.bind(n)}else{s={onReady:new u8.Base.Event(n)};if(i){u.put(i,s)}function o(n,i){if(r._isDisposed){return}var a;if(i.error){a={error:i.error,menuItem:{label:i.error.message}}}else{a=i.response?i.response.menu:null}if(!a){a={}}s.menu=a;var o=s.onReady;delete s.onReady;if(a.menuName&&a.menuName!=e.menuName){var l=t({processState:e.processState,menuName:a.menuName});u.put(l,{menu:a})}var d=c(a);o.raise(r,d);o.dispose()}var l=e.menuName;var d=$.extend({},e);delete d.applyTo;delete d.menuName;u8.request({endPoint:"MenusChannel.GetMenu",arguments:{menuName:l,options:d},errorMode:{autoHandleExceptions:false}},o,o,true)}function c(n){var t={};if(e.applyTo){e.applyTo.apply(n.rootItem)}else{t.menu=new u8.Base.Widgets.MenuModel(n)}return t}},buildModel:function(e){return this._root?this._root.buildModel(e):new u8.Base.Widgets.MenuModel},buildHierarchy:function(e,n){return this._root?this._root.buildHierarchy(e,n):null},registerMenuItems:function(e,n){e.forEach(function(e){this.registerMenuItem(e,n)}.bind(this))},registerMenuItem:function(n,t){if(typeof n=="function"){return this.registerMenuItemHandler(n,t)}if(!t){delete e[n]}else{e[n]=t}return this},registerMenuItemHandler:function(e,t){n.push({predicate:e,handler:t});return this},getRegisteredMenuItem:function(n){return e&&e[n]},hasRegisteredMenuItemHandlers:function(e){return n.some(u8._.call("predicate",e))},getRegisteredMenuItemHandlers:function(e){return n.filterAndMap(u8._.call("predicate",e),u8._.attr("handler"))},_onMenuLoad:function(){if(this._isLoaded){return}this._isLoaded=true}});function t(e){var n=e.menuName;if(!n){n="Default:"}if(e.infoAreaId){n+="/"+e.infoAreaId}return"Menu/"+(e.processState||"Default")+"/"+n}u8.services.add({name:"menus",scope:"Application",ctor:u8.Base.Menus})})();