|
|
|
1 |
/*global console MyError dojo dojox dijit umc */ |
2 |
|
3 |
dojo.provide("umc.modules._printers.QuotaDialog"); |
4 |
|
5 |
dojo.require("umc.i18n"); |
6 |
dojo.require("umc.dialog"); |
7 |
dojo.require("umc.store"); |
8 |
dojo.require("umc.tools"); |
9 |
|
10 |
dojo.require("umc.widgets.Page"); |
11 |
dojo.require("umc.widgets.Grid"); |
12 |
dojo.require("umc.widgets.Form"); |
13 |
|
14 |
dojo.declare("umc.modules._printers.QuotaDialog", |
15 |
[ |
16 |
dijit.Dialog, |
17 |
umc.i18n.Mixin |
18 |
], { |
19 |
|
20 |
i18nClass: 'umc.modules.printers', |
21 |
|
22 |
buildRendering: function() { |
23 |
|
24 |
this.inherited(arguments); |
25 |
|
26 |
var buttons = [ |
27 |
{ |
28 |
name: 'submit', |
29 |
label: this._("Save changes") |
30 |
// no callback here: the onSubmit() event of the form |
31 |
// will automatically be fired if our button has |
32 |
// the name 'submit' |
33 |
}, |
34 |
{ |
35 |
name: 'cancel', |
36 |
label: this._("Cancel"), |
37 |
// no special meaning of the button name 'cancel', so we |
38 |
// have to make a seperate callback for this button. |
39 |
callback: dojo.hitch(this, function() { |
40 |
this.onCancel(); |
41 |
}) |
42 |
} |
43 |
]; |
44 |
|
45 |
var widgets = [ |
46 |
{ |
47 |
name: 'printer', |
48 |
type: 'TextBox', |
49 |
label: this._("Printer name"), |
50 |
disabled: true |
51 |
}, |
52 |
{ |
53 |
name: 'user', |
54 |
type: 'ComboBox', |
55 |
label: this._("User name"), |
56 |
sortStaticValues: true, |
57 |
required: true |
58 |
}, |
59 |
{ |
60 |
name: 'soft', |
61 |
type: 'TextBox', |
62 |
regExp: '\\d+', |
63 |
required: true, |
64 |
label: this._("Soft limit") |
65 |
}, |
66 |
{ |
67 |
name: 'hard', |
68 |
type: 'TextBox', |
69 |
regExp: '\\d+', |
70 |
required: true, |
71 |
label: this._("Hard limit") |
72 |
} |
73 |
]; |
74 |
|
75 |
var layout = [ |
76 |
[ 'printer' ], |
77 |
[ 'user' ], |
78 |
[ 'soft' ], |
79 |
[ 'hard' ] |
80 |
]; |
81 |
|
82 |
this._form = new umc.widgets.Form({ |
83 |
buttons: buttons, |
84 |
widgets: widgets, |
85 |
layout: layout, |
86 |
onSubmit: dojo.hitch(this, function(values) { |
87 |
if (this._check_valid('onsubmit')) |
88 |
{ |
89 |
this.onSubmit(this._form.gatherFormValues()); |
90 |
} |
91 |
}) |
92 |
}); |
93 |
this.set('content',this._form); |
94 |
|
95 |
dojo.connect(this._form,'onCancel',dojo.hitch(this,function() { |
96 |
this.onCancel(); |
97 |
})); |
98 |
|
99 |
// check 'submit' allowance on every field change |
100 |
umc.tools.forIn(this._form._widgets, function(wname, wobj) { |
101 |
dojo.connect(wobj,'onChange',dojo.hitch(this, function() { |
102 |
this._check_valid(wname); |
103 |
})); |
104 |
}, this); |
105 |
|
106 |
}, |
107 |
|
108 |
// checks that all dialog elements are valid, allows |
109 |
// or forbids the 'submit' button. |
110 |
_check_valid: function(title) { |
111 |
|
112 |
var allow = true; |
113 |
for (var w in this._form._widgets) |
114 |
{ |
115 |
var wid = this._form._widgets[w]; |
116 |
|
117 |
if (! wid.isValid()) |
118 |
{ |
119 |
allow = false; |
120 |
wid.set('state','Error'); // force visibility of state |
121 |
} |
122 |
} |
123 |
this._form._buttons['submit'].setDisabled(! allow); |
124 |
|
125 |
return allow; |
126 |
}, |
127 |
|
128 |
onShow: function() { |
129 |
|
130 |
this.inherited(arguments); |
131 |
|
132 |
// reset all error indicators |
133 |
for (var w in this._form._widgets) |
134 |
{ |
135 |
var wid = this._form._widgets[w]; |
136 |
wid.setValid(null); |
137 |
} |
138 |
// allow/forbid SUBMIT according to current form contents |
139 |
this._check_valid(); |
140 |
}, |
141 |
|
142 |
// will be called from QuotaPage just before showing |
143 |
// the dialog. the 'values' are now composed from |
144 |
// different things: |
145 |
// |
146 |
// (1) initial values for the dialog elements (printer, user, hard, soft) |
147 |
// (2) the title for the dialog |
148 |
// (3) the list of users to show in the ComboBox |
149 |
// |
150 |
setValues: function(values) { |
151 |
|
152 |
// for 'add quota entry': set a list of users, excluding those |
153 |
// that already have a quota entry |
154 |
var userlist = []; |
155 |
|
156 |
if (values['users']) |
157 |
{ |
158 |
for (var u in values['users']) |
159 |
{ |
160 |
var un = values['users'][u]; |
161 |
var entry = { id: un, label: un }; |
162 |
userlist.push(entry); |
163 |
} |
164 |
} |
165 |
// for 'edit quota entry' the 'user' ComboBox is readonly, so it is |
166 |
// sufficient to set the list to the one user being edited... this will |
167 |
// catch the case where we have an entry for a user that doesn't exist |
168 |
// anymore. |
169 |
var disabled = false; |
170 |
|
171 |
if (values['user']) |
172 |
{ |
173 |
this._work_mode = 'edit'; |
174 |
var entry = { id: values['user'], label: values['users'] }; |
175 |
userlist.push(entry); |
176 |
disabled = true; |
177 |
} |
178 |
else |
179 |
{ |
180 |
this._work_mode = 'add'; |
181 |
values['user'] = null; // force them to touch the ComboBox at least once |
182 |
} |
183 |
this._form.getWidget('user').set('staticValues',userlist); |
184 |
this._form.getWidget('user').setDisabled(disabled); |
185 |
|
186 |
if (values['title']) |
187 |
{ |
188 |
this.set('title',values['title']); |
189 |
} |
190 |
|
191 |
this._form.setFormValues(values); |
192 |
}, |
193 |
|
194 |
// event stubs for our caller |
195 |
onSubmit: function(values) { |
196 |
this.hide(); |
197 |
}, |
198 |
|
199 |
onCancel: function() { |
200 |
this.hide(); |
201 |
} |
202 |
|
203 |
}); |