// grouped form format object Zymonic.FormFormat.Grouped = function() {}; // do the inheritance Zymonic.FormFormat.Grouped.prototype = new Zymonic.FormFormat.FormFormat(); Zymonic.FormFormat.Grouped.prototype.constructor = this; // setters Zymonic.FormFormat.Grouped.prototype.addGroupByField = function(group_by_field) { if (!this.group_by_fields) { this.group_by_fields = []; } // keep it sorted this.group_by_fields.push(group_by_field); this.group_by_fields.sort() }; Zymonic.FormFormat.Grouped.prototype.setShowHideConditions = function(conditions, condition_combination, show_message, hide_message) { this.show_hide_conditions = conditions; this.show_hide_condition_combination = condition_combination; this.show_message = show_message; this.hide_message = hide_message; // lookup unique condition lookup fields this.show_hide_condition_lookup_fields = []; var unique_condition_fields = {}; for (var i=0; i 0) { for (var i=0; i"); div.attr("id", this.ident+"_"+group.ident); div.addClass("GroupedFormFormatGroup"); group.container = div; var display_fields_container = $("
"); display_fields_container.addClass("GroupedFormFormatGroupDisplayFields"); div.append(display_fields_container); var message_container = $("

"); message_container.addClass("GroupedFormFormatGroupMessage"); div.append(message_container); var records_container = $("

"); records_container.addClass("GroupedFormFormatGroupRecords"); div.append(records_container); // if horizontal form then create table to put the display fields/records in if (this.isFormHorizontal()) { var records_table = $(""); records_table.addClass("HorizontalFormTable"); var records_header_row = this.buildRecordsDivHeaders(); records_table.append(records_header_row); records_container.append(records_table); records_container = records_table; // TODO: may only want the header row for the first group var display_fields_table = $("
"); display_fields_table.addClass("HorizontalFormTable"); var display_fields_header_row = this.buildDisplayFieldsDivHeaders(); display_fields_table.append(display_fields_header_row); display_fields_container.append(display_fields_table); display_fields_container = display_fields_table; } // move display fields for first record, then move all other records into the container for (var i=0; i"); row.addClass("record"); container.append(row); container = row; } var display_fields = {}; for (var i=0; i"); // add any display field labels for (var i=0; i"); button.addClass("GroupedFormFormatGroupShowHideButton"); var show_text = this.show_text; var hide_text = this.hide_text; button.html(show_text); Zymonic.Utils.attach_event(button, "click", this.ident, function() { if (records_container.is(":visible")) { button.html(show_text); records_container.hide(); } else { button.html(hide_text); records_container.show(); } // return false so it does not submit the form return false; }); if (this.isFormHorizontal()) { // if in horizontal form add as last cell var display_fields_row = display_fields_container.find("tr.record"); var cell = $("
"); cell.append(button); display_fields_row.append(cell); } else { display_fields_container.append(button); } // hide by default, once aggregations are set the show_hide condition // will be run to display if the condition passes records_container.hide(); // keep track of the button so can change the text easily group.show_hide_button = button; }; // sets the text to use on show/hide button Zymonic.FormFormat.Grouped.prototype.setShowHideButtonText = function(show_text, hide_text) { this.show_text = show_text || 'Show Records'; this.hide_text = hide_text || 'Hide Records'; }; // find aggregation display field and move it to the display fields container, also remove it from all records Zymonic.FormFormat.Grouped.prototype.calculateAggregation = function(aggregation, group) { var aggregation_value = this.calculateAggregationValue(aggregation, group.records); aggregation.group_display_field[group.ident].setValue(aggregation_value); }; //calculate the aggregation value over the incoming records Zymonic.FormFormat.Grouped.prototype.calculateAggregationValue = function(aggregation, records) { var aggregation_value = null; switch (aggregation.type) { case 'first': aggregation_value = this.calculateExpressionValue(aggregation.expression, aggregation.expression_default, aggregation.expression_eval, aggregation.expression_fields, records[0]); break; case 'last': aggregation_value = this.calculateExpressionValue(aggregation.expression, aggregation.expression_default, aggregation.expression_eval, aggregation.expression_fields, records[records.length-1]); break; case 'count': aggregation_value = 0; for (var i=0; i