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