(function(){"use strict";u8.Base.Widgets.MenuItem=function(e){if(e instanceof u8.Base.Widgets.MenuItem){return e}this.apply(e)};u8.Base.Widgets.MenuItem.makeClass({name:"MenuItem"});$.extend(u8.Base.Widgets.MenuItem.prototype,{load:function(e,t){var i=this.menuName;$assert(i,"Property 'menuName' must be set in order to load a menu!");var n=this;u8.services.menus.load($.extend({menuName:i,menuType:this.menuType,processState:this.processState,applyTo:this},e),function(){n._isLoaded=true;n._emptyChildren=!n.children}.chain(t))},isLoaded:function(){return!!(this.children||!this.menuName||this._isLoaded)},isRoot:function(){return!this.parent},isDynamic:function(){return this.name&&this.name.indexOf("D_")==0||u8.services.menus.hasRegisteredMenuItemHandlers(this)},isSeparator:function(){return!this.label},isPopup:function(){return this.hasChildren()||this.menuName&&!this._isLoaded||this._emptyChildren},hasChildren:function(){return!!this.children&&this.children.length>0},getParent:function(){return this.parent},isParentOf:function(e){while(e){e=e.parent;if(e==this){return true}}return false},getLevel:function(){var e=0;var t=this.parent;while(t){e++;t=t.parent}return e},indexOf:function(e){return this.children?this.children.indexOf(e):-1},getNextSibling:function(e){var t=this.getParent();if(!t){return null}var i=t.indexOf(this);if(!e){if(i<0||i+1>=t.children.length){return null}i++}else{if(i<0){i=0}else{i++;if(i>=t.children.length){i=0}}}return t.children[i]},getPrevSibling:function(e){var t=this.getParent();if(!t){return null}var i=t.indexOf(this);if(!e){if(i<1){return null}i--}else{if(i<1){i=t.children.length-1}else{i--}}return t.children[i]},each:function(e,t){e(this);if(typeof t=="undefined"){t=true}var i=this.children;if(i){var n,r=i.length,s;for(n=0;n<r;n++){s=i[n];if(t){s.each(e,true)}else{e(s)}}}return this},find:function(e){if(e(this)){return this}if(this.children){for(var t=0;t<this.children.length;t++){var i=this.children[t].find(e);if(i){return i}}}return null},findByName:function(e){return this.find(u8._.eqish("name",e))},add:function(e){if(!e){return this}e=new u8.Base.Widgets.MenuItem(e);if(!this.children){this.children=[]}this.children.push(e);e.parent=this;return this},insert:function(e,t){if(!t){return this}t=new u8.Base.Widgets.MenuItem(t);if(!this.children){this.children=[]}if(e<=0){this.children.unshift(t)}else if(e>=this.children.length){this.children.push(t)}else{this.children.splice(e,0,t)}t.parent=this;return this},remove:function(){if(this.parent){this.parent.children.remove(this);delete this.parent}if(this.model&&this.model.rootItem==this){this.model.rootItem=null}delete this.model;return this},removeAllChildren:function(){if(!this.children){return}for(var e=this.children.length-1;e>=0;e--){this.children[e].remove()}},update:function(e){var t=this;if(e instanceof u8.Base.Widgets.MenuItem){t=this}var i=this._getModel();if(i){i.update(t)}return this},attr:u8.Base.ComponentMixIn.attr,apply:function(e){if(this.applyOptions){e=$.extend({},e)}for(var t in this.applyOptions){if(this.applyOptions[t]===false){delete e[t]}}$.extend(this,e);if(this.action&&typeof this.action=="object"){this.action=new u8.Base.Action(this.action);this.action.name=this.name}if(this.children){var i=[];for(var n=0;n<this.children.length;n++){var r=new u8.Base.Widgets.MenuItem(this.children[n]);r.parent=this;i.push(r)}this.children=i}return this},clone:function(e){if(!e){e=u8._["true"]}var t=new u8.Base.Widgets.MenuItem;for(var i in this){if(this.hasOwnProperty(i)){t[i]=this[i]}}delete t.parent;delete t.model;delete t.children;delete t.__contextMenu_viewId;if(this.children){for(var n=0;n<this.children.length;n++){var r=this.children[n];if(e(r)){t.add(r.clone())}}}return t},prettify:function(){var e=this.children;var t=0;if(e){var i=true;for(var n=0;n<e.length;n++){var r=e[n];var s=r&&r.isSeparator();if(s&&i){r.visible=false;t++}else{if(s){r.visible=true}if(r.visible!==false){i=s}t+=r.prettify()}}if(i){n=e.length;while(--n&&n>=0&&(e[n].visible===false||e[n].isSeparator())){e[n].visible=false;t++}}}return t},"Debug.getDisplayString":function(){var e=this.menuName||this.action&&this.action.name||"<unnamed>";if(this.label){return'Menu Item "'+this.label+'" ('+e+")"}return'Menu Item "'+e+'"'},_getModel:function(){var e,t=this;while(!(e=t.model)&&!t.isRoot()){t=t.getParent()}return e}});u8.Base.Widgets.MenuItem.separatorItem=new u8.Base.Widgets.MenuItem({label:null})})();