question_pool.tpl 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. {% extends app.template_style ~ "/layout/layout_1_col.tpl" %}
  2. {% block content %}
  3. <script>
  4. function setSearchSelect(columnName) {
  5. $("#questions").jqGrid('setColProp', columnName, {
  6. /*searchoptions:{
  7. dataInit:function(el){
  8. $("option[value='1']",el).attr("selected", "selected");
  9. setTimeout(function(){
  10. $(el).trigger('change');
  11. }, 1000);
  12. }
  13. }*/
  14. });
  15. }
  16. var added_cols = [];
  17. var original_cols = [];
  18. function clean_cols(grid, added_cols) {
  19. //Cleaning
  20. for (key in added_cols) {
  21. //console.log('hide: ' + key);
  22. grid.hideCol(key);
  23. };
  24. grid.showCol('name');
  25. grid.showCol('display_start_date');
  26. grid.showCol('display_end_date');
  27. grid.showCol('course_title');
  28. }
  29. function show_cols(grid, added_cols) {
  30. grid.showCol('name').trigger('reloadGrid');
  31. for (key in added_cols) {
  32. //console.log('show: ' + key);
  33. grid.showCol(key);
  34. };
  35. }
  36. var second_filters = [];
  37. $(function () {
  38. {{ js }}
  39. setSearchSelect("status");
  40. var grid = $("#questions"),
  41. prmSearch = {
  42. multipleSearch : true,
  43. overlay : false,
  44. width: 'auto',
  45. caption: '{{ 'Search' | get_lang }}',
  46. formclass:'data_table',
  47. onSearch : function() {
  48. var postdata = grid.jqGrid('getGridParam', 'postData');
  49. if (postdata && postdata.filters) {
  50. filters = jQuery.parseJSON(postdata.filters);
  51. clean_cols(grid, added_cols);
  52. added_cols = [];
  53. $.each(filters, function(key, value) {
  54. /*console.log('key: ' + key );
  55. console.log('value: ' + value );*/
  56. if (key == 'rules') {
  57. $.each(value, function(subkey, subvalue) {
  58. if (subvalue.data == undefined) {
  59. return;
  60. }
  61. if (subvalue.data && subvalue.data == -1) {
  62. return;
  63. }
  64. /*console.log('subkey: ' + subkey );
  65. console.log('subvalue: ' + subvalue );
  66. console.log(subvalue);
  67. console.log('subvalue.field: ' + subvalue );
  68. console.log(subvalue.field);*/
  69. //if (added_cols[value.field] == undefined) {
  70. added_cols[subvalue.field] = subvalue.field;
  71. //}
  72. //grid.showCol(value.field);
  73. });
  74. }
  75. });
  76. show_cols(grid, added_cols);
  77. }
  78. },
  79. onReset: function() {
  80. clean_cols(grid, added_cols);
  81. }
  82. };
  83. original_cols = grid.jqGrid('getGridParam', 'colModel');
  84. grid.jqGrid('navGrid','#questions_pager',
  85. { edit:false, add:false, del:false },
  86. { height:280, reloadAfterSubmit:false }, // edit options
  87. { height:280, reloadAfterSubmit:false }, // add options
  88. { reloadAfterSubmit:false },// del options
  89. prmSearch
  90. );
  91. // create the searching dialog
  92. grid.searchGrid(prmSearch);
  93. // Fixes search table.
  94. var searchDialogAll = $("#fbox_"+grid[0].id);
  95. searchDialogAll.addClass("table");
  96. var searchDialog = $("#searchmodfbox_"+grid[0].id);
  97. searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
  98. searchDialog.css({position:"relative", "z-index":"auto", "float":"left"})
  99. var gbox = $("#gbox_"+grid[0].id);
  100. gbox.before(searchDialog);
  101. gbox.css({clear:"left"});
  102. $("#searchmodfbox_questions").after('<div id="result" style="float: left;position: relative; width: 100%;"></div>');
  103. //Select first elements by default
  104. $('.input-elm').each(function(){
  105. $(this).find('option:first').attr('selected', 'selected');
  106. });
  107. $('.delete-rule').each(function(){
  108. $(this).click(function(){
  109. $('.input-elm').each(function(){
  110. $(this).find('option:first').attr('selected', 'selected');
  111. });
  112. });
  113. });
  114. });
  115. function ajaxAction(obj) {
  116. var url = $(obj).attr('data-url');
  117. $.ajax({
  118. beforeSend: function(obj) {
  119. $("#result").html("<img src=\'{{ _p.web_img }}loadingAnimation.gif\' />");
  120. },
  121. type: "POST",
  122. url: url,
  123. success: function(data) {
  124. $("#result").html(data);
  125. }
  126. });
  127. event.preventDefault();
  128. return false;
  129. }
  130. </script>
  131. <div class="questions">
  132. {{ grid }}
  133. </div>
  134. {% endblock %}