add rule mechanisms for real number validation
[bse.git] / site / templates / preload.tmpl
CommitLineData
2de83e20
TC
1<:.set groups = 0 -:>
2<:.set grouplabel = "label" -:>
3<:.set groupid = "id" -:>
4<:.set itemgroupid = "groupid" -:>
b62cae00
TC
5<:# utility definitions :>
6<:-.define make_select-:>
19851056
TC
7 <:-.if !default.defined -:>
8 <:-.set default = "" -:>
9 <:.end if:>
411e6902 10 <select name="<:= name | html :>">
2de83e20
TC
11 <:- .if groups -:>
12 <:-.for i in list -:>
13 <:.if i.$itemgroupid eq "" -:>
411e6902 14 <option value="<:= i.$id | html :>"
2de83e20 15 <:- .if i.$id eq default :> selected="selected"<:.end if -:>
b62cae00 16 >
2de83e20
TC
17 <:-= i.$desc | html -:>
18 <:.end if -:>
19 <:.end for -:>
20 <:-.for g in groups -:>
21 <optgroup label="<:= g.$grouplabel | html -:>">
22 <:-.for i in list -:>
23 <:.if i.$itemgroupid == g.$groupid -:>
24 <option value="<:= i.$id | html :>"
25 <:- .if i.$id eq default :> selected="selected"<:.end if -:>
26 >
27 <:-= i.$desc | html -:>
28 <:.end if -:>
29 <:.end for -:>
30 </optgroup>
31 <:-.end for -:>
32 <:- .else -:>
33 <:-.for i in list -:>
34 <option value="<:= i.$id | html :>"
35 <:- .if i.$id eq default :> selected="selected"<:.end if -:>
36 >
37 <:-= i.$desc | html -:>
38 <:-.end for-:>
39 <:-.end if -:>
b62cae00
TC
40 </select>
41<:-.end define -:>
8f685a21
TC
42<:#
43page_list expects:
44base - base url for links
45pages - the result of the bse.pages call
46 :>
47<:-.define page_list-:>
48<:.set sep = base =~ /\?/ ? "&" : "?" -:>
49<:.set base = base _ sep :>
50<div class="pagelist">
51Page <:= pages.page :> of <:= pages.pagecount :>
52<:.if pages.previous_page -:>
53<a href="<:= base |html:><:= pages.pname | uri :>=1&amp;<:= pages.ppname | uri :>=<:= pages.pp | uri :>">&lt;&lt</a>
54<a href="<:= base |html:><:= pages.pname | uri :>=<:= pages.previous_page |uri:>&amp;<:= pages.ppname | uri :>=<:= pages.pp | uri :>">&lt;</a>
55<:.else -:>
56<span>&lt&lt</span>
57<span>&lt</span>
58<:.end if -:>
59<:.for p in pcats.pages :>
60<:.if p.link -:>
61<a href="<:= base |html :><:= pages.pname | uri:>=<:= p.page | uri :>&amp;<:=pages.ppname | uri :>=<:= pages.pp | uri :>"><:= p.page |html :></a>
62<:.else -:>
63<span><:= p.page |html:></span>
64<:.end if -:>
65<:.end for:>
66<:.if pages.next_page -:>
67<a href="<:= base |html:><:= pages.pname | uri :>=<:= pages.next_page |uri:>&amp;<:= pages.ppname | uri :>=<:= pages.pp | uri :>">&gt;</a>
68<a href="<:= base |html:><:= pages.pname | uri :>=<:= pages.pagecount |uri:>&amp;<:= pages.ppname | uri :>=<:= pages.pp | uri :>">&gt;&gt</a>
69<:.else -:>
70<span>&gt&gt</span>
71<span>&gt</span>
72<:.end if -:>
73</div>
59fca225
TC
74<:-.end define -:>
75
76<:.define old -:>
77<:# parameters: field, default -:>
78<: .if cgi.param(field).defined -:>
79<:= cgi.param(field) -:>
80<: .else -:>
81<:= default | html -:>
82<: .end if -:>
83<:.end define-:>
84
85<:.define error_img -:>
86<:# parameters: field -:>
87<:# this implementation should probably change -:>
6f186c3b 88<:= ("error_img " _ field).evaltag |raw -:>
80e0459c 89<:.end define -:>
16fff1cd 90
b26e625c
TC
91<:.define input -:>
92<:# paramaters:
93 name - field name
94 fields - hash of fields (may be set by page instead)
95 object - source for defaults in edit mode
96:>
97<: .set f = fields[name] -:>
98<: .if object -:>
99<: .set default = object.get(name) -:>
100<: .elsif f.default -:>
101<: .set default = f.default -:>
102<: .else -:>
103<: .set default = "" -:>
104<: .end if -:>
5522569e
TC
105<: .if f.type and f.type eq "date" and default ne "" -:>
106<: .set default = default.replace(/(\d+)\D+(\d+)\D+(\d+)/, "$3/$2/$1") -:>
107<: .elsif f.type and f.type eq "time" and default ne "" -:>
108<: .set default = bse.date(default =~ /:00$/ ? "%I:%M%p" : "%I:%M:%S%p", default).replace(/^0/, "").lower() -:>
109<: .end if -:>
110<: .if cgi.param(name).defined -:>
111<: .set default = cgi.param(name) -:>
112<: .end if -:>
b26e625c
TC
113<: .if f.htmltype eq "textarea" -:>
114<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 115<:-= default | html -:>
b26e625c
TC
116</textarea>
117<: .elsif f.htmltype eq "checkbox" -:>
118<:.set is_checked = request.method() eq 'post' ? cgi.param(name).defined : default -:>
119<input id="<:= name | html :>" type="checkbox" name="<:= name | html :>"<:= is_checked ? ' checked="checked"' : '' :> value="<:= f.value ? f.value : 1 | html :>" />
411e6902
TC
120<: .elsif f.htmltype eq "select" -:>
121<:.set values = f.select["values"] -:>
122<:.set values = values.is_code ? values() : values -:>
123<:.call "make_select",
124 "name":name,
125 "default":default,
126 "list":values,
127 "id":f.select.id,
2de83e20
TC
128 "desc":f.select.label,
129 "groupid": (f.select.groupid or "id"),
130 "itemgroupid": (f.select.itemgroupid or "groupid"),
131 "groups": f.select.groups ? (f.select.groups.is_code ? (f.select.groups)() : f.select.groups ) : 0,
132 "grouplabel": (f.select.grouplabel or "label")
411e6902 133-:>
b26e625c 134<: .else -:>
5522569e 135<input id="<:= name | html :>" type="text" name="<:= name | html :>" value="<:= default | html :>"
b26e625c 136<:-= f.maxlength ? ' maxlength="' _ f.maxlength _ '"' : '' :>
5522569e 137<:-= f.width ? ' size="' _ f.width _ '"' : '' :> />
b26e625c
TC
138<: .end if -:>
139<:.end define -:>
140
141<:.define field -:>
5522569e 142<:# parameters:
b26e625c
TC
143 name - field name
144 fields - hash of fields (may be set by page instead)
145:>
e9d454b4 146 <:.set f = fields[name] -:>
b26e625c 147<div>
d60f6781 148 <label for="<:= name | html :>"><:= f.nolabel ? "" : f.description | html :>:</label>
e9d454b4
TC
149 <span><:.call "input", "name":name -:><:.call "error_img", "field":name :>
150 <:-.if f.units -:>
151 <:-= f.units | html -:>
152 <:-.end if -:>
153</span>
b26e625c
TC
154</div>
155<:.end define -:>
156
157<:.define messages -:>
158<: .if request.messages.size -:>
159<div class="messages">
160<: .for m in request.messages -:>
6f186c3b 161 <div class="<:= m.class :>"><:= m.html |raw :></div>
b26e625c
TC
162<: .end for -:>
163</div>
164<: .end if -:>
165<:.end define -:>
166
491223ee
TC
167<:.define mover -:>
168<:# expects loop, parent
169 which in most cases means you can just supply parent
170-:>
171<:.set distim = cfg.entryIfVar("uri", "dist_images", "/images") -:>
172<:.set width = cfg.entry("arrows", "width", 17) -:>
173<:.set height = cfg.entry("arrows", "height", 13) -:>
174<:.set extras = 'width="' _ width _ '" height="' _ height _ '"' -:>
175<:.set blankim = '<img src="' _ (distim _ "/trans_pixel.gif").escape("html") _ '" alt="" ' _ extras _ ' />' -:>
176<:.if loop.prev -:>
177 <:.set upimg = cfg.entry("arrows", "upimg", distim _ "/admin/move_up.gif") -:>
178<a href="<:= cfg.admin_url("move", { "stepparent":parent.id, "d":"swap", "id":loop.current.id, "other":loop.prev.id, "r":top.admin }) :>"><img src="<:= upimg :>" <:= extras :> /></a>
179<:.else -:>
180<:= blankim |raw-:>
181<:.end if -:>
182<:.if loop.next -:>
183 <:.set downimg = cfg.entry("arrows", "downimg", distim _ "/admin/move_down.gif") -:>
184<a href="<:= cfg.admin_url("move", { "stepparent":parent.id, "d":"swap", "id":loop.current.id, "other":loop.next.id, "r":top.admin }) :>"><img src="<:= downimg :>" <:= extras :> /></a>
185<:.else -:>
186<:= blankim |raw-:>
187<:.end if -:>
188
189<:.end define -:>
190
16fff1cd 191<:- include includes/custom/preload.tmpl optional -:>