don't need filter console anymore. Convert other tools to new framework
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / evergreen / util / fm_view.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: About -->
4
5 <!-- Stylesheets -->
6 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
7 <?xml-stylesheet href="chrome://evergreen/skin/evergreen.css" type="text/css"?>
8
9 <!-- OVERLAYS -->
10 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
11
12 <window id="fm_view_win" 
13         onload="try { my_init(); } catch(E) { dump(E+'\n'); alert(E); }"
14         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
15
16         <script type="text/javascript">var myPackageDir = 'evergreen'; var IAMXUL = true; var g = {};</script>
17         <scripts id="openils_util_scripts"/>
18
19         <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
20
21         <script>
22         <![CDATA[
23                 var tree;
24                 var mw = {
25                         'get_list_from_tree_selection' : function() {
26                                 var d = document; var tree_w;
27                                 if (arguments.length == 1) {
28                                         tree_w = arguments[0];
29                                 } else {
30                                         d = arguments[0];
31                                         tree_w = arguments[1];
32                                 }
33                                 var hitlist;
34                                 if (typeof(tree_w) != 'object') {
35                                         hitlist = d.getElementById(tree_w);
36                                 } else {
37                                         hitlist = tree_w;
38                                 }
39                                 var list = [];
40                                 var start = new Object();
41                                 var end = new Object();
42                                 var numRanges = hitlist.view.selection.getRangeCount();
43                                 for (var t=0; t<numRanges; t++){
44                                         hitlist.view.selection.getRangeAt(t,start,end);
45                                         for (var v=start.value; v<=end.value; v++){
46                                                 var i = hitlist.contentView.getItemAtIndex(v);
47                                                 list.push( i );
48                                         }
49                                 }
50                                 return list;
51                         }
52                 };
53
54                 function my_init() {
55                         try {
56                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
57                                 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
58                                 JSAN.errorLevel = "die"; // none, warn, or die
59                                 JSAN.addRepository('/xul/server/');
60                                 JSAN.use('util.error'); g.error = new util.error();
61                                 JSAN.use('main.network'); g.network = new main.network();
62                                 JSAN.use('main.window'); g.window = new main.window();
63                                 JSAN.use('util.functional');
64                                 g.error.sdump('D_TRACE','my_init() for fm_view.xul');
65
66                                 var treechildren = window.document.getElementById('tc');
67                                 var fm = g.network.request('open-ils.actor','opensrf.open-ils.system.fieldmapper',[]);
68                                 var fma = []; var fmh = {} ; 
69                                 for (var i in fm) { fmh[ fm[i].hint ] = fm[i]; fma.push( [ fm[i].hint, i ] ); }
70                                 fma.sort();
71                                 for (var i = 0; i < fma.length; i++) {
72                                         var hint = fma[i][0]; var name = fma[i][1]; var o = fmh[ hint ];
73                                         var ti = window.document.createElement('treeitem');
74                                         treechildren.appendChild( ti );
75                                         ti.setAttribute( 'container', 'true' );
76                                         var tr = window.document.createElement('treerow');
77                                         ti.appendChild( tr );
78                                         var tc = window.document.createElement('treecell');
79                                         tr.appendChild( tc );
80                                         tc.setAttribute('label',hint);
81                                         tc = window.document.createElement('treecell');
82                                         tr.appendChild( tc );
83                                         tc.setAttribute('label', name );
84                                         var _treechildren = window.document.createElement( 'treechildren' );
85                                         ti.appendChild( _treechildren );
86                                         for (var j in o.fields) {
87                                                 var _ti = window.document.createElement( 'treeitem' );
88                                                 _treechildren.appendChild( _ti );
89                                                 _ti.setAttribute('fm_class',hint);
90                                                 _ti.setAttribute('fm_field',j);
91                                                 _ti.setAttribute('fm_virtual',o.fields[j].virtual);
92                                                 _ti.setAttribute('fm_position',o.fields[j].position);
93                                                 var _tr = window.document.createElement( 'treerow' );
94                                                 _ti.appendChild( _tr );
95                                                 var _tc = window.document.createElement( 'treecell' );
96                                                 _tr.appendChild( _tc );
97                                                 _tc.setAttribute('label',j);
98                                                 _tc = window.document.createElement( 'treecell' );
99                                                 _tr.appendChild( _tc );
100                                                 _tc.setAttribute('label','\t         Position: ' + o.fields[j].position + '  Virtual: ' + o.fields[j].virtual);
101                                         }
102                                 }
103                                 tree = window.document.getElementById('t');
104                                 tree.view.selection.select( 0 ); tree.focus();
105                         } catch(E) {
106                         }
107                 }
108
109                 function gen_cols() {
110                         var data_url = 'data:application/vnd.mozilla.xul+xml,<?xml version="1.0"?><window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"><?xml-stylesheet href="chrome://global/skin" type="text/css"?><vbox flex="1"><textbox id="desc" multiline="true" flex="1"/></vbox></window>';
111                         var w = g.window.SafeWindowOpen(data_url,'paged_tree cols','chrome,resizable,width=800,height=600');
112                         var css = '<?xml-stylesheet href="data:text/css,#a{-moz-box-flex:1;}"?>';
113                         var treeitems = mw.get_list_from_tree_selection( tree );
114                         setTimeout(
115                                 function() {
116                                         var tb = w.document.getElementById('desc');
117                                         for (var i = 0; i < treeitems.length; i++) {
118                                                 var hint = treeitems[i].getAttribute('fm_class');
119                                                 var field = treeitems[i].getAttribute('fm_field');
120                                                 var text = (
121                                                         "{\n\t'id' : '" + field + "', 'label' : getString('" + hint + "_" + 
122                                                         field + "_label'), 'flex' : 1,\n" + 
123                                                         "\t'primary' : false, 'hidden' : false, 'fm_class' : '" + hint + 
124                                                         "', 'fm_field_render' : '." + field + "()'\n},\n"
125                                                 );
126                                                 tb.value += text;
127                                         }
128                                         dump(tb.value + '\n');
129                                 }, 0
130                         );
131                 }
132
133                 function gen_properties() {
134                         var data_url = 'data:application/vnd.mozilla.xul+xml,<?xml version="1.0"?><window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"><?xml-stylesheet href="chrome://global/skin" type="text/css"?><vbox flex="1"><textbox id="desc" multiline="true" flex="1"/></vbox></window>';
135                         var w = g.window.SafeWindowOpen(data_url,'paged_tree cols','chrome,resizable,width=800,height=600');
136                         var css = '<?xml-stylesheet href="data:text/css,#a{-moz-box-flex:1;}"?>';
137                         var treeitems = mw.get_list_from_tree_selection( tree );
138                         setTimeout(
139                                 function() {
140                                         var tb = w.document.getElementById('desc');
141                                         for (var i = 0; i < treeitems.length; i++) {
142                                                 var hint = treeitems[i].getAttribute('fm_class');
143                                                 var field = treeitems[i].getAttribute('fm_field');
144                                                 var pretty = util.functional.map_list(
145                                                         field.split('_'),
146                                                         function (s) {
147                                                                 return s.substr(0,1).toUpperCase() + s.substr(1);
148                                                         }
149                                                 ).join(' ');
150                                                 var text = (
151                                                         hint + '_' + field + '_label=' + pretty + '\n'
152                                                 );
153                                                 tb.value += text;
154                                         }
155                                         dump(tb.value + '\n');
156                                 }, 0
157                         );
158                 }
159
160                 function gen_wikitable() {
161                         var data_url = 'data:application/vnd.mozilla.xul+xml,<?xml version="1.0"?><window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"><?xml-stylesheet href="chrome://global/skin" type="text/css"?><vbox flex="1"><textbox id="desc" multiline="true" flex="1"/></vbox></window>';
162                         var w = g.window.SafeWindowOpen(data_url,'paged_tree cols','chrome,resizable,width=800,height=600');
163                         var css = '<?xml-stylesheet href="data:text/css,#a{-moz-box-flex:1;}"?>';
164                         var treeitems = mw.get_list_from_tree_selection( tree );
165                         setTimeout(
166                                 function() {
167                                         var tb = w.document.getElementById('desc');
168                                         for (var i = 0; i < treeitems.length; i++) {
169                                                 var hint = treeitems[i].getAttribute('fm_class');
170                                                 var field = treeitems[i].getAttribute('fm_field');
171                                                 var text = (
172                                                         '|' + hint + '|' + field
173                                                 );
174                                         
175                                                 if (treeitems[i].getAttribute('fm_virtual') == '1') text += ' * ';
176                                                 text += '|\n'
177                                                 tb.value += text;
178                                         }
179                                         dump(tb.value + '\n');
180                                 }, 0
181                         );
182                 }
183
184
185         ]]>
186         </script>
187
188         <vbox flex="1" class="my_overflow">
189                 <groupbox orient="vertical" flex="1">
190                         <caption label="Fieldmapper Class Viewer"/>
191                         <hbox>
192                                 <button label="Generate paged_tree cols for selected fields" accesskey="G" oncommand="gen_cols();"/>
193                                 <button label="Generate string bundle properties for selected fields" accesskey="P" oncommand="gen_properties();"/>
194                                 <button label="Generate dokuwiki table for selected fields" accesskey="P" oncommand="gen_wikitable();"/>
195                         </hbox>
196                         <tree id="t" flex="1">
197                                 <treecols>
198                                         <treecol id="tcol1" label="opensrf.open-ils.system.fieldmapper" primary="true" flex="0"/>
199                                         <treecol id="tcol2" label="" flex="1"/>
200                                 </treecols>
201                                 <treechildren id="tc"/>
202                         </tree>
203                 </groupbox>
204         </vbox>
205
206 </window>
207