From 1926f112169690ada4f9a5ed9a8b9e49384edd73 Mon Sep 17 00:00:00 2001
From: jsatoh <junichi@rworks.jp>
Date: Wed, 21 Sep 2011 04:23:28 +0000
Subject: [PATCH] 2011-09-21  Junichi Satoh  <junichi@rworks.jp>

	* include/javascript/jquery.pandora.controls.js: Fixed disabled agents
	are shown as blank. Contributed by Yusuke Arai. Thanks!



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4975 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                     |   5 +
 .../javascript/jquery.pandora.controls.js     | 164 +++++++-----------
 2 files changed, 64 insertions(+), 105 deletions(-)

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index c4a0af8eb3..8087f2f4ef 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,8 @@
+2011-09-21  Junichi Satoh  <junichi@rworks.jp>
+
+	* include/javascript/jquery.pandora.controls.js: Fixed disabled agents
+	are shown as blank. Contributed by Yusuke Arai. Thanks!
+
 2011-09-21  Junichi Satoh  <junichi@rworks.jp>
 
 	* include/help/ja/help_servers.php,
diff --git a/pandora_console/include/javascript/jquery.pandora.controls.js b/pandora_console/include/javascript/jquery.pandora.controls.js
index e48cc27970..27cf3e17a2 100644
--- a/pandora_console/include/javascript/jquery.pandora.controls.js
+++ b/pandora_console/include/javascript/jquery.pandora.controls.js
@@ -2,118 +2,72 @@
 	var dummyFunc = function () {
 		return true;
 	};
-	
-	$.extend ({
-		pandoraSelectGroupAgent: new function() {
-			this.defaults = {
-				agentSelect: "select#id_agent",
-				recursion: 0,
-				loading: "#agent_loading",
-				callbackBefore: dummyFunc,
-				callbackPre: dummyFunc,
-				callbackPost: dummyFunc,
-				callbackAfter: dummyFunc,
-				debug: false
-			};
-			
-			/* public methods */
-			this.construct = function (settings) {
-				return this.each (function() {
-					this.config = {};
-					
-					this.config = $.extend (this.config, $.pandoraSelectGroupAgent.defaults, settings);
-					var config = this.config;
-					
-					$(this).change (function () {
-						var $select = $(config.agentSelect).disable ();
-						$(config.loading).show ();
-						$("option[value!=0]", $select).remove ();
-						if (! config.callbackBefore (this))
-							return;
-						
-						jQuery.post ("ajax.php",
-							{"page" : "godmode/groups/group_list",
-							"get_group_agents" : 1,
-							"id_group" : this.value,
-							"recursion" : config.recursion
-							},
-							function (data, status) {
-								jQuery.each (data, function (id, value) {
-									if (id !== 'keycount'){
-										config.callbackPre ();
-										option = $("<option></option>")
-											.attr ("value", id)
-											.html (value);
-										config.callbackPost (id, value, option);
-										$(config.agentSelect).append (option);
-									}
-								});
-								$(config.loading).hide ();
-								$select.enable ();
-								config.callbackAfter ();
-							},
-							"json"
-						);
-					});
-				});
-			};
-		}
-	});
-	
-	$.extend ({
-		pandoraSelectGroupAgentDisabled: new function() {
-			this.defaults = {
-				agentSelect: "select#id_agent",
-				recursion: 0,
-				loading: "#agent_loading",
-				callbackBefore: dummyFunc,
-				callbackPre: dummyFunc,
-				callbackPost: dummyFunc,
-				callbackAfter: dummyFunc,
-				debug: false
-			};
-			
-			/* public methods */
-			this.construct = function (settings) {
-				return this.each (function() {
-					this.config = {};
-					
-					this.config = $.extend (this.config, $.pandoraSelectGroupAgentDisabled.defaults, settings);
-					var config = this.config;
-					
-					$(this).change (function () {
-						var $select = $(config.agentSelect).disable ();
-						$(config.loading).show ();
-						$("option[value!=0]", $select).remove ();
-						if (! config.callbackBefore (this))
-							return;
-						
-						jQuery.post ("ajax.php",
-							{"page" : "godmode/groups/group_list",
-							"get_group_agents" : 1,
-							"disabled" : 1,
-							"id_group" : this.value,
-							"recursion" : config.recursion
-							},
-							function (data, status) {
-								jQuery.each (data, function (id, value) {
+
+	var _pandoraSelectGroupAgent = function (disabled) {
+		var that = this;
+
+		this.defaults = {
+			agentSelect: "select#id_agent",
+			recursion: 0,
+			loading: "#agent_loading",
+			callbackBefore: dummyFunc,
+			callbackPre: dummyFunc,
+			callbackPost: dummyFunc,
+			callbackAfter: dummyFunc,
+			debug: false,
+			disabled: disabled || false,
+		};
+
+		/* public methods */
+		this.construct = function (settings) {
+			return this.each (function() {
+				this.config = {};
+
+				this.config = $.extend (this.config, that.defaults, settings);
+				var config = this.config;
+
+				$(this).change (function () {
+					var $select = $(config.agentSelect).disable ();
+					$(config.loading).show ();
+					$("option[value!=0]", $select).remove ();
+					if (! config.callbackBefore (this))
+						return;
+
+					var opts = {
+						"page" : "godmode/groups/group_list",
+						"get_group_agents" : 1,
+						"id_group" : this.value,
+						"recursion" : config.recursion,
+						"disabled" : config.disabled ? 1 : 0,
+					};
+
+					jQuery.post ("ajax.php",
+						opts,
+						function (data, status) {
+							jQuery.each (data, function (id, value) {
+								if (id !== 'keycount'){
 									config.callbackPre ();
 									option = $("<option></option>")
 										.attr ("value", id)
 										.html (value);
 									config.callbackPost (id, value, option);
 									$(config.agentSelect).append (option);
-								});
-								$(config.loading).hide ();
-								$select.enable ();
-								config.callbackAfter ();
-							},
-							"json"
-						);
-					});
+								}
+							});
+							$(config.loading).hide ();
+							$select.enable ();
+							config.callbackAfter ();
+						},
+						"json"
+					);
 				});
-			};
-		}
+			});
+		};
+	};
+	
+	$.extend ({
+		pandoraSelectGroupAgent: new _pandoraSelectGroupAgent(),
+		pandoraSelectGroupAgentDisabled: new _pandoraSelectGroupAgent(true),
 	});
 	
 	$.extend ({