saner formatting for time input fields
[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 -:>
78<: .if f.htmltype eq "textarea" -:>
79<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 :>>
80<:- .call "old", "field":name, "default":default -:>
81</textarea>
82<: .elsif f.htmltype eq "checkbox" -:>
83<:.set is_checked = request.method() eq 'post' ? cgi.param(name).defined : default -:>
84<input id="<:= name | html :>" type="checkbox" name="<:= name | html :>"<:= is_checked ? ' checked="checked"' : '' :> value="<:= f.value ? f.value : 1 | html :>" />
411e6902
TC
85<: .elsif f.htmltype eq "select" -:>
86<:.set values = f.select["values"] -:>
87<:.set values = values.is_code ? values() : values -:>
88<:.call "make_select",
89 "name":name,
90 "default":default,
91 "list":values,
92 "id":f.select.id,
93 "desc":f.select.label
94-:>
b26e625c 95<: .else -:>
94b73c89
TC
96<: .if f.type and f.type eq "date" and default ne "" -:>
97<: .set default = default.replace(/(\d+)\D+(\d+)\D+(\d+)/, "$3/$2/$1") -:>
844ccd44
TC
98<: .elsif f.type and f.type eq "time" and default ne "" -:>
99<: .set default = bse.date(default =~ /:00$/ ? "%I:%M%p" : "%I:%M:%S%p", default).replace(/^0/, "").lower() -:>
94b73c89 100<: .end if -:>
b26e625c
TC
101<input id="<:= name | html :>" type="text" name="<:= name | html :>" value="<:.call "old", "field":name, "default":default :>"
102<:-= f.maxlength ? ' maxlength="' _ f.maxlength _ '"' : '' :>
103<:= f.width ? 'size="' _ f.width _ '"' : '' :> />
104<: .end if -:>
105<:.end define -:>
106
107<:.define field -:>
108<:# paramaters:
109 name - field name
110 fields - hash of fields (may be set by page instead)
111:>
e9d454b4 112 <:.set f = fields[name] -:>
b26e625c 113<div>
d60f6781 114 <label for="<:= name | html :>"><:= f.nolabel ? "" : f.description | html :>:</label>
e9d454b4
TC
115 <span><:.call "input", "name":name -:><:.call "error_img", "field":name :>
116 <:-.if f.units -:>
117 <:-= f.units | html -:>
118 <:-.end if -:>
119</span>
b26e625c
TC
120</div>
121<:.end define -:>
122
123<:.define messages -:>
124<: .if request.messages.size -:>
125<div class="messages">
126<: .for m in request.messages -:>
127 <div class="<:= m.class :>"><:= m.html :></div>
128<: .end for -:>
129</div>
130<: .end if -:>
131<:.end define -:>
132
16fff1cd 133<:- include includes/custom/preload.tmpl optional -:>