From aa4651272e9fdaa62b2881c78df3cbd90b88c0c2 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Fri, 1 Nov 2013 21:12:20 +0000 Subject: [PATCH] Some minor enhancements / bugfixes, such as - Better warnings - Check some vars before using - Fixes missing value on selects with tag attr --- etemplate/js/et2_extension_customfields.js | 8 ++++-- etemplate/js/et2_widget_selectbox.js | 29 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/etemplate/js/et2_extension_customfields.js b/etemplate/js/et2_extension_customfields.js index 4a05fd20c9..a55e362fb3 100644 --- a/etemplate/js/et2_extension_customfields.js +++ b/etemplate/js/et2_extension_customfields.js @@ -66,6 +66,9 @@ var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput this._super.apply(this, arguments); + // Allows server side to override prefix - not an attribute though + if(typeof this.options.prefix != 'undefined') this.prefix = this.options.prefix; + // Create the table body and the table this.tbody = $j(document.createElement("tbody")); this.table = $j(document.createElement("table")) @@ -151,7 +154,7 @@ var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput // Check for global setting changes (visibility) var global_data = this.getArrayMgr("modifications").getRoot().getEntry('~custom_fields~'); - if(global_data.fields && !this.options.fields) this.options.fields = global_data.fields; + if(global_data && global_data.fields && !this.options.fields) this.options.fields = global_data.fields; // For checking app entries var apps = this.egw().link_app_list(); @@ -329,7 +332,6 @@ var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput } }, - /** * et2_IInput so the custom field can be it's own widget. */ @@ -401,6 +403,8 @@ var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput attrs.rows = field.rows; attrs.select_options = field.values; + attrs.tags = field.tags; + return true; }, _setup_htmlarea: function(field_name, field, attrs) { diff --git a/etemplate/js/et2_widget_selectbox.js b/etemplate/js/et2_widget_selectbox.js index 4ca102cef0..bc31655c30 100644 --- a/etemplate/js/et2_widget_selectbox.js +++ b/etemplate/js/et2_widget_selectbox.js @@ -183,6 +183,17 @@ var et2_selectbox = et2_inputWidget.extend( { content_options = this.getArrayMgr("sel_options").getEntry(name_parts[name_parts.length-1]); } + + // Try name like widget[$row] + if(!content_options || content_options.length == 0) + { + var pop_that = jQuery.extend([],name_parts); + while(pop_that.length > 0 && (!content_options || content_options.length == 0)) + { + pop_that.pop(); + content_options = this.getArrayMgr('sel_options').getEntry(pop_that.join('[')); + } + } // Maybe in a row, and options got stuck in ${row} instead of top level var row_stuck = ['${row}','{$row}']; @@ -427,10 +438,16 @@ var et2_selectbox = et2_inputWidget.extend( { _value = _value.split(','); } + if(this.input !== null && this.options.select_options && this.input.children().length == 0) + { + // No options set yet + this.set_select_options(this.options.select_options); + } if(this.input !== null && (this.options.tags || this.options.search)) { this.input.val(_value); this.input.trigger("liszt:updated"); + this.value = this.input.val(); return; } if(this.input == null) @@ -459,14 +476,22 @@ var et2_selectbox = et2_inputWidget.extend( } else { - if(jQuery("option[value='"+_value+"']", this.input).prop("selected", true).length == 0) + if(_value && jQuery("option[value='"+_value+"']", this.input).prop("selected", true).length == 0) { if(this.options.select_options[_value]) { // Options not set yet? Do that now, which will try again. return this.set_select_options(this.options.select_options); } - this.egw().debug("warn", "Tried to set value that isn't an option", this, _value); + else if (jQuery.isEmptyObject(this.options.select_options)) + { + this.egw().debug("warn", "Can't set value to '%s', widget has no options set",_value, this); + } + else + { + this.egw().debug("warn", "Tried to set value '%s' that isn't an option", _value, this); + } + return; } }