9399911f10fac897e8fb6f06b6c11b9893e16de8
[Evergreen.git] / Open-ILS / src / reporter / templates / stage1.ttk
1 [%
2
3 PROCESS inputs;
4 PROCESS logic_header.ttk;
5
6 WRAPPER html/html;
7         INCLUDE header.ttk title="Basic Report Types";
8         WRAPPER html/body html.body.onload=
9                                                                 "if (document.getElementById('templatename')) {" _
10                                                                 "document.getElementById('templatename').focus();" _
11                                                                 "document.getElementById('templatename').select();}";
12                 INCLUDE logout.ttk;
13                 IF !CGI.param('id');
14                         IF CGI.param('detail');
15                                 %]|<a href="?detail=0">No Details (All)</a>[%
16                         ELSE;
17                                 %]|<a href="?detail=1">Details (All)</a>[%
18                         END;
19                         PROCESS all_stage1;
20                 ELSE;
21                         PROCESS one_stage1;
22                 END;
23         END;
24         INCLUDE footer.ttk;
25 END;
26
27
28
29
30 #=============================================================================
31
32
33 BLOCK one_stage1;
34         %]|<a href="[%
35         CGI.url('-absolute',1,'-path_info',1,'-query',1).replace('[&\?;]?id=[\w\.]+','');
36         %]">Show all</a>[%
37
38         table_xpath =
39                 '/reporter/tables/table[@id="' _
40                 CGI.param('id') _ '"]';
41         table = config.findnodes(table_xpath);
42
43         fact_table = table.findvalue('@id');
44         logme(fact_table);
45
46         INCLUDE stage1_summary;
47         INCLUDE stage2_new IF CGI.param('create_stage2') == 1;
48
49 END;
50
51
52
53
54 BLOCK all_stage1;
55         '<ul>';
56
57         FOR tab IN config.findnodes("//tables/table[@fact-table='true']");
58
59                 fact_table = tab.findvalue("@id");
60                 logme("Fact Table is $fact_table");
61
62                 '<li>';
63
64                 INCLUDE stage1_summary links = 1 table = tab;
65
66                 IF loop.count != loop.size;
67                 '<hr>';
68                 END;
69         END;
70         '</ul>';
71 END;
72
73
74
75
76 BLOCK stage1_summary links=0;
77         fact_table = table.findvalue('@id');
78         WRAPPER html/table width="100%";
79                 WRAPPER html/row;
80                         WRAPPER html/cell align="right";
81                                 %]<b>Name:</b>[%
82                         END;
83                         WRAPPER html/cell;
84                                 table.findvalue('label');
85                         END;
86                 END;
87                 WRAPPER html/row;
88                         WRAPPER html/cell align="right";
89                                 %]<b>Description:</b>[%
90                         END;
91                         WRAPPER html/cell;
92                                 table.findvalue('description');
93                         END;
94                 END;
95                 WRAPPER html/row;
96                         WRAPPER html/cell align="right";
97                                 %]<b>Actions:</b>[%
98                         END;
99                         WRAPPER html/cell;
100                                 IF CGI.param('detail');
101                                         %]<a href="?detail=0&id=[% fact_table %]">No Details</a>[%
102                                 ELSE;
103                                         %]<a href="?detail=1&id=[% fact_table %]">Details</a>[%
104                                 END;
105                                 %]|<a href="?create_stage2=1&id=[% fact_table %]">New Report Template</a>[%
106                         END;
107                 END;
108                 WRAPPER html/row;
109                         WRAPPER html/cell align="right" valign='top';
110                                 %]Report Templates:[%
111                         END;
112                         WRAPPER html/cell;
113                                 q = 'select * from reporter.stage2 ' _
114                                         'where pub is true or owner = ' _ DBI.quote(user.id());
115                                 FOR r IN DBI.query(q);
116                                         INCLUDE anchor
117                                                 href="stage2?id=" _ r.id
118                                                 text=utils.JSON2perl(r.params).templatename;
119                                                 '<br>';
120                                 END;
121                         END;
122                 END;
123
124                 PROCESS stage1_detail IF CGI.param('detail') == 1;
125         END;
126 END;
127
128
129 %][%
130
131 BLOCK stage2_new;
132         col_xpath = "/reporter/tables/table[@id='" _ fact_table _ "']/fields/field[@core='true']";
133         logme(col_xpath);
134
135         %]<br/><form id="stage2_new" name="stage2_new" action="stage2" method="POST">
136                 <input type="hidden" name="action" value="save">
137                         <input type="hidden" name="stage1" value="[% CGI.param('id') %]">
138                         <input type="text" name="templatename" id="templatename"
139                                 size="40" value="Template name (required)"><br/>
140                         <input type="checkbox" name="publictemplate" value="t">
141                                 Public template<br><br>[%
142
143         
144         WRAPPER html/table width="100%" border=1;
145                 WRAPPER html/row;
146                         WRAPPER html/cell colspan=2;
147                                 # hidden input here ...
148                                 table = config.findnodes("/reporter/tables/table[@id='$fact_table']");
149                                 INCLUDE hidden name="filter" value=fact_table;
150                                 table.findvalue('label');
151                                 ' Core Columns';
152                         END;
153                 END;
154                 INCLUDE widget_selector tableid=fact_table columns=config.findnodes(col_xpath) force=1;
155         END;
156
157         dim_xpath = "/reporter/tables/table[@id='$fact_table']/links/link/@table";
158         FOR dim_table IN config.findnodes(dim_xpath);
159                 dim_table = dim_table.value();
160                 dimension = config.findnodes("/reporter/tables/table[@id='$dim_table']");
161
162                 WRAPPER html/table width="100%" border=1;
163                         WRAPPER html/row;
164                                 WRAPPER html/cell colspan=2;
165                                         # checkbox input here ...
166                                         INCLUDE checkbox name="filter" value=dim_table checked=1;
167                                         dimension.findvalue('label');
168                                         ' Dimension';
169                                 END;
170                         END;
171                         INCLUDE widget_selector tableid=dim_table;
172                 END;
173         END;
174
175         INCLUDE submit name='button' value='Save';
176
177         %]</form>[%
178
179 END;
180
181
182 BLOCK widget_selector;
183
184         logme("widget_selector called for table $tableid");
185
186         #   if we got some columns, use them. if not, get all non-primary columns
187         IF ! columns;
188                 columns_xpath =
189                         '/reporter/tables/table[@id="' _ tableid _
190                         '"]/fields/field[not(@primary) or @primary!="true"]'
191                 columns = config.findnodes(columns_xpath);
192                 logme("widget_selector had to grab columns for table $tableid!");
193         END;
194
195         column_input_type="checkbox";
196         IF force;
197                 column_input_type="hidden";
198         END;
199
200         FOR column IN columns;
201                 column_name=column.findvalue('@name');
202
203                 WRAPPER html/row;
204                         WRAPPER html/cell valign='top' align='right';
205                                 # checkbox for column filter here ...
206                                 INCLUDE $column_input_type
207                                         name="filter:$tableid"
208                                         value=column_name
209                                         checked=1; 
210                                 column.findvalue('label');
211                         END;
212                         WRAPPER html/cell;
213
214                                 col_widget_fams_xpath =
215                                         '/reporter/widgets/widget-family[@datatype="' _
216                                         column.findvalue('@datatype') _ '"]';
217
218                                 IF column.findnodes('@widget-family');
219                                         col_widget_fams_xpath =
220                                                 '/reporter/widgets/widget-family[@name="' _
221                                                 column.findvalue('@widget-family') _ '"]';
222                                 END;
223
224                                 logme("finding widget families using $col_widget_fams_xpath");
225
226                                 widget_fams = config.findnodes(col_widget_fams_xpath);
227
228                                 '<UL>';
229                                 FOR fam IN widget_fams;
230
231                                         fam_input = 'radio';
232                                         IF loop.size == 1;
233                                                 fam_input = 'hidden';
234                                         END;
235
236                                         checked = 0;
237                                         IF loop.count == 1;
238                                                 checked = 1;
239                                         END;
240
241                                         fam_name = fam.findvalue('@name');
242                                         # radio for widget family here ...
243                                         '<LI>';
244                                         INCLUDE $fam_input
245                                                 name="filter:$tableid:$column_name"
246                                                 value= fam_name;
247                                         fam.findvalue('label');
248                                         '<UL>';
249                                         
250                                         FOR widget IN fam.findnodes('widget');
251
252                                                 fam_input = 'radio';
253                                                 IF loop.size == 1;
254                                                         fam_input = 'hidden';
255                                                 END;
256
257                                                 checked = 0;
258                                                 IF loop.count == 1;
259                                                         checked = 1;
260                                                 END;
261
262                                                 widget_name = widget.findvalue('@name');
263                                                 # radio for widget here ...
264                                                 '<LI>';
265                                                 INCLUDE $fam_input
266                                                         name="filter:$tableid:$column_name:$fam_name"
267                                                         value= widget_name;
268                                                 widget.findvalue('label');
269                                                 '</LI>';
270                                         END;
271                                         '</UL>';
272                                         '</LI>';
273                                 END;
274                                 '</UL>';
275                         END;
276                 END;
277         END;
278 END;
279
280
281
282
283
284 %][%
285
286
287
288
289 BLOCK text;
290         %]<INPUT TYPE="text" NAME="[%
291                 name;
292                 %]" VALUE="[%
293                 value;
294                 %]" [%
295                 IF sz;
296                         %]SIZE="[% sz %]" [%
297                 END;
298                 IF mx;
299                         %]MAXLENGTH="[% mx %]" [%
300                 END;
301                 %]>[%
302 END;
303
304 BLOCK textarea;
305         %]<TEXTAREA NAME="[% name %]">[% value %]</TEXTAREA>[%
306 END;
307
308 BLOCK hidden;
309         %]<INPUT TYPE="hidden" NAME="[% name %]" VALUE="[% value %]">[%
310 END;
311
312 BLOCK radio;
313         %]<INPUT TYPE="radio" NAME="[% name %]" VALUE="[% value %]" [% IF checked %]CHECKED[% END %]>[%
314 END;
315
316 BLOCK checkbox;
317         %]<INPUT TYPE="checkbox" NAME="[% name %]" VALUE="[% value %]" [% IF checked %]CHECKED[% END %]>[%
318 END;
319
320 BLOCK submit;
321         %]<INPUT TYPE="submit" NAME="[% name %]" VALUE="[% value %]">[%
322 END;
323
324 BLOCK anchor;
325         %]<a
326                 href="[%href%]"
327                 title="[%title%]"
328                 class="[%class%]"
329                 target="[%target%]"
330                 onclick="[%onclick%]"
331                 alt="[%alt%]">[%text%]</a>[%
332 END;
333
334
335
336
337 BLOCK render_dimension;
338         INCLUDE checkbox checked = 1 name = 's2_dim_table' value = dim_object.findvalue('@id');
339         %]<b>[% dim_object.findvalue('name') %]</b><br>[%
340         
341         WRAPPER html/table width="100%" ;
342                 WRAPPER html/row;
343                         WRAPPER html/cell align="right";
344                         END;
345                 END;
346         END;
347 END;
348
349
350
351
352
353 BLOCK dim_description;
354         WRAPPER html/row;
355                 WRAPPER html/cell align="right";
356                         %]Name:[%
357                 END;
358                 WRAPPER html/cell;
359                         dim.findvalue('label');
360                 END;
361         END;
362         PROCESS table_fields table = dim;
363 END; 
364
365
366
367
368
369
370 BLOCK table_fields;
371         FOR f IN table.findnodes('fields/field');
372                 WRAPPER html/row;
373                         WRAPPER html/cell align="right";
374                                 %]Field:[%
375                         END;
376                         WRAPPER html/cell;
377                                 f.findvalue('@name');
378                                 %] ([% f.findvalue('@datatype') %])[%
379                         END;
380                 END;
381         END;
382 END;
383
384
385
386
387
388
389 BLOCK stage1_detail;
390         PROCESS table_fields table = config.findnodes("/reporter/tables/table[@id='$fact_table']");
391
392         WRAPPER html/row;
393                 WRAPPER html/cell align="right";
394                         %]Report Attributes<br/>(dimensions):[%
395                 END;
396                 WRAPPER html/cell;
397                         incs_xpath =
398                                 '/reporter/tables/table[@id="' _ fact_table _'"]'_
399                                 '/links/link/@field';
400                         logme(incs_xpath);
401
402                         incs = config.findnodes(incs_xpath);
403
404                         FOR dim IN incs;
405                                 %]<table border=1 width="100%">[%
406
407                                 link_xpath = '/reporter/tables/table[@id="' _ fact_table _'"]'_
408                                                                         '/links/link[@field="' _ dim.value() _ '"]/@table';
409                                 logme(link_xpath);
410
411                                 dim_table = config.findvalue(link_xpath);
412
413                                 dim_xpath = '/reporter/tables/table[@id="' _ dim_table _ '"]';
414                                 logme(dim_xpath);
415                                                         
416                                 dim_def = config.findnodes(dim_xpath);
417
418                                 PROCESS dim_description dim = dim_def;
419                                 %]</table>[%
420                         END;
421                 END;
422         END;
423 END;
424
425 %]
426