1 dojo.requireLocalization("openils.reports", "reports");
3 var rpt_strings = dojo.i18n.getLocalization("openils.reports", "reports");
5 function removeReportAtom (args) {
8 var active_tab = filterByAttribute(
9 $('used-source-fields-tabbox').getElementsByTagName('tab'),
13 var tabname = active_tab.getAttribute('id');
15 var tabpanel = $( tabname + 'panel' );
16 var tree = tabpanel.getElementsByTagName('tree')[0];
17 var fields = getSelectedItems(tree);
20 for (var i in fields) {
21 var field = fields[i];
22 var colname = field.firstChild.firstChild.nextSibling.getAttribute('label');
23 var relation_alias = field.getAttribute('relation');
25 delete rpt_rel_cache[relation_alias].fields[tabname][colname];
26 if (tabname == 'dis_tab') {
28 for each (var _o_col in rpt_rel_cache.order_by) {
29 if (_o_col.relation == relation_alias && _o_col.field == colname) continue;
30 _o_tmp.push( _o_col );
32 rpt_rel_cache.order_by = _o_tmp
35 with (rpt_rel_cache[relation_alias].fields) {
36 if ( getKeys(dis_tab).length == 0 && getKeys(filter_tab).length == 0 && getKeys(aggfilter_tab).length == 0 )
37 delete rpt_rel_cache[relation_alias];
46 function getSourceDefinition(aClass) {
47 var class_obj = getIDLClass(aClass);
48 return class_obj.getAttributeNS(persistNS,'tablename') ||
49 '(' + class_obj.getElementsByTagNameNS(persistNS,'source_definition')[0].textContent + ')';
52 function addReportAtoms () {
53 var nope = $( 'source-add' ).getAttribute('disabled');
54 if (nope == 'true') return false;
56 var class_tree = $('class-view');
57 var transform_tree = $('trans-view');
59 var active_tab = filterByAttribute(
60 $('used-source-fields-tabbox').getElementsByTagName('tab'),
65 var tabname = active_tab.getAttribute('id')
67 var items = getSelectedItems(class_tree);
68 var transform = getSelectedItems(transform_tree)[0];
70 var reltype = $('path-label').getAttribute('reltype');
71 var class_label = $('path-label').value;
72 var relation_alias = hex_md5(class_label);
74 for (var i in items) {
77 var class_path = item.getAttribute('fullpath');
78 var field_class = item.getAttribute('idlclass');
79 var datatype = item.getAttribute('datatype');
80 var colname = item.getAttribute('idlfield');
81 var jointype = item.getAttribute('join');
82 var field_label = item.firstChild.firstChild.getAttribute('label');
85 var table_name = getSourceDefinition(field_class);
87 if ( !rpt_rel_cache[relation_alias] ) {
88 rpt_rel_cache[relation_alias] =
89 { label : class_label,
90 alias : relation_alias,
94 idlclass : field_class,
96 fields : { dis_tab : {}, filter_tab : {}, aggfilter_tab : {} }
100 if ( !rpt_rel_cache[relation_alias].fields[tabname][colname] ) {
101 rpt_rel_cache[relation_alias].fields[tabname][colname] =
103 transform : (transform && transform.getAttribute('name')) || rpt_strings.TEMPLATE_CONF_BARE,
104 aggregate : transform && transform.getAttribute('aggregate'),
105 params : transform && transform.getAttribute('params'),
106 transform_label: (transform && transform.getAttribute('alias')) || rpt_strings.TEMPLATE_CONF_RAW_DATA,
108 field_doc : field_doc,
111 op : (datatype == 'array') ? '= any' : '=',
112 op_label : rpt_strings.TEMPLATE_CONF_EQUALS,
116 if (!rpt_rel_cache.order_by)
117 rpt_rel_cache.order_by = [];
119 if (tabname == 'dis_tab')
120 rpt_rel_cache.order_by.push( { relation : relation_alias, field : colname } );
122 } else if (confirm(dojo.string.substitute( rpt_strings.TEMPLATE_CONF_CONFIRM_RESET, [field_label, class_label] )) ) {
123 rpt_rel_cache[relation_alias].fields[tabname][colname] =
125 transform : (transform && transform.getAttribute('name')) || rpt_strings.TEMPLATE_CONF_BARE,
126 aggregate : transform && transform.getAttribute('aggregate'),
127 params : transform && transform.getAttribute('params'),
128 transform_label: (transform && transform.getAttribute('alias')) || rpt_strings.TEMPLATE_CONF_RAW_DATA,
130 field_doc : field_doc,
134 op_label : rpt_strings.TEMPLATE_CONF_EQUALS,
145 function changeDisplayOrder (dir) {
146 var active_tab = filterByAttribute(
147 $('used-source-fields-tabbox').getElementsByTagName('tab'),
152 var tabname = active_tab.getAttribute('id');
154 var tabpanel = $( tabname + 'panel' );
155 var tree = tabpanel.getElementsByTagName('tree')[0];
156 var item = getSelectedItems(tree)[0];
158 var item_pos = tree.view.selection.currentIndex;
161 if ( item.previousSibling ) {
162 item.parentNode.insertBefore( item, item.previousSibling );
165 } else if (dir == 'd') {
166 if ( item.nextSibling ) {
167 if (item.nextSibling.nextSibling ) item.parentNode.insertBefore( item, item.nextSibling.nextSibling );
168 else item.parentNode.appendChild( item );
173 rpt_rel_cache.order_by = [];
174 var ordered_list = tree.getElementsByTagName('treeitem');
175 for (var i = 0; i < ordered_list.length; i++) {
176 rpt_rel_cache.order_by.push(
177 { relation : ordered_list[i].getAttribute('relation'),
178 field : ordered_list[i].firstChild.firstChild.nextSibling.getAttribute('label')
183 tree.view.selection.select( item_pos );
187 function alterColumnLabel () {
188 var active_tab = filterByAttribute(
189 $('used-source-fields-tabbox').getElementsByTagName('tab'),
194 var tabname = active_tab.getAttribute('id');
196 var tabpanel = $( tabname + 'panel' );
197 var tree = tabpanel.getElementsByTagName('tree')[0];
198 var item_pos = tree.view.selection.currentIndex;
200 var item = getSelectedItems(tree)[0];
201 var relation_alias = item.getAttribute('relation');
203 var field = item.firstChild.firstChild;
204 var colname = field.nextSibling.getAttribute('label');
206 var old_label = field.getAttribute("label");
207 var new_label = prompt( dojo.string.substitute(rpt_strings.TEMPLATE_CONF_PROMPT_CHANGE, [old_label]), old_label );
210 rpt_rel_cache[relation_alias].fields[tabname][colname].alias = new_label;
212 tree.view.selection.select( item_pos );
220 function changeFieldDoc () {
221 var active_tab = filterByAttribute(
222 $('used-source-fields-tabbox').getElementsByTagName('tab'),
227 var tabname = active_tab.getAttribute('id');
229 var tabpanel = $( tabname + 'panel' );
230 var tree = tabpanel.getElementsByTagName('tree')[0];
231 var item_pos = tree.view.selection.currentIndex;
233 var item = getSelectedItems(tree)[0];
234 var relation_alias = item.getAttribute('relation');
236 var field = item.firstChild.lastChild;
237 var colname = item.firstChild.firstChild.nextSibling.getAttribute('label');
239 var old_label = field.getAttribute("label");
240 var new_label = prompt( rpt_strings.TEMPLATE_FIELD_DOC_PROMPT_CHANGE, old_label );
243 rpt_rel_cache[relation_alias].fields[tabname][colname].field_doc = new_label;
245 tree.view.selection.select( item_pos );
253 function alterColumnTransform (trans) {
255 var transform = OILS_RPT_TRANSFORMS[trans];
257 var active_tab = filterByAttribute(
258 $('used-source-fields-tabbox').getElementsByTagName('tab'),
263 var tabname = active_tab.getAttribute('id');
265 var tabpanel = $( tabname + 'panel' );
266 var tree = tabpanel.getElementsByTagName('tree')[0];
267 var item_pos = tree.view.selection.currentIndex;
268 var item = getSelectedItems(tree)[0];
269 var relation_alias = item.getAttribute('relation');
271 var field = item.firstChild.firstChild;
272 var colname = field.nextSibling.getAttribute('label');
274 rpt_rel_cache[relation_alias].fields[tabname][colname].transform = trans;
275 rpt_rel_cache[relation_alias].fields[tabname][colname].aggregate = transform.aggregate;
276 rpt_rel_cache[relation_alias].fields[tabname][colname].params = transform.params;
277 rpt_rel_cache[relation_alias].fields[tabname][colname].transform_label = transform.label;
280 tree.view.selection.select( item_pos );
284 $(tabname + '_trans_menu').hidePopup();
288 function changeOperator (args) {
290 var active_tab = filterByAttribute(
291 $('used-source-fields-tabbox').getElementsByTagName('tab'),
296 var tabname = active_tab.getAttribute('id');
298 var tabpanel = $( tabname + 'panel' );
299 var tree = tabpanel.getElementsByTagName('tree')[0];
300 var item_pos = tree.view.selection.currentIndex;
301 var item = getSelectedItems(tree)[0];
303 var relation_alias = item.getAttribute('relation');
305 var field = item.firstChild.firstChild;
306 var colname = field.nextSibling.getAttribute('label');
308 rpt_rel_cache[relation_alias].fields[tabname][colname].op = args.op;
309 rpt_rel_cache[relation_alias].fields[tabname][colname].op_label = args.label;
312 tree.view.selection.select( item_pos );
316 $(tabname + '_op_menu').hidePopup();
320 function removeTemplateFilterValue () {
322 var active_tab = filterByAttribute(
323 $('used-source-fields-tabbox').getElementsByTagName('tab'),
328 var tabname = active_tab.getAttribute('id');
330 var tabpanel = $( tabname + 'panel' );
331 var tree = tabpanel.getElementsByTagName('tree')[0];
332 var item_pos = tree.view.selection.currentIndex;
333 var items = getSelectedItems(tree);
335 for (var i in items) {
337 var relation_alias = item.getAttribute('relation');
339 var field = item.firstChild.firstChild;
340 var colname = field.nextSibling.getAttribute('label');
342 rpt_rel_cache[relation_alias].fields[tabname][colname].op_value = {};
346 tree.view.selection.select( item_pos );
350 function timestampSetDate (obj, cal, date) {
351 obj.op_value.value = date;
352 obj.op_value.object = cal.date;
353 obj.op_value.label = '"' + date + '"';
361 function changeTemplateFilterValue () {
363 var active_tab = filterByAttribute(
364 $('used-source-fields-tabbox').getElementsByTagName('tab'),
369 var tabname = active_tab.getAttribute('id');
371 var tabpanel = $( tabname + 'panel' );
372 var tree = tabpanel.getElementsByTagName('tree')[0];
373 var items = getSelectedItems(tree);
375 var targetCmd = $( tabname + '_value_action' );
377 targetCmd.menu = null;
378 targetCmd.command = null;
379 targetCmd.oncommand = null;
380 targetCmd.removeEventListener( 'command', __handler_cache, true );
382 for (var i in items) {
384 var relation_alias = item.getAttribute('relation');
386 var field = item.firstChild.firstChild;
387 var colname = field.nextSibling.getAttribute('label');
389 var obj = rpt_rel_cache[relation_alias].fields[tabname][colname]
390 var operation = OILS_RPT_FILTERS[obj.op];
392 switch (obj.datatype) {
394 var cal_popup = $('calendar-widget');
396 while (cal_popup.firstChild) cal_popup.removeChild(cal_popup.lastChild);
397 var calendar = new Calendar(
400 function (cal,date) { return timestampSetDate(obj,cal,date) },
401 function (cal) { cal_popup.hidePopup(); cal.destroy(); return true; }
404 var format = OILS_RPT_TRANSFORMS[obj.transform].cal_format || '%Y-%m-%d';
406 calendar.setDateFormat(format);
407 calendar.create(cal_popup);
409 targetCmd.menu = 'calendar-widget';
415 function __bool_value_event_handler () {
419 // get a reference to the prompt service component.
420 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
421 .getService(Components.interfaces.nsIPromptService);
423 // set the buttons that will appear on the dialog. It should be
424 // a set of constants multiplied by button position constants. In this case,
425 // three buttons appear, Save, Cancel and a custom button.
426 var flags=promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 +
427 promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1 +
428 promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_2;
430 // display the dialog box. The flags set above are passed
431 // as the fourth argument. The next three arguments are custom labels used for
432 // the buttons, which are used if BUTTON_TITLE_IS_STRING is assigned to a
433 // particular button. The last two arguments are for an optional check box.
434 answer = promptService.select(
436 rpt_strings.TEMPLATE_CONF_BOOLEAN_VALUE,
437 rpt_strings.TEMPLATE_CONF_SELECT_CANCEL,
438 2, [rpt_strings.TEMPLATE_CONF_TRUE, rpt_strings.TEMPLATE_CONF_FALSE], state
442 state = confirm(rpt_strings.TEMPLATE_CONF_CONFIRM_STATE);
443 state ? state = 0 : state = 1;
448 obj.op_value.value = 'f';
449 obj.op_value.label = rpt_strings.TEMPLATE_CONF_FALSE;
451 obj.op_value.value = 't';
452 obj.op_value.label = rpt_strings.TEMPLATE_CONF_TRUE;
456 targetCmd.removeEventListener( 'command', __bool_value_event_handler, true );
458 tree.view.selection.select( item_pos );
462 __handler_cache = __bool_value_event_handler;
463 targetCmd.addEventListener( 'command', __bool_value_event_handler, true );
470 var promptstring = rpt_strings.TEMPLATE_CONF_NO_MATCH;
474 promptstring = rpt_strings.TEMPLATE_CONF_NOT_BETWEEN;
478 promptstring = rpt_strings.TEMPLATE_CONF_BETWEEN;
482 promptstring = rpt_strings.TEMPLATE_CONF_NOT_IN;
486 promptstring = rpt_strings.TEMPLATE_CONF_IN;
490 promptstring = dojo.string.substitute( rpt_strings.TEMPLATE_CONF_DEFAULT, [obj.op_label]);
494 function __default_value_event_handler () {
496 if (_v = prompt( promptstring, obj.op_value.value || '' )) {
502 obj.op_value.value = _v.split(/\s*,\s*/);
506 obj.op_value.value = _v;
510 obj.op_value.label = '"' + obj.op_value.value + '"';
513 targetCmd.removeEventListener( 'command', __default_value_event_handler, true );
515 tree.view.selection.select( item_pos );
519 __handler_cache = __default_value_event_handler;
520 targetCmd.addEventListener( 'command', __default_value_event_handler, true );
529 function populateOperatorContext () {
531 var active_tab = filterByAttribute(
532 $('used-source-fields-tabbox').getElementsByTagName('tab'),
537 var tabname = active_tab.getAttribute('id');
539 var tabpanel = $( tabname + 'panel' );
540 var tree = tabpanel.getElementsByTagName('tree')[0];
541 var items = getSelectedItems(tree);
544 for (var i in items) {
546 dtypes.push( item.getAttribute('datatype') );
549 var menu = $(tabname + '_op_menu');
550 while (menu.firstChild) menu.removeChild(menu.lastChild);
552 for (var i in OILS_RPT_FILTERS) {
553 var o = OILS_RPT_FILTERS[i];
558 onmouseup : "changeOperator({op:'"+i+"',label:'"+o.label+"'})"
565 var keys = getKeys(o.labels);
566 for ( var k in keys ) {
568 if ( grep(function(x){return key==x},dtypes).length ) {
571 { label : o.labels[key],
572 onmouseup : "changeOperator({op:'"+i+"',label:'"+o.labels[key]+"'});"
582 function populateTransformContext () {
584 var active_tab = filterByAttribute(
585 $('used-source-fields-tabbox').getElementsByTagName('tab'),
590 var tabname = active_tab.getAttribute('id');
592 var tabpanel = $( tabname + 'panel' );
593 var tree = tabpanel.getElementsByTagName('tree')[0];
594 var items = getSelectedItems(tree);
597 for (var i in items) {
599 var dtype = item.getAttribute('datatype');
600 var item_transforms = getTransforms({ datatype : dtype });
602 for (var j in item_transforms) {
603 transforms[item_transforms[j]] = OILS_RPT_TRANSFORMS[item_transforms[j]];
604 transforms[item_transforms[j]].name = item_transforms[j];
608 var transformList = [];
609 for (var i in transforms) {
610 transformList.push( transforms[i] );
613 transformList.sort( sortHashLabels );
615 var menu = $(tabname + '_trans_menu');
616 while (menu.firstChild) menu.removeChild(menu.lastChild);
618 for (var i in transformList) {
619 var t = transformList[i];
621 if (tabname.match(/filter/)) {
622 if (tabname.match(/^agg/)) {
623 if (!t.aggregate) continue;
625 if (t.aggregate) continue;
631 { aggregate : t.aggregate,
636 onmouseup : "alterColumnTransform('"+t.name+"')"
642 menu.parentNode.setAttribute('disabled','false');
643 if (menu.childNodes.length == 0) {
644 menu.parentNode.setAttribute('disabled','true');
649 function renderSources (selected) {
651 var tree = $('used-sources');
652 var sources = $('used-sources-treetop');
653 var tabs = $('used-source-fields-tabbox').getElementsByTagName('tab');
656 while (sources.firstChild) sources.removeChild(sources.lastChild);
658 selected = getSelectedItems(tree);
659 if (!selected.length) {
660 selected = undefined;
661 while (sources.firstChild) sources.removeChild(sources.lastChild);
665 for (var j = 0; j < tabs.length; j++) {
667 var tabname = tab.getAttribute('id')
668 var tabpanel = $( tab.getAttribute('id') + 'panel' );
669 var fieldtree = tabpanel.getElementsByTagName('treechildren')[0];
671 while (fieldtree.firstChild) fieldtree.removeChild(fieldtree.lastChild);
674 for (var relation_alias in rpt_rel_cache) {
675 if (!rpt_rel_cache[relation_alias].fields) continue;
681 return x.getAttribute('relation') == relation_alias;
688 $('used-sources-treetop').appendChild(
690 { relation : rpt_rel_cache[relation_alias].alias,
691 idlclass : rpt_rel_cache[relation_alias].idlclass,
692 reltype : rpt_rel_cache[relation_alias].reltype,
693 path : rpt_rel_cache[relation_alias].path
697 createTreeCell({ label : rpt_rel_cache[relation_alias].label }),
698 createTreeCell({ label : rpt_rel_cache[relation_alias].table }),
699 createTreeCell({ label : rpt_rel_cache[relation_alias].alias }),
700 createTreeCell({ label : rpt_rel_cache[relation_alias].reltype })
706 for each (var tabname in ['filter_tab','aggfilter_tab']) {
707 tabpanel = $( tabname + 'panel' );
708 fieldtree = tabpanel.getElementsByTagName('treechildren')[0];
710 for (var colname in rpt_rel_cache[relation_alias].fields[tabname]) {
712 // TODO: code would be clearer if we could access the loaded template
713 // version from here. Not sure how... it's not in rpt_rel_cache.
714 // Existing templates (e.g. from cloning) will not have a field_doc
715 // attribute. with() is not tolerant of nonexistent attributes.
716 if (!rpt_rel_cache[relation_alias].fields[tabname][colname].field_doc)
717 rpt_rel_cache[relation_alias].fields[tabname][colname].field_doc = '';
719 with (rpt_rel_cache[relation_alias].fields[tabname][colname]) {
720 fieldtree.appendChild(
722 { relation : relation_alias, datatype : datatype },
725 createTreeCell({ label : alias }),
726 createTreeCell({ label : colname }),
727 createTreeCell({ label : datatype }),
728 createTreeCell({ label : transform_label }),
729 createTreeCell({ label : transform })
734 fieldtree.lastChild.firstChild.appendChild(
735 createTreeCell({ op : op, label : op_label })
738 if (op_value.value != undefined) {
739 fieldtree.lastChild.firstChild.appendChild(
740 createTreeCell({ label : op_value.label })
743 fieldtree.lastChild.firstChild.appendChild(
748 fieldtree.lastChild.firstChild.appendChild(
749 createTreeCell({ label : field_doc })
756 tabpanel = $( 'dis_tabpanel' );
757 fieldtree = tabpanel.getElementsByTagName('treechildren')[0];
758 for each (var order in rpt_rel_cache.order_by) {
764 return x.getAttribute('relation') == order.relation;
771 // Existing templates (e.g. from cloning) will not have a field_doc
772 // attribute. with() is not tolerant of nonexistent attributes.
773 if (!rpt_rel_cache[order.relation].fields.dis_tab[order.field].field_doc)
774 rpt_rel_cache[order.relation].fields.dis_tab[order.field].field_doc = '';
776 with (rpt_rel_cache[order.relation].fields.dis_tab[order.field]) {
777 fieldtree.appendChild(
779 { relation : order.relation, datatype : datatype },
782 createTreeCell({ label : alias }),
783 createTreeCell({ label : colname }),
784 createTreeCell({ label : datatype }),
785 createTreeCell({ label : transform_label }),
786 createTreeCell({ label : transform }),
787 createTreeCell({ label : field_doc })
798 filter_tab : 'where',
799 aggfilter_tab : 'having',
803 function save_template () {
808 doc_url : $('template-doc-url').value,
809 core_class : $('sources-treetop').getElementsByTagName('treeitem')[0].getAttribute('idlclass'),
817 for (var relname in rpt_rel_cache) {
818 var relation = rpt_rel_cache[relname];
819 if (!relation.fields) continue;
821 // first, add the where and having clauses (easier)
822 for each (var tab_name in [ 'filter_tab', 'aggfilter_tab' ]) {
823 var tab = relation.fields[tab_name];
824 for (var field in tab) {
825 fleshTemplateField( template, relation, tab_name, field );
829 // now the from clause
830 fleshFromPath( template, relation );
833 // and now for select (based on order_by)
834 for each (var order in rpt_rel_cache.order_by)
835 fleshTemplateField( template, rpt_rel_cache[order.relation], 'dis_tab', order.field );
837 template.rel_cache = rpt_rel_cache;
839 //prompt( 'template', js2JSON( template ) );
841 // and the saving throw ...
843 var session = cgi.param('ses');
844 fetchUser( session );
847 tmpl.name( $('template-name').value );
848 tmpl.description( $('template-description').value );
849 tmpl.owner(USER.id());
850 tmpl.folder(cgi.param('folder'));
851 tmpl.data(js2JSON(template));
853 if(!confirm(dojo.string.substitute( rpt_strings.TEMPLATE_CONF_CONFIRM_SAVE, [tmpl.name(), tmpl.description()] )))
856 var req = new Request('open-ils.reporter:open-ils.reporter.template.create', session, tmpl);
857 req.request.alertEvent = false;
860 var res = r.getResultObject();
861 if(checkILSEvent(res)) {
864 if( res && res != '0' ) {
865 alert(dojo.string.substitute( rpt_strings.TEMPLATE_CONF_SUCCESS_SAVE, [tmpl.name()] ));
866 _l('../oils_rpt.xhtml');
875 function fleshFromPath ( template, rel ) {
876 var table_path = rel.path.split( /\./ );
877 if (table_path.length > 1 || rel.path.indexOf('-') > -1) table_path.push( rel.idlclass );
881 var current_path = '';
882 var current_obj = template.from;
884 while (link = table_path.shift()) {
886 if (prev_link != '') {
887 var prev_class = getIDLClass( prev_link.split(/-/)[0] );
888 var prev_field = prev_link.split(/-/)[1];
890 var prev_join = prev_field;
892 prev_field = prev_field.split(/>/)[0];
893 prev_join = prev_join.split(/>/)[1];
895 var current_link = getIDLLink( prev_class, prev_field );
896 current_obj.key = current_link.getAttribute('key');
898 //console.log("prev_link in fleshFromPath is: " + prev_link);
899 //console.log("prev_join in fleshFromPath is: " + prev_join);
901 if (prev_join) current_obj.type = prev_join
904 current_link.getAttribute('reltype') != 'has_a' ||
905 prev_type == 'left' ||
906 rel.reltype != 'has_a'
908 // This disallows outer joins when the item is used in a filter
910 // getKeys(rel.fields.filter_tab).length == 0 &&
911 // getKeys(rel.fields.aggfitler_tab).length == 0
914 ) current_obj.type = 'left';
916 prev_type = current_obj.type;
920 if (current_path) current_path += '-';
921 current_path += link.split(/>/)[0];
923 var leaf = table_path.length == 0 ? true : false;
925 current_obj.path = current_path;
926 current_obj.table = getSourceDefinition( link.split(/-/)[0] );
931 var join_type = link.split(/-/)[1];
933 join_type = join_type.split(/>/)[1];
934 if (join_type && join_type != 'undefined') current_obj.type = join_type;
937 current_obj.label = rel.label;
938 current_obj.alias = rel.alias;
939 current_obj.idlclass = rel.idlclass;
940 current_obj.template_path = rel.path;
942 var current_class = getIDLClass( link.split(/-/)[0] );
943 var join_field = link.split(/-/)[1];
944 var join_type = join_field;
946 join_field = join_field.split(/>/)[0];
947 join_type = join_type.split(/>/)[1];
949 //console.log("join_field in fleshFromPath is: " + join_field);
951 var join_link = getIDLLink(current_class, join_field);
953 if (join_link.getAttribute('reltype') != 'has_a') {
954 var fields_el = current_class.getElementsByTagName('fields')[0];
956 fields_el.getAttributeNS(persistNS, 'primary') +
957 '-' + join_link.getAttribute('class') +
958 '-' + join_link.getAttribute('key');
961 if (!current_obj.alias) current_obj.alias = hex_md5( current_path ) ;
962 join_field += '-' + current_obj.alias;
964 if (!current_obj.join) current_obj.join = {};
965 if (!current_obj.join[join_field]) current_obj.join[join_field] = {};
967 if (current_obj.type == 'left') current_obj.join[join_field].type = 'left';
969 current_obj = current_obj.join[join_field];
978 function fleshTemplateField ( template, rel, tab_name, field ) {
980 if (!rel.fields[tab_name] || !rel.fields[tab_name][field]) return;
982 var tab = rel.fields[tab_name];
984 var table_path = rel.path.split( /\./ );
985 if (table_path.length > 1 || rel.path.indexOf('-') > -1)
986 table_path.push( rel.idlclass );
988 table_path.push( field );
990 var field_path = table_path.join('-');
993 alias : tab[field].alias,
994 field_doc : tab[field].field_doc,
997 transform : tab[field].transform,
998 transform_label : tab[field].transform_label
1001 relation : rel.alias
1004 if (tab_name.match(/filter/)) {
1005 element.condition = {};
1006 if (tab[field].op == 'is' || tab[field].op == 'is not' || tab[field].op == 'is blank' || tab[field].op == 'is not blank') {
1007 element.condition[tab[field].op] = null;
1009 element.condition[tab[field].op] =
1010 tab[field].op_value.value ?
1011 tab[field].op_value.value :
1012 '::P' + param_count++;
1016 template[tab_use[tab_name]].push(element);