1 | define([ |
---|
2 | "dojo/_base/lang", |
---|
3 | "dojo/_base/declare", |
---|
4 | "dojo/_base/connect", |
---|
5 | "dijit/layout/StackContainer", |
---|
6 | "dijit/_TemplatedMixin", |
---|
7 | "dijit/_WidgetsInTemplateMixin", |
---|
8 | "dojo/i18n", |
---|
9 | "dojo/text!./Wizard/Wizard.html", |
---|
10 | "dojo/i18n!dijit/nls/common", |
---|
11 | "dojo/i18n!./nls/Wizard", |
---|
12 | "dijit/form/Button" // used by template |
---|
13 | ], function (lang, declare, connect, StackContainer, _TemplatedMixin, _WidgetsInTemplateMixin, i18n, template) { |
---|
14 | |
---|
15 | var Wizard = declare("dojox.widget.Wizard", [StackContainer, _TemplatedMixin, _WidgetsInTemplateMixin], { |
---|
16 | // summary: |
---|
17 | // A set of panels that display sequentially, typically notating a step-by-step |
---|
18 | // procedure like an install |
---|
19 | |
---|
20 | templateString: template, |
---|
21 | |
---|
22 | // nextButtonLabel: String |
---|
23 | // Label override for the "Next" button. |
---|
24 | nextButtonLabel: "", |
---|
25 | |
---|
26 | // previousButtonLabel: String |
---|
27 | // Label override for the "Previous" button. |
---|
28 | previousButtonLabel: "", |
---|
29 | |
---|
30 | // cancelButtonLabel: String |
---|
31 | // Label override for the "Cancel" button. |
---|
32 | cancelButtonLabel: "", |
---|
33 | |
---|
34 | // doneButtonLabel: String |
---|
35 | // Label override for the "Done" button. |
---|
36 | doneButtonLabel: "", |
---|
37 | |
---|
38 | // cancelFunction: Function|String |
---|
39 | // Name of function to call if user presses cancel button. |
---|
40 | // Cancel button is not displayed if function is not specified. |
---|
41 | cancelFunction: null, |
---|
42 | |
---|
43 | // hideDisabled: Boolean |
---|
44 | // If true, disabled buttons are hidden; otherwise, they are assigned the |
---|
45 | // "WizardButtonDisabled" CSS class |
---|
46 | hideDisabled: false, |
---|
47 | |
---|
48 | postMixInProperties: function(){ |
---|
49 | this.inherited(arguments); |
---|
50 | var labels = lang.mixin({cancel: i18n.getLocalization("dijit", "common", this.lang).buttonCancel}, |
---|
51 | i18n.getLocalization("dojox.widget", "Wizard", this.lang)); |
---|
52 | var prop; |
---|
53 | for(prop in labels){ |
---|
54 | if(!this[prop + "ButtonLabel"]){ |
---|
55 | this[prop + "ButtonLabel"] = labels[prop]; |
---|
56 | } |
---|
57 | } |
---|
58 | }, |
---|
59 | |
---|
60 | startup: function(){ |
---|
61 | if(this._started){ |
---|
62 | //console.log('started'); |
---|
63 | return; |
---|
64 | } |
---|
65 | this.inherited(arguments); |
---|
66 | |
---|
67 | this.connect(this.nextButton, "onClick", "_forward"); |
---|
68 | this.connect(this.previousButton, "onClick", "back"); |
---|
69 | |
---|
70 | if(this.cancelFunction){ |
---|
71 | if(lang.isString(this.cancelFunction)){ |
---|
72 | this.cancelFunction = lang.getObject(this.cancelFunction); |
---|
73 | } |
---|
74 | this.connect(this.cancelButton, "onClick", this.cancelFunction); |
---|
75 | }else{ |
---|
76 | this.cancelButton.domNode.style.display = "none"; |
---|
77 | } |
---|
78 | this.connect(this.doneButton, "onClick", "done"); |
---|
79 | |
---|
80 | this._subscription = connect.subscribe(this.id + "-selectChild", lang.hitch(this,"_checkButtons")); |
---|
81 | this._started = true; |
---|
82 | |
---|
83 | }, |
---|
84 | |
---|
85 | resize: function(){ |
---|
86 | this.inherited(arguments); |
---|
87 | this._checkButtons(); |
---|
88 | }, |
---|
89 | |
---|
90 | _checkButtons: function(){ |
---|
91 | |
---|
92 | var sw = this.selectedChildWidget; |
---|
93 | |
---|
94 | var lastStep = sw.isLastChild; |
---|
95 | this.nextButton.set("disabled", lastStep); |
---|
96 | this._setButtonClass(this.nextButton); |
---|
97 | if(sw.doneFunction){ |
---|
98 | //console.log(sw.doneFunction); |
---|
99 | this.doneButton.domNode.style.display = ""; |
---|
100 | if(lastStep){ |
---|
101 | this.nextButton.domNode.style.display = "none"; |
---|
102 | } |
---|
103 | }else{ |
---|
104 | // #1438 issue here. |
---|
105 | this.doneButton.domNode.style.display = "none"; |
---|
106 | } |
---|
107 | this.previousButton.set("disabled", !this.selectedChildWidget.canGoBack); |
---|
108 | this._setButtonClass(this.previousButton); |
---|
109 | }, |
---|
110 | |
---|
111 | _setButtonClass: function(button){ |
---|
112 | button.domNode.style.display = (this.hideDisabled && button.disabled) ? "none" : ""; |
---|
113 | }, |
---|
114 | |
---|
115 | _forward: function(){ |
---|
116 | // summary: |
---|
117 | // callback when next button is clicked |
---|
118 | if(this.selectedChildWidget._checkPass()){ |
---|
119 | this.forward(); |
---|
120 | } |
---|
121 | }, |
---|
122 | |
---|
123 | done: function(){ |
---|
124 | // summary: |
---|
125 | // 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 | return Wizard; |
---|
137 | }); |
---|