ajaxoldcustom.html.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /**
  3. * The view file of datatable module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2014-2014 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license business(商业软件)
  7. * @author Hao sun <sunhao@cnezsoft.com>
  8. * @package datatable
  9. * @version $Id$
  10. * @link https://www.zentao.net
  11. */
  12. ?>
  13. <style>
  14. .cols-list {margin-bottom: 10px;}
  15. .cols-list .col {border: 1px solid #ddd; height: 30px; line-height: 29px; padding: 0 10px; border-bottom: none; background: #fff; float:none; padding-left: 6px;}
  16. .cols-list .checkbox-primary {display: inline-block; position: relative; top: -1px;}
  17. .cols-list .checkbox-primary > label {padding: 0; width: 21px;}
  18. .cols-list .col.drag-shadow {border: 1px solid #ddd;}
  19. .cols-list {border-bottom: 1px solid #ddd}
  20. .cols-list .col:hover {background: #E9F2FB}
  21. .cols-list .col.require:hover {background: none}
  22. .cols-list .col .actions {line-height: 30px; vertical-align: top;}
  23. .cols-list .col .form-control {display: inline-block; width: 50px; padding: 0px 5px; height: 20px; line-height: 20px; border-color: transparent; position: relative; top: -2px}
  24. .cols-list .col .form-control:hover {border-color: #ddd}
  25. .cols-list .col .form-control[disabled] {background: none}
  26. .cols-list .col .form-control[disabled]:hover {border-color: transparent;}
  27. .cols-list .col .btn {padding: 0px 5px; position: relative; top: -1px}
  28. .cols-list .col .btn.show-hide {font-size: 13px}
  29. .cols-list .col .title {cursor: pointer; display: inline-block; width: 500px;}
  30. .cols-list .col .title-bar {white-space:nowrap; cursor: pointer; display: inline-block; width: 300px; background: #f1f1f1; border-left: 1px solid #ddd; border-right: 1px solid #ddd; padding-left: 6px; position: relative; max-width: 500px; min-width: 30px}
  31. .cols-list .col .title .icon-move {width: 20px; height: 20px; line-height: 20px; text-align: center; position: relative; left: 3px;}
  32. .cols-list .col:hover .title-bar {background: #eee; transition: width 0.3s;}
  33. .cols-list .col.require .title {cursor: default;}
  34. .cols-list .col.disabled .title {opacity: 0.5;}
  35. .cols-list .col.disabled .title strong {font-weight: normal;}
  36. .cols-list .col.disabled .icon-ok {opacity: 0.05;}
  37. .cols-list .col .label-hide {color: #03c; background: none}
  38. .cols-list .col .label-show {color: #fff; background: #aaa}
  39. .cols-list .col.disabled .label-hide {color: #fff; background: #aaa}
  40. .cols-list .col.disabled .label-show {color: #03c; background: none}
  41. .cols-list .col.drop-to, .cols-list .col.drag-from {opacity: 0.5; visibility: visible; background: #e5e5e5}
  42. .cols-list .col .btn.disabled, .cols-list .col.disabled .btn.disabled, .cols-list .col .btn.disabled .label-hide {border: none; color: #aaa; cursor: not-allowed; background: none}
  43. .cols-list .col .icon-move {opacity: 0; transition:all 0.2s; cursor: move;}
  44. .cols-list .col:hover .icon-move {opacity: 0.7;}
  45. .cols-list.sort-disabled .icon-move {display: none;}
  46. #customDatatable .form-actions {margin-top: 10px;}
  47. #customDatatable .form-actions .checkbox-primary {margin-bottom: 10px; margin-left: 7px;}
  48. </style>
  49. <div class='modal-dialog' id='customDatatable' style='width: 800px'>
  50. <div class='modal-content'>
  51. <div class='modal-header'>
  52. <button class="close" data-dismiss="modal"><i class="icon icon-close"></i></button>
  53. <h4 class='modal-title'>
  54. <?php echo $lang->datatable->custom?>
  55. &nbsp; <small><?php echo $lang->datatable->customTip ?></small>
  56. </h4>
  57. </div>
  58. <div class='modal-body'>
  59. <div id='colsFixedLeft' class='cols-list'></div>
  60. <div id='colsFixedFlex' class='cols-list'></div>
  61. <div id='colsFixedRight' class='cols-list'></div>
  62. <div class='cols-list template' id="originCols">
  63. <?php foreach ($cols as $key => $col):?>
  64. <?php
  65. $required = $col['required'] == 'yes';
  66. $fixed = $col['fixed'];
  67. $autoWidth = $col['width'] == 'auto';
  68. ?>
  69. <div class='clearfix col<?php echo ($required ? ' require' : '') . (' fixed-' . $fixed) ?>' data-key='<?php echo $key?>' data-fixed='<?php echo $fixed?>' data-width='<?php echo $col['width']?>'>
  70. <div class='actions pull-right' <?php if($autoWidth) echo "style='padding-right: 11px'";?>>
  71. <?php if(isset($col['name'])) echo html::hidden('name', $col['name'])?>
  72. <span><span class='text-muted'><?php echo $lang->datatable->width?></span> <input type='text' id='width' class='form-control' value='<?php echo $col['width']?>'><?php echo $autoWidth ? '&nbsp;' : 'px' ?></span>
  73. </div>
  74. <div class="checkbox-primary<?php echo $required ? ' disabled' : '';?>"><label></label></div>
  75. <span class='title'><span class='title-bar'><strong><?php echo $col['title']?></strong><i class='icon-move'></i></span></span> <?php if($required) echo "<span class='text-muted'>({$lang->datatable->required})</span>"?>
  76. </div>
  77. <?php endforeach;?>
  78. </div>
  79. <div class='form-actions text-left'>
  80. <?php if(common::hasPriv('datatable', 'setGlobal')) echo html::checkbox('global', array(1 => $lang->datatable->setGlobal));?>
  81. <button type='button' class='btn btn-wide btn-primary btn-save' id='btnSaveCustom'><?php echo $lang->save ?></button>
  82. <button type='button' class='btn btn-wide' data-dismiss='modal'><?php echo $lang->close ?></button>
  83. <button type='button' class='btn btn-wide' id='resetBtn'><?php echo $lang->datatable->reset ?></button>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. <?php
  89. js::set('resetText', $lang->datatable->reset);
  90. js::set('resetGlobalText', $lang->datatable->resetGlobal);
  91. ?>
  92. <script>
  93. $(function()
  94. {
  95. var setting = JSON.parse('<?php echo $setting;?>');
  96. var $cols = $('#originCols .col').addClass('disabled');
  97. $cols.filter('.fixed-left').appendTo('#colsFixedLeft');
  98. $cols.filter('.fixed-flex, .fixed-no').appendTo('#colsFixedFlex');
  99. $cols.filter('.fixed-right').appendTo('#colsFixedRight');
  100. $('#originCols').remove();
  101. $('[data-key=actions] #width').attr('disabled', 'disabled');
  102. if(typeof setting[0] === 'string')
  103. {
  104. var newSetting = [];
  105. $('.col').each(function(idx)
  106. {
  107. var $col = $(this);
  108. var id = $col.data('key');
  109. newSetting.push({id: id, order: idx, show: $.inArray(id, setting) > -1});
  110. });
  111. setting = newSetting;
  112. }
  113. setting.sort(function(a, b)
  114. {
  115. if(a.order !== undefined && b.order !== undefined)
  116. {
  117. if(typeof a.order === 'string') a.order = parseInt(a.order);
  118. if(typeof b.order === 'string') b.order = parseInt(b.order);
  119. return a.order - b.order;
  120. }
  121. return 0;
  122. });
  123. for(var i = 0; i< setting.length; i++)
  124. {
  125. var col = setting[i];
  126. if(typeof col === 'string')
  127. {
  128. col = {id: col, disabled: false};
  129. }
  130. var $col = $cols.filter('[data-key=' + col.id + ']');
  131. $col.toggleClass('disabled', !col.show).attr('data-order', col.order);
  132. $col.find('.checkbox-primary').toggleClass('checked', !!col.show);
  133. if(col.width) $col.find('input#width').val(col.width.replace('px', ''));
  134. }
  135. $('.cols-list').on('click', '.col:not(.require) .title, .col:not(.require) .checkbox-primary', function()
  136. {
  137. var $col = $(this).closest('.col').toggleClass('disabled');
  138. $col.find('.checkbox-primary').toggleClass('checked', !$col.hasClass('disabled'));
  139. }).each(function()
  140. {
  141. var $list = $(this),
  142. $cols = $list.children('.col');
  143. if($cols.length < 2)
  144. {
  145. $list.addClass('sort-disabled');
  146. }
  147. else
  148. {
  149. $cols.detach().sort(function(a, b)
  150. {
  151. return $(a).data('order') - $(b).data('order');
  152. }).appendTo($list);
  153. $list.sortable({trigger: '.title', selector: '.col'});
  154. }
  155. }).on('keyup change', 'input#width', function()
  156. {
  157. renderColWidth($(this).closest('.col'));
  158. });
  159. function renderColWidth($col)
  160. {
  161. var width = $col.find('input#width').val();
  162. if(width == 'auto')
  163. {
  164. width = '500';
  165. }
  166. else
  167. {
  168. width = parseInt(width);
  169. if(isNaN(width))
  170. {
  171. width = $col.data('width');
  172. }
  173. if(width == 'auto') width = '500';
  174. }
  175. $col.find('.title-bar').css('width', width);
  176. }
  177. $('.col').each(function(){renderColWidth($(this));});
  178. $('#btnSaveCustom').on('click', function()
  179. {
  180. var setting = $('.col').map(function(index)
  181. {
  182. var $col = $(this);
  183. var sets = {id: $col.data('key'), order: index + 1, show: !$col.hasClass('disabled'), width: $col.find('input#width').val(), fixed: $col.data('fixed')};
  184. if(sets.width !== 'auto') sets.width += 'px';
  185. if($col.find('#name').size() > 0) sets.name = $col.find('#name').val();
  186. return sets;
  187. }).get();
  188. window.saveDatatableConfig('<?php echo $mode == 'table' ? 'tablecols' : 'cols';?>', setting, true, $('#global1').prop('checked') ? 1 : 0);
  189. });
  190. $('#resetBtn').on("click", function()
  191. {
  192. var system = $('#global1').prop('checked') ? 1 : 0;
  193. var param = "<?php echo "module=$module&method=$method"?>&system=" + system;
  194. hiddenwin.location.href = createLink('datatable', 'ajaxOldReset', param);
  195. })
  196. $('#global1').change(function()
  197. {
  198. if($(this).prop('checked'))$('#resetBtn').text(resetGlobalText);
  199. if(!$(this).prop('checked'))$('#resetBtn').text(resetText);
  200. })
  201. });
  202. </script>