1 dojo.requireLocalization("openils.reports", "reports");
3 var rpt_strings = dojo.i18n.getLocalization("openils.reports", "reports");
4 var idlNS = "http://opensrf.org/spec/IDL/base/v1";
5 var persistNS = "http://open-ils.org/spec/opensrf/IDL/persistence/v1";
6 var objNS = "http://open-ils.org/spec/opensrf/IDL/objects/v1";
7 var rptNS = "http://open-ils.org/spec/opensrf/IDL/reporter/v1";
8 var gwNS = "http://opensrf.org/-/namespaces/gateway/v1";
9 var xulNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
12 var rpt_rel_cache = {};
14 function sortHashLabels (a,b) { return a.label.toLowerCase() < b.label.toLowerCase() ? -1 : 1; }
16 function sortNames (a,b) {
17 var aname = a.name.toLowerCase();
18 if (!aname) aname = a.idlclass.toLowerCase();
20 var bname = b.name.toLowerCase();
21 if (!bname) bname = b.idlclass.toLowerCase();
23 return aname < bname ? -1 : 1;
26 function sortLabels (a,b) {
27 var aname = a.getAttributeNS(rptNS, 'label').toLowerCase();
28 if (!aname) aname = a.getAttribute('name');
29 if (!aname) aname = a.getAttribute('id');
31 var bname = b.getAttributeNS(rptNS, 'label').toLowerCase();
32 if (!bname) bname = b.getAttribute('name');
33 if (!bname) bname = b.getAttribute('id');
35 return aname < bname ? -1 : 1;
39 function loadTemplate(id) {
41 var session = cgi.param('ses');
43 var r = new Request('open-ils.reporter:open-ils.reporter.template.retrieve', session, id);
47 var tmpl = res.getResultObject();
48 var template = JSON2js( tmpl.data() );
50 resetUI( template.core_class );
52 $('template-name').value = tmpl.name() + ' (clone)';
53 $('template-description').value = tmpl.description();
55 rpt_rel_cache = template.rel_cache;
65 var req = new XMLHttpRequest();
66 req.open('GET', '../fm_IDL.xml', true);
67 req.onreadystatechange = function() {
68 if( req.readyState == 4 ) {
69 oilsIDL = req.responseXML;
71 filterByAttributeNS( oilsIDL.getElementsByTagName('class'), rptNS, 'core', 'true' )
75 var template_id = cgi.param('ct');
76 if (template_id) loadTemplate(template_id);
83 function getIDLClass (id) { return filterByAttribute( oilsIDL.getElementsByTagName('class'), 'id', id )[0] }
84 function getIDLField (classNode,field) { return filterByAttribute( classNode.getElementsByTagName('field'), 'name', field )[0] }
85 function getIDLLink (classNode,field) { return filterByAttribute( classNode.getElementsByTagName('link'), 'field', field )[0] }
87 function resetUI (idlclass) {
88 if (getKeys(rpt_rel_cache).length > 0) {
89 if (!confirm( rpt_strings.SOURCE_SETUP_CONFIRM_EXIT)) return false;
93 try { renderSources(); } catch (e) {}
95 populateSourcesTree( idlclass );
97 var tree = $('sources-treetop').parentNode;
99 tree.view.selection.select(0);
103 function populateSourcesMenu (classList) {
104 classList.sort( sortLabels );
106 var menu = $('source-menu');
110 { label : rpt_strings.SOURCE_SETUP_CORE_SOURCES,
112 style : 'color: black; text-decoration: underline;'
118 for (var i in classList) {
120 var name = classList[i].getAttributeNS(rptNS,'label');
121 var id = classList[i].getAttribute('id');
122 if (!name) name = id;
126 { container : 'true',
129 onmouseup : 'resetUI( "' + id + '");'
136 menu.appendChild( createMenuSeparator() );
139 { label : rpt_strings.SOURCE_SETUP_ALL_AVAIL_SOURCES },
143 { label : rpt_strings.SOURCE_SETUP_ALL_AVAIL_SOURCES,
145 style : 'color: black; '
148 createMenuSeparator()
152 menu.appendChild( _m );
153 menu = _m.firstChild;
155 var all = map(function(x){return x;}, oilsIDL.getElementsByTagNameNS(idlNS,'class'));
156 all.sort( sortLabels );
158 for (var i = 0; i < all.length; i++) {
160 if (all[i].getAttributeNS(persistNS,'virtual') == 'true') continue;
162 var name = all[i].getAttributeNS(rptNS,'label');
163 var id = all[i].getAttribute('id');
164 if (!name) name = id;
168 { container : 'true',
171 onmouseup : 'resetUI( "' + id + '");'
181 function populateSourcesTree (idlclass) {
183 var tcNode = $('sources-treetop');
184 while (tcNode.childNodes.length) tcNode.removeChild(tcNode.lastChild);
186 var c = getIDLClass( idlclass );
187 var name = c.getAttributeNS(rptNS,'label');
188 if (!name) name = idlclass;
192 { container : 'true',
198 createTreeCell( { label : '' } ),
199 createTreeCell( { label : name } )
201 createTreeChildren( { alternatingbackground : true } )
206 function populateSourcesSubtree (tcNode, classList) {
207 classList.sort(sortNames);
208 for (var i in classList) {
209 var obj = classList[i];
211 var p = getIDLClass( obj.idlclass );
212 var cont = p.getElementsByTagName('link').length ? 'true' : 'false';
217 idlclass : obj.idlclass,
223 reltype : obj.reltype,
224 fullpath : obj.fullpath
228 createTreeCell( { label : obj.nullable } ),
229 createTreeCell( { label : obj.name } )
231 createTreeChildren( { alternatingbackground : true } )
239 function populateDetailTree (tcNode, c, item) {
240 var fullpath = item.getAttribute('fullpath');
241 var reltype = item.getAttribute('reltype');
243 var fields = nodelistToArray(c.getElementsByTagName('field'));
244 fields.sort( sortLabels );
246 var id = c.getAttribute('id');
249 var steps = fullpath.split('.');
250 for (var k in steps) {
252 if (!steps[k]) continue;
254 var atom = steps[k].split('-');
255 var classNode = getIDLClass(atom[0]);
257 var _cname = classNode.getAttributeNS(rptNS, 'label');
258 if (!_cname) _cname = classNode.getAttribute('id');
262 if (atom.length > 1 && k == steps.length - 1) {
263 var field_name = atom[1];
264 var join_type = field_name;
266 field_name = field_name.split(/>/)[0];
267 join_type = join_type.split(/>/)[1];
269 var _f = getIDLField(classNode, field_name);
270 var _fname = _f.getAttributeNS(rptNS, 'label');
271 if (!_fname) _fname = _f.getAttribute('name');
272 if (_fname) _label += ' :: ' + _fname;
273 if (join_type) _label += ' (' + join_type + ')';
275 } else if (atom[1]) {
276 var field_name = atom[1];
277 var join_type = field_name;
281 _label += ' (' + rpt_strings.LINK_NULLABLE_RIGHT + ')';
284 _label += ' (' + rpt_strings.LINK_NULLABLE_LEFT + ')';
287 _label += ' (' + rpt_strings.LINK_NULLABLE_NONE + ')';
292 path_label.push(_label);
295 $('path-label').value = path_label.join(' -> ');
296 $('path-label').setAttribute('reltype',reltype);
298 for (var i in fields) {
300 var type = fields[i].getAttributeNS(rptNS, 'datatype');
301 //if (!type) type = 'text';
303 var label = fields[i].getAttributeNS(rptNS, 'label');
304 var name = fields[i].getAttribute('name');
305 if (!label) label = name;
316 createTreeCell( { label : label } ),
317 createTreeCell( { label : type } )