I have a window, and have two child items panel1, panel2. I have apply buttons in docked items. button is part of window...panel1, and panel2 does not have button.
I have to do different operations for Panel1, Panel2. If Panel1 is activated, and when use click on apply, it would call some handler, but when panel2 is activated, it calls handler of panel1. So, what should I do?
Here is my reference for calling handler:
'myxtype button[action=apply]':{
click: someFunction
}
Is there any way to do operations for panel1, and panel2 with Same apply button? or anything else?
you need to do a switch in your eventhandler:
'myxtype button[action=apply]': {
click: this.someFunction
},
someFunction: function (button) {
var tab = button.up('tabpanel').getActiveTab();
if (tab.title === 'tabtitle1') { // insert title of tab1 here
handlerForPanel1(); // insert function for tab1 here
} else {
handlerForPanel2(); // insert function for tab2 here
}
}
in extjs a component can only have one listener function for each event type
you can't assign different handlers based on the circumstances around this component
so the only solution is to dispatch the event in the event handler and delegate it to 2 different functions
Related
Is there a dismiss event for paper-dialog? I tried dialog-dismiss but it doesn't listen to ESC keyboard press. I tried iron-overlay-close but this one bugs if there is another iron-overlay within the dialog (such as an iron-dropdown)
There is no specific dismiss event for paper-dialog because it inherits the iron-overlay behaviour. However, you could create a custom event to trigger a dialog-dismiss:
// Fire a custom event
this.fire('custom-dialog-dismiss');
// Listen to the event on an element OR add a listener
<my-element on-custom-dialog-dismiss="_handleDismiss"></my-element>
...or...
listeners: {
'custom-dialog-dismiss': '_handleDismiss'
}
// Then handle the action
_handleDismiss: function(e) {
this.$.myDialog.close();
}
I have a button and in my controller i created one mouse over event and a click event for that button's id. But everytime when i click button it goes to the mouseover event function only, but when I comment the mouseover it goes to the click event function nicely. Why this is so? I am using ext4.1
thanks in advance.
me.control({
'#notificationIconId':{
click:me.notificationClick
},
'#notificationIconId':{
mouseover:me.notificationMouseOver
}
});
},
notificationMouseOver : function (){
alert('1')
},
notificationClick :function(menuitem)
{
alert('2')
}
You're using two times the same key '#notificationIconId' in a Javascript object... So, the last one is overriding previous ones.
You can add multiple listeners for the same selector:
'#notificationIconId': {
click: me.notificationClick
,mouseover: me.notificationMouseOver
}
If I have a View in backbone.js and it has an event in the events list:
events: {
'click #somebutton': 'clicked'
},
clicked: function () {
console.log('clicked');
}
How can I then disable/enable that event? So for instance if its clicked then
the event is removed (the button remains on screen but is greyed out etc). When some other part of the view is updated or whatever the event
enabled. Sure I can use jquery but I want to know if this functionality is available in backbone.
Thanks for any answers
Paul
You can always use delegateEvents() and undelegateEvents() to redo your event binding between the DOM and your Backbone View. That said, I usually just keep the event handler and add a conditional in the handler.
// .disabled class (CSS) grays out the button
clicked: function(event) {
var buttonEl = $(event.currentTarget);
if (buttonEl.hasClass('disabled')) {
// Do nothing
} else {
// Do something AND...
buttonEl.addClass('disabled');
}
}
Then you can have your other view or code simply removeClass('disabled') when you want to restore functionality.
UPDATE - disabled property
See comments, but a simpler, much better solution is to use the disabled property disabled="disabled" of buttons.
Use delegateEvents and undelegateEvents for binding and unbinding events. Check for reference: delegateEvents
I have an MVC app which has a Tab Panel rendered as the only item in the viewport. Within the tabs I would like to put the same type of component, for which the event handling is equal within all tabs.
Therefore I need an ExtJS MVC Controller ref to the active tab, that would lead me to execute events on the components in the active tab. Is it possible to have such a ref?
My current approach is this:
get reference to Tab Panel
call getActiveTab()
call the controller events for the component in active tab
Is it possible to encapsulate the above 3 steps in one controller ref? Would be beautiful :-)
I'm using ExtJS 4.1.
Personally, I think controller refs are overrated. This sounds like a simple case where you can use one as you describe, but I prefer to listen to the event, and navigate from the firing component to the one I need.
In your case, assuming your tab panel contains regular ext panels, I'd do something like the following:
onButtonClick: function (button) {
var panel = button.up('panel[tab]');
if (panel) {
panel.someMethod();
}
}
The up method will find the closest ancestor that is of xtype panel and has a property named tab. If you have more specific xtypes or known properties, use those instead.
The panel should be the active one (else how was its button clicked?) but you can check that by going up another level to the tab panel and getting the activeTab there.
onButtonClick: function (button) {
var panel = button.up('panel[tab]'),
tabPanel = button.up('tabpanel'),
activeTab = tabPanel && tabPanel.getActiveTab();
if (panel && panel === activeTab) {
panel.someMethod();
}
}
Say your tabPanel has itemId: 'content'. Inside that panel you will have bunch of tabs and on each tab you will have bunch of buttons (as an example). And you want to handle all these button's click in one controller. Do I understand you correctly?
I believe that simple ref inside your controller would work:
this.control('#content button', {
click: this.buttonClicked
}
});
I'm using the rowEditing on my grid in my mvc application. I'm able to handle the event when the user clicks update. However i'm having issues get the selected record. The below behaves strangely. I do not get the record.data.Name value the first time i click update. Tho i can see the value in fire bug.
init: function () {
this.control({
'button[text=Update]': {
click: this.onMaterialUpdate
}
});
},
onLaunch: function () {
},
onMaterialUpdate: function (button) {
var grid = Ext.getCmp('materialsContainer');
var record= grid.getSelectionModel().getSelection()[0];
if (record != null) {
console.log(record.data.Name);
}
}
Not sure about it... but I think the click event happens before completeEdit, thus the record is neither committed, nor updated in the grid (or its selection).
Perhaps try to capture the edit event of the row editor instead of click? You should get the correct record there?
I'd suggested handle edit event of the RowEditor plugin. You could subscribe to this event on grid render event for example. By getting the plugin by pluginId.