Skip to content
Browse files

conf tool: allow custom variables in suggestion

  • Loading branch information...
1 parent bd3bba1 commit f463b0d5f8a9fa07f4d0bab0593a21cdc0927077 @sni committed Apr 14, 2012
View
1 plugins/plugins-available/conf/lib/Thruk/Controller/conf.pm
@@ -285,6 +285,7 @@ sub _process_json_page {
if($type eq 'attribute') {
my $for = $c->{'request'}->{'parameters'}->{'obj'};
my $attr = $c->{'obj_db'}->get_default_keys($for, { no_alias => 1 });
+ push @{$attr}, 'customvariable';
my $json = [{ 'name' => $type.'s',
'data' => [ sort @{Thruk::Utils::array_uniq($attr)} ],
}];
View
27 plugins/plugins-available/conf/root/conf.js
@@ -20,6 +20,10 @@ function set_sub(nr) {
var running_number = 0;
function add_conf_attribute(table, key, rt) {
+ if(fields[key] == undefined) {
+ key = 'customvariable';
+ }
+
running_number--;
if(key != 'customvariable' && key != 'exception') {
jQuery('#new_' + key + '_btn').css('display', 'none');
@@ -50,6 +54,9 @@ function add_conf_attribute(table, key, rt) {
newObj.cells[2].innerHTML = newObj.cells[2].innerHTML.replace(/id_key\d+/g, 'id_'+running_number);
newObj.cells[2].innerHTML = newObj.cells[2].innerHTML.replace(/class="obj_customvariable"/g, 'class="obj_customvariable obj_'+running_number+'"');
}
+ if(key == 'customvariable') {
+ newObj.cells[2].innerHTML = newObj.cells[2].innerHTML.replace(/id="id_customvariable0"/g, 'id="id_customvariable'+running_number+'"');
+ }
// insert row at 3rd last position
tblBody.insertBefore(newObj, tblBody.rows[tblBody.rows.length -3]);
@@ -569,3 +576,23 @@ function new_attr_filter(str) {
}
return true;
}
+
+/* new attribute onselect */
+var newid, inp;
+function on_attr_select() {
+ newid = add_conf_attribute('attr_table', jQuery('#newattr').val(),true);
+ ajax_search.reset();
+ window.setTimeout('jQuery(\'#\'+newid).focus()', 300);
+ return newid;
+}
+
+/* new attribute onselect */
+function on_empty_click(inp) {
+ var input = document.getElementById(ajax_search.input_field);
+ var v = input.value;
+ input.value = 'customvariable';
+ newid = on_attr_select();
+ var tr = document.getElementById(newid).parentNode.parentNode;
+ tr.cells[0].firstChild.value = '_'+v.toUpperCase();
+ return false;
+}
View
2 plugins/plugins-available/conf/templates/_conf_object_edit.tt
@@ -51,7 +51,7 @@
[% END %]
<tr class="[% loopclass %]">
<td class='dataVar [% loopclass +%] conf_row' align="left">
- <input type="text" class="attrkey new_attr" name="newattr" id="newattr" value="new attribute..." [% IF use_ajax_search %] onfocus="this.click()" onclick="ajax_search.init(this, 'attribute', {url:'conf.cgi?action=json&amp;type=attribute&amp;obj=[% type %]', autosubmit:false, empty: true, emptytxt: 'new attribute...', emptyclass:'new_attr', filter:new_attr_filter, onselect:function() {newid=add_conf_attribute('attr_table', jQuery('#newattr').val(),true); ajax_search.reset(); window.setTimeout('jQuery(\'#\'+newid).focus()', 300); return; false; } })"[% END %]>
+ <input type="text" class="attrkey new_attr" name="newattr" id="newattr" value="new attribute..." [% IF use_ajax_search %]onfocus="this.click()" onclick="ajax_search.init(this, 'attribute', { url:'conf.cgi?action=json&amp;type=attribute&amp;obj=[% type %]', autosubmit:false, empty: true, emptytxt: 'new attribute...', emptyclass:'new_attr', filter:new_attr_filter, emptymsg:'add custom variable', onselect:function() { on_attr_select(); return false; }, onemptyclick: function() { on_empty_click(); } })"[% END %]>
</td>
<td class='dataVar [% loopclass +%] conf_row' align="left"></td>
<td class='dataVal [% loopclass %] conf_row' colspan=2></td>
View
14 root/thruk/javascript/all_in_one-1.27.js
@@ -2199,6 +2199,7 @@ var ajax_search = {
emptytxt : '',
emptyclass : '',
onselect : undefined,
+ onemptyclick : undefined,
filter : undefined,
/* initialize search
@@ -2217,6 +2218,7 @@ var ajax_search = {
* emptytxt: text when empty
* emptyclass: class when empty
* onselect: run this function after selecting something
+ * onemptyclick: when clicking on the empty button
* filter: run this function as additional filter
* }
*/
@@ -2283,6 +2285,10 @@ var ajax_search = {
if(options.onselect != undefined) {
ajax_search.onselect = options.onselect;
}
+ ajax_search.onemptyclick = undefined;
+ if(options.onemptyclick != undefined) {
+ ajax_search.onemptyclick = options.onemptyclick;
+ }
ajax_search.filter = undefined;
if(options.filter != undefined) {
ajax_search.filter = options.filter;
@@ -2668,7 +2674,7 @@ var ajax_search = {
ajax_search.result_size = x;
resultHTML += '<\/ul>';
if(results.length == 0) {
- resultHTML += '<a href="#">'+ ajax_search.emptymsg +'</a>';
+ resultHTML += '<a href="#" onclick="ajax_search.onempty()">'+ ajax_search.emptymsg +'</a>';
if(ajax_search.hideempty) {
ajax_search.hide_results();
return;
@@ -2690,6 +2696,12 @@ var ajax_search = {
input.focus();
},
+ onempty: function() {
+ if(ajax_search.onemptyclick != undefined) {
+ ajax_search.onemptyclick();
+ }
+ },
+
/* set the value into the input field */
set_result: function(value) {
if(value == 'more' || (value == undefined && ajax_search.res.length == ajax_search.cur_select)) {
View
14 root/thruk/javascript/thruk-1.27.js
@@ -2182,6 +2182,7 @@ var ajax_search = {
emptytxt : '',
emptyclass : '',
onselect : undefined,
+ onemptyclick : undefined,
filter : undefined,
/* initialize search
@@ -2200,6 +2201,7 @@ var ajax_search = {
* emptytxt: text when empty
* emptyclass: class when empty
* onselect: run this function after selecting something
+ * onemptyclick: when clicking on the empty button
* filter: run this function as additional filter
* }
*/
@@ -2266,6 +2268,10 @@ var ajax_search = {
if(options.onselect != undefined) {
ajax_search.onselect = options.onselect;
}
+ ajax_search.onemptyclick = undefined;
+ if(options.onemptyclick != undefined) {
+ ajax_search.onemptyclick = options.onemptyclick;
+ }
ajax_search.filter = undefined;
if(options.filter != undefined) {
ajax_search.filter = options.filter;
@@ -2651,7 +2657,7 @@ var ajax_search = {
ajax_search.result_size = x;
resultHTML += '<\/ul>';
if(results.length == 0) {
- resultHTML += '<a href="#">'+ ajax_search.emptymsg +'</a>';
+ resultHTML += '<a href="#" onclick="ajax_search.onempty()">'+ ajax_search.emptymsg +'</a>';
if(ajax_search.hideempty) {
ajax_search.hide_results();
return;
@@ -2673,6 +2679,12 @@ var ajax_search = {
input.focus();
},
+ onempty: function() {
+ if(ajax_search.onemptyclick != undefined) {
+ ajax_search.onemptyclick();
+ }
+ },
+
/* set the value into the input field */
set_result: function(value) {
if(value == 'more' || (value == undefined && ajax_search.res.length == ajax_search.cur_select)) {

0 comments on commit f463b0d

Please sign in to comment.
Something went wrong with that request. Please try again.