make admin user api even saner
[bse.git] / site / templates / preload.tmpl
CommitLineData
b62cae00
TC
1<:# utility definitions :>
2<:-.define make_select-:>
19851056
TC
3 <:-.if !default.defined -:>
4 <:-.set default = "" -:>
5 <:.end if:>
411e6902 6 <select name="<:= name | html :>">
b62cae00 7 <:-.for i in list -:>
411e6902
TC
8 <option value="<:= i.$id | html :>"
9 <:- .if i.$id eq default :> selected="selected"<:.end if -:>
b62cae00 10 >
411e6902 11 <:= i.$desc | html :>
b62cae00
TC
12 <:-.end for-:>
13 </select>
14<:-.end define -:>
8f685a21
TC
15<:#
16page_list expects:
17base - base url for links
18pages - the result of the bse.pages call
19 :>
20<:-.define page_list-:>
21<:.set sep = base =~ /\?/ ? "&" : "?" -:>
22<:.set base = base _ sep :>
23<div class="pagelist">
24Page <:= pages.page :> of <:= pages.pagecount :>
25<:.if pages.previous_page -:>
26<a href="<:= base |html:><:= pages.pname | uri :>=1&amp;<:= pages.ppname | uri :>=<:= pages.pp | uri :>">&lt;&lt</a>
27<a href="<:= base |html:><:= pages.pname | uri :>=<:= pages.previous_page |uri:>&amp;<:= pages.ppname | uri :>=<:= pages.pp | uri :>">&lt;</a>
28<:.else -:>
29<span>&lt&lt</span>
30<span>&lt</span>
31<:.end if -:>
32<:.for p in pcats.pages :>
33<:.if p.link -:>
34<a href="<:= base |html :><:= pages.pname | uri:>=<:= p.page | uri :>&amp;<:=pages.ppname | uri :>=<:= pages.pp | uri :>"><:= p.page |html :></a>
35<:.else -:>
36<span><:= p.page |html:></span>
37<:.end if -:>
38<:.end for:>
39<:.if pages.next_page -:>
40<a href="<:= base |html:><:= pages.pname | uri :>=<:= pages.next_page |uri:>&amp;<:= pages.ppname | uri :>=<:= pages.pp | uri :>">&gt;</a>
41<a href="<:= base |html:><:= pages.pname | uri :>=<:= pages.pagecount |uri:>&amp;<:= pages.ppname | uri :>=<:= pages.pp | uri :>">&gt;&gt</a>
42<:.else -:>
43<span>&gt&gt</span>
44<span>&gt</span>
45<:.end if -:>
46</div>
59fca225
TC
47<:-.end define -:>
48
49<:.define old -:>
50<:# parameters: field, default -:>
51<: .if cgi.param(field).defined -:>
52<:= cgi.param(field) -:>
53<: .else -:>
54<:= default | html -:>
55<: .end if -:>
56<:.end define-:>
57
58<:.define error_img -:>
59<:# parameters: field -:>
60<:# this implementation should probably change -:>
61<:= ("error_img " _ field).evaltag -:>
80e0459c 62<:.end define -:>
16fff1cd 63
b26e625c
TC
64<:.define input -:>
65<:# paramaters:
66 name - field name
67 fields - hash of fields (may be set by page instead)
68 object - source for defaults in edit mode
69:>
70<: .set f = fields[name] -:>
71<: .if object -:>
72<: .set default = object.get(name) -:>
73<: .elsif f.default -:>
74<: .set default = f.default -:>
75<: .else -:>
76<: .set default = "" -:>
77<: .end if -:>
5522569e
TC
78<: .if f.type and f.type eq "date" and default ne "" -:>
79<: .set default = default.replace(/(\d+)\D+(\d+)\D+(\d+)/, "$3/$2/$1") -:>
80<: .elsif f.type and f.type eq "time" and default ne "" -:>
81<: .set default = bse.date(default =~ /:00$/ ? "%I:%M%p" : "%I:%M:%S%p", default).replace(/^0/, "").lower() -:>
82<: .end if -:>
83<: .if cgi.param(name).defined -:>
84<: .set default = cgi.param(name) -:>
85<: .end if -:>
b26e625c
TC
86<: .if f.htmltype eq "textarea" -:>
87<textarea id="<:= name | html :>" name="<:= name | html :>" rows="<:= f.height ? f.height : cfg.entry("forms", "textarea_rows", 10) :>" cols=<:= f.width ? f.width : cfg.entry("textarea_cols", 60) | html :>>
5522569e 88<:-= default | html -:>
b26e625c
TC
89</textarea>
90<: .elsif f.htmltype eq "checkbox" -:>
91<:.set is_checked = request.method() eq 'post' ? cgi.param(name).defined : default -:>
92<input id="<:= name | html :>" type="checkbox" name="<:= name | html :>"<:= is_checked ? ' checked="checked"' : '' :> value="<:= f.value ? f.value : 1 | html :>" />
411e6902
TC
93<: .elsif f.htmltype eq "select" -:>
94<:.set values = f.select["values"] -:>
95<:.set values = values.is_code ? values() : values -:>
96<:.call "make_select",
97 "name":name,
98 "default":default,
99 "list":values,
100 "id":f.select.id,
101 "desc":f.select.label
102-:>
b26e625c 103<: .else -:>
5522569e 104<input id="<:= name | html :>" type="text" name="<:= name | html :>" value="<:= default | html :>"
b26e625c 105<:-= f.maxlength ? ' maxlength="' _ f.maxlength _ '"' : '' :>
5522569e 106<:-= f.width ? ' size="' _ f.width _ '"' : '' :> />
b26e625c
TC
107<: .end if -:>
108<:.end define -:>
109
110<:.define field -:>
5522569e 111<:# parameters:
b26e625c
TC
112 name - field name
113 fields - hash of fields (may be set by page instead)
114:>
e9d454b4 115 <:.set f = fields[name] -:>
b26e625c 116<div>
d60f6781 117 <label for="<:= name | html :>"><:= f.nolabel ? "" : f.description | html :>:</label>
e9d454b4
TC
118 <span><:.call "input", "name":name -:><:.call "error_img", "field":name :>
119 <:-.if f.units -:>
120 <:-= f.units | html -:>
121 <:-.end if -:>
122</span>
b26e625c
TC
123</div>
124<:.end define -:>
125
126<:.define messages -:>
127<: .if request.messages.size -:>
128<div class="messages">
129<: .for m in request.messages -:>
130 <div class="<:= m.class :>"><:= m.html :></div>
131<: .end for -:>
132</div>
133<: .end if -:>
134<:.end define -:>
135
16fff1cd 136<:- include includes/custom/preload.tmpl optional -:>