checking in Mike's stage 3 / widget work from yesterday
[working/Evergreen.git] / Open-ILS / src / reporter / templates / stage2.ttk
1 [%
2
3 PROCESS inputs;
4 PROCESS class_manip;
5 PROCESS widget_manip;
6 PROCESS logic_header.ttk;
7
8 templates = DBI.tie('reporter.stage2', 'id')
9 tmpl = {};
10
11
12 IF CGI.param('id');
13         tid = CGI.param('id');
14         tmpl = templates.$tid;
15 END;
16
17
18 WRAPPER html/html;
19    INCLUDE header.ttk title="Report Templates";
20    WRAPPER html/body;
21       INCLUDE logout.ttk;
22       IF CGI.param('action') == 'save';
23          PROCESS save_stage2;
24       ELSIF CGI.param('action') == 'edit';
25          PROCESS edit_stage2;
26       ELSIF CGI.param('action') == 'run';
27          PROCESS run_stage2;
28                 ELSE;
29          PROCESS view_stage2;
30       END;
31    END;
32    INCLUDE footer.ttk;
33 END;
34
35
36
37
38 BLOCK save_stage2;
39         stage1 = CGI.param('stage1');
40         pub = CGI.param('publictemplate') OR 'f';
41         owner = user.id();
42
43         p_obj = {};
44         FOR p IN CGI.param();
45
46                 logme([p,CGI.param(p)]);
47
48                 parts = p.split(':');
49                 p1 = parts.0;
50                 p2 = parts.1;
51                 p3 = parts.2;
52                 p4 = parts.3;
53                 
54                 IF p4
55                         AND (CGI.param("$p1:$p2:$p3") == p4)
56                         AND (CGI.param("$p1:$p2").list.grep(p3).size > 0)
57                         AND (CGI.param("$p1").list.grep(p2).size > 0);
58
59                         p_obj.$p1.$p2.$p3.$p4 = CGI.param(p);
60
61                 ELSIF p2
62                         AND (CGI.param("$p1").list.grep(p2).size > 0);
63                         p_obj.dims.$p2 = 1;
64                 ELSIF p1 != 'filter';
65                         p_obj.$p1 = CGI.param(p);
66                 END;
67
68         END;
69
70         params = utils.perl2JSON( p_obj );
71
72         logme([stage1, params, owner, pub]);
73
74         q = DBI.prepare( stage2_insert );
75         CALL q.execute(stage1, params, owner, pub);
76
77         FOR new_s2 = DBI.query("SELECT * FROM reporter.stage2_id_seq;");
78                 tid = new_s2.last_value;
79                 INCLUDE view_stage2 tmpl = templates.$tid;
80         END;
81 END;
82
83
84
85
86 BLOCK edit_stage2;
87
88 END;
89
90
91
92
93
94 BLOCK view_stage2;
95         logme(tmpl.params);
96         params = utils.JSON2perl( tmpl.params );
97
98         WRAPPER html/table border=0 width='100%';
99                 WRAPPER html/row;
100                         WRAPPER html/cell colspan=5 align='center';
101                                 s1_name_xpath = '/reporter/tables/table[@id="' _ params.stage1 _ '"]/label';
102                                 INCLUDE anchor
103                                         text=config.findvalue( s1_name_xpath )
104                                         href="stage1?id=" _ params.stage1;
105                                 ' :: ' _ params.templatename _ '<br>';
106                                 INCLUDE anchor
107                                         text="Create a report from this template"
108                                         href=CGI.url('-path', 1) _ '?action=run&id=' _ tmpl.id;
109                         END;
110                 END;
111
112                 WRAPPER html/row;
113                         INCLUDE html/cell colspan=4 content="<b>Filterable Attributes:</b>";
114                 END;
115
116                 FOR f_table IN params.filter.keys;
117                         logme([f_table]);
118                         table = config.findnodes( "/reporter/tables/table[@id='$f_table']");
119                         WRAPPER html/row;
120                                 INCLUDE html/cell;
121                                 INCLUDE html/cell colspan=4 align='left' content=table.findvalue( 'label' );
122                         END;
123
124                         FOR f_field IN params.filter.$f_table.keys;
125                                 logme([f_table,f_field]);
126                                 FOR f_fam IN params.filter.$f_table.$f_field.keys;
127                                         logme([f_table,f_field,f_fam]);
128                                         f_widget = params.filter.$f_table.$f_field.$f_fam;
129                                         logme([f_table,f_field,f_fam,f_widget]);
130
131                                         WRAPPER html/row;
132                                                 field = table.findnodes( "fields/field[@name='$f_field']" );
133                                                 fam = config.findnodes( "/reporter/widgets/widget-family[@name='$f_fam']" );
134                                                 widget = fam.findnodes( "widget[@name='$f_widget']" );
135
136                                                 INCLUDE html/cell colspan=2;
137                                                 INCLUDE html/cell align='right' content=field.findvalue( 'label' );
138                                                 INCLUDE html/cell align='center' content=fam.findvalue( 'label' );
139                                                 INCLUDE html/cell align='left' content=widget.findvalue( 'label' );
140                                         END;
141                                 END;
142                         END;
143                 END;
144
145                 WRAPPER html/row;
146                         INCLUDE html/cell colspan=5 content="<br>";
147                 END;
148
149                 WRAPPER html/row;
150                         INCLUDE html/cell colspan=5 content="<b>Attributes Available for Output</b>";
151                 END;
152
153                 FOR f_table IN params.dims.keys;
154                         table = config.findnodes( "/reporter/tables/table[@id='$f_table']");
155                         tname = table.findvalue( "label" );
156                         tdesc = table.findvalue( "desription" );
157
158                         NEXT IF table.findvalue('@fact-table') == 'true';
159                         
160                         WRAPPER html/row;
161                                 INCLUDE html/cell;
162                                 INCLUDE html/cell colspan=4 align='left' content=tname;
163                         END;
164
165
166                         FOR field IN table.findnodes('fields/field[not(@primary) or @primary != "true"]');
167                                 fname = field.findvalue( "label" );
168                                 fdesc = field.findvalue( "desription" );
169
170                                 WRAPPER html/row;
171
172                                         INCLUDE html/cell colspan=2;
173                                         INCLUDE html/cell align='right' content=fname;
174                                         INCLUDE html/cell colspan=2 align='center' content=fdesc;
175                                 END;
176                         END;
177                 END;
178
179         END;
180 END;
181
182
183
184
185
186 BLOCK run_stage2;
187         logme(tmpl.params);
188         params = utils.JSON2perl( tmpl.params );
189
190    %]<br/><form id="stage3_new" name="stage3_new" action="stage3" method="POST">[%
191
192         INCLUDE hidden name='stage2' value=CGI.param('id');
193
194         WRAPPER html/table border=0 width='100%';
195                 WRAPPER html/row;
196                         WRAPPER html/cell colspan=4 align='center';
197                                 s1_name_xpath = '/reporter/tables/table[@id="' _ params.stage1 _ '"]/label';
198                                 INCLUDE anchor
199                                         text=config.findvalue( s1_name_xpath )
200                                         href="stage1?id=" _ params.stage1;
201                                 ' :: ' _ params.templatename;
202                         END;
203                 END;
204
205                 WRAPPER html/row;
206                         INCLUDE html/cell colspan=4 content="<b>Filterable Attributes:</b>";
207                 END;
208
209                 FOR f_table IN params.filter.keys;
210                         logme([f_table]);
211                         table = config.findnodes( "/reporter/tables/table[@id='$f_table']");
212                         WRAPPER html/row;
213                                 INCLUDE html/cell colspan=3 align='left' content=table.findvalue( 'label' );
214                         END;
215
216                         FOR f_field IN params.filter.$f_table.keys;
217                                 logme([f_table,f_field]);
218                                 FOR f_fam IN params.filter.$f_table.$f_field.keys;
219                                         logme([f_table,f_field,f_fam]);
220                                         f_widget = params.filter.$f_table.$f_field.$f_fam;
221                                         logme([f_table,f_field,f_fam,f_widget]);
222
223                                         WRAPPER html/row;
224                                                 field = table.findnodes( "fields/field[@name='$f_field']" );
225                                                 fam = config.findnodes( "/reporter/widgets/widget-family[@name='$f_fam']" );
226                                                 widget = fam.findnodes( "widget[@name='$f_widget']" );
227
228                                                 w_file = 'widgets/' _ fam.findvalue('@name') _ '.' _ widget.findvalue('@name');
229                                                 INCLUDE html/cell;
230                                                 INCLUDE html/cell align='right' content=field.findvalue( 'label' );
231
232                                                 WRAPPER html/cell align='center';
233                                                         TRY;
234                                                                         classname = table.findvalue('@id');
235                                                                         fieldname = field.findvalue('@name');
236                                                                         widgetname = widget.findvalue('@name');
237                                                                         famname = fam.findvalue('@name');
238
239                                                                         input_prefix = "filter:$famname:$widgetname:$classname:$fieldname";
240
241                                                                         INCLUDE $w_file widget_family=fam;
242                                                         CATCH;
243                                                                 %]ARG!! Couldn't render widget [% $w_file %] ([% error.info %])!!![%
244                                                         END;
245                                                 END;
246                                         END;
247                                 END;
248                         END;
249                 END;
250
251                 WRAPPER html/row;
252                         INCLUDE html/cell colspan=4 content="<br>";
253                 END;
254
255                 WRAPPER html/row;
256                         INCLUDE html/cell colspan=4 content="<b>Attributes Available for Output</b>";
257                 END;
258
259                 FOR f_table IN params.dims.keys;
260                         table = config.findnodes( "/reporter/tables/table[@id='$f_table']");
261                         classname = table.findvalue( "@id" );
262                         tname = table.findvalue( "label" );
263                         tdesc = table.findvalue( "desription" );
264                         
265                         WRAPPER html/row;
266                                 INCLUDE html/cell colspan=4 align='left' content=tname;
267                         END;
268
269
270                         fields_xpath =
271                                 'fields/field[not(@primary) or @primary != "true"]';
272                         FOR field IN table.findnodes(fields_xpath);
273                                 link_test = '../../links/link[@field="' _ field.findvalue('@name') _ '"]';
274                                 logme(['link_test',link_test]);
275                                 NEXT IF field.findnodes( link_test );
276
277                                 fname = field.findvalue( "label" );
278                                 fid = field.findvalue( "@name" );
279
280                                 WRAPPER html/row;
281
282                                         WRAPPER html/cell align='right';
283                                                 INCLUDE checkbox name="output:$classname:$fid" value="include";
284                                         END;
285                                         INCLUDE html/cell align='right' content=fname;
286                                         WRAPPER html/cell align='center';
287                                                 'Output Transformation: ';
288                                                 dtype = field.findvalue('@datatype');
289                                                 WRAPPER select name="xform:type:$classname:$fid";
290                                                         INCLUDE option value='' content='None' selected=1;
291                                                         FOR xform IN dtype_xform_map.$dtype;
292                                                                 xform_label = dtype_xforms.$xform.label;
293                                                                 IF dtype_xforms.$xform.param;
294                                                                         xform_label = "$xform_label (*)";
295                                                                 END;
296                                                                 INCLUDE option value=xform content=xform_label;
297                                                         END;
298                                                 END;
299                                                 '<br/>';
300                                                 '<small><super>*</super>Output Tranformation Parameter: </small>';
301                                                 INCLUDE text name="xform:param:$classname:$fid";
302                                         END;
303                                 END;
304                         END;
305                 END;
306         END;
307
308         INCLUDE checkbox name="publicreport" value="t";
309         'Public Report<br>';
310         INCLUDE submit name="action" value="Run Now";
311         INCLUDE submit name="action" value="Schedule";
312
313         %]</form>[%
314 END;
315
316 %]