pandorafms/pandora_console/include/javascript/jquery.pandora.controls.js
esanchezm 7a65a5670e 2009-02-23 Esteban Sanchez <estebans@artica.es>
* include/javascript/jquery.pandora.controls.js: Changed agent and
	module selector to allow any kind of object instead of only an id.
	Tiny changes to allow multiple elements in a page.

	* include/functions_html.php: Added a separator for duplicated select
	elements (it's useful sometimes to get this number with javascript and
	using a separator helps)

	* godmode/agentes/manage_delete.php,
	godmode/agentes/manage_config.php: Fixed agent and group selector to
	fits changes in pandora.controls.js.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1475 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-02-23 16:23:58 +00:00

115 lines
3.0 KiB
JavaScript

$(document).ready (function () {
var dummyFunc = function () {
return;
};
$.extend ({
pandoraSelectGroup: new function() {
this.defaults = {
agentSelect: "select#id_agent",
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, $.pandoraSelectGroup.defaults, settings);
var config = this.config;
$(this).change (function () {
var $select = $(config.agentSelect).disable ();
$(config.loading).show ();
$("option[value!=0]", $select).remove ();
config.callbackBefore (this);
jQuery.post ("ajax.php",
{"page" : "godmode/groups/group_list",
"get_group_agents" : 1,
"id_group" : this.value
},
function (data, status) {
jQuery.each (data, function (id, value) {
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 ({
pandoraSelectAgent: new function() {
this.defaults = {
moduleSelect: "select#id_agent_module",
loading: "module_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, $.pandoraSelectAgent.defaults, settings);
var config = this.config;
$(this).change (function () {
var $select = $(config.moduleSelect).disable ();
$(config.loading).show ();
$("option[value!=0]", $select).remove ();
config.callbackBefore (this);
jQuery.post ('ajax.php',
{"page": "operation/agentes/ver_agente",
"get_agent_modules_json": 1,
"id_agent": this.value
},
function (data) {
jQuery.each (data, function (i, value) {
config.callbackPre ();
option = $("<option></option>")
.attr ("value", value['id_agente_modulo'])
.html (html_entity_decode (value['nombre']));
config.callbackPost (i, value, option);
$(config.moduleSelect).append (option);
});
$(config.loading).hide ();
$select.enable ();
config.callbackAfter ();
},
"json"
);
});
});
};
}
});
$.fn.extend({
pandoraSelectGroup: $.pandoraSelectGroup.construct,
pandoraSelectAgent: $.pandoraSelectAgent.construct,
});
});