// subform filter action object Zymonic.FilterAction.Action = function() {}; // do the inheritance Zymonic.FilterAction.Action.prototype = new Zymonic.FilterAction.FilterAction(); Zymonic.FilterAction.Action.prototype.constructor = this; //get the filter action link Zymonic.FilterAction.Action.prototype.getLink = function() { if ( this.run_in_new_block || this.run_in_place || (!this.global && !this.per_record) ) { return Zymonic.FilterAction.FilterAction.prototype.getLink.call(this); } else { return $("#"+this.ident+"_link"); } }; // run this report Zymonic.FilterAction.Action.prototype.run = function() { if (this.run_in_new_block) { this.runInNewBlock(); } else if (this.run_in_place) { this.runInPlace(); } else { this.generateReport(); } }; // run action filter action in a new block Zymonic.FilterAction.Action.prototype.runInNewBlock = function() { if (!this.block_id) { Zymonic.log_error("No block_id found on FilterAction "+this.zname, true); return; } var extras = {}; extras["ZZwebserviceblockid"] = this.block_id; extras["ZZno_display_attributes"] = "false"; extras["ZZwebservicemode"] = 'filter'; extras["ZZBzname"] = this.filter_zname; extras["ZZFident"] = this.filter_ident; extras[this.filter_ident + 'search'] = 'Show Results'; extras[this.filter_ident + 'report_only'] = 'true'; extras[this.ident+"_do"] = "true"; extras[this.ident+"_to_run"] = this.record_ident; extras["ZZFblock_id"] = this.block_id; extras["ZZFget_block_params"] = "true"; if (this.page_id) { extras["ZZFpage_id"] = this.page_id; } extras['ZZno_display_attributes'] = 'false'; Zymonic.openBlock(undefined, undefined, undefined, this.target_location, extras); }; // run action filter action in place Zymonic.FilterAction.Action.prototype.runInPlace = function() { // reload the filter to run it, action can change filter results // so need to reload the whole thing var form_data = Zymonic.new_form_data(); form_data.append(this.ident+"_do", "true"); form_data.append(this.ident+"_to_run", this.record_ident); var filter_action = this; this.getParentFilter().refresh( null, null, function() { // if flag set, trigger another refresh on success var action_results = filter_action.getLink().parent().siblings(".ActionFilterActionResults:first").find(".ActionResult"); if ( filter_action.refresh_filter_after_run && action_results.length > 0 ) { filter_action.getParentFilter().refresh(); } }, form_data ); }; // run action filter action to generate report Zymonic.FilterAction.Action.prototype.generateReport = function() { var filter_action = this; var params = {}; params[this.ident+"_do"] = "true"; if (!this.global && !this.per_record) { params[this.ident+"_to_run"] = this.record_ident; } var filter = this.getParentFilter(); // setup params if (this.skip_results) { params[filter.getIdent()+'skip_results'] = this.skip_results.toString(); } if (this.report_only) { params[filter.getIdent()+'report_only'] = this.report_only.toString(); } if (this.no_header_options) { params[filter.getIdent()+'no_header_options'] = this.no_header_options.toString(); } // if in a Linked field send through param to force its filter to always output results var parent_field = filter.getParentField() if (parent_field) { params[parent_field.getIdent() + 'force_output_filter_results'] = 'true'; } // check if we can continue with this var can_continue = 'Y'; if (this.user_error) { can_continue = 'N'; } else if (this.can_continue_js) { can_continue = eval(this.can_continue_js); } // if can't continue, display appropriate error and stop if (can_continue == 'N') { var error = "Unable to generate report."; if (this.user_error_js) { error = eval(this.user_error_js); } else if (this.user_error) { error = this.user_error; } Zymonic.log_error(error, true); return false; } else if (can_continue == 'C') { // can continue with confirmation var message = 'Report Exceeds Limits. Do you wish to proceed anyway? WARNING: Due to the large number of results this report may take a long time to generate.'; if (this.user_confirmation_js) { message = eval(this.user_confirmation_js); } else if (this.user_confirmation) { message = this.user_confirmation; } var result = confirm(message); if (result) { params[this.ident+'_user_confirmation'] = 'true'; } else { return false; } } // function to generatereport of the correct type var generate_report_function; if (this.generate_report_js) { var generate_report_js = this.generate_report_js; generate_report_function = function() { eval(generate_report_js); } } else if (this.open_in_new_window) { generate_report_function = function() { filter.reloadInNewTab(params); } } else { generate_report_function = function() { var form_data = Zymonic.new_form_data(); for (var key in params) { form_data.append(key, params[key]); } filter.refresh(null, null, null, form_data); } } // generate report via ping to ensure session is set Zymonic.ping( this.ident, generate_report_function, function(type, error, xml) { var alert_error = true; if (type == 'Zymonic' && xml && $(xml).find("session_errors:contains('Security token does not match')").length) { alert_error = false; } // if session error don't alert anything as it's already been handled // either by relogin or forcing page reload if (type == 'Zymonic' && xml && $(xml).find("session_errors:contains('Session expired')").length) { alert_error = false; } var errors = []; $(xml).find("session_errors").each(function() { errors.push($(this).text()); }); $(xml).find('Zymonic > error > message').each(function() { errors.push($(this).text()); }); Zymonic.log_error("Error running report: "+type+" - "+error+": "+errors.join(" "), alert_error); } ); };