allow add.pl to run as fcgi
[bse.git] / site / templates / preload.tmpl
CommitLineData
f04ca377 1<:# see preload.pod for documentation -:>
5251d8e2 2<:.set dist_image_uri = cfg.entryIfVar("uri", "dist_images", "/images") -:>
b62cae00 3<:# utility definitions :>
d1132d88
TC
4<:-.define make_select; groups: 0, grouplabel: "label", groupid: "id",
5 itemgroupid: "groupid" -:>
19851056
TC
6 <:-.if !default.defined -:>
7 <:-.set default = "" -:>
8 <:.end if:>
411e6902 9 <select name="<:= name | html :>">
2de83e20
TC
10 <:- .if groups -:>
11 <:-.for i in list -:>
12 <:.if i.$itemgroupid eq "" -:>
411e6902 13 <option value="<:= i.$id | html :>"
2de83e20 14 <:- .if i.$id eq default :> selected="selected"<:.end if -:>
b62cae00 15 >
2de83e20
TC
16 <:-= i.$desc | html -:>
17 <:.end if -:>
18 <:.end for -:>
19 <:-.for g in groups -:>
20 <optgroup label="<:= g.$grouplabel | html -:>">
21 <:-.for i in list -:>
22 <:.if i.$itemgroupid == g.$groupid -:>
23 <option value="<:= i.$id | html :>"
24 <:- .if i.$id eq default :> selected="selected"<:.end if -:>
25 >
26 <:-= i.$desc | html -:>
27 <:.end if -:>
28 <:.end for -:>
29 </optgroup>
30 <:-.end for -:>
31 <:- .else -:>
32 <:-.for i in list -:>
33 <option value="<:= i.$id | html :>"
34 <:- .if i.$id eq default :> selected="selected"<:.end if -:>
35 >
36 <:-= i.$desc | html -:>
37 <:-.end for-:>
38 <:-.end if -:>
b62cae00
TC
39 </select>
40<:-.end define -:>
8f685a21 41<:#
f04ca377
TC
42make_multicheck expects:
43 values - list of hashes
44 default - a list of ids of checks to be checked
45 id - the name of the id field
46 desc - the name of the description field.
47 name - the name of the input elements
48 readonly - true to make it readonly
49-:>
d1132d88 50<:-.define make_multicheck; readonly: 0-:>
f04ca377
TC
51 <:.if !readonly -:>
52 <input type="hidden" name="_save_<:= name -:>" value="1">
53 <:.end if -:>
54 <:-.if !default.defined -:>
55 <:-.set default = [] -:>
56 <:.end if:>
57 <:.set checked = {} -:>
58 <:.for v in default -:>
59 <:% checked.set(v, 1) -:>
60 <:.end for -:>
61 <ul>
62 <:-.for i in values -:>
63 <li>
64 <:.set element_id = name _ "-" _ i.$id -:>
65 <input type="checkbox" name="<:= name :>" <:= checked[i.$id] ? 'checked ' : '' -:>
66 id="<:= element_id -:>" value="<:= i.$id :>"
67<:-# readonly attribute isn't valid for checkboxes -:>
68<:-= readonly ? " disabled" : "" -:>
69 >
70 <label for="<:= element_id :>"><:= i.$desc -:></label>
71 </li>
72 <:-.end for -:>
73 </ul>
74<:-.end define -:>
75<:#
8f685a21
TC
76page_list expects:
77base - base url for links
78pages - the result of the bse.pages call
79 :>
80<:-.define page_list-:>
81<:.set sep = base =~ /\?/ ? "&" : "?" -:>
82<:.set base = base _ sep :>
83<div class="pagelist">
84Page <:= pages.page :> of <:= pages.pagecount :>
85<:.if pages.previous_page -:>
86<a href="<:= base |html:><:= pages.pname | uri :>=1&amp;<:= pages.ppname | uri :>=<:= pages.pp | uri :>">&lt;&lt</a>
87<a href="<:= base |html:><:= pages.pname | uri :>=<:= pages.previous_page |uri:>&amp;<:= pages.ppname | uri :>=<:= pages.pp | uri :>">&lt;</a>
88<:.else -:>
89<span>&lt&lt</span>
90<span>&lt</span>
91<:.end if -:>
92<:.for p in pcats.pages :>
93<:.if p.link -:>
94<a href="<:= base |html :><:= pages.pname | uri:>=<:= p.page | uri :>&amp;<:=pages.ppname | uri :>=<:= pages.pp | uri :>"><:= p.page |html :></a>
95<:.else -:>
96<span><:= p.page |html:></span>
97<:.end if -:>
98<:.end for:>
99<:.if pages.next_page -:>
100<a href="<:= base |html:><:= pages.pname | uri :>=<:= pages.next_page |uri:>&amp;<:= pages.ppname | uri :>=<:= pages.pp | uri :>">&gt;</a>
101<a href="<:= base |html:><:= pages.pname | uri :>=<:= pages.pagecount |uri:>&amp;<:= pages.ppname | uri :>=<:= pages.pp | uri :>">&gt;&gt</a>
102<:.else -:>
103<span>&gt&gt</span>
104<span>&gt</span>
105<:.end if -:>
106</div>
59fca225
TC
107<:-.end define -:>
108
109<:.define old -:>
110<:# parameters: field, default -:>
111<: .if cgi.param(field).defined -:>
112<:= cgi.param(field) -:>
113<: .else -:>
114<:= default | html -:>
115<: .end if -:>
116<:.end define-:>
117
5251d8e2
TC
118<:.define error_img_n -:>
119<:# parameters:
120 field - name of field
121 index - index of field
122 errors - hash of error messages (should be set by code)
123-:>
124 <:.if errors.$field -:>
125 <:.set msg = errors.$field -:>
126 <:.set msg = msg.is_list ? msg[index] : msg -:>
c46eae4a
TC
127 <:.if msg.defined -:>
128 <:.set image = cfg.entry("error_img", "image", dist_image_uri _ "/admin/error.gif") -:>
129 <:.set width = cfg.entry("error_img", "width", 16) -:>
130 <:.set height = cfg.entry("error_img", "height", 16) -:>
5251d8e2 131 <img src="<:= image -:>" alt="<:= msg :>" title="<:= msg :>" width="<:= width :>" height="<:= height :>" class="error_img">
c46eae4a 132 <:.end if -:>
5251d8e2
TC
133 <:.end if -:>
134<:.end define -:>
135
59fca225 136<:.define error_img -:>
d1132d88 137<:.call "error_img_n", index:0 -:>
80e0459c 138<:.end define -:>
16fff1cd 139
b26e625c 140<:.define input -:>
c6369510 141<:# parameters:
b26e625c 142 name - field name
f04ca377 143 field - entry from fields
b26e625c
TC
144 object - source for defaults in edit mode
145:>
b26e625c 146<: .if object -:>
f04ca377
TC
147<: .set default = object.$name -:>
148<: .elsif field.default -:>
149<: .set default = field.default -:>
b26e625c
TC
150<: .else -:>
151<: .set default = "" -:>
152<: .end if -:>
f04ca377 153<: .if field.type and field.type eq "date" and default ne "" -:>
5522569e 154<: .set default = default.replace(/(\d+)\D+(\d+)\D+(\d+)/, "$3/$2/$1") -:>
f04ca377 155<: .elsif field.type and field.type eq "time" and default ne "" -:>
5522569e
TC
156<: .set default = bse.date(default =~ /:00$/ ? "%I:%M%p" : "%I:%M:%S%p", default).replace(/^0/, "").lower() -:>
157<: .end if -:>
158<: .if cgi.param(name).defined -:>
159<: .set default = cgi.param(name) -:>
160<: .end if -:>
f04ca377
TC
161<: .if field.htmltype eq "textarea" -:>
162<textarea id="<:= name | html :>" name="<:= name | html :>" rows="<:= field.height ? field.height : cfg.entry("forms", "textarea_rows", 10) :>" cols=<:= field.width ? field.width : cfg.entry("textarea_cols", 60) | html :>>
5522569e 163<:-= default | html -:>
b26e625c 164</textarea>
f04ca377
TC
165<: .elsif field.htmltype eq "checkbox" -:>
166<:.set is_checked = cgi.param("_save_" _ name) ? cgi.param(name).defined : default -:>
167<input type="hidden" name="_save_<:= name -:>" value="1">
168<input id="<:= name | html :>" type="checkbox" name="<:= name | html :>"<:= is_checked ? ' checked="checked"' : '' :> value="<:= field.value ? field.value : 1 | html :>" />
169<: .elsif field.htmltype eq "multicheck" -:>
170<:# we expect default to be a list of selected checks -:>
171<:.set values = field.select["values"] -:>
172<:.set values = values.is_code ? values() : values -:>
173<:.set default = cgi.param("_save_" _ name) ? [ cgi.param(name) ] : default -:>
174<:.call "make_multicheck",
d1132d88
TC
175 id:field.select.id,
176 desc:field.select.label -:>
f04ca377
TC
177<: .elsif field.htmltype eq "select" -:>
178<:.set values = field.select["values"] -:>
411e6902
TC
179<:.set values = values.is_code ? values() : values -:>
180<:.call "make_select",
d1132d88
TC
181 name: name,
182 default: default,
183 list: values,
184 id: field.select.id,
185 desc: field.select.label,
186 groupid : (field.select.groupid or "id"),
187 itemgroupid: (field.select.itemgroupid or "groupid"),
188 groups: field.select.groups ? (field.select.groups.is_code ? (field.select.groups)() : field.select.groups ) : 0,
189 grouplabel: (field.select.grouplabel or "label")
411e6902 190-:>
b26e625c 191<: .else -:>
5522569e 192<input id="<:= name | html :>" type="text" name="<:= name | html :>" value="<:= default | html :>"
f04ca377
TC
193<:-= field.maxlength ? ' maxlength="' _ field.maxlength _ '"' : '' |raw:>
194<:-= field.width ? ' size="' _ field.width _ '"' : '' | raw :> />
b26e625c
TC
195<: .end if -:>
196<:.end define -:>
197
198<:.define field -:>
5522569e 199<:# parameters:
b26e625c
TC
200 name - field name
201 fields - hash of fields (may be set by page instead)
202:>
f04ca377
TC
203 <:.if fields.is_hash -:>
204 <:.set f = fields[name] -:>
205 <:.if f -:>
d1132d88 206 <:.call "inlinefield", field:f, name:name -:>
f04ca377
TC
207 <:.else -:>
208<p>Unknown field id '<b><:= name :></b>', available fields are '<:= fields.keys.join("', '") :>'</p>
209 <:.end if -:>
210 <:.else -:>
211<p>fields isn't a hash, something is wrong.</p>
212 <:.end if -:>
213<:.end define -:>
214
215<:.define inlinefield -:>
216<:# parameters:
217 name - the field name
218 field - a field, as an entry in fields
219-:>
220 <:.if field.is_hash -:>
b26e625c 221<div>
f04ca377 222 <label for="<:= name | html :>"><:= field.nolabel ? "" : field.description | html :>:</label>
2ced88e0
TC
223 <span>
224 <:-.if field.readonly -:>
d1132d88 225<:-.call "display", name:name -:>
2ced88e0 226 <:.else -:>
d1132d88 227<:-.call "input", name:name -:><:.call "error_img", field:name :>
2ced88e0 228 <:-.end if -:>
f04ca377
TC
229 <:-.if field.units -:>
230 <:-= field.units | html -:>
231 <:-.end if -:>
f04ca377
TC
232</span>
233</div>
672a2e42 234 <:.end if -:>
f04ca377
TC
235<:.end define -:>
236
237<:.define fieldset -:>
238<:# like field, but wrap in a per-field field set.
239parameters:
240 name - field name
241 fields - hash of fields (may be set by page instead)
242:>
243 <:.set f = fields[name] -:>
244 <:.if f.is_hash -:>
245<fieldset>
246 <:.if !f.nolabel -:>
247 <legend><:= f.description :></legend>
248 <:.end if -:>
d1132d88 249 <:.call "input", name: name, field: f -:>
f04ca377
TC
250</fieldset>
251 <:.elsif fields.is_hash -:>
252<p>Unknown field id '<b><:= name :></b>', available fields are '<:= fields.keys.join("', '") :>'</p>
253 <:.else -:>
254<p>fields isn't a hash, something is wrong.</p>
255 <:.end if -:>
256<:.end define -:>
257
258<:.define display -:>
259<:# paramaters:
260 name - field name
261 field - entry from fields
262 object - source for defaults in edit mode
263:>
264<: .if object -:>
265<: .set default = object.$name -:>
266<: .end if -:>
267<: .if field.type and field.type eq "date" and default ne "" -:>
268<: .set default = default.replace(/(\d+)\D+(\d+)\D+(\d+)/, "$3/$2/$1") -:>
269<: .elsif field.type and field.type eq "time" and default ne "" -:>
270<: .set default = bse.date(default =~ /:00$/ ? "%I:%M%p" : "%I:%M:%S%p", default).replace(/^0/, "").lower() -:>
271<: .end if -:>
272<: .if field.htmltype eq "textarea" -:>
273<textarea id="<:= name | html :>" name="<:= name | html :>" rows="<:= field.height ? field.height : cfg.entry("forms", "textarea_rows", 10) :>" cols=<:= field.width ? field.width : cfg.entry("textarea_cols", 60) | html :> readonly>
274<:-= default | html -:>
275</textarea>
276<: .elsif field.htmltype eq "checkbox" -:>
277<input id="<:= name | html :>" type="checkbox" name="<:= name | html :>"<:= is_checked ? ' checked="checked"' : '' :> value="<:= field.value ? field.value : 1 | html :>" readonly>
278<: .elsif field.htmltype eq "multicheck" -:>
279<:# we expect default to be a list of selected checks -:>
280<:.set values = field.select["values"] -:>
281<:.set values = values.is_code ? values() : values -:>
282<:.call "make_multicheck",
d1132d88
TC
283 id: field.select.id,
284 desc: field.select.label,
285 readonly: 1 -:>
f04ca377
TC
286<: .elsif field.htmltype eq "select" -:>
287<:.set values = field.select["values"] -:>
288<:.set values = values.is_code ? values() : values -:>
289<:# find the selected value and display it's label -:>
290<:.set sid = field.select.id -:>
291<:.set sdesc = field.select.label -:>
292<:.for value in values -:>
293 <:.if value.$id eq default -:>
294 <:= value.$desc -:>
295 <:.end if -:>
296<:.end for -:>
297<: .else -:>
298<input id="<:= name :>" type="text" name="<:= name :>" value="<:= default :>"
299<:-= field.width ? ' size="' _ field.width _ '"' : '' | raw :> readonly>
300<: .end if -:>
301<:.end define -:>
302
303<:.define inlinefieldro -:>
304<:# parameters:
305 name - the field name
306 field - a field, as an entry in fields
307-:>
308 <:.if field.is_hash -:>
309<div>
310 <label for="<:= name :>"><:= field.nolabel ? "" : field.description :>:</label>
d1132d88 311 <span><:.call "display", name:name -:>
f04ca377
TC
312 <:-.if field.units -:>
313 <:-= field.units -:>
314 <:-.end if -:>
315 <:.end if -:>
e9d454b4 316</span>
b26e625c
TC
317</div>
318<:.end define -:>
319
f04ca377
TC
320<:.define fieldro -:>
321<:# like field, but for display, not editing -:>
322 <:.if fields.is_hash -:>
323 <:.set f = fields[name] -:>
324 <:.if f -:>
d1132d88 325 <:.call "inlinefieldro", field:f, name:name -:>
f04ca377
TC
326 <:.else -:>
327<p>Unknown field id '<b><:= name :></b>', available fields are '<:= fields.keys.join("', '") :>'</p>
328 <:.end if -:>
329 <:.else -:>
330<p>fields isn't a hash, something is wrong.</p>
331 <:.end if -:>
332<:.end define -:>
333
334<:.define fieldsetro -:>
335<:# like fieldro, but wrap in a per-field field set.
336parameters:
337 name - field name
338 fields - hash of fields (may be set by page instead)
339:>
340 <:.set f = fields[name] -:>
341 <:.if f.is_hash -:>
342<fieldset>
343 <:.if !f.nolabel -:>
344 <legend><:= f.description :></legend>
345 <:.end if -:>
346 <:.call "display", "name":name, "field":f -:>
347</fieldset>
348 <:.elsif fields.is_hash -:>
349<p>Unknown field id '<b><:= name :></b>', available fields are '<:= fields.keys.join("', '") :>'</p>
350 <:.else -:>
351<p>fields isn't a hash, something is wrong.</p>
352 <:.end if -:>
353<:.end define -:>
354
b26e625c
TC
355<:.define messages -:>
356<: .if request.messages.size -:>
357<div class="messages">
358<: .for m in request.messages -:>
6f186c3b 359 <div class="<:= m.class :>"><:= m.html |raw :></div>
b26e625c
TC
360<: .end for -:>
361</div>
362<: .end if -:>
363<:.end define -:>
364
491223ee 365<:.define mover -:>
f34ff248 366<:# expects loop, request, parent
491223ee
TC
367 which in most cases means you can just supply parent
368-:>
f34ff248 369<:.if request.user_can("bse_edit_reorder_children", parent) -:>
7c670eb8
AO
370 <:.set down_url = loop.next ? cfg.admin_url("move", { "stepparent":parent.id, "d":"swap", "id":loop.current.id, "other":loop.next.id, "r":top.admin }) : 0 -:>
371 <:.set up_url = loop.prev ? cfg.admin_url("move", { "stepparent":parent.id, "d":"swap", "id":loop.current.id, "other":loop.prev.id, "r":top.admin }) : 0 -:>
372 <:.set class = cfg.entry("arrows", "class", "bse_arrows") -:>
373 <span class="<:= m.class :>">
374 <:-.call "make_arrows", "down_url":down_url, "up_url":up_url -:>
375 </span>
376<:.end if -:>
377<:.end define -:>
378
379<:.define make_arrows -:>
380<:# expects down_url, up_url
381-:>
1fa69b29
AO
382 <:.set width = cfg.entry("arrows", "image_width", 17) -:>
383 <:.set height = cfg.entry("arrows", "image_height", 13) -:>
f34ff248 384 <:.set extras = 'width="' _ width _ '" height="' _ height _ '"' -:>
f56525a7
AO
385 <:.set blank_img = '<img src="' _ (dist_image_uri _ "/trans_pixel.gif").escape("html") _ '" alt="" ' _ extras _ ' />' -:>
386 <:.set down_img = '<img src="' _ cfg.entry("arrows", "downimg", dist_image_uri _ "/admin/move_down.gif").escape("html") _ '" alt="Down" ' _ extras _ ' />' -:>
387 <:.set up_img = '<img src="' _ cfg.entry("arrows", "upimg", dist_image_uri _ "/admin/move_up.gif").escape("html") _ '" alt="Up" ' _ extras _ ' />' -:>
7c670eb8
AO
388 <:-.if down_url -:>
389 <a href="<:= down_url :>"><:= down_img |raw:></a>
a371b043
AO
390 <:-.else -:>
391 <:= blank_img |raw:>
392 <:-.end if -:>
7c670eb8
AO
393 <:-.if up_url -:>
394 <a href="<:= up_url :>"><:= up_img |raw:></a>
a371b043
AO
395 <:-.else -:>
396 <:= blank_img |raw:>
397 <:-.end if -:>
491223ee
TC
398
399<:.end define -:>
400
16fff1cd 401<:- include includes/custom/preload.tmpl optional -:>