questions.tpl 4.4 KB

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