2 var idlNS = "http://opensrf.org/spec/IDL/base/v1";
3 var persistNS = "http://open-ils.org/spec/opensrf/IDL/persistance/v1";
4 var objNS = "http://open-ils.org/spec/opensrf/IDL/objects/v1";
5 var rptNS = "http://open-ils.org/spec/opensrf/IDL/reporter/v1";
6 var gwNS = "http://opensrf.org/-/namespaces/gateway/v1";
7 var xulNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
10 var rpt_rel_cache = {};
12 function sortHashLabels (a,b) { return a.label.toLowerCase() < b.label.toLowerCase() ? -1 : 1; }
14 function sortNames (a,b) {
15 var aname = a.name.toLowerCase();
16 if (!aname) aname = a.idlclass.toLowerCase();
18 var bname = b.name.toLowerCase();
19 if (!bname) bname = b.idlclass.toLowerCase();
21 return aname < bname ? -1 : 1;
24 function sortLabels (a,b) {
25 var aname = a.getAttributeNS(rptNS, 'label').toLowerCase();
26 if (!aname) aname = a.getAttribute('name');
27 if (!aname) aname = a.getAttribute('id');
29 var bname = b.getAttributeNS(rptNS, 'label').toLowerCase();
30 if (!bname) bname = b.getAttribute('name');
31 if (!bname) bname = b.getAttribute('id');
33 return aname < bname ? -1 : 1;
37 var req = new XMLHttpRequest();
38 req.open('GET', '../fm_IDL.xml', true);
39 req.onreadystatechange = function() {
40 if( req.readyState == 4 ) {
41 oilsIDL = req.responseXML;
43 filterByAttributeNS( oilsIDL.getElementsByTagName('class'), rptNS, 'core', 'true' )
50 function getIDLClass (id) { return filterByAttribute( oilsIDL.getElementsByTagName('class'), 'id', id )[0] }
51 function getIDLField (classNode,field) { return filterByAttribute( classNode.getElementsByTagName('field'), 'name', field )[0] }
52 function getIDLLink (classNode,field) { return filterByAttribute( classNode.getElementsByTagName('link'), 'field', field )[0] }
54 function resetUI (idlclass) {
55 if (getKeys(rpt_rel_cache).length > 0) {
57 "You have started building a template!\n" +
58 "Selecting a new starting source will destroy " +
59 "the current template and start over. Is this OK?"
64 try { renderSources(); } catch (e) {}
66 populateSourcesTree( idlclass );
68 var tree = $('sources-treetop').parentNode;
70 tree.view.selection.select(0);
74 function populateSourcesMenu (classList) {
75 classList.sort( sortLabels );
77 var menu = $('source-menu');
81 { label : 'Core Sources',
83 style : 'color: black; text-decoration: underline;'
89 for (var i in classList) {
91 var name = classList[i].getAttributeNS(rptNS,'label');
92 var id = classList[i].getAttribute('id');
100 onmouseup : 'resetUI( "' + id + '");'
107 menu.appendChild( createMenuSeparator() );
110 { label : 'All Available Sources' },
114 { label : 'All Available Sources',
116 style : 'color: black; '
119 createMenuSeparator()
123 menu.appendChild( _m );
124 menu = _m.firstChild;
126 var all = map(function(x){return x;}, oilsIDL.getElementsByTagNameNS(idlNS,'class'));
127 all.sort( sortLabels );
129 for (var i = 0; i < all.length; i++) {
131 if (all[i].getAttributeNS(persistNS,'virtual') == 'true') continue;
133 var name = all[i].getAttributeNS(rptNS,'label');
134 var id = all[i].getAttribute('id');
135 if (!name) name = id;
139 { container : 'true',
142 onmouseup : 'resetUI( "' + id + '");'
152 function populateSourcesTree (idlclass) {
154 var tcNode = $('sources-treetop');
155 while (tcNode.childNodes.length) tcNode.removeChild(tcNode.lastChild);
157 var c = getIDLClass( idlclass );
158 var name = c.getAttributeNS(rptNS,'label');
159 if (!name) name = idlclass;
163 { container : 'true',
169 createTreeCell( { label : name } )
171 createTreeChildren( { alternatingbackground : true } )
176 function populateSourcesSubtree (tcNode, classList) {
177 classList.sort(sortNames);
178 for (var i in classList) {
179 var obj = classList[i];
181 var p = getIDLClass( obj.idlclass );
182 var cont = p.getElementsByTagName('link').length ? 'true' : 'false';
187 idlclass : obj.idlclass,
192 reltype : obj.reltype,
193 fullpath : obj.fullpath,
197 createTreeCell( { label : obj.name } )
199 createTreeChildren( { alternatingbackground : true } )
207 function populateDetailTree (tcNode, c, item) {
208 var fullpath = item.getAttribute('fullpath');
209 var reltype = item.getAttribute('reltype');
211 var fields = filterByAttributeNS(c.getElementsByTagName('field'),persistNS, 'virtual','false');
212 fields.sort( sortLabels );
214 var id = c.getAttribute('id');
217 var steps = fullpath.split('.');
218 for (var k in steps) {
220 if (!steps[k]) continue;
222 var atom = steps[k].split('-');
223 var classNode = getIDLClass(atom[0]);
225 var _cname = classNode.getAttributeNS(rptNS, 'label');
226 if (!_cname) _cname = classNode.getAttribute('id');
230 if (atom.length > 1 && k == steps.length - 1) {
231 var _f = getIDLField(classNode, atom[1]);
232 var _fname = _f.getAttributeNS(rptNS, 'label');
233 if (!_fname) _fname = _f.getAttribute('name');
234 if (_fname) _label += ' :: ' + _fname;
237 path_label.push(_label);
240 $('path-label').value = path_label.join(' -> ');
241 $('path-label').setAttribute('reltype',reltype);
243 for (var i in fields) {
245 var type = fields[i].getAttributeNS(rptNS, 'datatype');
246 //if (!type) type = 'text';
248 var label = fields[i].getAttributeNS(rptNS, 'label');
249 var name = fields[i].getAttribute('name');
250 if (!label) label = name;
261 createTreeCell( { label : label } ),
262 createTreeCell( { label : type } )