1 | define([ |
---|
2 | "dojo/_base/lang", |
---|
3 | "dojo/_base/declare", |
---|
4 | "dojo/_base/connect", |
---|
5 | "dijit/layout/StackContainer", |
---|
6 | "dijit/layout/ContentPane", |
---|
7 | "dijit/form/Button", |
---|
8 | "dijit/_TemplatedMixin", |
---|
9 | "dijit/_WidgetsInTemplateMixin", |
---|
10 | "dojo/i18n", |
---|
11 | "dojo/text!./Wizard/Wizard.html", |
---|
12 | "dojo/i18n!dijit/nls/common", |
---|
13 | "dojo/i18n!./nls/Wizard" |
---|
14 | ], function (lang, declare, connect, StackContainer, ContentPane, Button, _TemplatedMixin, _WidgetsInTemplateMixin, i18n, template) { |
---|
15 | |
---|
16 | var Wizard = declare("dojox.widget.Wizard", [StackContainer, _TemplatedMixin, _WidgetsInTemplateMixin], { |
---|
17 | // summary: |
---|
18 | // A set of panels that display sequentially, typically notating a step-by-step |
---|
19 | // procedure like an install |
---|
20 | // |
---|
21 | |
---|
22 | templateString: template, |
---|
23 | |
---|
24 | // nextButtonLabel: String |
---|
25 | // Label override for the "Next" button. |
---|
26 | nextButtonLabel: "", |
---|
27 | |
---|
28 | // previousButtonLabel: String |
---|
29 | // Label override for the "Previous" button. |
---|
30 | previousButtonLabel: "", |
---|
31 | |
---|
32 | // cancelButtonLabel: String |
---|
33 | // Label override for the "Cancel" button. |
---|
34 | cancelButtonLabel: "", |
---|
35 | |
---|
36 | // doneButtonLabel: String |
---|
37 | // Label override for the "Done" button. |
---|
38 | doneButtonLabel: "", |
---|
39 | |
---|
40 | // cancelFunction: Function|String |
---|
41 | // Name of function to call if user presses cancel button. |
---|
42 | // Cancel button is not displayed if function is not specified. |
---|
43 | cancelFunction: null, |
---|
44 | |
---|
45 | // hideDisabled: Boolean |
---|
46 | // If true, disabled buttons are hidden; otherwise, they are assigned the |
---|
47 | // "WizardButtonDisabled" CSS class |
---|
48 | hideDisabled: false, |
---|
49 | |
---|
50 | postMixInProperties: function(){ |
---|
51 | this.inherited(arguments); |
---|
52 | var labels = lang.mixin({cancel: i18n.getLocalization("dijit", "common", this.lang).buttonCancel}, |
---|
53 | i18n.getLocalization("dojox.widget", "Wizard", this.lang)); |
---|
54 | var prop; |
---|
55 | for(prop in labels){ |
---|
56 | if(!this[prop + "ButtonLabel"]){ |
---|
57 | this[prop + "ButtonLabel"] = labels[prop]; |
---|
58 | } |
---|
59 | } |
---|
60 | }, |
---|
61 | |
---|
62 | startup: function(){ |
---|
63 | if(this._started){ |
---|
64 | //console.log('started'); |
---|
65 | return; |
---|
66 | } |
---|
67 | this.inherited(arguments); |
---|
68 | |
---|
69 | this.connect(this.nextButton, "onClick", "_forward"); |
---|
70 | this.connect(this.previousButton, "onClick", "back"); |
---|
71 | |
---|
72 | if(this.cancelFunction){ |
---|
73 | if(lang.isString(this.cancelFunction)){ |
---|
74 | this.cancelFunction = lang.getObject(this.cancelFunction); |
---|
75 | } |
---|
76 | this.connect(this.cancelButton, "onClick", this.cancelFunction); |
---|
77 | }else{ |
---|
78 | this.cancelButton.domNode.style.display = "none"; |
---|
79 | } |
---|
80 | this.connect(this.doneButton, "onClick", "done"); |
---|
81 | |
---|
82 | this._subscription = connect.subscribe(this.id + "-selectChild", lang.hitch(this,"_checkButtons")); |
---|
83 | this._started = true; |
---|
84 | |
---|
85 | }, |
---|
86 | |
---|
87 | resize: function(){ |
---|
88 | this.inherited(arguments); |
---|
89 | this._checkButtons(); |
---|
90 | }, |
---|
91 | |
---|
92 | _checkButtons: function(){ |
---|
93 | |
---|
94 | var sw = this.selectedChildWidget; |
---|
95 | |
---|
96 | var lastStep = sw.isLastChild; |
---|
97 | this.nextButton.set("disabled", lastStep); |
---|
98 | this._setButtonClass(this.nextButton); |
---|
99 | if(sw.doneFunction){ |
---|
100 | //console.log(sw.doneFunction); |
---|
101 | this.doneButton.domNode.style.display = ""; |
---|
102 | if(lastStep){ |
---|
103 | this.nextButton.domNode.style.display = "none"; |
---|
104 | } |
---|
105 | }else{ |
---|
106 | // #1438 issue here. |
---|
107 | this.doneButton.domNode.style.display = "none"; |
---|
108 | } |
---|
109 | this.previousButton.set("disabled", !this.selectedChildWidget.canGoBack); |
---|
110 | this._setButtonClass(this.previousButton); |
---|
111 | }, |
---|
112 | |
---|
113 | _setButtonClass: function(button){ |
---|
114 | button.domNode.style.display = (this.hideDisabled && button.disabled) ? "none" : ""; |
---|
115 | }, |
---|
116 | |
---|
117 | _forward: function(){ |
---|
118 | // summary: callback when next button is clicked |
---|
119 | if(this.selectedChildWidget._checkPass()){ |
---|
120 | this.forward(); |
---|
121 | } |
---|
122 | }, |
---|
123 | |
---|
124 | done: function(){ |
---|
125 | // summary: Finish the wizard's operation |
---|
126 | this.selectedChildWidget.done(); |
---|
127 | }, |
---|
128 | |
---|
129 | destroy: function(){ |
---|
130 | connect.unsubscribe(this._subscription); |
---|
131 | this.inherited(arguments); |
---|
132 | } |
---|
133 | |
---|
134 | }); |
---|
135 | |
---|
136 | declare("dojox.widget.WizardPane", ContentPane, { |
---|
137 | // summary: A panel in a `dojox.widget.Wizard` |
---|
138 | // |
---|
139 | // description: |
---|
140 | // An extended ContentPane with additional hooks for passing named |
---|
141 | // functions to prevent the pane from going either forward or |
---|
142 | // backwards. |
---|
143 | // |
---|
144 | // canGoBack: Boolean |
---|
145 | // If true, then can move back to a previous panel (by clicking the "Previous" button) |
---|
146 | canGoBack: true, |
---|
147 | |
---|
148 | // passFunction: String |
---|
149 | // Name of function that checks if it's OK to advance to the next panel. |
---|
150 | // If it's not OK (for example, mandatory field hasn't been entered), then |
---|
151 | // returns an error message (String) explaining the reason. Can return null (pass) |
---|
152 | // or a Boolean (true == pass) |
---|
153 | passFunction: null, |
---|
154 | |
---|
155 | // doneFunction: String |
---|
156 | // Name of function that is run if you press the "Done" button from this panel |
---|
157 | doneFunction: null, |
---|
158 | |
---|
159 | startup: function(){ |
---|
160 | this.inherited(arguments); |
---|
161 | if(this.isFirstChild){ this.canGoBack = false; } |
---|
162 | if(lang.isString(this.passFunction)){ |
---|
163 | this.passFunction = lang.getObject(this.passFunction); |
---|
164 | } |
---|
165 | if(lang.isString(this.doneFunction) && this.doneFunction){ |
---|
166 | this.doneFunction = lang.getObject(this.doneFunction); |
---|
167 | } |
---|
168 | }, |
---|
169 | |
---|
170 | _onShow: function(){ |
---|
171 | if(this.isFirstChild){ this.canGoBack = false; } |
---|
172 | this.inherited(arguments); |
---|
173 | }, |
---|
174 | |
---|
175 | _checkPass: function(){ |
---|
176 | // summary: |
---|
177 | // Called when the user presses the "next" button. |
---|
178 | // Calls passFunction to see if it's OK to advance to next panel, and |
---|
179 | // if it isn't, then display error. |
---|
180 | // Returns true to advance, false to not advance. If passFunction |
---|
181 | // returns a string, it is assumed to be a custom error message, and |
---|
182 | // is alert()'ed |
---|
183 | var r = true; |
---|
184 | if(this.passFunction && lang.isFunction(this.passFunction)){ |
---|
185 | var failMessage = this.passFunction(); |
---|
186 | switch(typeof failMessage){ |
---|
187 | case "boolean": |
---|
188 | r = failMessage; |
---|
189 | break; |
---|
190 | case "string": |
---|
191 | alert(failMessage); |
---|
192 | r = false; |
---|
193 | break; |
---|
194 | } |
---|
195 | } |
---|
196 | return r; // Boolean |
---|
197 | }, |
---|
198 | |
---|
199 | done: function(){ |
---|
200 | if(this.doneFunction && lang.isFunction(this.doneFunction)){ this.doneFunction(); } |
---|
201 | } |
---|
202 | |
---|
203 | }); |
---|
204 | |
---|
205 | return Wizard; |
---|
206 | |
---|
207 | }); |
---|