Skip to content

Commit

Permalink
QA: Add request variables to callback, fix predefined timespan callback
Browse files Browse the repository at this point in the history
* These two little filters make drop_callback be able to append request variables to the various methods.
* The predefined_timespan should send all variables.
* rfilter should come over as base64_encoded
* Allow the filter to have the post method by default
  • Loading branch information
TheWitness committed Dec 23, 2024
1 parent ee56a27 commit b20a3f6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
37 changes: 34 additions & 3 deletions include/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4047,9 +4047,21 @@ function handlePopState(e) {

function applyGraphTimespan() {
var href = correctUrlParameters(graphPage + '?action=' + pageAction +
'&predefined_timespan=' + $('#predefined_timespan').val() +
($('#rfilter').length ? '&rfilter=' + base64_encode($('#rfilter').val()) : '') +
'&predefined_timeshift=' + $('#predefined_timeshift').val());
'&predefined_timespan=' + $('#predefined_timespan').val() +
'&predefined_timeshift=' + $('#predefined_timeshift').val() +
(typeof $('#site_id').val() != 'undefined' ? '&site_id=' + $('#site_id').val() : '') +
(typeof $('#location').val() != 'undefined' ? '&location=' + $('#location').val() : '') +
(typeof $('#host_id').val() != 'undefined' ? '&host_id=' + $('#host_id').val() : '') +
(typeof $('#graph_source').val() != 'undefined' ? '&graph_source=' + $('#graph_source').val() : '') +
(typeof $('#graph_order').val() != 'undefined' ? '&graph_order=' + $('#graph_order').val() : '') +
(typeof $('#cf').val() != 'undefined' ? '&cf=' + $('#cf').val() : '') +
(typeof $('#measure').val() != 'undefined' ? '&measure=' + $('#measure').val() : '') +
'&columns=' + $('#columns').val() +
'&graphs=' + $('#graphs').val() +
'&graph_template_id=' + $('#graph_template_id').val() +
'&thumbnails=' + $('#thumbnails').is(':checked') +
'&business_hours=' + $('#business_hours').is(':checked'));

closeDateFilters();

Expand Down Expand Up @@ -4929,6 +4941,7 @@ function makeCallbacks() {
var title = searchSelect;
var action = $(this).attr('data-action');
var value = $(this).attr('data-value');
var reqvars = $(this).attr('data-variables');

var Id = $(this).attr('id');
var dcId = '#' + Id;
Expand Down Expand Up @@ -4962,7 +4975,25 @@ function makeCallbacks() {
$(this).hide();

$(dcInput).autocomplete({
source: pageName + '?action=' + action,
source: function(request, response) {
var _action = pageName + '?action=' + action;

if (reqvars != '') {
var variables = reqvars.split(',');

$.each(variables, function(index, data) {
if ($('#'+data).length) {
_action += "&" + data + "=" + $('#'+data).val();
}
});
}

_action += '&term=' + request.term;

$.getJSON(_action, function(data) {
response(data);
});
},
autoFocus: true,
minLength: 0,
select: function(event, ui) {
Expand Down
5 changes: 3 additions & 2 deletions lib/html_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CactiTableFilter {
public $form_header = '';
public $form_action = '';
public $form_id = '';
public $form_method = 'get';
public $session_var = 'sess_';
public $action_url = '';
public $action_label = '';
Expand Down Expand Up @@ -424,7 +425,7 @@ private function create_filter() {
}

if (isset($this->filter_array['rows'])) {
print "<form id='" . $this->form_id . "' action='" . $this->form_action . "'>";
print "<form id='" . $this->form_id . "' action='" . $this->form_action . "' method='" . $this->form_method . "'>";

foreach($this->filter_array['rows'] as $index => $row) {
if ($index > 0 && !$text_appended) {
Expand Down Expand Up @@ -783,7 +784,7 @@ private function create_javascript() {
if ($field_name != 'rfilter') {
$applyFilter .= ($filterLength == 0 ? '&':"+'&") . $field_name . "='+$('#" . $field_name . "').val()";
} else {
$applyFilter .= ($filterLength == 0 ? '&':"+'&") . $field_name . "='+atob($('#" . $field_name . "').val())";
$applyFilter .= ($filterLength == 0 ? '&':"+'&") . $field_name . "='+base64_encode($('#" . $field_name . "').val())";
}
$filterLength++;

Expand Down
8 changes: 5 additions & 3 deletions lib/html_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ function draw_edit_control($field_name, &$field_array) {
((isset($field_array['default'])) ? $field_array['default'] : ''),
((isset($field_array['class'])) ? $field_array['class'] : ''),
((isset($field_array['on_change'])) ? $field_array['on_change'] : ''),
((isset($field_array['friendly_name'])) ? $field_array['friendly_name'] : '')
((isset($field_array['friendly_name'])) ? $field_array['friendly_name'] : ''),
((isset($field_array['request_vars'])) ? $field_array['request_vars'] : '')
);

break;
Expand Down Expand Up @@ -1008,10 +1009,11 @@ function form_droplanguage($form_name, $column_display, $column_id, $form_previo
* @param string $class Optional. Additional CSS classes for the form element.
* @param string $on_change Optional. JavaScript function to call on form element change.
* @param string $display_name Optional. The display name for the column.
* @param string $request_vars Optional. The the request variables to include in the action
*
* @return void
*/
function form_callback($form_name, $classic_sql, $column_display, $column_id, $action, $previous_id, $previous_value, $none_entry, $default_value, $class = '', $on_change = '', $display_name = '') {
function form_callback($form_name, $classic_sql, $column_display, $column_id, $action, $previous_id, $previous_value, $none_entry, $default_value, $class = '', $on_change = '', $display_name = '', $request_vars = '') {
if ($previous_value == '') {
$previous_value = $default_value;
}
Expand Down Expand Up @@ -1046,7 +1048,7 @@ function form_callback($form_name, $classic_sql, $column_display, $column_id, $a
$previous_value = $none_entry;
}

print "<input id='$form_name' name='$form_name' type='text' class='drop-callback ui-state-default ui-corner-all' data-action='$action' data-callback='$on_change' data-value='" . html_escape($previous_value) . "' value='" . html_escape($previous_id) . "'>";
print "<input id='$form_name' name='$form_name' type='text' class='drop-callback ui-state-default ui-corner-all' data-action='$action' data-variables='$request_vars' data-callback='$on_change' data-value='" . html_escape($previous_value) . "' value='" . html_escape($previous_id) . "'>";
}
}

Expand Down

0 comments on commit b20a3f6

Please sign in to comment.