- Listen to sub-template deferred to allow children of children to finish initializing (allows more complex sub-templates)

- Special case for sub-template filter having null value
- On sub-template input change, only update changed values instead of resetting & re-generating filters
Fixes some sub-template filters & col_filters conflicting and overwriting each other
This commit is contained in:
Nathan Gray 2014-05-08 16:25:28 +00:00
parent 609d1df763
commit c886f46122

View File

@ -1960,16 +1960,17 @@ var et2_nextmatch_header_bar = et2_DOMWidget.extend(et2_INextmatchHeader,
} }
// Load the template // Load the template
var self = this;
var header = et2_createWidget("template", {"id": template_name}, this); var header = et2_createWidget("template", {"id": template_name}, this);
jQuery(header.getDOMNode()).addClass(location == "left" ? "et2_hbox_left": location=="right" ?"et2_hbox_right":'').addClass("nm_header"); jQuery(header.getDOMNode()).addClass(location == "left" ? "et2_hbox_left": location=="right" ?"et2_hbox_right":'').addClass("nm_header");
this.headers[id] = header; this.headers[id] = header;
$j(header.getDOMNode()).on("load", jQuery.proxy(function() { var deferred = [];
//header.loadingFinished(); header.loadingFinished(deferred);
this._bindHeaderInput(header);
},this)); // Wait until all child widgets are loaded, then bind
// Don't care about deferred promises, using load event instead jQuery.when(deferred).then(function() {
// to only catch not available templates self._bindHeaderInput(header);
header.loadingFinished([]); });
}, },
/** /**
@ -2231,12 +2232,20 @@ var et2_nextmatch_header_bar = et2_DOMWidget.extend(et2_INextmatchHeader,
return null; return null;
}, },
_bindHeaderInput: function(_widget) { /**
* Bind all the inputs in the header sub-templates to update the filters
* on change, and update current filter with the inputs' current values
*
* @param {et2_template} sub_header
*/
_bindHeaderInput: function(sub_header) {
var header = this; var header = this;
_widget.iterateOver(function(_widget){
sub_header.iterateOver(function(_widget){
// Previously set change function // Previously set change function
var widget_change = _widget.change; var widget_change = _widget.change;
_widget.change = function(_node) {
var change = function(_node) {
// Call previously set change function // Call previously set change function
var result = widget_change.call(_widget,_node); var result = widget_change.call(_widget,_node);
@ -2245,16 +2254,36 @@ var et2_nextmatch_header_bar = et2_DOMWidget.extend(et2_INextmatchHeader,
// Update dirty // Update dirty
_widget._oldValue = _widget.getValue(); _widget._oldValue = _widget.getValue();
var value = this.getInstanceManager().getValues(header); // Widget will not have an entry in getValues() because nulls
// are not returned, we remove it from activeFilters
// Filter now, but reset - handles nulled values if(_widget._oldValue == null)
header.nextmatch.activeFilters = {}; {
header.nextmatch.applyFilters(value[header.nextmatch.id]); var path = _widget.getArrayMgr('content').explodeKey(_widget.id);
if(path.length > 0)
{
var entry = header.nextmatch.activeFilters;
var i = 0;
for(; i < path.length-1; i++)
{
entry = entry[path[i]];
}
delete entry[path[i]];
}
header.nextmatch.applyFilters(header.nextmatch.activeFilters);
}
else
{
// Not null is easy, just get values
var value = this.getInstanceManager().getValues(sub_header);
header.nextmatch.applyFilters(value[header.nextmatch.id]);
}
} }
// In case this gets bound twice, it's important to return // In case this gets bound twice, it's important to return
return true; return true;
}; };
_widget.change = change;
// Set activeFilters to current value // Set activeFilters to current value
// Use an array mgr to hande non-simple IDs // Use an array mgr to hande non-simple IDs
var value = {}; var value = {};