4b444295b5e0f71fa7ed6631e50c6a04c5b8a4f1
[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                                         var _tr = window.document.createElement( 'treerow' );
46                                         _ti.appendChild( _tr );
47                                         var _tc = window.document.createElement( 'treecell' );
48                                         _tr.appendChild( _tc );
49                                         _tc.setAttribute('label',j);
50                                         _tc = window.document.createElement( 'treecell' );
51                                         _tr.appendChild( _tc );
52                                         _tc.setAttribute('label','\t         Position: ' + o.fields[j].position + '  Virtual: ' + o.fields[j].virtual);
53                                 }
54                         }
55                         tree = window.document.getElementById('t');
56                         tree.view.selection.select( 0 ); tree.focus();
57                 }
58
59                 function gen_cols() {
60                         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>';
61                         var w = mw.SafeWindowOpen(data_url,'paged_tree cols','chrome,resizable,width=800,height=600');
62                         var css = '<?xml-stylesheet href="data:text/css,#a{-moz-box-flex:1;}"?>';
63                         var treeitems = mw.get_list_from_tree_selection( tree );
64                         setTimeout(
65                                 function() {
66                                         var tb = w.document.getElementById('desc');
67                                         for (var i = 0; i < treeitems.length; i++) {
68                                                 var hint = treeitems[i].getAttribute('fm_class');
69                                                 var field = treeitems[i].getAttribute('fm_field');
70                                                 var text = (
71                                                         "{\n\t'id' : '" + field + "', 'label' : getString('" + hint + "_" + 
72                                                         field + "_label'), 'flex' : 1,\n" + 
73                                                         "\t'primary' : false, 'hidden' : false, 'fm_class' : '" + hint + 
74                                                         "', 'fm_field_render' : '." + field + "()'\n},\n"
75                                                 );
76                                                 tb.value += text;
77                                         }
78                                 }, 0
79                         );
80                 }
81
82                 function gen_properties() {
83                         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>';
84                         var w = mw.SafeWindowOpen(data_url,'paged_tree cols','chrome,resizable,width=800,height=600');
85                         var css = '<?xml-stylesheet href="data:text/css,#a{-moz-box-flex:1;}"?>';
86                         var treeitems = mw.get_list_from_tree_selection( tree );
87                         setTimeout(
88                                 function() {
89                                         var tb = w.document.getElementById('desc');
90                                         for (var i = 0; i < treeitems.length; i++) {
91                                                 var hint = treeitems[i].getAttribute('fm_class');
92                                                 var field = treeitems[i].getAttribute('fm_field');
93                                                 var pretty = mw.map_list(
94                                                         field.split('_'),
95                                                         function (s) {
96                                                                 return s.substr(0,1).toUpperCase() + s.substr(1);
97                                                         }
98                                                 ).join(' ');
99                                                 var text = (
100                                                         hint + '_' + field + '_label=' + pretty + '\n'
101                                                 );
102                                                 tb.value += text;
103                                         }
104                                 }, 0
105                         );
106                 }
107
108         ]]>
109         </script>
110
111         <vbox flex="1" class="my_overflow">
112                 <groupbox orient="vertical" flex="1">
113                         <caption label="Fieldmapper Class Viewer"/>
114                         <hbox>
115                                 <button label="Generate paged_tree cols for selected fields" accesskey="G" oncommand="gen_cols();"/>
116                                 <button label="Generate string bundle properties for selected fields" accesskey="P" oncommand="gen_properties();"/>
117                         </hbox>
118                         <tree id="t" flex="1">
119                                 <treecols>
120                                         <treecol id="tcol1" label="opensrf.open-ils.system.fieldmapper" primary="true" flex="0"/>
121                                         <treecol id="tcol2" label="" flex="1"/>
122                                 </treecols>
123                                 <treechildren id="tc"/>
124                         </tree>
125                 </groupbox>
126         </vbox>
127
128 </window>
129