adding widgets
[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         WRAPPER html/table border=0 width='100%';
193                 WRAPPER html/row;
194                         WRAPPER html/cell colspan=4 align='center';
195                                 s1_name_xpath = '/reporter/tables/table[@id="' _ params.stage1 _ '"]/label';
196                                 INCLUDE anchor
197                                         text=config.findvalue( s1_name_xpath )
198                                         href="stage1?id=" _ params.stage1;
199                                 ' :: ' _ params.templatename;
200                         END;
201                 END;
202
203                 WRAPPER html/row;
204                         INCLUDE html/cell colspan=4 content="<b>Filterable Attributes:</b>";
205                 END;
206
207                 FOR f_table IN params.filter.keys;
208                         logme([f_table]);
209                         table = config.findnodes( "/reporter/tables/table[@id='$f_table']");
210                         WRAPPER html/row;
211                                 INCLUDE html/cell;
212                                 INCLUDE html/cell colspan=3 align='left' content=table.findvalue( 'label' );
213                         END;
214
215                         FOR f_field IN params.filter.$f_table.keys;
216                                 logme([f_table,f_field]);
217                                 FOR f_fam IN params.filter.$f_table.$f_field.keys;
218                                         logme([f_table,f_field,f_fam]);
219                                         f_widget = params.filter.$f_table.$f_field.$f_fam;
220                                         logme([f_table,f_field,f_fam,f_widget]);
221
222                                         WRAPPER html/row;
223                                                 field = table.findnodes( "fields/field[@name='$f_field']" );
224                                                 fam = config.findnodes( "/reporter/widgets/widget-family[@name='$f_fam']" );
225                                                 widget = fam.findnodes( "widget[@name='$f_widget']" );
226
227                                                 w_file = 'widgets/' _ fam.findvalue('@name') _ '.' _ widget.findvalue('@name');
228                                                 INCLUDE html/cell colspan=2;
229                                                 INCLUDE html/cell align='right' content=field.findvalue( 'label' );
230
231                                                 WRAPPER html/cell align='center';
232                                                         TRY;
233                                                                         classname = table.findvalue('@id');
234                                                                         fieldname = field.findvalue('@name');
235                                                                         widgetname = widget.findvalue('@name');
236                                                                         famname = fam.findvalue('@name');
237
238                                                                         input_prefix = "$famname:$widgetname:$classname:$fieldname";
239
240                                                                         INCLUDE $w_file widget_family=fam;
241                                                         CATCH;
242                                                                 %]ARG!! Couldn't render widget [% $w_file %] ([% error.info %])!!![%
243                                                         END;
244                                                 END;
245                                         END;
246                                 END;
247                         END;
248                 END;
249
250                 WRAPPER html/row;
251                         INCLUDE html/cell colspan=5 content="<br>";
252                 END;
253
254                 WRAPPER html/row;
255                         INCLUDE html/cell colspan=5 content="<b>Attributes Available for Output</b>";
256                 END;
257
258                 FOR f_table IN params.dims.keys;
259                         table = config.findnodes( "/reporter/tables/table[@id='$f_table']");
260                         tname = table.findvalue( "label" );
261                         tdesc = table.findvalue( "desription" );
262
263                         NEXT IF table.findvalue('@fact-table') == 'true';
264                         
265                         WRAPPER html/row;
266                                 INCLUDE html/cell;
267                                 INCLUDE html/cell colspan=4 align='left' content=tname;
268                         END;
269
270
271                         FOR field IN table.findnodes('fields/field[not(@primary) or @primary != "true"]');
272                                 fname = field.findvalue( "label" );
273
274                                 WRAPPER html/row;
275
276                                         INCLUDE html/cell colspan=2;
277                                         INCLUDE html/cell align='right' content=fname;
278                                         WRAPPER html/cell align='center';
279                                         END;
280                                 END;
281                         END;
282                 END;
283
284         END;
285
286         INCLUDE submit name="action" value="schedule";
287
288         %]</form>[%
289 END;
290
291 %]