PDA

View Full Version : the same context menu is duplicated several times as well as its items



flamant
18 Jan 2011, 5:01 AM
Hi,
I implemented a context menu on a field

That context menu is duplicated several times in the page while it should be displayed only once.

As well as their items : the context menu has 3 items which id are 'addDpCtxMenu_'+field.getId() and 'addMcCtxMenu_'+field.getId() and 'forceConstBreakCtxMenu_'+field.getId()
These 3 items are displayed several times for each context menu on the page while they should appear only once

I give you the code :



elt.on('contextmenu', function(evt, elRef) {
evt.stopEvent();
var rowId = this.rowId;
var field = this.field;
if (!this.ctxMenu) {
this.ctxMenu = new Ext.menu.Menu({
id: 'ctxMenu_'+field.getId(),
items: [
{ id: 'addDpCtxMenu_'+field.getId(),
text: '<spring:message code="action.DataPending"/>',
iconCls: 's4xx',
listeners: {
click: function(item, evt) {
if (rowId == null) {
var hiddenMandatory = Ext.getCmp(field.getId()+'_MAND');
if (field.fldDp == 'Y') {
hiddenMandatory.setValue('DP');
field.allowBlank = true;
field.validate();
}
} else {
var record = field.jsonStore.getById(field.rowId);
var oldStatus = record.get(field.fieldId+'_STAT');
var newStatus;
if (oldStatus == Status.NEVENT || oldStatus == Status.HIDDEN) {
newStatus = Status.NOTCLE_NEVMAR_DATPEND;
} else {
newStatus = oldStatus.substring(0, 2)+ Status._DATPEND.substring(2,3);
}
record.set(field.fieldId+'_STAT', newStatus);
field.allowBlank = true;
field.validate();
}
dataPending.push(field);
missingConfirmed.remove(field);
mandatory.remove(field);
updateAllDpMcAvailability();
}
}

},
{ id: 'addMcCtxMenu_'+field.getId(),
text: '<spring:message code="action.missingConfirmed"/>',
iconCls: 's2xx',
listeners: {
click: function(item, evt) {
if (rowId == null) {
var hiddenMandatory = Ext.getCmp(field.getId()+'_MAND');
if (field.fldMc == 'Y') {
hiddenMandatory.setValue('MC');
field.allowBlank = true;
}
} else {
var record = field.jsonStore.getById(field.rowId);
var oldStatus = record.get(field.fieldId+'_STAT');
var newStatus;
if (oldStatus == Status.NEVENT || oldStatus == Status.HIDDEN) {
newStatus = Status.NOTCLE_NEVMAR_MISSCONF;
} else {
newStatus = oldStatus.substring(0, 2)+ Status._MISSCONF.substring(2,3);
}
record.set(field.fieldId+'_STAT', newStatus);
field.allowBlank = true;
}
missingConfirmed.push(field);
dataPending.remove(field);
mandatory.remove(field);
updateAllDpMcAvailability();
}
}

},
{ id: 'forceConstBreakCtxMenu_'+field.getId(),
text: '<spring:message code="action.forceConstBreak"/>',
iconCls: 'forceValidBreak',
listeners: {
click: function(item, evt) {
forceValidationBreak(field, rowId);
}
}

}]
});
}
var result = updateMandCtxMenuAvailability(field, rowId);
if (result)
this.ctxMenu.showAt([evt.getPageX(), evt.getPageY()]);
});



Thank you in advance for your answers

razvanioan
20 Jan 2011, 12:14 PM
Hi flamant,

Try to remove your ID of your contextMenu.

Cheers,
Razvan

peterversnee
7 Mar 2011, 2:25 AM
Had the same problem and removing the id worked. Thanks!