Last active
August 29, 2015 14:06
-
-
Save hobbes3/040881d6fc102fa73b0a to your computer and use it in GitHub Desktop.
textarea list of hosts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require([ | |
'jquery', | |
'underscore', | |
'splunkjs/mvc', | |
'splunkjs/mvc/simplexml/ready!' | |
], function( | |
$, | |
_, | |
mvc | |
) { | |
function submit_and_update_url() { | |
submitted_tokens.set(unsubmitted_tokens.toJSON()); | |
mvc.Components.get('url').saveOnlyWithPrefix('form\\.', unsubmitted_tokens.toJSON(), { | |
replaceState: false | |
}); | |
} | |
var unsubmitted_tokens = mvc.Components.get('default'); | |
var submitted_tokens = mvc.Components.get('submitted'); | |
$("#field1, #field2").hide(); | |
var host_textarea = $('<textarea id="host_textarea">'); | |
var host_input = $( | |
'<div class="input input-text splunk-view" id="host_input">' + | |
'<label for="host_textarea">Enter a list of hosts (one host per line)</label>' + | |
'</div>' | |
); | |
$(host_input).append(host_textarea); | |
$(".fieldset").append(host_input); | |
$(host_textarea).on("change", function() { | |
var value = $(this).val(); | |
var hosts = value.split("\n"); | |
hosts = _.chain(hosts) | |
.compact() | |
.map(function(v) { | |
return v.trim(); | |
}) | |
.value(); | |
var hosts_string_db = "(" + | |
_.map(hosts, function(v) { | |
return "'" + v + "'"; | |
}) | |
.join(", ") + | |
")"; | |
var hosts_string_cn = _.map(hosts, function(v) { | |
return "cn=\"" + v + "\""; | |
}) | |
.join(" OR "); | |
unsubmitted_tokens.set("form.hosts_string_db", hosts_string_db); | |
unsubmitted_tokens.set("form.hosts_string_cn", hosts_string_cn); | |
submit_and_update_url(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment