From b89f39785db924df7471d1cabb2f68ef8dc5aad4 Mon Sep 17 00:00:00 2001
From: Nathan Gray <nathangray.bsc@gmail.com>
Date: Mon, 19 Mar 2012 20:30:38 +0000
Subject: [PATCH] Use global visibility settings, handle skipped columns in the
 middle

---
 etemplate/js/et2_extension_nextmatch.js | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js
index 493f7b9bb1..b408edc90d 100644
--- a/etemplate/js/et2_extension_nextmatch.js
+++ b/etemplate/js/et2_extension_nextmatch.js
@@ -630,6 +630,11 @@ var et2_nextmatch = et2_DOMWidget.extend(et2_IResizeable, {
 				var column = 0;
 				for(var i = 0; i < value.length; i++)
 				{
+					// Handle skipped columns
+					while(value[i] != "col_"+column && column < columnMgr.columns.length)
+					{
+						column++;
+					}
 					if(visibility[value[i]])
 					{
 						visibility[value[i]].visible = true;
@@ -644,7 +649,6 @@ var et2_nextmatch = et2_DOMWidget.extend(et2_IResizeable, {
 						{
 							visible[field_name] = false;
 						}
-						i++;
 						// Turn on selected custom fields - start from 0 in case they're not in order
 						for(var j = 0; j < value.length; j++)
 						{
@@ -654,7 +658,6 @@ var et2_nextmatch = et2_DOMWidget.extend(et2_IResizeable, {
 						}
 						self.columns[column].widget.set_visible(visible);
 					}
-					column++;
 				}
 				columnMgr.setColumnVisibilitySet(visibility);
 				self.selectPopup.toggle();
@@ -1164,6 +1167,11 @@ var et2_nextmatch_customfields = et2_customfields_list.extend(et2_INextmatchHead
 			}
 		}
 		if(!nm_column) return;
+		
+		// Check for global setting changes (visibility)
+		var global_data = this.getArrayMgr("modifications").getRoot().getEntry('~custom_fields~');
+		if(global_data.fields) this.options.fields = global_data.fields;
+
 		var apps = egw.link_app_list();
 		for(var field_name in this.options.customfields)
 		{