2009-02-16 Esteban Sanchez <estebans@artica.es>
* include/javascript/jquery.pandora.controls.js: Added to repository. New file to hold all common jQuery Pandora operations. Currently it holds a generic process to loads a list of agents from a group dropdown menu. * godmode/agentes/manage_config.php: Loading spinners moved next to the label because it was causing some ugly flickers due to 100% width elements. Use code from jquery.pandora.controls.js. * godmode/alerts/alert_compounds.php: Rewritten to be more user friendly. Filtering is now possible. New operations like enable/disable or delete are now available. * include/styles/pandora.css: Added style for alert_compounds.php. * include/functions.php: Make offset parameter optional in pagination(). Style correction. * include/functions_alerts.php: Added delete_alert_compound(). git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1460 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
6a73cfab72
commit
ad1c804342
|
@ -1,3 +1,25 @@
|
|||
2009-02-16 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* include/javascript/jquery.pandora.controls.js: Added to repository.
|
||||
New file to hold all common jQuery Pandora operations. Currently it
|
||||
holds a generic process to loads a list of agents from a group
|
||||
dropdown menu.
|
||||
|
||||
* godmode/agentes/manage_config.php: Loading spinners moved next to
|
||||
the label because it was causing some ugly flickers due to 100%
|
||||
width elements. Use code from jquery.pandora.controls.js.
|
||||
|
||||
* godmode/alerts/alert_compounds.php: Rewritten to be more user
|
||||
friendly. Filtering is now possible. New operations like
|
||||
enable/disable or delete are now available.
|
||||
|
||||
* include/styles/pandora.css: Added style for alert_compounds.php.
|
||||
|
||||
* include/functions.php: Make offset parameter optional in
|
||||
pagination(). Style correction.
|
||||
|
||||
* include/functions_alerts.php: Added delete_alert_compound().
|
||||
|
||||
2009-02-16 Jorge Gonzalez <jorgegonz@artica.es>
|
||||
|
||||
* godmode/agentes/module_manager_editor_common.php: Changed string
|
||||
|
|
|
@ -121,10 +121,10 @@ $table->style = array ();
|
|||
$table->style[0] = 'font-weight: bold; vertical-align:top';
|
||||
$table->style[2] = 'font-weight: bold';
|
||||
$table->size = array ();
|
||||
$table->size[0] = '10%';
|
||||
$table->size[1] = '40%';
|
||||
$table->size[2] = '10%';
|
||||
$table->size[3] = '40%';
|
||||
$table->size[0] = '15%';
|
||||
$table->size[1] = '35%';
|
||||
$table->size[2] = '15%';
|
||||
$table->size[3] = '35%';
|
||||
|
||||
/* Source selection */
|
||||
$table->id = 'source_table';
|
||||
|
@ -132,11 +132,11 @@ $table->data[0][0] = __('Group');
|
|||
$table->data[0][1] = print_select ($groups, 'source_id_group', $source_id_group,
|
||||
false, '', '', true);
|
||||
$table->data[0][2] = __('Agent');
|
||||
$table->data[0][2] .= ' <span id="source_agent_loading" class="invisible">';
|
||||
$table->data[0][2] .= '<img src="images/spinner.gif" />';
|
||||
$table->data[0][2] .= '</span>';
|
||||
$table->data[0][3] = print_select (get_group_agents ($source_id_group, false, "none"),
|
||||
'source_id_agent', $source_id_agent, false, __('Select'), 0, true);
|
||||
$table->data[0][3] .= '<span id="source_agent_loading" class="invisible">';
|
||||
$table->data[0][3] .= '<img src="images/spinner.gif" />';
|
||||
$table->data[0][3] .= '</span>';
|
||||
|
||||
echo '<form id="manage_config_form" method="post" action="index.php?sec=gagente&sec2=godmode/agentes/manage_config">';
|
||||
|
||||
|
@ -210,11 +210,11 @@ $table->data = array ();
|
|||
$table->data[0][0] = __('Group');
|
||||
$table->data[0][1] = print_select ($groups, 'destiny_id_group', $destiny_id_group,
|
||||
false, '', '', true);
|
||||
$table->data[0][1] .= '<span id="destiny_agent_loading" class="invisible">';
|
||||
$table->data[0][1] .= '<img src="images/spinner.gif" />';
|
||||
$table->data[0][1] .= '</span>';
|
||||
|
||||
$table->data[1][0] = __('Agent');
|
||||
$table->data[1][0] .= '<span id="destiny_agent_loading" class="invisible">';
|
||||
$table->data[1][0] .= '<img src="images/spinner.gif" />';
|
||||
$table->data[1][0] .= '</span>';
|
||||
$table->data[1][1] = print_select (get_group_agents ($destiny_id_group, false, "none"),
|
||||
'destiny_id_agent[]', 0, false, '', '', true, true);
|
||||
|
||||
|
@ -232,29 +232,25 @@ echo '</form>';
|
|||
echo '<h3 class="error invisible" id="message"> </h3>';
|
||||
|
||||
$config['jquery'][] = 'form';
|
||||
$config['jquery'][] = 'pandora.controls';
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready (function () {
|
||||
$("#source_id_group").change (function () {
|
||||
$("#source_agent_loading").show ();
|
||||
var select = $("#source_id_agent").disable ();
|
||||
/* Remove all but "Select" */
|
||||
$("option[value!=0]", select).remove ();
|
||||
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) {
|
||||
$(select).append ($("<option></option>").attr ("value", id).html (value));
|
||||
});
|
||||
$("#source_agent_loading").hide ();
|
||||
$("#source_id_agent").enable ();
|
||||
},
|
||||
"json"
|
||||
);
|
||||
$("#source_id_group").pandoraSelectGroup ({
|
||||
agentSelectId: "source_id_agent",
|
||||
loadingId: "source_agent_loading"
|
||||
});
|
||||
|
||||
$("#destiny_id_group").pandoraSelectGroup ({
|
||||
agentSelectId: "destiny_id_agent\\[\\]",
|
||||
loadingId: "destiny_agent_loading",
|
||||
callbackPost: function (id, value, option) {
|
||||
if ($("#source_id_agent").fieldValue ().in_array (id)) {
|
||||
/* Hide source agent */
|
||||
$(option).hide ();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#source_id_agent").change (function () {
|
||||
|
@ -352,31 +348,6 @@ $(document).ready (function () {
|
|||
);
|
||||
});
|
||||
|
||||
$("#destiny_id_group").change (function () {
|
||||
$("#destiny_agent_loading").show ();
|
||||
var select = $("#destiny_id_agent\\[\\]").disable ();
|
||||
$("#destiny_id_agent\\[\\] option").remove ();
|
||||
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) {
|
||||
option = $("<option></option>").attr ("value", id).html (value)
|
||||
if ($("#source_id_agent").fieldValue ().in_array (id)) {
|
||||
/* Hide source agent */
|
||||
$(option).hide ();
|
||||
}
|
||||
$(select).append (option);
|
||||
});
|
||||
$("#destiny_agent_loading").hide ();
|
||||
$("#destiny_id_agent\\[\\]").enable ();
|
||||
},
|
||||
"json"
|
||||
);
|
||||
});
|
||||
|
||||
$("#manage_config_form").submit (function () {
|
||||
$("h3:not([id=message])").remove ();
|
||||
if ($("#source_id_agent").attr ("value") == 0) {
|
||||
|
|
|
@ -24,46 +24,174 @@ if (! give_acl ($config['id_user'], 0, "LM")) {
|
|||
exit;
|
||||
}
|
||||
|
||||
require_once ('include/functions_agents.php');
|
||||
require_once ('include/functions_alerts.php');
|
||||
|
||||
$id_group = (int) get_parameter ('id_group');
|
||||
$id_agent = (int) get_parameter ('id_agent');
|
||||
$search = (string) get_parameter ('search');
|
||||
|
||||
$url = 'index.php?galertas&sec2=godmode/alerts/alert_compounds';
|
||||
if ($id_group)
|
||||
$url .= '&id_group='.$id_group;
|
||||
if ($id_agent)
|
||||
$url .= '&id_agent='.$id_agent;
|
||||
if ($search != '');
|
||||
$url .= '&search='.$search;
|
||||
|
||||
$groups = get_user_groups (0, 'LM');
|
||||
$agents = get_group_agents ($id_group, false, "none");
|
||||
|
||||
$delete_alert = (int) get_parameter ('delete_alert');
|
||||
$enable_alert = (int) get_parameter ('enable_alert');
|
||||
$disable_alert = (int) get_parameter ('disable_alert');
|
||||
|
||||
if ($delete_alert) {
|
||||
$id = (int) get_parameter ('id');
|
||||
$result = delete_alert_compound ($id);
|
||||
print_error_message ($result, __('Successfully deleted'),
|
||||
__('Could not be deleted'));
|
||||
if (defined ('AJAX'))
|
||||
return;
|
||||
}
|
||||
|
||||
if ($enable_alert) {
|
||||
$id = (int) get_parameter ('id');
|
||||
$result = set_alerts_compound_disable ($id, false);
|
||||
print_error_message ($result, __('Successfully enabled'),
|
||||
__('Could not be enabled'));
|
||||
if (defined ('AJAX'))
|
||||
return;
|
||||
}
|
||||
|
||||
if ($disable_alert) {
|
||||
$id = (int) get_parameter ('id');
|
||||
$result = set_alerts_compound_disable ($id, true);
|
||||
print_error_message ($result, __('Successfully disabled'),
|
||||
__('Could not be disabled'));
|
||||
if (defined ('AJAX'))
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<h1>'.__('Compound alerts').'</h1>';
|
||||
|
||||
$groups = get_user_groups ();
|
||||
$agents = get_group_agents (array_keys ($groups), false, "none");
|
||||
|
||||
$table->class = 'alert_list';
|
||||
$table->id = 'filter_compound_table';
|
||||
$table->width = '90%';
|
||||
$table->data = array ();
|
||||
$table->style = array ();
|
||||
$table->style[0] = 'font-weight: bold; vertical-align:top';
|
||||
$table->style[2] = 'font-weight: bold';
|
||||
$table->size = array ();
|
||||
$table->colspan = array ();
|
||||
$table->size[0] = '15%';
|
||||
$table->size[1] = '35%';
|
||||
$table->size[2] = '15%';
|
||||
$table->size[3] = '35%';
|
||||
|
||||
foreach ($agents as $agent_id => $agent_name) {
|
||||
$alerts = get_agent_alerts_compound ($agent_id);
|
||||
if (empty ($alerts))
|
||||
$table->data[0][0] = __('Group');
|
||||
$table->data[0][1] = print_select ($groups, 'id_group', $id_group, false, '',
|
||||
'', true);
|
||||
$table->data[0][2] = __('Agent');
|
||||
$table->data[0][2] .= ' <span id="agent_loading" class="invisible">';
|
||||
$table->data[0][2] .= '<img src="images/spinner.gif" />';
|
||||
$table->data[0][2] .= '</span>';
|
||||
$table->data[0][3] = print_select ($agents, 'id_agent', $id_agent, false,
|
||||
__('All'), 0, true);
|
||||
|
||||
$table->data[1][0] = __('Free search');
|
||||
$table->data[1][1] = print_input_text ('search', $search, '', 20, 40, true);
|
||||
$table->colspan[1][1] = 3;
|
||||
|
||||
echo '<form id="filter_form" method="post" action="index.php?galertas&sec2=godmode/alerts/alert_compounds">';
|
||||
print_table ($table);
|
||||
echo '<div class="action-buttons" style="width: 90%">';
|
||||
print_input_hidden ('do_search', 1);
|
||||
print_submit_button (__('Search'), 'search_btn', false, 'class="sub search"');
|
||||
echo '</div>';
|
||||
echo '</form>';
|
||||
unset ($table);
|
||||
|
||||
$where = '';
|
||||
if ($search != '')
|
||||
$where = sprintf (' AND (description LIKE "%%%s%%" OR name LIKE "%%%s%%")',
|
||||
$search, $search);
|
||||
if ($id_agent)
|
||||
$agents = array ($id_agent => $id_agent);
|
||||
$sql = sprintf ('SELECT COUNT(*) FROM talert_compound
|
||||
WHERE id_agent in (%s)%s',
|
||||
implode (',', array_keys ($agents)), $where);
|
||||
$total = (int) get_db_sql ($sql);
|
||||
pagination ($total, $url);
|
||||
|
||||
$table->id = 'alert_list';
|
||||
$table->class = 'alert_list databox';
|
||||
$table->width = '90%';
|
||||
$table->data = array ();
|
||||
$table->head = array ();
|
||||
$table->style = array ();
|
||||
$table->style[1] = 'font-weight: bold';
|
||||
$table->align = array ();
|
||||
$table->align[3] = 'center';
|
||||
$table->size = array ();
|
||||
$table->size[0] = '20px';
|
||||
$table->size[3] = '20px';
|
||||
$table->head[0] = '';
|
||||
$table->head[1] = __('Name');
|
||||
$table->head[2] = __('Agent');
|
||||
$table->head[3] = __('Delete');
|
||||
|
||||
$sql = sprintf ('SELECT id FROM talert_compound
|
||||
WHERE id_agent in (%s)%s LIMIT %d OFFSET %d',
|
||||
implode (',', array_keys ($agents)), $where,
|
||||
$config['block_size'], get_parameter ('offset'));
|
||||
$id_alerts = get_db_all_rows_sql ($sql);
|
||||
|
||||
if ($id_alerts === false)
|
||||
$id_alerts = array ();
|
||||
|
||||
foreach ($id_alerts as $alert) {
|
||||
$alert = get_alert_compound ($alert['id']);
|
||||
if ($alert === false)
|
||||
continue;
|
||||
|
||||
echo '<h3>'.$agent_name.' - '.__('Compound alerts').'</h3>';
|
||||
$data = array ();
|
||||
|
||||
$table->data = array ();
|
||||
$table->head = array ();
|
||||
$table->style = array ();
|
||||
$table->style[0] = 'font-weight: bold';
|
||||
$table->head[0] = __('Name');
|
||||
|
||||
foreach ($alerts as $alert) {
|
||||
$data = array ();
|
||||
|
||||
$data[0] = '<a href="index.php?sec=galertas&sec2=godmode/alerts/configure_alert_compound&id='.$alert['id'].'">';
|
||||
$data[0] .= $alert['name'];
|
||||
$data[0] .= '</a>';
|
||||
|
||||
array_push ($table->data, $data);
|
||||
$data[0] = '<form class="disable_alert_form" action="'.$url.'" method="post" style="display: inline;">';
|
||||
if ($alert['disabled']) {
|
||||
$data[0] .= print_input_image ('enable', 'images/lightbulb_off.png', 1, '', true);
|
||||
$data[0] .= print_input_hidden ('enable_alert', 1, true);
|
||||
} else {
|
||||
$data[0] .= print_input_image ('disable', 'images/lightbulb.png', 1, '', true);
|
||||
$data[0] .= print_input_hidden ('disable_alert', 1, true);
|
||||
}
|
||||
$data[0] .= print_input_hidden ('id', $alert['id'], true);
|
||||
$data[0] .= '</form>';
|
||||
|
||||
print_table ($table);
|
||||
$data[1] = '<a href="index.php?sec=galertas&sec2=godmode/alerts/configure_alert_compound&id='.$alert['id'].'">';
|
||||
$data[1] .= $alert['name'];
|
||||
$data[1] .= '</a>';
|
||||
$data[2] = get_agent_name ($alert['id_agent']);
|
||||
$data[3] = '<a href="'.$url.'&delete_alert=1&id='.$alert['id'].'"
|
||||
onClick="javascript:confirm(\''.__('Are you sure').'\')">';
|
||||
$data[3] .= '<img src="images/cross.png" title="'.__('Delete').'" />';
|
||||
$data[3] .= '</a>';
|
||||
|
||||
array_push ($table->data, $data);
|
||||
}
|
||||
|
||||
print_table ($table);
|
||||
|
||||
echo '<div class="action-buttons" style="width: '.$table->width.'">';
|
||||
echo '<form method="post" action="index.php?sec=galertas&sec2=godmode/alerts/configure_alert_compound">';
|
||||
print_submit_button (__('Create'), 'crtbtn', false, 'class="sub next"');
|
||||
print_input_hidden ('new_compound', 1);
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
|
||||
$config['jquery'][] = 'pandora.controls';
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready (function () {
|
||||
$("#id_group").pandoraSelectGroup ();
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -254,20 +254,27 @@ function list_files ($directory, $stringSearch, $searchHandler, $return = false)
|
|||
* Prints a pagination menu to browse into a collection of data.
|
||||
*
|
||||
* @param int $count Number of elements in the collection.
|
||||
* @param string $url URL of the pagination links. It must include all form values as GET form.
|
||||
* @param int $offset Current offset for the pagination
|
||||
* @param int $pagination Current pagination size. If a user requests a larger pagination than config["block_size"]
|
||||
* @param string $url URL of the pagination links. It must include all form
|
||||
* values as GET form.
|
||||
* @param int $offset Current offset for the pagination. Default value would be
|
||||
* taken from $_REQUEST['offset']
|
||||
* @param int $pagination Current pagination size. If a user requests a larger
|
||||
* pagination than config["block_size"]
|
||||
* @param bool $return Whether to return or print this
|
||||
*
|
||||
* @return string The pagination div or nothing if no pagination needs to be done
|
||||
*/
|
||||
function pagination ($count, $url, $offset, $pagination = 0, $return = false) {
|
||||
function pagination ($count, $url, $offset = 0, $pagination = 0, $return = false) {
|
||||
global $config;
|
||||
|
||||
if (empty ($pagination)) {
|
||||
$pagination = $config["block_size"];
|
||||
}
|
||||
|
||||
if (empty ($offset)) {
|
||||
$offset = (int) get_parameter ('offset');
|
||||
}
|
||||
|
||||
/* URL passed render links with some parameter
|
||||
&offset - Offset records passed to next page
|
||||
&counter - Number of items to be blocked
|
||||
|
@ -351,15 +358,14 @@ function pagination ($count, $url, $offset, $pagination = 0, $return = false) {
|
|||
// get offset for index calculation
|
||||
// Draw "last" block link, ajust for last block will be the same
|
||||
// as painted in last block (last integer block).
|
||||
if (($count - $pagination) > 0){
|
||||
$myoffset = floor(($count-1) / $pagination) * $pagination;
|
||||
if (($count - $pagination) > 0) {
|
||||
$myoffset = floor (($count - 1) / $pagination) * $pagination;
|
||||
$output .= '<a href="'.$url.'&offset='.$myoffset.'"><img class="bot" src="images/control_end_blue.png" /></a>';
|
||||
}
|
||||
// End div and layout
|
||||
$output .= "</div>";
|
||||
if ($return === false) {
|
||||
if ($return === false)
|
||||
echo $output;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
|
@ -1071,4 +1071,14 @@ function validate_alert_compound ($id_alert_compound) {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function delete_alert_compound ($id_alert_compound) {
|
||||
$id_alert_compound = safe_int ($id_alert_compound, 1);
|
||||
if (empty ($id_alert_compound))
|
||||
return false;
|
||||
|
||||
$sql = sprintf ('DELETE FROM talert_compound WHERE id = %d',
|
||||
$id_alert_compound);
|
||||
return @process_sql ($sql);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
$(document).ready (function () {
|
||||
var dummyFunc = function () {
|
||||
return;
|
||||
};
|
||||
|
||||
$.extend ({
|
||||
pandoraSelectGroup: new function() {
|
||||
this.defaults = {
|
||||
agentSelectId: "id_agent",
|
||||
loadingId: "agent_loading",
|
||||
callbackBefore: dummyFunc,
|
||||
callbackPre: dummyFunc,
|
||||
callbackPost: dummyFunc,
|
||||
callbackAfter: dummyFunc,
|
||||
debug: false
|
||||
};
|
||||
|
||||
/* public methods */
|
||||
this.construct = function (settings) {
|
||||
return this.each (function() {
|
||||
this.config = {};
|
||||
|
||||
var config = $.extend (this.config, $.pandoraSelectGroup.defaults, settings);
|
||||
|
||||
$(this).change (function () {
|
||||
var $select = $("select#"+config.agentSelectId).disable ();
|
||||
$("#"+config.loadingId).show ();
|
||||
$("option[value!=0]", $select).remove ();
|
||||
|
||||
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.agentSelectId).append (option);
|
||||
});
|
||||
$("#"+config.loadingId).hide ();
|
||||
$select.enable ();
|
||||
config.callbackAfter ();
|
||||
},
|
||||
"json"
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
$.fn.extend({
|
||||
pandoraSelectGroup: $.pandoraSelectGroup.construct
|
||||
});
|
||||
});
|
|
@ -759,7 +759,9 @@ table#simple input#text-snmp_oid,
|
|||
table#simple select#prediction_module,
|
||||
table#source_table select,
|
||||
table#destiny_table select,
|
||||
table#target_table select {
|
||||
table#target_table select,
|
||||
table#filter_compound_table select,
|
||||
table#filter_compound_table #text-search {
|
||||
width: 100%;
|
||||
}
|
||||
.clickable {
|
||||
|
@ -872,7 +874,9 @@ fieldset legend span {
|
|||
font-style:italic;
|
||||
|
||||
}
|
||||
|
||||
form#filter_form {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
/* timeEntry styles */
|
||||
.timeEntry_control {
|
||||
vertical-align: middle;
|
||||
|
|
Loading…
Reference in New Issue