Add set_value() so selectbox can show current value

This commit is contained in:
Nathan Gray
2011-09-26 16:01:42 +00:00
parent db3f408f18
commit 29501fc027
4 changed files with 61 additions and 10 deletions

View File

@@ -78,7 +78,7 @@ var et2_inputWidget = et2_valueWidget.extend(et2_IInput, {
this._super.apply(this, arguments); this._super.apply(this, arguments);
// Check whether an validation error entry exists // Check whether an validation error entry exists
if (this.id) if (this.id && this.getArrayMgr("validation_errors"))
{ {
var val = this.getArrayMgr("validation_errors").getEntry(this.id); var val = this.getArrayMgr("validation_errors").getEntry(this.id);
if (val) if (val)

View File

@@ -515,14 +515,17 @@ var et2_widget = Class.extend({
console.log(this.id); console.log(this.id);
} }
var data = this.getArrayMgr("modifications").getEntry(this.id); if(this.getArrayMgr("modifications"))
if (data instanceof Object)
{ {
for (var key in data) var data = this.getArrayMgr("modifications").getEntry(this.id);
if (data instanceof Object)
{ {
if (!(data[key] instanceof Object)) for (var key in data)
{ {
_attrs[key] = data[key]; if (!(data[key] instanceof Object))
{
_attrs[key] = data[key];
}
} }
} }
} }

View File

@@ -477,20 +477,21 @@ var et2_nextmatch_header_bar = Class.extend(et2_INextmatchHeader, {
var self = this; var self = this;
var nm_div = this.nextmatch.div; var nm_div = this.nextmatch.div;
var settings = this.nextmatch.options.settings;
this.div.prependTo(nm_div); this.div.prependTo(nm_div);
// Left // Left
// Record count // Record count
this.count = jQuery(document.createElement("span")) this.count = jQuery(document.createElement("div"))
.addClass("header_count") .addClass("header_count")
.appendTo(this.div); .appendTo(this.div);
this.count.append("? - ? ").append(egw.lang("of")).append(" "); this.count.append("? - ? ").append(egw.lang("of")).append(" ");
this.count_total = jQuery(document.createElement("span")) this.count_total = jQuery(document.createElement("span"))
.appendTo(this.count) .appendTo(this.count)
.text(this.nextmatch.options.settings.total + ""); .text(settings.total + "");
// Set up so if row count changes, display is updated // Set up so if row count changes, display is updated
nm_div.bind('nm_data', function(e) { // Have to bind to DOM node, not et2 widget nm_div.bind('nm_data', function(e) { // Have to bind to DOM node, not et2 widget
@@ -499,13 +500,39 @@ var et2_nextmatch_header_bar = Class.extend(et2_INextmatchHeader, {
// Right // Right
var filters = jQuery(document.createElement("div")).appendTo(this.div);
// Add category // Add category
if(!settings.no_cat) {
this.category = this._build_select('cat_id', 'select-cat', settings.cat_id, true);
filters.append(this.category.getDOMNode());
}
// Filter 1 // Filter 1
if(!settings.no_filter) {
this.filter = this._build_select('filter', 'select', settings.filter, settings.filter_no_lang);
filters.append(this.filter.getDOMNode());
}
// Filter 2 // Filter 2
if(!settings.no_filter2) {
this.filter2 = this._build_select('filter2', 'select', settings.filter2, settings.filter2_no_lang);
filters.append(this.filter2.getDOMNode());
}
// Search // Search
this.search = et2_createWidget("textbox", {}, this.nextmatch);
this.search.input.attr("type", "search");
filters.append(this.search.getDOMNode());
jQuery(document.createElement("button"))
.appendTo(filters)
.text(">")
.click(this.nextmatch, function(event) {
event.data.activeFilters.search = self.search.getValue()
event.data.applyFilters();
});
// Export // Export
@@ -545,7 +572,16 @@ var et2_nextmatch_header_bar = Class.extend(et2_INextmatchHeader, {
event.data.applyFilters(); event.data.applyFilters();
}); });
} }
},
_build_select: function(name, type, value, lang) {
var select = et2_createWidget(type, {
"id": this.nextmatch.id + "_"+name,
},this.nextmatch);
select.set_value(value);
return select;
} }
}); });
et2_register_widget(et2_nextmatch_header_bar, ["nextmatch_header_bar"]); et2_register_widget(et2_nextmatch_header_bar, ["nextmatch_header_bar"]);

View File

@@ -77,7 +77,10 @@ var et2_selectbox = et2_inputWidget.extend({
this._super.apply(this, arguments); this._super.apply(this, arguments);
// Try to find the options inside the "sel-options" array // Try to find the options inside the "sel-options" array
_attrs["select_options"] = this.getArrayMgr("sel_options").getEntry(this.id); if(this.getArrayMgr("sel_options"))
{
_attrs["select_options"] = this.getArrayMgr("sel_options").getEntry(this.id);
}
// Check whether the options entry was found, if not read it from the // Check whether the options entry was found, if not read it from the
// content array. // content array.
@@ -145,6 +148,15 @@ var et2_selectbox = et2_inputWidget.extend({
} }
}, },
set_value: function(_value) {
jQuery("option",this.input).attr("selected", false);
this.value = null;
if(jQuery("option[value='"+_value+"']", this.input).attr("selected", true).length > 0)
{
this.value = _value;
}
},
/** /**
* The set_select_options function is added, as the select options have to be * The set_select_options function is added, as the select options have to be
* added after the "option"-widgets were added to selectbox. * added after the "option"-widgets were added to selectbox.
@@ -171,7 +183,7 @@ var et2_selectbox = et2_inputWidget.extend({
} }
}); });
et2_register_widget(et2_selectbox, ["menupopup", "listbox", "select-cat", et2_register_widget(et2_selectbox, ["menupopup", "listbox", "select", "select-cat",
"select-account", "select-percent", 'select-priority', 'select-access', "select-account", "select-percent", 'select-priority', 'select-access',
'select-country', 'select-state', 'select-year', 'select-month', 'select-country', 'select-state', 'select-year', 'select-month',
'select-day', 'select-dow', 'select-hour', 'select-number', 'select-app', 'select-day', 'select-dow', 'select-hour', 'select-number', 'select-app',