Skip to content

Instantly share code, notes, and snippets.

@TrevorS
Created February 6, 2013 22:08
Show Gist options
  • Save TrevorS/4726344 to your computer and use it in GitHub Desktop.
Save TrevorS/4726344 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
var operations = {};
// attach a date/time picker to the seizure start field and icon
$("#seizure_start").datetimepicker();
// attach a date/time picker to the seizure end field and icon
$("#seizure_end").datetimepicker();
// populate the query fields dependent on the switch selected
$("#search_switch_id").on('change', function() {
// start with clearing out the field options
$("#search_query_field").empty();
// enable the field select input
$("#search_query_field").removeAttr('disabled');
// grab the list of fields from the selected switch
$.getJSON('/switches/' + $(this).find('option:selected').attr('value'), function(json) {
$.each(json, function(key, field) {
// add the fields to the field input
$('#search_query_field').append($('<option/>', {
value: field.id,
text: field.name
}));
// store the operator information for looking up when a user selects a field
operations[field.id] = field.operations;
});
});
});
$("#search_query_field").on('change', function() {
// start with clearing out the operator options
$("#search_query_operator").empty();
// enable the operator and value select inputs
$("#search_query_operator").removeAttr('disabled');
$("#search_query_value").removeAttr('disabled');
// grab the selected field
var selected = $(this).find('option:selected').attr('value');
// start basic...
var operators = ['='];
// add the rest of the operators if it is advanced.
if (operations[selected] === 'advanced') {
operators = ['=', '>', '<', '>=', '<='];
}
// put them in the operator select
$.each(operators, function(index, operator) {
$('#search_query_operator').append($('<option/>', {
value: index,
text: operator
}));
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment