531812dfeec6a0248b740902b01469b5ca7b5ea8
[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                         INCLUDE html/cell align="right" valign='top' content='Report Templates:';
110                         WRAPPER html/cell;
111                                 q = 'select * from reporter.stage2 ' _
112                                         'where pub is true or owner = ' _ DBI.quote(user.id());
113                                 FOR r IN DBI.query(q);
114                                         INCLUDE anchor
115                                                 href="stage2?id=" _ r.id
116                                                 text=utils.JSON2perl(r.params).templatename;
117                                                 '<br>';
118                                 END;
119                         END;
120                 END;
121
122                 PROCESS stage1_detail IF CGI.param('detail') == 1;
123         END;
124 END;
125
126
127 %][%
128
129 BLOCK stage2_new;
130         col_xpath = "/reporter/tables/table[@id='" _ fact_table _ "']/fields/field[@core='true']";
131         logme(col_xpath);
132
133         %]<br/><form id="stage2_new" name="stage2_new" action="stage2" method="POST">
134                 <input type="hidden" name="action" value="save">
135                         <input type="hidden" name="stage1" value="[% CGI.param('id') %]">
136                         <input type="text" name="templatename" id="templatename"
137                                 size="40" value="Template name (required)"><br/>
138                         <input type="checkbox" name="publictemplate" value="t">
139                                 Public template<br><br>[%
140
141         
142         WRAPPER html/table width="100%" border=1;
143                 WRAPPER html/row;
144                         WRAPPER html/cell colspan=2;
145                                 # hidden input here ...
146                                 table = config.findnodes("/reporter/tables/table[@id='$fact_table']");
147                                 INCLUDE hidden name="filter" value=fact_table;
148                                 table.findvalue('label');
149                                 ' Core Columns';
150                         END;
151                 END;
152                 INCLUDE widget_selector tableid=fact_table columns=config.findnodes(col_xpath) force=1;
153         END;
154
155         dim_xpath = "/reporter/tables/table[@id='$fact_table']/links/link/@table";
156         FOR dim_table IN config.findnodes(dim_xpath);
157                 dim_table = dim_table.value();
158                 dimension = config.findnodes("/reporter/tables/table[@id='$dim_table']");
159
160                 WRAPPER html/table width="100%" border=1;
161                         WRAPPER html/row;
162                                 WRAPPER html/cell colspan=2;
163                                         # checkbox input here ...
164                                         INCLUDE checkbox name="filter" value=dim_table checked=1;
165                                         dimension.findvalue('label');
166                                         ' Dimension';
167                                 END;
168                         END;
169                         INCLUDE widget_selector tableid=dim_table;
170                 END;
171         END;
172
173         INCLUDE submit name='button' value='Save';
174
175         %]</form>[%
176
177 END;
178
179
180 BLOCK widget_selector;
181
182         logme("widget_selector called for table $tableid");
183
184         #   if we got some columns, use them. if not, get all non-primary columns
185         IF ! columns;
186                 columns_xpath =
187                         '/reporter/tables/table[@id="' _ tableid _
188                         '"]/fields/field[not(@primary) or @primary!="true"]'
189                 columns = config.findnodes(columns_xpath);
190                 logme("widget_selector had to grab columns for table $tableid!");
191         END;
192
193         column_input_type="checkbox";
194         IF force;
195                 column_input_type="hidden";
196         END;
197
198         FOR column IN columns;
199                 column_name=column.findvalue('@name');
200
201                 WRAPPER html/row;
202                         WRAPPER html/cell valign='top' align='right';
203                                 # checkbox for column filter here ...
204                                 INCLUDE $column_input_type
205                                         name="filter:$tableid"
206                                         value=column_name
207                                         checked=1; 
208                                 column.findvalue('label');
209                         END;
210                         WRAPPER html/cell;
211
212                                 col_widget_fams_xpath =
213                                         '/reporter/widgets/widget-family[@datatype="' _
214                                         column.findvalue('@datatype') _ '"]';
215
216                                 IF column.findnodes('@widget-family');
217                                         col_widget_fams_xpath =
218                                                 '/reporter/widgets/widget-family[@name="' _
219                                                 column.findvalue('@widget-family') _ '"]';
220                                 END;
221
222                                 logme("finding widget families using $col_widget_fams_xpath");
223
224                                 widget_fams = config.findnodes(col_widget_fams_xpath);
225
226                                 '<UL>';
227                                 FOR fam IN widget_fams;
228
229                                         fam_input = 'radio';
230                                         IF loop.size == 1;
231                                                 fam_input = 'hidden';
232                                         END;
233
234                                         checked = 0;
235                                         IF loop.count == 1;
236                                                 checked = 1;
237                                         END;
238
239                                         fam_name = fam.findvalue('@name');
240                                         # radio for widget family here ...
241                                         '<LI>';
242                                         INCLUDE $fam_input
243                                                 name="filter:$tableid:$column_name"
244                                                 value= fam_name;
245                                         fam.findvalue('label');
246                                         '<UL>';
247                                         
248                                         FOR widget IN fam.findnodes('widget');
249
250                                                 fam_input = 'radio';
251                                                 IF loop.size == 1;
252                                                         fam_input = 'hidden';
253                                                 END;
254
255                                                 checked = 0;
256                                                 IF loop.count == 1;
257                                                         checked = 1;
258                                                 END;
259
260                                                 widget_name = widget.findvalue('@name');
261                                                 # radio for widget here ...
262                                                 '<LI>';
263                                                 INCLUDE $fam_input
264                                                         name="filter:$tableid:$column_name:$fam_name"
265                                                         value= widget_name;
266                                                 widget.findvalue('label');
267                                                 '</LI>';
268                                         END;
269                                         '</UL>';
270                                         '</LI>';
271                                 END;
272                                 '</UL>';
273                         END;
274                 END;
275         END;
276 END;
277
278
279
280
281
282 %][%
283
284
285
286
287 BLOCK text;
288         %]<INPUT TYPE="text" NAME="[%
289                 name;
290                 %]" VALUE="[%
291                 value;
292                 %]" [%
293                 IF sz;
294                         %]SIZE="[% sz %]" [%
295                 END;
296                 IF mx;
297                         %]MAXLENGTH="[% mx %]" [%
298                 END;
299                 %]>[%
300 END;
301
302 BLOCK textarea;
303         %]<TEXTAREA NAME="[% name %]">[% value %]</TEXTAREA>[%
304 END;
305
306 BLOCK hidden;
307         %]<INPUT TYPE="hidden" NAME="[% name %]" VALUE="[% value %]">[%
308 END;
309
310 BLOCK radio;
311         %]<INPUT TYPE="radio" NAME="[% name %]" VALUE="[% value %]" [% IF checked %]CHECKED[% END %]>[%
312 END;
313
314 BLOCK checkbox;
315         %]<INPUT TYPE="checkbox" NAME="[% name %]" VALUE="[% value %]" [% IF checked %]CHECKED[% END %]>[%
316 END;
317
318 BLOCK submit;
319         %]<INPUT TYPE="submit" NAME="[% name %]" VALUE="[% value %]">[%
320 END;
321
322 BLOCK anchor;
323         %]<a
324                 href="[%href%]"
325                 title="[%title%]"
326                 class="[%class%]"
327                 target="[%target%]"
328                 onclick="[%onclick%]"
329                 alt="[%alt%]">[%text%]</a>[%
330 END;
331
332
333
334
335 BLOCK render_dimension;
336         INCLUDE checkbox checked = 1 name = 's2_dim_table' value = dim_object.findvalue('@id');
337         %]<b>[% dim_object.findvalue('name') %]</b><br>[%
338         
339         WRAPPER html/table width="100%" ;
340                 WRAPPER html/row;
341                         WRAPPER html/cell align="right";
342                         END;
343                 END;
344         END;
345 END;
346
347
348
349
350
351 BLOCK dim_description;
352         WRAPPER html/row;
353                 WRAPPER html/cell align="right";
354                         %]Name:[%
355                 END;
356                 WRAPPER html/cell;
357                         dim.findvalue('label');
358                 END;
359         END;
360         PROCESS table_fields table = dim;
361 END; 
362
363
364
365
366
367
368 BLOCK table_fields;
369         FOR f IN table.findnodes('fields/field');
370                 WRAPPER html/row;
371                         WRAPPER html/cell align="right";
372                                 %]Field:[%
373                         END;
374                         WRAPPER html/cell;
375                                 f.findvalue('@name');
376                                 %] ([% f.findvalue('@datatype') %])[%
377                         END;
378                 END;
379         END;
380 END;
381
382
383
384
385
386
387 BLOCK stage1_detail;
388         PROCESS table_fields table = config.findnodes("/reporter/tables/table[@id='$fact_table']");
389
390         WRAPPER html/row;
391                 WRAPPER html/cell align="right";
392                         %]Report Attributes<br/>(dimensions):[%
393                 END;
394                 WRAPPER html/cell;
395                         incs_xpath =
396                                 '/reporter/tables/table[@id="' _ fact_table _'"]'_
397                                 '/links/link/@field';
398                         logme(incs_xpath);
399
400                         incs = config.findnodes(incs_xpath);
401
402                         FOR dim IN incs;
403                                 %]<table border=1 width="100%">[%
404
405                                 link_xpath = '/reporter/tables/table[@id="' _ fact_table _'"]'_
406                                                                         '/links/link[@field="' _ dim.value() _ '"]/@table';
407                                 logme(link_xpath);
408
409                                 dim_table = config.findvalue(link_xpath);
410
411                                 dim_xpath = '/reporter/tables/table[@id="' _ dim_table _ '"]';
412                                 logme(dim_xpath);
413                                                         
414                                 dim_def = config.findnodes(dim_xpath);
415
416                                 PROCESS dim_description dim = dim_def;
417                                 %]</table>[%
418                         END;
419                 END;
420         END;
421 END;
422
423 %]
424