// ReportContainer Contains ReportBuilder objects for all DocTypes // - Only one ReportContainer exists // - Page header is als a part // - New ReportBuilder is made here _r.ReportContainer = function() { this.wrapper = page_body.add_page("Report Builder", function() { }); this.wrapper.className ='layout_wrapper'; var head_div = $a(this.wrapper, 'div'); this.rb_area = $a(this.wrapper, 'div'); $dh(this.wrapper); var me = this; this.rb_dict = {}; // tool bar this.page_head = new PageHeader(head_div); $y(this.page_head.wrapper, {marginBottom:'0px'}); // buttons var run_fn = function() { if(me.cur_rb){ me.cur_rb.dt.start_rec = 1; me.cur_rb.dt.run(); } } var runbtn = this.page_head.add_button('Run', run_fn, 1, 'ui-icon-circle-triangle-e', 1); // new if(has_common(['Administrator', 'System Manager'], user_roles)) { // save var savebtn = this.page_head.add_button('Save', function() {if(me.cur_rb) me.cur_rb.save_criteria(); }, 0, 'ui-icon-disk'); // advanced var fn = function() { if(me.cur_rb) { if(!me.cur_rb.current_loaded) { msgprint("error:You must save the report before you can set Advanced features"); return; } loaddoc('Search Criteria', me.cur_rb.sc_dict[me.cur_rb.current_loaded]); } }; var advancedbtn = this.page_head.add_button('Advanced Settings', fn); } // set a type this.set_dt = function(dt, onload) { my_onload = function(f) { if(!f.forbidden) { me.cur_rb = f; me.cur_rb.mytabs.items['Result'].expand(); if(onload)onload(f); } } if(me.cur_rb) me.cur_rb.hide(); if(me.rb_dict[dt]){ me.rb_dict[dt].show(my_onload); } else { me.rb_dict[dt] = new _r.ReportBuilder(me.rb_area, dt, my_onload); } } } // =================================================================================== // + ReportBuilder // + Datatable (grid) // + ColumnPicker // + ReportFilter // // - Contains all methods relating to saving, loading and executing Search Criteria // - Contains ui objects of the report including tabs _r.ReportBuilder = function(parent, doctype, onload) { this.menuitems = {}; this.has_primary_filters = false; this.doctype = doctype; this.forbidden = 0; this.filter_fields = []; this.filter_fields_dict = {}; var me = this; this.fn_list = ['beforetableprint','beforerowprint','afterrowprint','aftertableprint','customize_filters','get_query']; this.wrapper = $a(parent, 'div', 'finder_wrapper'); this.make_tabs(); this.current_loaded = null; this.setup_doctype(onload); this.hide = function() { $dh(me.wrapper); } this.show = function(my_onload) { $ds(me.wrapper); // reset main title this.set_main_title('Report: ' + get_doctype_label(me.doctype)); if(my_onload)my_onload(me); } } // ------------------------------------------------------------------------------------- _r.ReportBuilder.prototype.make_tabs = function() { this.tab_wrapper = $a(this.wrapper, 'div', 'finder_tab_area'); this.mytabs = new TabbedPage(this.tab_wrapper); this.mytabs.add_item('Result', null, null, 1); this.mytabs.add_item('More Filters', null, null, 1); this.mytabs.add_item('Select Columns', null, null, 1); this.mytabs.tabs = this.mytabs.items; } // ------------------------------------------------------------------------------------- _r.ReportBuilder.prototype.make_body = function() { this.set_main_title('Report: ' + get_doctype_label(this.doctype)); var me = this; this.make_save_criteria(); this.column_picker = new _r.ReportColumnPicker(this); this.report_filters = new _r.ReportFilters(this); } // // Make list of all Criterias relating to this DocType // ------------------------------------------------------------------------------------- // Search Criterias are loaded with the DocType - put them in a list and dict _r.ReportBuilder.prototype.make_save_criteria = function() { var me = this; // make_list // --------- this.sc_list = []; this.sc_dict = {}; for(var n in locals['Search Criteria']) { var d = locals['Search Criteria'][n]; if(d.doc_type==this.doctype) { this.sc_list[this.sc_list.length] = d.criteria_name; this.sc_dict[d.criteria_name] = n; } } } // Save Criteria // ------------------------------------------------------------------------------------- _r.ReportBuilder.prototype.save_criteria = function(save_as) { var overwrite = 0; // is loaded? if(this.current_loaded && (!save_as)) { var overwrite = confirm('Do you want to overwrite the saved criteria "'+this.current_loaded+'"'); if(overwrite) { var doc = locals['Search Criteria'][this.sc_dict[this.current_loaded]]; var criteria_name = this.current_loaded; } } // new criteria if(!overwrite) { var criteria_name = prompt('Select a name for the criteria:', ''); if(!criteria_name) return; var dn = createLocal('Search Criteria'); var doc = locals['Search Criteria'][dn]; doc.criteria_name = criteria_name; doc.doc_type = this.doctype; } var cl = []; var fl = {}; // save columns var t = this.column_picker.get_selected(); for(var i=0;i