1 | define([ |
---|
2 | "dojo/_base/lang", |
---|
3 | "dojo/_base/declare", |
---|
4 | "dijit/layout/ContentPane" |
---|
5 | ], function(lang, declare, ContentPane){ |
---|
6 | |
---|
7 | return declare("dojox.widget.WizardPane", ContentPane, { |
---|
8 | // summary: |
---|
9 | // A panel in a `dojox.widget.Wizard` |
---|
10 | // description: |
---|
11 | // An extended ContentPane with additional hooks for passing named |
---|
12 | // functions to prevent the pane from going either forward or |
---|
13 | // backwards. |
---|
14 | |
---|
15 | // canGoBack: Boolean |
---|
16 | // If true, then can move back to a previous panel (by clicking the "Previous" button) |
---|
17 | canGoBack: true, |
---|
18 | |
---|
19 | // passFunction: String |
---|
20 | // Name of function that checks if it's OK to advance to the next panel. |
---|
21 | // If it's not OK (for example, mandatory field hasn't been entered), then |
---|
22 | // returns an error message (String) explaining the reason. Can return null (pass) |
---|
23 | // or a Boolean (true == pass) |
---|
24 | passFunction: null, |
---|
25 | |
---|
26 | // doneFunction: String |
---|
27 | // Name of function that is run if you press the "Done" button from this panel |
---|
28 | doneFunction: null, |
---|
29 | |
---|
30 | startup: function(){ |
---|
31 | this.inherited(arguments); |
---|
32 | if(this.isFirstChild){ this.canGoBack = false; } |
---|
33 | if(lang.isString(this.passFunction)){ |
---|
34 | this.passFunction = lang.getObject(this.passFunction); |
---|
35 | } |
---|
36 | if(lang.isString(this.doneFunction) && this.doneFunction){ |
---|
37 | this.doneFunction = lang.getObject(this.doneFunction); |
---|
38 | } |
---|
39 | }, |
---|
40 | |
---|
41 | _onShow: function(){ |
---|
42 | if(this.isFirstChild){ this.canGoBack = false; } |
---|
43 | this.inherited(arguments); |
---|
44 | }, |
---|
45 | |
---|
46 | _checkPass: function(){ |
---|
47 | // summary: |
---|
48 | // Called when the user presses the "next" button. |
---|
49 | // Calls passFunction to see if it's OK to advance to next panel, and |
---|
50 | // if it isn't, then display error. |
---|
51 | // Returns true to advance, false to not advance. If passFunction |
---|
52 | // returns a string, it is assumed to be a custom error message, and |
---|
53 | // is alert()'ed |
---|
54 | var r = true; |
---|
55 | if(this.passFunction && lang.isFunction(this.passFunction)){ |
---|
56 | var failMessage = this.passFunction(); |
---|
57 | switch(typeof failMessage){ |
---|
58 | case "boolean": |
---|
59 | r = failMessage; |
---|
60 | break; |
---|
61 | case "string": |
---|
62 | alert(failMessage); |
---|
63 | r = false; |
---|
64 | break; |
---|
65 | } |
---|
66 | } |
---|
67 | return r; // Boolean |
---|
68 | }, |
---|
69 | |
---|
70 | done: function(){ |
---|
71 | if(this.doneFunction && lang.isFunction(this.doneFunction)){ this.doneFunction(); } |
---|
72 | } |
---|
73 | }); |
---|
74 | |
---|
75 | }); |
---|
76 | |
---|