PDA

View Full Version : setDisabled(false) for Menu item



mjhaston
14 Nov 2011, 7:52 AM
I'm making reference to a button menu. The top level reference works and handles disable or enable of the button.



visitationGrid.deliverBtn.setDisabled(false);
visitationGrid.viewBtn.setDisabled(false);



A lower level reference does not.



visitationGrid.reviewedBtn.setDisabled(false);



I get the message ...

visitationGrid.reviewedBtn is undefined

The important portions of code below are towards the bottom in red.





var visitationGrid = new xg.GridPanel({
title : 'Visitation Report',
id : 'visitation-panel',
store : visitationStore,
// deferRowRender: true,
stripeRows : true,
loadMask : true,
sm : sm,
viewConfig : {

getRowClass : function(record, index, rowParams, store) {

var myDate = new Date(record.get('visit-date'));
var myDateYear = myDate.getFullYear();
var currentDate = new Date();
var currentYear = currentDate.getFullYear();

if (myDateYear == currentYear) {
return 'visitedCss';
} else {
return '';
}

}
},
tbar : {
xtype : 'toolbar',
items : [{
xtype : 'button',
text : 'Change Filters',
tooltip : 'Click to set data filters.',
iconCls : 'icon-page_find',
handler : function() {
filtersWindow.show();
Ext.getCmp('filters-reset').enable();
}
}, '-', {
xtype : 'button',
text : 'Clear Filters',
tooltip : 'Click to clear current data filters.',
id : 'filters-reset',
iconCls : 'reset',
disabled : true,
handler : function() {
filtersForm.form.reset();
message = '<span style="color:green;">Form reset successfully!</span>';
Ext.getCmp('details-panel').body.update(message);
visitationStore.load({
params : {
state : filtersForm.getForm()
.findField('state').getValue(),
ssn : filtersForm.getForm()
.findField('combo-ssn').getValue(),
zips : filtersForm.getForm()
.findField('zips').getValue(),
userid : filtersForm.getForm()
.findField('hiddenUser').getValue(),
view : filtersForm.getForm()
.findField('hiddenView').getValue(),
dummy : 'reset_button'
}
});
}
}, {
xtype : 'tbfill'
}, {
xtype : 'button',
text : 'Export Options',
// ref : '../printButton',
disabled : false,
iconCls : 'icon-table_go',
menu : {
xtype : 'menu',
items : [{
xtype : 'menuitem',
text : ' Export to .XLS',
tooltip : 'Click to download current view to Excel.',
iconCls : 'icon-page_excel',
handler : function() {

var body = Ext.getBody();

var myForm = body.createChild({
tag : 'form',
cls : 'x-hidden',
id : 'hidden_form',
method : 'post',
target : '_blank'
});

Ext.Ajax.request({
url : '/cgidev2p/jsonStr012.pgm',
form : myForm,
params : {
state : filtersForm
.getForm()
.findField('state')
.getValue(),
zips : filtersForm
.getForm()
.findField('zips')
.getValue(),
ssn : filtersForm
.getForm()
.findField('combo-ssn')
.getValue(),
hiddenUser : filtersForm
.getForm()
.findField('hiddenUser')
.getValue(),
format : 'XLS'
},
isUpload : true

});
}
}, {
xtype : 'menuitem',
text : 'Export to .CSV',
tooltip : 'Click to download current view to CSV.',
iconCls : 'icon-csv_download',
handler : function() {

var body = Ext.getBody();

var myForm = body.createChild({
tag : 'form',
cls : 'x-hidden',
id : 'hidden_form',
method : 'post',
target : '_blank'
});

Ext.Ajax.request({
url : '/cgidev2p/jsonStr012.pgm',
form : myForm,
params : {
state : filtersForm
.getForm()
.findField('state')
.getValue(),
zips : filtersForm
.getForm()
.findField('zips')
.getValue(),
ssn : filtersForm
.getForm()
.findField('combo-ssn')
.getValue(),
hiddenUser : filtersForm
.getForm()
.findField('hiddenUser')
.getValue(),
format : 'CSV'
},
isUpload : true

});
}
}]
}
}, '-', {
xtype : 'button',
text : 'Delivery Options',
ref : '../deliverBtn',
tooltip : 'Check off reports to deliver.',
disabled : true,
menu : {
xtype : 'menu',
items : [{
xtype : 'menuitem',
text : 'Print Selected',
iconCls : 'icon-printer',
tooltip : 'Click to print selected documents.',
handler : function() {
var mode = 'PRINT';
submitJob(mode);
}
}, {
xtype : 'menuitem',
text : 'Email Selected',
iconCls : 'icon-email_attach',
tooltip : 'Click to email selected documents.',
handler : function() {
var mode = 'EMAIL';
submitJob(mode);
}
}, {
xtype : 'menuitem',
text : 'Report Selected',
iconCls : 'icon-report_go',
tooltip : 'Click to report selected documents.',
handler : function() {
var mode = 'REPORT';
submitJob(mode);
}
}]
}
}, '-', {
xtype : 'button',
text : 'View Options',
ref : '../viewBtn',
disabled : false,
menu : {
items : [{
text : 'Open Reports',
checked : true,
group : 'theme',
handler : function() {
var view = 'OPEN';
viewOptions(view);
}
}, {
text : 'Filed Reports',
checked : false,
group : 'theme',
handler : function() {
var view = 'FILED';
viewOptions(view);
}
}, {
text : 'Reviewed Reports',
checked : false,
group : 'theme',
disabled : true,
ref : '../../reviewedBtn',
handler : function() {
var view = 'REVIEWED';
viewOptions(view);
}

}]
}
}, {
xtype : 'spacer',
width : 10
}]
},

Uberdude
14 Nov 2011, 8:05 AM
ref does not work for items in menus as they aren't components.

mjhaston
14 Nov 2011, 8:08 AM
Is there an alternative method? I'm trying to enable and disable. Would "visible" work any differently with another method?

Thanks for the quick reply already.

mjhaston
14 Nov 2011, 12:30 PM
I'm trying to make a menu item available at time. I guess I'll search on adding a menu item instead of disabling it?

Uberdude
15 Nov 2011, 2:06 AM
You can disable the menu item if that's what you want to do. The problem was not with the setDisabled method, but the fact you weren't getting a reference to the menu item object to be able to call setDisabled on it. If you can't do that you can't do setVisible either. In order to get a reference to the menu item you could create it explicitly and store it in a variable and use that, rather than creating it with anonymous config objects.

mjhaston
15 Nov 2011, 12:01 PM
[SOLVED]




var menu = new Ext.menu.Menu({
id : 'myMenu',
items : [{
text : 'Open Reports',
checked : true,
group : 'theme',
handler : function() {
var view = 'OPEN';
viewOptions(view);
}
}, {
text : 'Filed Reports',
checked : false,
group : 'theme',
handler : function() {
var view = 'FILED';
viewOptions(view);
}
}]
});

var viewOptionsButton = {
xtype : 'button',
text : 'View Options',
ref : '../viewBtn',
disabled : false,
menu : menu
};

function loadOptionsBtn() {

if (treePanelExt.getNodeById('admin')) {
console.log('admin');
//console.dir(viewOptionsButton);

menu.addMenuItem({
text : 'Reviewed Reports',
checked : false,
group : 'theme',
disabled : false,
handler : function() {
var view = 'REVIEWED';
viewOptions(view);
}
});

} else {
console.log('not admin');
}
};