term_search.html 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. {% extends 'base.html' %}
  2. {% block title %}Term Search{% endblock %}
  3. {% block content %}
  4. <p>Enter terms to query.</p>
  5. <form id="term-search-form" class="form-inline" method="POST" action="">
  6. <div class="row">
  7. <label for="logic">Logic</label>
  8. <select class="form-control" name="logic">
  9. <option value="and" selected>AND</option>
  10. <option value="or">OR</option>
  11. </select>
  12. </div>
  13. <div id="term-cont">
  14. <div class="row term-block">
  15. <div class="form-group">
  16. <label for="pred_ns[]">Prefix</label>
  17. <select class="form-control" name="pred_ns[]">
  18. <option selected value="">(none)</option>
  19. {% for ns in nsm.namespaces() | sort %}
  20. <option value="{{ns[0]}}">{{ns[0]}}</option>
  21. {% endfor %}
  22. </select>
  23. </div>
  24. <div class="form-group">
  25. <label for="pred[]">Predicate</label>
  26. <input type="text" class="form-control" name="pred[]">
  27. </div>
  28. <div class="form-group">
  29. <label for="op[]">Operand</label>
  30. <select class="form-control" name="op[]">
  31. {% for op in operands %}
  32. <option value="{{op[0]}}">{{op[1]}}</option>
  33. {% endfor %}
  34. </select>
  35. </div>
  36. <div class="form-group">
  37. <label for="val[]">Value</label>
  38. <input type="text" class="form-control" name="val[]">
  39. </div>
  40. <div class="form-group">
  41. <a class="delete-row btn btn-danger" href="#">- Remove</a>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="row">
  46. <a class="add-row btn btn-success" id="add-row" href="#">+ Add Row</a>
  47. </div>
  48. <div class="row">
  49. <input type="submit" class="btn btn-primary btn-lg">
  50. </div>
  51. </form>
  52. <div id="search-results-wrap"></div>
  53. {% include 'namespaces.html' %}
  54. {% endblock %}
  55. {% block tail_js %}
  56. <script>
  57. $(function(){
  58. $('.term-block').first().find('.delete-row').hide();
  59. $('#add-row').on('click', function(){
  60. var term = $('.term-block').last().clone(true, true);
  61. term.find('input[type="text"]').val('');
  62. term.find('select').val('');
  63. term.find('.delete-row').show();
  64. term.appendTo('#term-cont');
  65. });
  66. $('.delete-row').on('click', function(){
  67. $(this).closest('.term-block').remove();
  68. });
  69. $('#term-search-form').submit(function(ev) {
  70. $.ajax({
  71. type: 'POST',
  72. url: '',
  73. data: $(this).serialize(),
  74. encode: true
  75. })
  76. .done(function(data) {
  77. //var cont = $('#search-results-wrap')
  78. $('#search-results-wrap').removeClass('bg-danger')
  79. .html(data);
  80. })
  81. .fail(function(data) {
  82. $('#search-results-wrap').addClass('bg-danger')
  83. .html(data.responseText);
  84. });
  85. ev.preventDefault();
  86. });
  87. });
  88. </script>
  89. {% endblock %}