1 | define([ |
---|
2 | "dojo/_base/lang", |
---|
3 | "dojo/_base/kernel", |
---|
4 | "dojo/dom-attr", |
---|
5 | "./_Mixin", |
---|
6 | "dojo/_base/declare" |
---|
7 | ], function(lang, dojo, domAttr, _Mixin, declare){ |
---|
8 | var fm = lang.getObject("dojox.form.manager", true), |
---|
9 | aa = fm.actionAdapter, |
---|
10 | ia = fm.inspectorAdapter; |
---|
11 | |
---|
12 | return declare("dojox.form.manager._EnableMixin", null, { |
---|
13 | // summary: |
---|
14 | // Form manager's mixin for controlling enable/disable state of |
---|
15 | // form elements. |
---|
16 | // description: |
---|
17 | // This mixin provides unified enable/disable functionality for |
---|
18 | // form widgets and form elements. It should be used together |
---|
19 | // with dojox.form.manager.Mixin. |
---|
20 | |
---|
21 | gatherEnableState: function(names){ |
---|
22 | // summary: |
---|
23 | // Gather enable state of all form elements and return as a dictionary. |
---|
24 | // names: Object? |
---|
25 | // If it is an array, it is a list of names to be processed. |
---|
26 | // If it is an object, dictionary keys are names to be processed. |
---|
27 | // If it is omitted, all known form elements are to be processed. |
---|
28 | |
---|
29 | var result = this.inspectFormWidgets(ia(function(name, widget){ |
---|
30 | return !widget.get("disabled"); |
---|
31 | }), names); |
---|
32 | |
---|
33 | if(this.inspectFormNodes){ |
---|
34 | lang.mixin(result, this.inspectFormNodes(ia(function(name, node){ |
---|
35 | return !domAttr.get(node, "disabled"); |
---|
36 | }), names)); |
---|
37 | } |
---|
38 | |
---|
39 | return result; // Object |
---|
40 | }, |
---|
41 | |
---|
42 | enable: function(state, defaultState){ |
---|
43 | // summary: |
---|
44 | // Enable form controls according to the supplied state object. |
---|
45 | // state: Object? |
---|
46 | // Optional. If a name-value dictionary, the value is true |
---|
47 | // to enable and false to disable. If an array, all names in the |
---|
48 | // array will be set to defaultState. If omitted, all form |
---|
49 | // elements will be set to defaultState. |
---|
50 | // defaultState: Boolean |
---|
51 | // The default state (true, if omitted). |
---|
52 | |
---|
53 | if(arguments.length < 2 || defaultState === undefined){ |
---|
54 | defaultState = true; |
---|
55 | } |
---|
56 | |
---|
57 | this.inspectFormWidgets(aa(function(name, widget, value){ |
---|
58 | widget.set("disabled", !value); |
---|
59 | }), state, defaultState); |
---|
60 | |
---|
61 | if(this.inspectFormNodes){ |
---|
62 | this.inspectFormNodes(aa(function(name, node, value){ |
---|
63 | domAttr.set(node, "disabled", !value); |
---|
64 | }), state, defaultState); |
---|
65 | } |
---|
66 | |
---|
67 | return this; // self |
---|
68 | }, |
---|
69 | |
---|
70 | disable: function(state){ |
---|
71 | // summary: |
---|
72 | // Disable form controls according to the supplied state object |
---|
73 | // returning the previous state. |
---|
74 | // state: Object? |
---|
75 | // Optional. If a name-value dictionary, the value is true |
---|
76 | // to enable and false to disable. If an array, all names in the |
---|
77 | // array will be disabled. If omitted, disables all. |
---|
78 | var oldState = this.gatherEnableState(); |
---|
79 | this.enable(state, false); |
---|
80 | return oldState; // Object |
---|
81 | } |
---|
82 | }); |
---|
83 | }); |
---|