From 237d1d809eb636ef6205c18cad1330eb462b5612 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 11 May 2015 17:29:31 +0000 Subject: [PATCH] * If column information is stored in a favorite, restore it along with the filters To get column information in the favorite, change the visible columns before you create the favorite. If the favorite has no column information, the visible columns will not be changed. --- etemplate/js/et2_extension_nextmatch.js | 62 +++++++++++++++++++++++++ infolog/inc/class.infolog_ui.inc.php | 3 +- infolog/js/app.js | 9 +++- phpgwapi/js/jsapi/app_base.js | 5 ++ 4 files changed, 76 insertions(+), 3 deletions(-) diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js index a43793d7db..570cdeaf7b 100644 --- a/etemplate/js/et2_extension_nextmatch.js +++ b/etemplate/js/et2_extension_nextmatch.js @@ -1436,6 +1436,68 @@ 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(); + }, + /** * 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 b84f5bf1b4..30e179a44b 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 8cf7a2e217..7717e52358 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 dc96bb9586..8214fd4f73 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);