root / trunk / web / dojo / dojox / form / BusyButton.js
History | View | Annotate | Download (2.36 KB)
| 1 | 9 | andrej.cim | /*
 | 
|---|---|---|---|
| 2 |         Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
 | ||
| 3 |         Available via Academic Free License >= 2.1 OR the modified BSD license.
 | ||
| 4 |         see: http://dojotoolkit.org/license for details
 | ||
| 5 | */
 | ||
| 6 | |||
| 7 | |||
| 8 | if(!dojo._hasResource["dojox.form.BusyButton"]){ | ||
| 9 | dojo._hasResource["dojox.form.BusyButton"]=true; | ||
| 10 | dojo.provide("dojox.form.BusyButton");
 | ||
| 11 | dojo.require("dijit.form.Button");
 | ||
| 12 | dojo.requireLocalization("dijit","loading",null,"ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw"); | ||
| 13 | dojo.declare("dojox.form._BusyButtonMixin",null,{isBusy:false,busyLabel:"",timeout:null,useIcon:true,postMixInProperties:function(){ | ||
| 14 | this.inherited(arguments); | ||
| 15 | if(!this.busyLabel){ | ||
| 16 | this.busyLabel=dojo.i18n.getLocalization("dijit","loading",this.lang).loadingState; | ||
| 17 | } | ||
| 18 | },postCreate:function(){ | ||
| 19 | this.inherited(arguments); | ||
| 20 | this._label=this.containerNode.innerHTML; | ||
| 21 | this._initTimeout=this.timeout; | ||
| 22 | if(this.isBusy){ | ||
| 23 | this.makeBusy();
 | ||
| 24 | } | ||
| 25 | },makeBusy:function(){ | ||
| 26 | this.isBusy=true; | ||
| 27 | this.set("disabled",true); | ||
| 28 | this.setLabel(this.busyLabel,this.timeout); | ||
| 29 | },cancel:function(){ | ||
| 30 | this.set("disabled",false); | ||
| 31 | this.isBusy=false; | ||
| 32 | this.setLabel(this._label); | ||
| 33 | if(this._timeout){ | ||
| 34 | clearTimeout(this._timeout);
 | ||
| 35 | } | ||
| 36 | this.timeout=this._initTimeout; | ||
| 37 | },resetTimeout:function(_1){ | ||
| 38 | if(this._timeout){ | ||
| 39 | clearTimeout(this._timeout);
 | ||
| 40 | } | ||
| 41 | if(_1){
 | ||
| 42 | this._timeout=setTimeout(dojo.hitch(this,function(){ | ||
| 43 | this.cancel();
 | ||
| 44 | }),_1); | ||
| 45 | }else{
 | ||
| 46 | if(_1==undefined||_1===0){ | ||
| 47 | this.cancel();
 | ||
| 48 | } | ||
| 49 | } | ||
| 50 | },setLabel:function(_2,_3){ | ||
| 51 | this.label=_2;
 | ||
| 52 | while(this.containerNode.firstChild){ | ||
| 53 | this.containerNode.removeChild(this.containerNode.firstChild); | ||
| 54 | } | ||
| 55 | this.containerNode.innerHTML=this.label; | ||
| 56 | if(this.showLabel==false&&!(dojo.attr(this.domNode,"title"))){ | ||
| 57 | this.titleNode.title=dojo.trim(this.containerNode.innerText||this.containerNode.textContent||""); | ||
| 58 | } | ||
| 59 | if(_3){
 | ||
| 60 | this.resetTimeout(_3);
 | ||
| 61 | }else{
 | ||
| 62 | this.timeout=null; | ||
| 63 | } | ||
| 64 | if(this.useIcon&&this.isBusy){ | ||
| 65 | var _4=new Image(); | ||
| 66 | _4.src=this._blankGif;
 | ||
| 67 | dojo.attr(_4,"id",this.id+"_icon"); | ||
| 68 | dojo.addClass(_4,"dojoxBusyButtonIcon");
 | ||
| 69 | this.containerNode.appendChild(_4);
 | ||
| 70 | } | ||
| 71 | },_clicked:function(e){ | ||
| 72 | if(!this.isBusy){ | ||
| 73 | this.makeBusy();
 | ||
| 74 | } | ||
| 75 | }}); | ||
| 76 | dojo.declare("dojox.form.BusyButton",[dijit.form.Button,dojox.form._BusyButtonMixin],{});
 | ||
| 77 | dojo.declare("dojox.form.BusyComboButton",[dijit.form.ComboButton,dojox.form._BusyButtonMixin],{});
 | ||
| 78 | dojo.declare("dojox.form.BusyDropDownButton",[dijit.form.DropDownButton,dojox.form._BusyButtonMixin],{});
 | ||
| 79 | } |