// linked field object Zymonic.Field.LinkedField = function() {}; // do the inheritance Zymonic.Field.LinkedField.prototype = new Zymonic.Field.Field(); Zymonic.Field.LinkedField.prototype.constructor = this; // Accept additional args (including filter) Zymonic.Field.LinkedField.prototype.addArgs = function(args) { for (var key in args) { this[key] = args[key]; } // if filter is set, set extra param on filter for ajax calls if (this.filter) { this.filter.addExtraParam('ZZFparent_fap_from_block', 'true'); // add and linking field lookups to the filter for (var i=0; i *[type="Field"]').attr('horizontal','true'); } // transform the result var result = ZTransformXML(xml); // Pick out the top-level field divs and replace them individually for(var i=0;i < result.childNodes.length;i++ ) { if($(result.childNodes[i]).is('div')) { var id = $(result.childNodes[i]).attr('id'); if($('#'+id).length) { $('#'+id).replaceWith(result.childNodes[i]); } else { this.container_div().append(result.childNodes[i]); } $('#' + id).addClass("partof_" + this.ident + "_auto_fg"); ZReRunJS($('#' + id)); } } this.addDisplayFieldClick(); // This seems to be needed when LFs are used as search fields. this.showCorrectSection(); } // Show the correct section based on the 'unselected' attribute Zymonic.Field.LinkedField.prototype.showCorrectSection = function() { if(this.filterOpen) { // Show filter $('#' + this.ident + '_LFF').show(); // Hide fields $('div[id^=' + this.ident + '_sr].ZymonicField').hide(); } else { // Hide filter $('#' + this.ident + '_LFF').hide(); // Show fields $('div[id^=' + this.ident + '_sr].ZymonicField').show(); } }; // Add handlers to the filters XML updated events Zymonic.Field.LinkedField.prototype.addFilterEventHandlers = function() { var thislf = this; $(this.filter).bind('xmlReceived', function() { thislf.addOurAttibutesToFilterXML(); }); $(this.filter).bind('xmlTransformed', function() { thislf.attachResultRowHandlers(); }); }; // Add Linked Field attributes/elements to top-level results in filter XML Zymonic.Field.LinkedField.prototype.addOurAttibutesToFilterXML = function() { var xmlDoc = this.filter.getXML(); var thislf = this; // For each result in top level report $(xmlDoc).find("report:first > result").each(function(i, el) { // Add Linked field attribute // Unless they are already present if(!$(el).attr('LinkedFieldEntry')) { $(el).attr('LinkedFieldEntry', thislf.ident); $(el).attr('LinkedFieldType', thislf.type); $(el).attr('LinkedFieldSelected', ''); $(el).attr('LinkedFieldValue', $(el).find(thislf.source_field_zname + " > Value").text()); } }); this.filter.setXML(xmlDoc); }; //getValue mechanism Zymonic.Field.LinkedField.prototype.getValue = function() { // if field is hidden or read only, then call super as there won't be a filter if (this.hidden || this.display_only ) { return Zymonic.Field.Field.prototype.getValue.call(this); } var chkd = $('input[name="' + this.ident + '"]:checked'); if(chkd.length) { return $(chkd).val(); } else { if( $('input[name="' + this.ident + '"]:hidden').val()) return $('input[name="' + this.ident + '"]:hidden').val(); return ''; } }; // Act on filter result clicked. Zymonic.Field.LinkedField.prototype.selectResult = function(inputId) { // Check the appropriate button - NOTE this will need changing to use prop() on update to jquery 1.6 or higher $('#' + inputId).attr('checked','checked'); this.selectedId = inputId; // Ensure the unselected flag is cleared this.unselected = false; this.setValueAsChanged(); this.setNotInUse(); // do the field reload. this.reloadInPlace('', true, false, true, true, true, this.ident + "_auto_fg_inner_div"); }; // Attach handlers to the filter's top-level result rows Zymonic.Field.LinkedField.prototype.attachResultRowHandlers = function() { var thislf = this; this.beforeAttachResultRowHandlers(); // Hide the linked field selector header. $('#' + this.filter.getIdent() + 'reportresults .LinkedFieldSelectorHeader').hide(); // Loop through the table rows that have a td with class FilterLinkedFieldCell $('#' + this.filter.getIdent() + 'reportresults > table > tbody > tr').each(function() { thislf.initialiseUnselectedResultRow(this); }); }; // Stub Zymonic.Field.LinkedField.prototype.beforeAttachResultRowHandlers = function() { return; }; Zymonic.Field.LinkedField.prototype.initialiseUnselectedResultRow = function(row) { var thislf = this; var FLFC = $(row).find('.FilterLinkedFieldCell'); if(FLFC) { // Hide the FilterLinkedFieldCell td $(FLFC).hide(); // For each td that contains a ReportField class div add an onclick handler to the div $(row).find('.ReportField').each(function() { $(this).unbind('click'); $(this).click(function() { thislf.selectResult($(FLFC).find('input').attr('id')); }); $(this).addClass('LFSelectable'); }); this.unselectedRowFound(FLFC); } }; // Stub function only used by MCLF Zymonic.Field.LinkedField.prototype.unselectedRowFound = function(FLFC) { return; }; // Return correct div Zymonic.Field.LinkedField.prototype.container_div = function() { return this.jquery("_auto_fg_inner_div"); }; Zymonic.Field.LinkedField.prototype.noBasicValidation = function() { return false; }; //function called on setting/clearing validation errors //used by subclasses to do additional work on the validation errors Zymonic.Field.LinkedField.prototype.validationErrorsSet = function() { // copy errors to the container div var container_div = this.container_div(); container_div.addClass('FieldContainsError').removeClass('FieldIsValid').children('.inputError').remove(); this.moveContainedValidationErrors(); }; Zymonic.Field.LinkedField.prototype.validationErrorsCleared = function() { // clear errors on parent field group this.container_div().addClass('FieldIsValid').removeClass('FieldContainsError').children('.inputError').remove(); }; Zymonic.Field.LinkedField.prototype.moveContainedValidationErrors = function() { // copy errors to the container div var container_div = this.container_div(); container_div.find('.inputError').detach().appendTo(container_div); }; Zymonic.Field.LinkedField.prototype.getFields = function() { var super_fields = Zymonic.Field.Field.prototype.getFields.call(this); var search_fields = (this.filter ? this.filter.getSearchFields() : []); return super_fields.concat(search_fields); };