Wizard_wev8.js
5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
Copyright (c) 2004-2005, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.widget.Wizard");
dojo.require("dojo.widget.*");
dojo.require("dojo.widget.LayoutPane");
dojo.require("dojo.event.*");
dojo.require("dojo.html");
dojo.require("dojo.style");
//////////////////////////////////////////
// Wizard -- a set of panels
//////////////////////////////////////////
dojo.widget.Wizard = function() {
dojo.widget.html.LayoutPane.call(this);
}
dojo.inherits(dojo.widget.Wizard, dojo.widget.html.LayoutPane);
dojo.lang.extend(dojo.widget.Wizard, {
widgetType: "Wizard",
labelPosition: "top",
templatePath: dojo.uri.dojoUri("src/widget/templates/Wizard.html"),
templateCssPath: dojo.uri.dojoUri("src/widget/templates/Wizard_wev8.css"),
selected: null, // currently selected panel
wizardNode: null, // the outer wizard node
wizardPanelContainerNode: null, // the container for the panels
wizardControlContainerNode: null, // the container for the wizard controls
previousButton: null, // the previous button
nextButton: null, // the next button
cancelButton: null, // the cancel button
doneButton: null, // the done button
nextButtonLabel: "next",
previousButtonLabel: "previous",
cancelButtonLabel: "cancel",
doneButtonLabel: "done",
cancelFunction : "",
hideDisabledButtons: false,
fillInTemplate: function(args, frag){
dojo.event.connect(this.nextButton, "onclick", this, "nextPanel");
dojo.event.connect(this.previousButton, "onclick", this, "previousPanel");
if (this.cancelFunction){
dojo.event.connect(this.cancelButton, "onclick", this.cancelFunction);
}else{
this.cancelButton.style.display = "none";
}
dojo.event.connect(this.doneButton, "onclick", this, "done");
this.nextButton.value = this.nextButtonLabel;
this.previousButton.value = this.previousButtonLabel;
this.cancelButton.value = this.cancelButtonLabel;
this.doneButton.value = this.doneButtonLabel;
},
checkButtons: function(){
var lastStep = !this.hasNextPanel();
this.nextButton.disabled = lastStep;
this.setButtonClass(this.nextButton);
if(this.selected.doneFunction){
this.doneButton.style.display = "";
// hide the next button if this is the last one and we have a done function
if(lastStep){
this.nextButton.style.display = "none";
}
}else{
this.doneButton.style.display = "none";
}
this.previousButton.disabled = ((!this.hasPreviousPanel()) || (!this.selected.canGoBack));
this.setButtonClass(this.previousButton);
},
setButtonClass: function(button){
if(!this.hideDisabledButtons){
button.style.display = "";
dojo.html.setClass(button, button.disabled ? "WizardButtonDisabled" : "WizardButton");
}else{
button.style.display = button.disabled ? "none" : "";
}
},
registerChild: function(panel, insertionIndex){
dojo.widget.Wizard.superclass.registerChild.call(this, panel, insertionIndex);
this.wizardPanelContainerNode.appendChild(panel.domNode);
panel.hide();
if(!this.selected){
this.onSelected(panel);
}
this.checkButtons();
},
onSelected: function(panel){
// Deselect old panel and select new one
if(this.selected ){
if (this.selected.checkPass()) {
this.selected.hide();
} else {
return;
}
}
panel.show();
this.selected = panel;
},
getPanels: function() {
return this.getChildrenOfType("WizardPane", false);
},
selectedIndex: function() {
if (this.selected) {
return dojo.lang.indexOf(this.getPanels(), this.selected);
}
return -1;
},
nextPanel: function() {
var selectedIndex = this.selectedIndex();
if ( selectedIndex > -1 ) {
var childPanels = this.getPanels();
if (childPanels[selectedIndex + 1]) {
this.onSelected(childPanels[selectedIndex + 1]);
}
}
this.checkButtons();
},
previousPanel: function() {
var selectedIndex = this.selectedIndex();
if ( selectedIndex > -1 ) {
var childPanels = this.getPanels();
if (childPanels[selectedIndex - 1]) {
this.onSelected(childPanels[selectedIndex - 1]);
}
}
this.checkButtons();
},
hasNextPanel: function() {
var selectedIndex = this.selectedIndex();
return (selectedIndex < (this.getPanels().length - 1));
},
hasPreviousPanel: function() {
var selectedIndex = this.selectedIndex();
return (selectedIndex > 0);
},
done: function() {
this.selected.done();
}
});
dojo.widget.tags.addParseTreeHandler("dojo:Wizard");
//////////////////////////////////////////
// WizardPane -- a panel in a wizard
//////////////////////////////////////////
dojo.widget.WizardPane = function() {
dojo.widget.html.LayoutPane.call(this);
}
dojo.inherits(dojo.widget.WizardPane, dojo.widget.html.LayoutPane);
dojo.lang.extend(dojo.widget.WizardPane, {
widgetType: "WizardPane",
canGoBack: true,
passFunction: "",
doneFunction: "",
fillInTemplate: function(args, frag) {
if (this.passFunction) {
this.passFunction = dj_global[this.passFunction];
}
if (this.doneFunction) {
this.doneFunction = dj_global[this.doneFunction];
}
},
checkPass: function() {
if (this.passFunction && dojo.lang.isFunction(this.passFunction)) {
var failMessage = this.passFunction();
if (failMessage) {
alert(failMessage);
return false;
}
}
return true;
},
done: function() {
if (this.doneFunction && dojo.lang.isFunction(this.doneFunction)) {
this.doneFunction();
}
}
});
dojo.widget.tags.addParseTreeHandler("dojo:WizardPane");