PDA

View Full Version : Duplicity in contextMenu



danielbertini
15 Jul 2009, 12:16 PM
Hello, i have a problem with contextMenu.
When i reopen a tab with treepanel the contextMenu show duplicity items.
My code is:


var tree = new Ext.tree.TreePanel({
useArrows:true,
autoScroll:true,
animate:true,
enableDD:true,
border:false,
dataUrl:'blogimagens/diretorio',
root:{id:'0', text:'Raiz', nodeType:'async'},
contextMenu:new Ext.menu.Menu({
items:[
{id:'add', text:'Adicionar', iconCls:'icon-add'},
{id:'edit', text:'Editar', iconCls:'icon-edit'},
{id:'delete', text:'Remover', iconCls:'icon-remove'}
],
listeners:{
itemclick:function(item){
switch(item.id){
case 'delete-node':
var n = item.parentMenu.contextNode;
if(n.parentNode){ n.remove(); }
break;
}
}
}
}),
listeners:{
contextmenu:function(node,e){
node.select();
var c = node.getOwnerTree().contextMenu;
c.contextNode = node;
c.showAt(e.getXY());
}
}
});
tree.getRootNode().expand();

var arquivos = new Ext.Panel({
title:'Arquivos',
region: 'center',
margins:'5 5 5 0'
});

var diretorios = new Ext.Panel({
title:'Diretórios',
region:'west',
split:true,
width:225,
minSize:225,
maxSize:400,
collapsible:true,
autoScroll:true,
margins:'5 0 5 5',
cmargins:'5 5 5 5',
items:[tree]
});

var painel = new Ext.Panel({
id:'blog-imagens',
closable:true,
title:'Imagens',
region:'west',
margins:'5 5 5 0',
cmargins:'5 5 5 5',
activeTab: 0,
split:true,
layout:'border',
collapsible:true,
items:[arquivos,diretorios]
});

function addFolder(){

var form = new Ext.FormPanel({
labelWidth:120,
defaults:{width:250},
baseCls:'x-plain',
items:[
{xtype:'textfield', fieldLabel:'Nome', name:'nome', allowBlank:false}
]
});

var window = new Ext.Window({
title:'Adicionar',
iconCls:'icon-add',
width:415,
height:115,
modal:true,
resizable:false,
layout:'fit',
plain:true,
buttonAlign:'center',
bodyStyle:'padding:10px;',
items:form,
buttons:[
{text:'Salvar', iconCls:'icon-save', handler:function(){ salvar(); }},
{text:'Cancelar', iconCls:'icon-cancel', handler:function(){ window.close(); }}
]
});

window.show();

var salvar = function(){
if(form.form.isValid()){
form.form.submit({
url:'blogimagens/insert',
method:'post',
waitTitle:'Aguarde:',
waitMsg:'Salvando dados...',
reset:false,
failure:function(result, action){
var obj = Ext.decode(action.response.responseText);
Ext.MessageBox.alert('Erro(s):', obj.message);
},
success: function(result, action){
var obj = Ext.decode(action.response.responseText);
window.close();
tree.root.reload();
}
});
}
else{
Ext.MessageBox.alert('Erro(s):', 'Verifique se preencheu todos os campos do formulário.<br />Os campos que estão em vermelho são de preenchimento obrigatório.');
}
};

}

if(!Ext.getCmp('tab-panel').findById('blog-imagens')){
Ext.getCmp('tab-panel').add(painel);
Ext.getCmp('tab-panel').setActiveTab('blog-imagens');
Ext.getCmp('center-panel').doLayout();
}
else{
Ext.getCmp('tab-panel').setActiveTab('blog-imagens');
Ext.getCmp('center-panel').doLayout();
}

ARankin
24 Aug 2009, 7:17 AM
I have this same issue, it followed a move from ExtJS 2.X to 3.X.

Were you able to find a solution? I've done the following in the mean time:



var menu = new Ext.menu.Menu({
listeners: {
hide: function(n){
menu.destroy();
}
},
items: [{
[...]



Andrew

Condor
24 Aug 2009, 7:23 AM
From the Upgrading to Ext 3 (http://extjs.com/forum/showthread.php?t=70352) post:

Breaking change: MenuItem ids are no longer local to their menu but global component ids. This means that you can't use the same id in multiple menus. Suggested fix: Use unique ids or switch to using itemIds.

jose_555
1 Jul 2010, 12:31 PM
thank you condor once again your advices save my day .....

j.l