PDA

View Full Version : Ext Js Button



ramesbabu
28 Oct 2012, 10:25 AM
Hi,
I'm using Extjs button for save operation,

new Ext.Button({
text: 'Save',
id:'save_id',
width:'108px',
height: '25px',
renderTo: 'save_button',
listeners: {
click: function(){ save(); }
}});

I'm calling this method by F9 (functional key on keyboard) and
also by on click with mouse.

By F9:

document.onkeyup = function (e) {
var unicode=e.keyCode? e.keyCode : e.charCode;
if(unicode==120){
Ext.getCmp('save_id').fireEvent("click", this);
}
}


while simultaneously access using keyboard and mouse , save function called for two times
but my requirement is , the function should called once even though accessed by keyboard and mouse.
Please guide me to resolve this parallel issue.

mitchellsimoens
30 Oct 2012, 2:17 AM
First, I wouldn't fire the click event. I would use the handler config on the button and then execute the handler method on the button.

So you only want to fire save once per x amount of time or while an action is taken?

If while an action is taken I would set a variable or property to say that the action is pending and when the action is finished change that var/prop so that the save method will continue to fire (of course the save method should check the var/prop to allow it to continue to execute).

If after x amount of time, same as above only set the var/prop as a date object and then check the difference between that var/prop with the current time and if the difference is more than your x amount of time then allow the save method to continue to execute.

ramesbabu
30 Oct 2012, 2:45 AM
Hi Dude,
Can you give some examples about this parallel issue, It is possible without time factor.

willigogs
30 Oct 2012, 3:00 AM
This is just basic JS logic.

Set a global/namespaced variable:

var currentlySaving;

Then when you call the save function:

if(currentlySaving != true) {
save()
}

Then in your save function:


currentlySaving = true;
// Save logic here
currentlySaving = false;

ramesbabu
30 Oct 2012, 3:24 AM
Thanks a lot... willigogs and mitchellsimoens

mitchellsimoens
30 Oct 2012, 5:11 AM
I wouldn't do a global variable. Functions are really objects and can have properties (watch out for memory leaks tho)