allow editing image tags on the big image tool page
[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 -:>
896e13b5 92<:.for p in pages.pages :>
8f685a21
TC
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
6436e424
TC
109<:.define old; default: "", index: 0 -:>
110<:# parameters: field, default, index -:>
111<: .set vals = [ cgi.param(field) ] -:>
112<: .if index < vals.size -:>
113<:= vals[index] -:>
59fca225
TC
114<: .else -:>
115<:= default | html -:>
116<: .end if -:>
117<:.end define-:>
118
5251d8e2
TC
119<:.define error_img_n -:>
120<:# parameters:
121 field - name of field
122 index - index of field
123 errors - hash of error messages (should be set by code)
124-:>
125 <:.if errors.$field -:>
126 <:.set msg = errors.$field -:>
127 <:.set msg = msg.is_list ? msg[index] : msg -:>
c46eae4a
TC
128 <:.if msg.defined -:>
129 <:.set image = cfg.entry("error_img", "image", dist_image_uri _ "/admin/error.gif") -:>
130 <:.set width = cfg.entry("error_img", "width", 16) -:>
131 <:.set height = cfg.entry("error_img", "height", 16) -:>
5251d8e2 132 <img src="<:= image -:>" alt="<:= msg :>" title="<:= msg :>" width="<:= width :>" height="<:= height :>" class="error_img">
c46eae4a 133 <:.end if -:>
5251d8e2
TC
134 <:.end if -:>
135<:.end define -:>
136
59fca225 137<:.define error_img -:>
d1132d88 138<:.call "error_img_n", index:0 -:>
80e0459c 139<:.end define -:>
16fff1cd 140
6dd128ea 141<:.define input; options: {} -:>
c6369510 142<:# parameters:
b26e625c 143 name - field name
f04ca377 144 field - entry from fields
b26e625c 145 object - source for defaults in edit mode
4029e8ab 146-:>
6dd128ea
TC
147<: .set default = options.default -:>
148<: .if !default.defined -:>
149<: .if object -:>
150<: .set default = object.$name -:>
151<: .elsif field.default -:>
152<: .set default = field.default -:>
153<: .else -:>
154<: .set default = "" -:>
155<: .end if -:>
b26e625c 156<: .end if -:>
f04ca377 157<: .if field.type and field.type eq "date" and default ne "" -:>
5522569e 158<: .set default = default.replace(/(\d+)\D+(\d+)\D+(\d+)/, "$3/$2/$1") -:>
f04ca377 159<: .elsif field.type and field.type eq "time" and default ne "" -:>
5522569e
TC
160<: .set default = bse.date(default =~ /:00$/ ? "%I:%M%p" : "%I:%M:%S%p", default).replace(/^0/, "").lower() -:>
161<: .end if -:>
162<: .if cgi.param(name).defined -:>
163<: .set default = cgi.param(name) -:>
164<: .end if -:>
f04ca377 165<: .if field.htmltype eq "textarea" -:>
6dd128ea 166<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("forms", "textarea_cols", 60) | html :>>
5522569e 167<:-= default | html -:>
b26e625c 168</textarea>
f04ca377
TC
169<: .elsif field.htmltype eq "checkbox" -:>
170<:.set is_checked = cgi.param("_save_" _ name) ? cgi.param(name).defined : default -:>
171<input type="hidden" name="_save_<:= name -:>" value="1">
172<input id="<:= name | html :>" type="checkbox" name="<:= name | html :>"<:= is_checked ? ' checked="checked"' : '' :> value="<:= field.value ? field.value : 1 | html :>" />
173<: .elsif field.htmltype eq "multicheck" -:>
174<:# we expect default to be a list of selected checks -:>
175<:.set values = field.select["values"] -:>
176<:.set values = values.is_code ? values() : values -:>
177<:.set default = cgi.param("_save_" _ name) ? [ cgi.param(name) ] : default -:>
178<:.call "make_multicheck",
d1132d88
TC
179 id:field.select.id,
180 desc:field.select.label -:>
f04ca377
TC
181<: .elsif field.htmltype eq "select" -:>
182<:.set values = field.select["values"] -:>
411e6902
TC
183<:.set values = values.is_code ? values() : values -:>
184<:.call "make_select",
d1132d88
TC
185 name: name,
186 default: default,
187 list: values,
188 id: field.select.id,
189 desc: field.select.label,
190 groupid : (field.select.groupid or "id"),
191 itemgroupid: (field.select.itemgroupid or "groupid"),
192 groups: field.select.groups ? (field.select.groups.is_code ? (field.select.groups)() : field.select.groups ) : 0,
193 grouplabel: (field.select.grouplabel or "label")
411e6902 194-:>
4029e8ab
TC
195<: .elsif field.htmltype eq 'file' -:>
196<: .if default.length -:>
197<span class="filename"><:= default :></span>
198<: .end if -:>
199<input id="<:= name :>" type="file" name="<:= name :>" />
200<:- .else -:>
5522569e 201<input id="<:= name | html :>" type="text" name="<:= name | html :>" value="<:= default | html :>"
f04ca377
TC
202<:-= field.maxlength ? ' maxlength="' _ field.maxlength _ '"' : '' |raw:>
203<:-= field.width ? ' size="' _ field.width _ '"' : '' | raw :> />
b26e625c
TC
204<: .end if -:>
205<:.end define -:>
206
6dd128ea 207<:.define field; options: {} -:>
5522569e 208<:# parameters:
b26e625c
TC
209 name - field name
210 fields - hash of fields (may be set by page instead)
6dd128ea
TC
211 object - object containing defaults (can be set globally instead)
212 default - a default value not dependent on object (overrides object)
b26e625c 213:>
f04ca377
TC
214 <:.if fields.is_hash -:>
215 <:.set f = fields[name] -:>
216 <:.if f -:>
6dd128ea 217 <:.call "inlinefield", field:f, name:name, options: options -:>
f04ca377
TC
218 <:.else -:>
219<p>Unknown field id '<b><:= name :></b>', available fields are '<:= fields.keys.join("', '") :>'</p>
220 <:.end if -:>
221 <:.else -:>
222<p>fields isn't a hash, something is wrong.</p>
223 <:.end if -:>
224<:.end define -:>
225
6dd128ea 226<:.define inlinefield; options: {} -:>
f04ca377
TC
227<:# parameters:
228 name - the field name
229 field - a field, as an entry in fields
c29434c9
TC
230 options - various options, including:
231 note - display this text as a note below the field
232 delete - add a delete checkbox
233 default - a custom default value, overrides object
f04ca377
TC
234-:>
235 <:.if field.is_hash -:>
b26e625c 236<div>
c29434c9 237 <label for="<:= name :>"><:= field.nolabel ? "" : field.description | html :>:</label>
2ced88e0
TC
238 <span>
239 <:-.if field.readonly -:>
6dd128ea 240<:-.call "display", name:name, options: options -:>
2ced88e0 241 <:.else -:>
6dd128ea 242<:-.call "input", name:name, options: options -:><:.call "error_img", field:name :>
2ced88e0 243 <:-.end if -:>
f04ca377
TC
244 <:-.if field.units -:>
245 <:-= field.units | html -:>
246 <:-.end if -:>
6dd128ea
TC
247 <:-.if options.note -:>
248<br /><:= options.note | raw :>
249 <:-.end if -:>
c29434c9
TC
250 <:-.if options["delete"] -:>
251<br /><input type="checkbox" name="delete_<:= name :>" value="1" id="delete_<:= name :>"><label for="delete_<:= name :>">Delete</label>
252 <:-.end if -:>
f04ca377
TC
253</span>
254</div>
672a2e42 255 <:.end if -:>
f04ca377
TC
256<:.end define -:>
257
258<:.define fieldset -:>
259<:# like field, but wrap in a per-field field set.
260parameters:
261 name - field name
262 fields - hash of fields (may be set by page instead)
263:>
264 <:.set f = fields[name] -:>
265 <:.if f.is_hash -:>
266<fieldset>
267 <:.if !f.nolabel -:>
268 <legend><:= f.description :></legend>
269 <:.end if -:>
d1132d88 270 <:.call "input", name: name, field: f -:>
f04ca377
TC
271</fieldset>
272 <:.elsif fields.is_hash -:>
273<p>Unknown field id '<b><:= name :></b>', available fields are '<:= fields.keys.join("', '") :>'</p>
274 <:.else -:>
275<p>fields isn't a hash, something is wrong.</p>
276 <:.end if -:>
277<:.end define -:>
278
279<:.define display -:>
280<:# paramaters:
281 name - field name
282 field - entry from fields
283 object - source for defaults in edit mode
284:>
285<: .if object -:>
286<: .set default = object.$name -:>
287<: .end if -:>
288<: .if field.type and field.type eq "date" and default ne "" -:>
289<: .set default = default.replace(/(\d+)\D+(\d+)\D+(\d+)/, "$3/$2/$1") -:>
290<: .elsif field.type and field.type eq "time" and default ne "" -:>
291<: .set default = bse.date(default =~ /:00$/ ? "%I:%M%p" : "%I:%M:%S%p", default).replace(/^0/, "").lower() -:>
292<: .end if -:>
293<: .if field.htmltype eq "textarea" -:>
294<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>
295<:-= default | html -:>
296</textarea>
297<: .elsif field.htmltype eq "checkbox" -:>
298<input id="<:= name | html :>" type="checkbox" name="<:= name | html :>"<:= is_checked ? ' checked="checked"' : '' :> value="<:= field.value ? field.value : 1 | html :>" readonly>
299<: .elsif field.htmltype eq "multicheck" -:>
300<:# we expect default to be a list of selected checks -:>
301<:.set values = field.select["values"] -:>
302<:.set values = values.is_code ? values() : values -:>
303<:.call "make_multicheck",
d1132d88
TC
304 id: field.select.id,
305 desc: field.select.label,
306 readonly: 1 -:>
f04ca377
TC
307<: .elsif field.htmltype eq "select" -:>
308<:.set values = field.select["values"] -:>
309<:.set values = values.is_code ? values() : values -:>
310<:# find the selected value and display it's label -:>
311<:.set sid = field.select.id -:>
312<:.set sdesc = field.select.label -:>
313<:.for value in values -:>
314 <:.if value.$id eq default -:>
315 <:= value.$desc -:>
316 <:.end if -:>
317<:.end for -:>
318<: .else -:>
319<input id="<:= name :>" type="text" name="<:= name :>" value="<:= default :>"
320<:-= field.width ? ' size="' _ field.width _ '"' : '' | raw :> readonly>
321<: .end if -:>
322<:.end define -:>
323
324<:.define inlinefieldro -:>
325<:# parameters:
326 name - the field name
327 field - a field, as an entry in fields
328-:>
329 <:.if field.is_hash -:>
330<div>
331 <label for="<:= name :>"><:= field.nolabel ? "" : field.description :>:</label>
d1132d88 332 <span><:.call "display", name:name -:>
f04ca377
TC
333 <:-.if field.units -:>
334 <:-= field.units -:>
335 <:-.end if -:>
336 <:.end if -:>
e9d454b4 337</span>
b26e625c
TC
338</div>
339<:.end define -:>
340
f04ca377
TC
341<:.define fieldro -:>
342<:# like field, but for display, not editing -:>
343 <:.if fields.is_hash -:>
344 <:.set f = fields[name] -:>
345 <:.if f -:>
d1132d88 346 <:.call "inlinefieldro", field:f, name:name -:>
f04ca377
TC
347 <:.else -:>
348<p>Unknown field id '<b><:= name :></b>', available fields are '<:= fields.keys.join("', '") :>'</p>
349 <:.end if -:>
350 <:.else -:>
351<p>fields isn't a hash, something is wrong.</p>
352 <:.end if -:>
353<:.end define -:>
354
355<:.define fieldsetro -:>
356<:# like fieldro, but wrap in a per-field field set.
357parameters:
358 name - field name
359 fields - hash of fields (may be set by page instead)
360:>
361 <:.set f = fields[name] -:>
362 <:.if f.is_hash -:>
363<fieldset>
364 <:.if !f.nolabel -:>
365 <legend><:= f.description :></legend>
366 <:.end if -:>
367 <:.call "display", "name":name, "field":f -:>
368</fieldset>
369 <:.elsif fields.is_hash -:>
370<p>Unknown field id '<b><:= name :></b>', available fields are '<:= fields.keys.join("', '") :>'</p>
371 <:.else -:>
372<p>fields isn't a hash, something is wrong.</p>
373 <:.end if -:>
374<:.end define -:>
375
b26e625c
TC
376<:.define messages -:>
377<: .if request.messages.size -:>
378<div class="messages">
379<: .for m in request.messages -:>
6f186c3b 380 <div class="<:= m.class :>"><:= m.html |raw :></div>
b26e625c
TC
381<: .end for -:>
382</div>
383<: .end if -:>
384<:.end define -:>
385
491223ee 386<:.define mover -:>
f34ff248 387<:# expects loop, request, parent
491223ee
TC
388 which in most cases means you can just supply parent
389-:>
f34ff248 390<:.if request.user_can("bse_edit_reorder_children", parent) -:>
7c670eb8
AO
391 <:.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 -:>
392 <:.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 -:>
393 <:.set class = cfg.entry("arrows", "class", "bse_arrows") -:>
394 <span class="<:= m.class :>">
395 <:-.call "make_arrows", "down_url":down_url, "up_url":up_url -:>
396 </span>
397<:.end if -:>
398<:.end define -:>
399
400<:.define make_arrows -:>
401<:# expects down_url, up_url
402-:>
1fa69b29
AO
403 <:.set width = cfg.entry("arrows", "image_width", 17) -:>
404 <:.set height = cfg.entry("arrows", "image_height", 13) -:>
f34ff248 405 <:.set extras = 'width="' _ width _ '" height="' _ height _ '"' -:>
f56525a7
AO
406 <:.set blank_img = '<img src="' _ (dist_image_uri _ "/trans_pixel.gif").escape("html") _ '" alt="" ' _ extras _ ' />' -:>
407 <:.set down_img = '<img src="' _ cfg.entry("arrows", "downimg", dist_image_uri _ "/admin/move_down.gif").escape("html") _ '" alt="Down" ' _ extras _ ' />' -:>
408 <:.set up_img = '<img src="' _ cfg.entry("arrows", "upimg", dist_image_uri _ "/admin/move_up.gif").escape("html") _ '" alt="Up" ' _ extras _ ' />' -:>
7c670eb8
AO
409 <:-.if down_url -:>
410 <a href="<:= down_url :>"><:= down_img |raw:></a>
a371b043
AO
411 <:-.else -:>
412 <:= blank_img |raw:>
413 <:-.end if -:>
7c670eb8
AO
414 <:-.if up_url -:>
415 <a href="<:= up_url :>"><:= up_img |raw:></a>
a371b043
AO
416 <:-.else -:>
417 <:= blank_img |raw:>
418 <:-.end if -:>
491223ee
TC
419
420<:.end define -:>
421
3027c97c
TC
422<:.define word_wrap; text: @undef, prefix:"", noncontin: "", contin:"", escape1: "", escape2: "", width: 70 -:>
423<:# Word wrap "text" at width columns, following settings:
424width - word wrap width (default 70)
425prefix - prefix to add to all lines
426noncontin - prefix to additionally add to first line of each paragraph
427contin - prefix to additionally add to lines that have been wrapped
428escape1 - suffix to add to lines wrapped on a non-word
429escape2 - suffix to add to lines wrapped on a word boundary
430-:>
431<:.set re = "^.{1," _ width _ "}\\s+" -:>
432<:.set paras = text.split(/\n/) -:>
433<:.for para in paras -:>
434<: .set work = para -:>
435<: .set first = 1 -:>
436<: .while work.length -:>
437<: .if !first -:>
438<: .set work = work.replace(/^\s+/, "") -:>
439<: .end if -:>
440<: .if work.length < 70 -:>
441<: .set line = work -:>
442<: .set work = "" -:>
443<: .else -:>
444<: .set m = work.match(re) -:>
445<: .if m -:>
446<: .set line = work.substring(0, m.length).replace(/\s+$/, "") _ escape2 -:>
447<: .set work = work.substring(m.length) -:>
448<: .else -:>
449<: .set line = work.substring(0, width) _ escape1 -:>
450<: .set work = work.substring(width) -:>
451<: .end if -:>
452<: .end if -:>
453<:= prefix _ (first ? noncontin : contin) _ line.replace(/\s+$/, "") |raw:>
454<: .set first = 0 -:>
455<: .end while -:>
456<:.end for -:>
457<:.end define -:>
458
16fff1cd 459<:- include includes/custom/preload.tmpl optional -:>