root / trunk / web / dojo / dojox / wire / ml / Action.js @ 12
History | View | Annotate | Download (2.38 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.wire.ml.Action"]){ |
||
9 | dojo._hasResource["dojox.wire.ml.Action"]=true; |
||
10 | dojo.provide("dojox.wire.ml.Action");
|
||
11 | dojo.provide("dojox.wire.ml.ActionFilter");
|
||
12 | dojo.require("dijit._Widget");
|
||
13 | dojo.require("dijit._Container");
|
||
14 | dojo.require("dojox.wire.Wire");
|
||
15 | dojo.require("dojox.wire.ml.util");
|
||
16 | dojo.declare("dojox.wire.ml.Action",[dijit._Widget,dijit._Container],{trigger:"",triggerEvent:"",triggerTopic:"",postCreate:function(){ |
||
17 | this._connect();
|
||
18 | },_connect:function(){ |
||
19 | if(this.triggerEvent){ |
||
20 | if(this.trigger){ |
||
21 | var _1=dojox.wire.ml._getValue(this.trigger); |
||
22 | if(_1){
|
||
23 | if(!_1[this.triggerEvent]){ |
||
24 | _1[this.triggerEvent]=function(){ |
||
25 | }; |
||
26 | } |
||
27 | this._triggerHandle=dojo.connect(_1,this.triggerEvent,this,"run"); |
||
28 | } |
||
29 | }else{
|
||
30 | var _2=this.triggerEvent.toLowerCase(); |
||
31 | if(_2=="onload"){ |
||
32 | var _3=this; |
||
33 | dojo.addOnLoad(function(){
|
||
34 | _3._run.apply(_3,arguments);
|
||
35 | }); |
||
36 | } |
||
37 | } |
||
38 | }else{
|
||
39 | if(this.triggerTopic){ |
||
40 | this._triggerHandle=dojo.subscribe(this.triggerTopic,this,"run"); |
||
41 | } |
||
42 | } |
||
43 | },_disconnect:function(){ |
||
44 | if(this._triggerHandle){ |
||
45 | if(this.triggerTopic){ |
||
46 | dojo.unsubscribe(this.triggerTopic,this._triggerHandle); |
||
47 | }else{
|
||
48 | dojo.disconnect(this._triggerHandle);
|
||
49 | } |
||
50 | } |
||
51 | },run:function(){ |
||
52 | var _4=this.getChildren(); |
||
53 | for(var i in _4){ |
||
54 | var _5=_4[i];
|
||
55 | if(_5 instanceof dojox.wire.ml.ActionFilter){ |
||
56 | if(!_5.filter.apply(_5,arguments)){ |
||
57 | return;
|
||
58 | } |
||
59 | } |
||
60 | } |
||
61 | this._run.apply(this,arguments); |
||
62 | },_run:function(){ |
||
63 | var _6=this.getChildren(); |
||
64 | for(var i in _6){ |
||
65 | var _7=_6[i];
|
||
66 | if(_7 instanceof dojox.wire.ml.Action){ |
||
67 | _7.run.apply(_7,arguments);
|
||
68 | } |
||
69 | } |
||
70 | },uninitialize:function(){ |
||
71 | this._disconnect();
|
||
72 | return true; |
||
73 | }}); |
||
74 | dojo.declare("dojox.wire.ml.ActionFilter",dijit._Widget,{required:"",requiredValue:"",type:"",message:"",error:"",filter:function(){ |
||
75 | if(this.required===""){ |
||
76 | return true; |
||
77 | }else{
|
||
78 | var _8=dojox.wire.ml._getValue(this.required,arguments); |
||
79 | if(this.requiredValue===""){ |
||
80 | if(_8){
|
||
81 | return true; |
||
82 | } |
||
83 | }else{
|
||
84 | var _9=this.requiredValue; |
||
85 | if(this.type!==""){ |
||
86 | var _a=this.type.toLowerCase(); |
||
87 | if(_a==="boolean"){ |
||
88 | if(_9.toLowerCase()==="false"){ |
||
89 | _9=false;
|
||
90 | }else{
|
||
91 | _9=true;
|
||
92 | } |
||
93 | }else{
|
||
94 | if(_a==="number"){ |
||
95 | _9=parseInt(_9,10);
|
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | if(_8===_9){
|
||
100 | return true; |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | if(this.message){ |
||
105 | if(this.error){ |
||
106 | dojox.wire.ml._setValue(this.error,this.message); |
||
107 | }else{
|
||
108 | alert(this.message);
|
||
109 | } |
||
110 | } |
||
111 | return false; |
||
112 | }}); |
||
113 | } |