making wiki work easier
[Evergreen.git] / Evergreen / 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 <window id="fm_view_win" 
10         onload="try { my_init(); } catch(E) { alert(E); }"
11         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
12
13         <script>mw.sdump('D_TRACE','Loading fm_view.xul\n');</script>
14
15         <script>
16         <![CDATA[
17                 var tree;
18
19                 function my_init() {
20                         var treechildren = window.document.getElementById('tc');
21                         var fm = mw.user_request('open-ils.actor','opensrf.open-ils.system.fieldmapper',[])[0];
22                         var fma = []; var fmh = {} ; 
23                         for (var i in fm) { fmh[ fm[i].hint ] = fm[i]; fma.push( [ fm[i].hint, i ] ); }
24                         fma.sort();
25                         for (var i = 0; i < fma.length; i++) {
26                                 var hint = fma[i][0]; var name = fma[i][1]; var o = fmh[ hint ];
27                                 var ti = window.document.createElement('treeitem');
28                                 treechildren.appendChild( ti );
29                                 ti.setAttribute( 'container', 'true' );
30                                 var tr = window.document.createElement('treerow');
31                                 ti.appendChild( tr );
32                                 var tc = window.document.createElement('treecell');
33                                 tr.appendChild( tc );
34                                 tc.setAttribute('label',hint);
35                                 tc = window.document.createElement('treecell');
36                                 tr.appendChild( tc );
37                                 tc.setAttribute('label', name );
38                                 var _treechildren = window.document.createElement( 'treechildren' );
39                                 ti.appendChild( _treechildren );
40                                 for (var j in o.fields) {
41                                         var _ti = window.document.createElement( 'treeitem' );
42                                         _treechildren.appendChild( _ti );
43                                         _ti.setAttribute('fm_class',hint);
44                                         _ti.setAttribute('fm_field',j);
45                                         _ti.setAttribute('fm_virtual',o.fields[j].virtual);
46                                         _ti.setAttribute('fm_position',o.fields[j].position);
47                                         var _tr = window.document.createElement( 'treerow' );
48                                         _ti.appendChild( _tr );
49                                         var _tc = window.document.createElement( 'treecell' );
50                                         _tr.appendChild( _tc );
51                                         _tc.setAttribute('label',j);
52                                         _tc = window.document.createElement( 'treecell' );
53                                         _tr.appendChild( _tc );
54                                         _tc.setAttribute('label','\t         Position: ' + o.fields[j].position + '  Virtual: ' + o.fields[j].virtual);
55                                 }
56                         }
57                         tree = window.document.getElementById('t');
58                         tree.view.selection.select( 0 ); tree.focus();
59                 }
60
61                 function gen_cols() {
62                         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>';
63                         var w = mw.SafeWindowOpen(data_url,'paged_tree cols','chrome,resizable,width=800,height=600');
64                         var css = '<?xml-stylesheet href="data:text/css,#a{-moz-box-flex:1;}"?>';
65                         var treeitems = mw.get_list_from_tree_selection( tree );
66                         setTimeout(
67                                 function() {
68                                         var tb = w.document.getElementById('desc');
69                                         for (var i = 0; i < treeitems.length; i++) {
70                                                 var hint = treeitems[i].getAttribute('fm_class');
71                                                 var field = treeitems[i].getAttribute('fm_field');
72                                                 var text = (
73                                                         "{\n\t'id' : '" + field + "', 'label' : getString('" + hint + "_" + 
74                                                         field + "_label'), 'flex' : 1,\n" + 
75                                                         "\t'primary' : false, 'hidden' : false, 'fm_class' : '" + hint + 
76                                                         "', 'fm_field_render' : '." + field + "()'\n},\n"
77                                                 );
78                                                 tb.value += text;
79                                         }
80                                         dump(tb.value + '\n');
81                                 }, 0
82                         );
83                 }
84
85                 function gen_properties() {
86                         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>';
87                         var w = mw.SafeWindowOpen(data_url,'paged_tree cols','chrome,resizable,width=800,height=600');
88                         var css = '<?xml-stylesheet href="data:text/css,#a{-moz-box-flex:1;}"?>';
89                         var treeitems = mw.get_list_from_tree_selection( tree );
90                         setTimeout(
91                                 function() {
92                                         var tb = w.document.getElementById('desc');
93                                         for (var i = 0; i < treeitems.length; i++) {
94                                                 var hint = treeitems[i].getAttribute('fm_class');
95                                                 var field = treeitems[i].getAttribute('fm_field');
96                                                 var pretty = mw.map_list(
97                                                         field.split('_'),
98                                                         function (s) {
99                                                                 return s.substr(0,1).toUpperCase() + s.substr(1);
100                                                         }
101                                                 ).join(' ');
102                                                 var text = (
103                                                         hint + '_' + field + '_label=' + pretty + '\n'
104                                                 );
105                                                 tb.value += text;
106                                         }
107                                         dump(tb.value + '\n');
108                                 }, 0
109                         );
110                 }
111
112                 function gen_wikitable() {
113                         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>';
114                         var w = mw.SafeWindowOpen(data_url,'paged_tree cols','chrome,resizable,width=800,height=600');
115                         var css = '<?xml-stylesheet href="data:text/css,#a{-moz-box-flex:1;}"?>';
116                         var treeitems = mw.get_list_from_tree_selection( tree );
117                         setTimeout(
118                                 function() {
119                                         var tb = w.document.getElementById('desc');
120                                         for (var i = 0; i < treeitems.length; i++) {
121                                                 var hint = treeitems[i].getAttribute('fm_class');
122                                                 var field = treeitems[i].getAttribute('fm_field');
123                                                 var text = (
124                                                         '|' + hint + '|' + field
125                                                 );
126                                         
127                                                 if (treeitems[i].getAttribute('fm_virtual') == '1') text += ' * ';
128                                                 text += '|\n'
129                                                 tb.value += text;
130                                         }
131                                         dump(tb.value + '\n');
132                                 }, 0
133                         );
134                 }
135
136
137         ]]>
138         </script>
139
140         <vbox flex="1" class="my_overflow">
141                 <groupbox orient="vertical" flex="1">
142                         <caption label="Fieldmapper Class Viewer"/>
143                         <hbox>
144                                 <button label="Generate paged_tree cols for selected fields" accesskey="G" oncommand="gen_cols();"/>
145                                 <button label="Generate string bundle properties for selected fields" accesskey="P" oncommand="gen_properties();"/>
146                                 <button label="Generate dokuwiki table for selected fields" accesskey="P" oncommand="gen_wikitable();"/>
147                         </hbox>
148                         <tree id="t" flex="1">
149                                 <treecols>
150                                         <treecol id="tcol1" label="opensrf.open-ils.system.fieldmapper" primary="true" flex="0"/>
151                                         <treecol id="tcol2" label="" flex="1"/>
152                                 </treecols>
153                                 <treechildren id="tc"/>
154                         </tree>
155                 </groupbox>
156         </vbox>
157
158 </window>
159