You have many options:

#1: Cloning the button

#2: Write an own class which extends Button. Add the event listeners and 
styling into the constructor for example. Then create instances from 
this class instead of Button.

#3: To extract the command part, it's better to create a instance of 
qx.client.Command, attach the stuff there and connect all Commands with 
the Button instances (buttonInstance.setCommand(commandInstance))

I would suggest #2 or #3 because they perform best. You can combine #2 
and #3, too.

Sebastian


Aaron Cooper schrieb:
> Hi all,
>  
> I've got a button (well several actually) that I want to use on multiple 
> windows of my app. In this case it's for logging out:
>  
> /****************************************************************************
> /* Logout Button
> /***************************************************************************/
> var btnLogout = new qx.ui.form.Button("Logout", "icon/16/decrypted.png");
> btnLogout.setRight(5);
> btnLogout.setBottom(5);
> btnLogout.name= 'logoutButton';
>  
> btnLogout.addEventListener("execute", function(e) {
>  // Run ajax process for logout
>  ajax.requestFile = "ajax/logout.php";
>  ajax.method = 'get';
>  ajax.onError = whenLogoutError;
>  ajax.onCompletion = whenLogoutComplete;
>  ajax.runAJAX();
> });
>  
> // Actions to take when a logout has bee completed
> function whenLogoutComplete() {
>  if(ajax.response == 1) {
>   currentWindow.close();
>   loginBox.open();
>   currentWindow = loginBox;
>  } else {
>   alert('Logout Failed');
>  }
> }
>  
> // Only a serious error will kick this (e.g. PHP file missing)
> function whenLogoutError() {
>  alert('There has been a backend error while logging out - Please 
> contact Us');
> }
> /****************************************************************************
> /* END Logout Button
> /***************************************************************************/
>  
> Don't worry too much about the code itself, as it works fine.
>  
> What I want to do be able to use multiple instances of this button 
> whereever I want. At the moment, even if I add the button to more than 
> one window, it will only display on the last one it was added to.
>  
> I'm reading up on OO and prototyping as I havn't done this aspect of JS 
> before, and can only guess that it's the key to what I want.
>  
> I was wondering if anyone had any guidence on the this sort of thing please?
>  
> Cheers
> Aaron
> 
> 
> ------------------------------------------------------------------------
> 
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to