DHTMLXMenu Reload

hi Team,



I have a Layout and I have attached a Menu with Layout using a XMl string return by a Web service, but on click on one menu Item I need to Load the menu again as My XML string is rolesbased and on click on menuy Item Role is gettig changed and webservice is returing diffrent XMLstring, but I am not able to attach this string.

When I am truing to do so either Original keeps there or Menu disappers…





Please help me in resolving the same:





Small chunk of my code here:



var COPMenu = window.COPMenu || {};

COPMenu = function() {



function onClick(id, zoneId, casState) {

if ((id == “m10-1”) || (id.indexOf(“md1-”)!=-1)) {

MainMenu = null

COPMenu.initMainMenu();

COPMenu.hideMenuItems();



}

}



/** @private /

function success(result) {

MainMenu.loadXMLString(result);

COPMenu.hideMenuItems();

}



/
* @private /

function failure() {



}



// public methods

/
* @scope COPMenu /

return {

/
* Initialize the main (top) menu /

initMainMenu: function() {



MainMenu = Layout1.attachMenu();

MainMenu.setImagePath(imgPathMenu);

MainMenu.setIconsPath(imgMenuIconPath);

COPMenu.getMainMenu();

MainMenu.attachEvent(“onClick”, onClick);

GUITools.LogMessage(‘MainMenu Initialized’, 1);

},



/
*

* Gets the main menu data either from a static xml file or from the WCF service

/

getMainMenu: function() {

if (isStaticData) {

MainMenu.loadXML(xmlLoanMainMenu,COPMenu.hideMenuItems);

}

else {

var obj = new GUIServices.GUIService();

obj.GetMainMenu(success, failure);

}

},



/
*

* Function to hide menu items based on Dashboard / Loan Mode

/

hideMenuItems : function(){

COPMenu.hide(“m2”);

COPMenu.hide(“m3”);

COPMenu.hide(“m4”);

COPMenu.hide(“m5”);

COPMenu.hide(“m6”);

COPMenu.hide(“m10-2”);

},



/
*

* Function to show menu items based on Dashboard / Loan Mode

/

showMenuItems : function(){

COPMenu.show(“m2”);

COPMenu.show(“m3”);

COPMenu.show(“m4”);

COPMenu.show(“m5”);

COPMenu.show(“m6”);

},



/
* Hides a main (top) menu Item

* @param id ID of the Menu Item that is to be hidden /

hide: function(id) {

MainMenu.hideItem(id);

GUITools.LogMessage(‘MainMenu Item Hidden’, 1);

},



/
* Shows a main (top) menu Item

* @param id ID of the Menu Item that is to be shown /

show: function(id) {

MainMenu.showItem(id);

GUITools.LogMessage(‘MainMenu Item Shown’, 1);

},



/
* Disables a main (top) menu Item

* @param id ID of the Menu Item that is to be disabled /

disable: function(id) {

MainMenu.setItemDisabled(id);

GUITools.LogMessage(‘MainMenu Item Disabled’, 1);

},



/
* Enables a main (top) menu Item

* @param id ID of the Menu Item that is to be enabled */

enable: function(id) {

MainMenu.setItemEnabled(id);

GUITools.LogMessage(‘MainMenu Item Enabled’, 1);

}

};

} ();







Regards

Shalini


Hello,


you can try to use clearAll and loadXML (loadXML string) method to reload menu:


dhtmlx.com/docs/products/dhtmlxM … arall.html

but we are using 2.1 and these options are not available here…


clearAll method is the following:


dhtmlXMenuObject.prototype.clearAll = function() {


for (var a in this.itemPull) {


if (this.itemPull[a][“parent”] == this.idPrefix+this.topId) {
this.removeItem(String(a).replace(this.idPrefix,""));
}
}
this._isInited = false;

}


Try to add it to the page with menu to use it.




Hi Alex,



When I added this function(clearAll) in my DHTMLXMenu.js and called this function from:



 



/** @private */
function success(result) {
MainMenu.clearAll();



MainMenu.loadXMLString(result);
COPMenu.hideMenuItems();
}




its giving me attached error:



Please help me in resolving the same:



Thanks



Shalini



 




Hello,


the issue is confirmed. We have attached the sample that contains fixed dhtmlxmenu.js


sample.zip (41.8 KB)


Hi alex,



 



I replaced my DHTMLXMenu.js with new Js used in above sample, but its still giving me some error,Error is attached.



Please Advise…



Regards



Shalini




hi alex, its working fine now, i forget to add clearall function on my page,



but still I have an issue that its changing the Order of Menus and submenu, which were not loaded first time in the system and getting added in reload functionality are coming at the Last position in Menu…



Please help…



Regards



Shalini



 


Hello,


please provide the complete demo to recreate the issue (sample should be without server-side scripts)


hi alex,



 



Please find the sample attached.



 I have removed   item from First XML and then added this in second XML at same loctioon but coming as last Submenu of File Menu.



Regards



Shalini



 


sample.zip (63.4 KB)


The issue is confirmed.


To fix it please add the highlighted line in the end of the clearAll method:


dhtmlXMenuObject.prototype.clearAll = function() {
for (var a in this.itemPull) {
if (this.itemPull[a][“parent”] == this.idPrefix+this.topId) {
this.removeItem(String(a).replace(this.idPrefix,""));
}
}
this._isInited = false;
this.idPrefix=this._genStr(12);
}




Thanks Alex,



its working fine now…



Shalini