1 | ## $Id: resources.py 7592 2012-02-06 16:58:55Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | """Special JavaScript and CSS resources provided by waeup.sirp. |
---|
19 | """ |
---|
20 | #from hurry import yui |
---|
21 | from hurry.resource import Library, ResourceInclusion |
---|
22 | from hurry.jqueryui import jqueryui, base, blitzer, ui_lightness, humanity |
---|
23 | from hurry.jquery import jquery |
---|
24 | |
---|
25 | |
---|
26 | #: All local resources are registered under the name ``waeup_sirp``. |
---|
27 | waeup_sirp = Library('waeup_sirp', 'static') |
---|
28 | |
---|
29 | #: A resource that binds a jQueryUI datepicker widget to each |
---|
30 | #: <div> or <input> tag with class ``datepicker``. |
---|
31 | #: If you want to let a JavaScript datepicker appear when |
---|
32 | #: clicking into some input field, then you have to perform |
---|
33 | #: two steps: |
---|
34 | #: |
---|
35 | #: * In the `update()` method of the responsible view/page/form |
---|
36 | #: require the JavaScript code to be rendered into the page:: |
---|
37 | #: |
---|
38 | #: from waeup.sirp.browser.resources import datepicker |
---|
39 | #: # ... |
---|
40 | #: class MyPage(...): |
---|
41 | #: # ... |
---|
42 | #: def update(self): |
---|
43 | #: datepicker.need() |
---|
44 | #: |
---|
45 | #: This way all required JavaScripts will be rendered correctly |
---|
46 | #: into the HTML page generated. |
---|
47 | #: |
---|
48 | #: * In your HTML code add some ``<input>`` or ``<div>`` tag with |
---|
49 | #: ``class`` set to ``datepicker``, like this: |
---|
50 | #: |
---|
51 | #: .. code-block:: html |
---|
52 | #: |
---|
53 | #: <input type="text" name="entrydate" class="datepicker" /> |
---|
54 | #: |
---|
55 | #: When the HTML is rendered, clicking into the field will open |
---|
56 | #: a datepicker widget. The datepicker functionality will be |
---|
57 | #: delivered by jQueryUI for every ``<div>/<input>`` field with class |
---|
58 | #: ``datepicker`` set. |
---|
59 | #: |
---|
60 | #: That means, you can also have several date input fields on a |
---|
61 | #: single page as long as each one has class ``datepicker``. |
---|
62 | #: |
---|
63 | #: Furthermore :func:`datepicker` supports different kinds of date |
---|
64 | #: representation from which you can choose simply by setting a |
---|
65 | #: different CSS class. The ``datepicker`` CSS mentioned above is |
---|
66 | #: only one of the following possibilities: |
---|
67 | #: |
---|
68 | #: ``"datepicker"`` |
---|
69 | #: renders date in format ``YYYY-MM-DD`` (ISO standard) |
---|
70 | #: |
---|
71 | #: ``"datepicker-year"`` |
---|
72 | #: same but also adds a select field for year |
---|
73 | #: |
---|
74 | #: ``"datepicker-le"`` |
---|
75 | #: renders date in format ``DD/MM/YYYY`` (little endian) |
---|
76 | #: |
---|
77 | #: ``"datepicker-le-year"`` |
---|
78 | #: same but also adds a select field for year |
---|
79 | #: |
---|
80 | #: ``"datepicker-de"`` |
---|
81 | #: renders date in format ``DD.MM.YYYY`` (german format) |
---|
82 | #: |
---|
83 | #: ``"datepicker-de-year"`` |
---|
84 | #: same but also adds a select field for year |
---|
85 | #: |
---|
86 | #: ``"datepicker-us"`` |
---|
87 | #: renders date in format ``MM/DD/YYYY`` (U.S. format) |
---|
88 | #: |
---|
89 | #: ``"datepicker-us-year"`` |
---|
90 | #: same but also adds a select field for year |
---|
91 | datepicker = ResourceInclusion(waeup_sirp, 'datepicker.js', |
---|
92 | depends=[jqueryui]) |
---|
93 | |
---|
94 | |
---|
95 | #: If you want generate alert or confirm messages then you have to perform |
---|
96 | #: two steps: |
---|
97 | #: |
---|
98 | #: * In the `update()` method of the responsible view/page/form |
---|
99 | #: require the JavaScript code to be rendered into the page:: |
---|
100 | #: |
---|
101 | #: from waeup.sirp.browser.resources import warning |
---|
102 | #: # ... |
---|
103 | #: class MyPage(...): |
---|
104 | #: # ... |
---|
105 | #: def update(self): |
---|
106 | #: warning.need() |
---|
107 | #: |
---|
108 | #: This way all required JavaScripts will be rendered correctly |
---|
109 | #: into the HTML page generated. |
---|
110 | #: |
---|
111 | #: In your HTML code add some <input> or <a> tag with onClick event: |
---|
112 | #: |
---|
113 | #: .. code-block:: html |
---|
114 | #: |
---|
115 | #: <input type="submit" name="xyz" value="abc"> |
---|
116 | #: onclick="return confirmPost('Are you sure?')"/> |
---|
117 | warning = ResourceInclusion(waeup_sirp, 'warning.js') |
---|
118 | |
---|
119 | #: If you have many select boxes in a from which have to be selected at the same |
---|
120 | #: time you have to perform two steps: |
---|
121 | #: |
---|
122 | #: * In the `update()` method of the responsible view/page/form |
---|
123 | #: require the JavaScript code to be rendered into the page:: |
---|
124 | #: |
---|
125 | #: from waeup.sirp.browser.resources import toggleall |
---|
126 | #: # ... |
---|
127 | #: class MyPage(...): |
---|
128 | #: # ... |
---|
129 | #: def update(self): |
---|
130 | #: toggleall.need() |
---|
131 | #: |
---|
132 | #: This way all required JavaScripts will be rendered correctly |
---|
133 | #: into the HTML page generated. |
---|
134 | #: |
---|
135 | #: In your HTML code add some <input> tag with onClick event: |
---|
136 | #: |
---|
137 | #: .. code-block:: html |
---|
138 | #: |
---|
139 | #: <input type="checkbox" onClick="toggle(this, 'entries')" /> |
---|
140 | toggleall = ResourceInclusion(waeup_sirp, 'toggleall.js') |
---|
141 | |
---|
142 | #: A resource that binds Bootstrap tabs to <div> tags with class |
---|
143 | #: ``tabs``. |
---|
144 | #: |
---|
145 | #: If you want Bootstrap tabs in your page then you |
---|
146 | #: have to perform two steps: |
---|
147 | #: |
---|
148 | #: * In the `update()` method of the responsible view/page/form |
---|
149 | #: require the JavaScript code to be rendered into the page and set |
---|
150 | #: tab for redirection:: |
---|
151 | #: |
---|
152 | #: from waeup.sirp.browser.resources import tabs |
---|
153 | #: |
---|
154 | #: class MyPage(...): |
---|
155 | #: |
---|
156 | #: def update(self): |
---|
157 | #: tabs.need() |
---|
158 | #: self.tab1 = self.tab2 = self.tab3 = '' |
---|
159 | #: qs = self.request.get('QUERY_STRING', '') |
---|
160 | #: if not qs: |
---|
161 | #: qs = 'tab1' |
---|
162 | #: setattr(self, qs, 'active') |
---|
163 | #: |
---|
164 | #: This way all required JavaScripts will be rendered correctly |
---|
165 | #: into the HTML page generated. |
---|
166 | #: |
---|
167 | #: * In your HTML code add some tags with like this: |
---|
168 | #: |
---|
169 | #: .. code-block:: html |
---|
170 | #: |
---|
171 | #: <ul class="tabs" data-tabs="tabs" > |
---|
172 | #: <li tal:attributes="class view/tab1"><a href="#tab-1">Tab 1 Heading</a></li> |
---|
173 | #: <li tal:attributes="class view/tab2"><a href="#tab-2">Tab 2 Heading</a></li> |
---|
174 | #: <li tal:attributes="class view/tab3"><a href="#tab-3">Tab 3 Heading</a></li> |
---|
175 | #: </ul> |
---|
176 | |
---|
177 | #: <div class="tab-content"> |
---|
178 | #: <div id="tab-1" tal:attributes="class view/tab1">...</div> |
---|
179 | #: <div id="tab-2" tal:attributes="class view/tab2">...</div> |
---|
180 | #: <div id="tab-3" tal:attributes="class view/tab3">...</div> |
---|
181 | #: </div> |
---|
182 | #: |
---|
183 | #: When the HTML is rendered, clicking into one of the tabs will make |
---|
184 | #: other <div>s disappear. See |
---|
185 | #: |
---|
186 | #: http://twitter.github.com/bootstrap/javascript.html#tabs |
---|
187 | #: |
---|
188 | #: for details. |
---|
189 | #: |
---|
190 | tabs = ResourceInclusion(waeup_sirp, 'bootstrap-tabs-1.4.0.js', |
---|
191 | depends=[jquery]) |
---|
192 | |
---|
193 | |
---|
194 | #: Resource that makes datatables for jQuery UI available. |
---|
195 | #: |
---|
196 | #: We register a normal version and a minified version. To make real |
---|
197 | #: use of datatables you might want to add some specialized CSS like |
---|
198 | #: `datatable_css` below. |
---|
199 | datatables = ResourceInclusion(waeup_sirp, 'jquery.dataTables.js', |
---|
200 | minified='jquery.dataTables.min.js', |
---|
201 | depends=[jquery]) |
---|
202 | |
---|
203 | #: A stylesheet for datatables |
---|
204 | datatables_css = ResourceInclusion(waeup_sirp, 'datatables.css') |
---|
205 | |
---|
206 | #: A resource that turns HTML tables into sortable, searchable and : |
---|
207 | #: multi-page widgets using jQuery and the dataTables plugin available |
---|
208 | #: from http://www.datatables.net. |
---|
209 | #: |
---|
210 | #: If you want jQuery datatables for some <table> in your page then you |
---|
211 | #: have to perform two steps: |
---|
212 | #: |
---|
213 | #: * In the `update()` method of the responsible view/page/form |
---|
214 | #: require the JavaScript code to be rendered into the page:: |
---|
215 | #: |
---|
216 | #: from waeup.sirp.browser.resources import datatable |
---|
217 | #: # ... |
---|
218 | #: class MyPage(...): |
---|
219 | #: # ... |
---|
220 | #: def update(self): |
---|
221 | #: datatable.need() |
---|
222 | #: |
---|
223 | #: This way all required JavaScripts will be rendered correctly |
---|
224 | #: into the HTML page generated. |
---|
225 | #: |
---|
226 | #: * Assign a ``display dataTable`` class to the HTML table you want to tune: |
---|
227 | #: |
---|
228 | #: .. code-block:: html |
---|
229 | #: |
---|
230 | #: <table class="display dataTable"> |
---|
231 | #: <thead> |
---|
232 | #: <tr> |
---|
233 | #: <th>Name</th><th>Title</th> |
---|
234 | #: </tr> |
---|
235 | #: </thead> |
---|
236 | #: <tbody> |
---|
237 | #: <tr class="gradeA"> |
---|
238 | #: <td>Manfred</td><td>Mammoth of the year</td> |
---|
239 | #: </tr> |
---|
240 | #: <tr class="gradeA"> |
---|
241 | #: <td>Wolfgang</td><td>Junior</td> |
---|
242 | #: </tr> |
---|
243 | #: </tbody> |
---|
244 | #: </table> |
---|
245 | #: |
---|
246 | #: When the HTML is rendered, clicking into one of the tabs will make |
---|
247 | #: other <div>s disappear. See |
---|
248 | #: |
---|
249 | #: http://www.datatables.net/ |
---|
250 | #: |
---|
251 | #: for details. |
---|
252 | #: |
---|
253 | datatable = ResourceInclusion(waeup_sirp, 'datatable.js', |
---|
254 | depends=[datatables, datatables_css]) |
---|
255 | |
---|
256 | #: Register Twitter's Bootsrap css including dropdown js as a resource. |
---|
257 | bootstrap_min = ResourceInclusion( |
---|
258 | waeup_sirp, 'bootstrap-1.4.0.css') |
---|
259 | |
---|
260 | dropdown = ResourceInclusion( |
---|
261 | waeup_sirp, 'bootstrap-dropdown-1.4.0.js', |
---|
262 | depends=[jquery]) |
---|
263 | |
---|
264 | #: Register basic SIRP CSS (which is based on ``bootstrap.min-1.4.0.css`` |
---|
265 | #: and ``base`` as a resource. |
---|
266 | waeup_base_css = ResourceInclusion( |
---|
267 | waeup_sirp, 'waeup-base.css', |
---|
268 | depends=[dropdown,bootstrap_min, base]) |
---|
269 | |
---|
270 | #: A basic theme based on jQuery only (crappy yet). |
---|
271 | waeuptheme_empty = ResourceInclusion( |
---|
272 | waeup_sirp, 'empty.css', |
---|
273 | depends=[humanity]) |
---|