admin.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. $(function()
  2. {
  3. if(config.requestType == 'GET') $('.treeview li a[href$="=' + window.action + '"]').parent('li').addClass('active');
  4. if(config.requestType == 'PATH_INFO') $('.treeview li a[href$="-' + window.action + '.html"]').parent('li').addClass('active');
  5. $('#triggerModal').addClass('layout-modal').attr('data-action', window.action);
  6. var $trs = $('tr');
  7. $trs.filter('.fixed-enabled').appendTo('#fixedEnabled');
  8. $trs.filter('.fixed-required').appendTo('#fixedRequired');
  9. $('.table-origin').remove();
  10. $requireTrs = $('#fixedRequired tr');
  11. $enableTrs = $('#fixedEnabled tr');
  12. if(!$requireTrs.length) $('#fixedRequired').hide();
  13. if($enableTrs.length < 2)
  14. {
  15. $('#fixedEnabled').addClass('sort-disabled');
  16. $enableTrs.find('input[name*=width]').val('auto').attr('disabled', 'disabled');
  17. }
  18. else
  19. {
  20. $('#fixedEnabled').sortable({trigger: '.icon-move', selector: 'tr'});
  21. }
  22. $('#reversechecker').click(function()
  23. {
  24. $('.table-layout').find('tr').each(function()
  25. {
  26. if($(this).hasClass('head')) return;//exclude main table and sub table.
  27. if($(this).hasClass('disabled'))
  28. {
  29. $(this).removeClass('disabled').find('input[name*=show]').val('1');
  30. }
  31. else
  32. {
  33. $(this).addClass('disabled').find('input[name*=show]').val('0');
  34. }
  35. });
  36. });
  37. $(document).on('click', '#allchecker', function()
  38. {
  39. $('.table-layout').find('tr').removeClass('disabled').find('input[name*=show]').val('1');
  40. });
  41. /**
  42. * Show or hide a row.
  43. */
  44. $('#adminLayoutForm .table-layout').on('click', 'tr:not(.required, :first-child) .show-hide, tr:not(.required, :first-child) .title', function()
  45. {
  46. var $tr = $(this).closest('tr');
  47. $tr.toggleClass('disabled');
  48. if($tr.hasClass('disabled')) $tr.find('input[name*=show]').val('0');
  49. if(!$tr.hasClass('disabled')) $tr.find('input[name*=show]').val('1');
  50. if($tr.data('child') != undefined)
  51. {
  52. var child = '.child-' + $tr.data('child');
  53. $(child).toggleClass('disabled', $tr.hasClass('disabled'));
  54. $(child).find('thead th').click();
  55. $(child).find('tr').toggleClass('disabled', $tr.hasClass('disabled'));
  56. $(child).find('tr').find('input[name*=show]').val($tr.hasClass('disabled') ? '0' : '1');
  57. }
  58. if(window.method != 'browse' && window.method != 'view')
  59. {
  60. if($tr.data('field') == 'subStatus' && !$tr.hasClass('disabled'))
  61. {
  62. var $statusTr = $(this).parents('.table-layout').find('tr[data-field=status]');
  63. $tr.before($statusTr);
  64. if($statusTr.hasClass('disabled'))
  65. {
  66. $statusTr.removeClass('disabled');
  67. $statusTr.find('input[name*=show]').val('1');
  68. }
  69. }
  70. }
  71. });
  72. $('.child').each(function()
  73. {
  74. var module = '.module-' + $(this).data('module');
  75. $(this).toggleClass('disabled', $(module).hasClass('disabled'));
  76. })
  77. $('input[name*=custom]').change(function()
  78. {
  79. let control = $(this).parents('tr').data('control');
  80. if(control == 'file') return false;
  81. var $group = $(this).parents('.input-group');
  82. if($(this).prop('checked'))
  83. {
  84. $group.find(('select[name*=defaultValue]')).attr('disabled', true).hide();
  85. $group.find(('input[name*=defaultValue]')).attr('disabled', false).show();
  86. $group.find('[id^=defaultValue][id$=chosen]').hide();
  87. $group.find('.picker').hide();
  88. }
  89. else
  90. {
  91. $group.find(('select[name*=defaultValue]')).attr('disabled', false);
  92. $group.find(('input[name*=defaultValue]')).attr('disabled', true).hide();
  93. $group.find('[id^=defaultValue][id$=chosen]').show();
  94. $group.find('.picker').show();
  95. }
  96. if(window.mode == 'view' || control == '')
  97. {
  98. $group.find(('select[name*=defaultValue]')).attr('disabled', true);
  99. $group.find(('input[name*=defaultValue]')).attr('disabled', true);
  100. }
  101. })
  102. $('.fixed-required').find('input:not([name*=width], [name*=show]), select').attr('disabled', true);
  103. $('.child').sortable({trigger: '.icon-move', selector: 'tr'});
  104. $('.child').on('click', 'tr:first-child', function()
  105. {
  106. if(window.mode == 'view') return false;
  107. $(this).toggleClass('disabled');
  108. if($(this).hasClass('disabled')) $(this).parents('.table-layout').find('tr:not(:first-child)').hide().find('input[name*=show]').val('0');
  109. if(!$(this).hasClass('disabled')) $(this).parents('.table-layout').find('tr:not(:first-child)').show().find('input[name*=show]').val('1');
  110. });
  111. $.setAjaxForm('#adminLayoutForm', function(response)
  112. {
  113. if(response.result == 'success')
  114. {
  115. setTimeout(function()
  116. {
  117. $('#triggerModal').load(response.locate, function(){ $.zui.ajustModalPosition(); });
  118. }, 1200);
  119. }
  120. });
  121. $('input[name*=custom]').change();
  122. });