diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js index e4e11d2468..5fda74654b 100644 --- a/etemplate/js/et2_extension_nextmatch.js +++ b/etemplate/js/et2_extension_nextmatch.js @@ -1436,6 +1436,71 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin .css("left", s_position.left + this.div.width() - this.selectPopup.width()); }, + /** + * Set the currently displayed columns, without updating user's preference + * + * @param {string[]} column_list List of column names + * @param {boolean} trigger_update=false - explicitly trigger an update + */ + set_columns: function(column_list, trigger_update) + { + var columnMgr = this.dataview.getColumnMgr(); + var visibility = {}; + + // Initialize to false + for (var i = 0; i < columnMgr.columns.length; i++) + { + var col = columnMgr.columns[i]; + if(col.caption && col.visibility != ET2_COL_VISIBILITY_ALWAYS_NOSELECT ) + { + visibility[col.id] = {visible: false}; + } + } + for(var i = 0; i < this.columns.length; i++) + { + + var widget = this.columns[i].widget; + var colName = this._getColumnName(widget); + if(column_list.indexOf(colName) !== -1) + { + visibility[columnMgr.columns[i].id].visible = true; + } + // Custom fields are listed seperately in column list, but are only 1 column + if(widget && widget.instanceOf(et2_nextmatch_customfields)) { + + // Just the ID for server side, not the whole nm name - some apps use it to skip custom fields + colName = widget.id; + if(column_list.indexOf(colName) !== -1) + { + visibility[columnMgr.columns[i].id].visible = true; + } + + var cf = this.columns[i].widget.options.customfields; + var visible = this.columns[i].widget.options.fields; + + // Turn off all custom fields + for(var field_name in cf) + { + visible[field_name] = false; + } + // Turn on selected custom fields - start from 0 in case they're not in order + for(var j = 0; j < column_list.length; j++) + { + if(column_list[j].indexOf(et2_customfields_list.prototype.prefix) != 0) continue; + visible[column_list[j].substring(1)] = true; + } + widget.set_visible(visible); + } + } + columnMgr.setColumnVisibilitySet(visibility); + + // We don't want to update user's preference, so directly update + this.dataview._updateColumns(); + + // Allow column widgets a chance to resize + this.iterateOver(function(widget) {widget.resize();}, this, et2_IResizeable); + }, + /** * Set the letter search preference, and update the UI * diff --git a/infolog/inc/class.infolog_ui.inc.php b/infolog/inc/class.infolog_ui.inc.php index ac1c95172f..3769e78f69 100644 --- a/infolog/inc/class.infolog_ui.inc.php +++ b/infolog/inc/class.infolog_ui.inc.php @@ -422,8 +422,7 @@ class infolog_ui $columselection = $this->prefs[$columnselection_pref]; - //_debug_array($columselection); - if ($columselection) + if (!$query['selectcols'] && $columselection) { $columselection = is_array($columselection) ? $columselection : explode(',',$columselection); } diff --git a/infolog/js/app.js b/infolog/js/app.js index 0627f1aa42..6596c01d35 100644 --- a/infolog/js/app.js +++ b/infolog/js/app.js @@ -213,7 +213,12 @@ app.classes.infolog = AppJS.extend( { // Show / hide descriptions this.show_details(filter2.value == 'all', nm.getDOMNode(nm)); + } + // Only change columns for a real user event, to avoid interfering with + // favorites + if (nm && filter2 && !nm.update_in_progress) + { // Store selection as implicit preference egw.set_preference('infolog', nm.options.settings.columnselection_pref.replace('-details','')+'-details-pref', filter2.value); @@ -223,6 +228,8 @@ app.classes.infolog = AppJS.extend( // Load new preferences var colData = nm.columns.slice(); for(var i = 0; i < nm.columns.length; i++) colData[i].disabled=false; + + nm.set_columns(egw.preference(nm.options.settings.columnselection_pref,'infolog').split(',')); nm._applyUserPreferences(nm.columns, colData); // Now apply them to columns @@ -231,7 +238,7 @@ app.classes.infolog = AppJS.extend( nm.dataview.getColumnMgr().columns[i].set_width(colData[i].width); nm.dataview.getColumnMgr().columns[i].set_visibility(!colData[i].disabled); } - nm.dataview.getColumnMgr().updated = true; + nm.dataview.getColumnMgr().updated = true; // Update page nm.dataview.updateColumns(); } diff --git a/phpgwapi/js/jsapi/app_base.js b/phpgwapi/js/jsapi/app_base.js index 083c716994..aa176a3d49 100644 --- a/phpgwapi/js/jsapi/app_base.js +++ b/phpgwapi/js/jsapi/app_base.js @@ -291,6 +291,11 @@ var AppJS = Class.extend( { _widget.sortBy(state.state.sort.id, state.state.sort.asc,false); } + if(state.state && state.state.selectcols) + { + // Make sure it's a real array, not an object, then set cols + _widget.set_columns(jQuery.extend([],state.state.selectcols)); + } _widget.applyFilters(state.state || state.filter || {}); nextmatched = true; }, this, et2_nextmatch);