excel.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**
  2. * Change group by role.
  3. *
  4. * @param string $role
  5. * @param int $i
  6. * @access public
  7. * @return void
  8. */
  9. function changeGroup(role, i)
  10. {
  11. if(role && roleGroup[role])
  12. {
  13. $('#group' + i).val(roleGroup[role]);
  14. }
  15. else
  16. {
  17. $('#group' + i).val('');
  18. }
  19. $('#group' + i).trigger('chosen:updated');
  20. }
  21. /**
  22. * Toggle checkbox and check password strength.
  23. *
  24. * @param object $obj
  25. * @param int $i
  26. * @access public
  27. * @return void
  28. */
  29. function toggleCheck(obj, i)
  30. {
  31. var $this = $(obj);
  32. var password = $this.val();
  33. var $ditto = $('#ditto' + i);
  34. var $passwordStrength = $this.closest('.input-group').find('.passwordStrength');
  35. if(password == '')
  36. {
  37. $ditto.attr('checked', true);
  38. $ditto.closest('.input-group-addon').show();
  39. $passwordStrength.hide();
  40. $passwordStrength.html('');
  41. }
  42. else
  43. {
  44. $ditto.removeAttr('checked');
  45. $ditto.closest('.input-group-addon').hide();
  46. $passwordStrength.html(passwordStrengthList[computePasswordStrength(password)]);
  47. $passwordStrength.show();
  48. }
  49. }
  50. $(function()
  51. {
  52. removeDitto(); //Remove 'ditto' in first row.
  53. window.onscroll = function()
  54. {
  55. var winHeight = $(window).height();
  56. var bounds = $('#batchCreateForm')[0].getBoundingClientRect();
  57. if(bounds.bottom > winHeight && bounds.top < (winHeight - 64))
  58. {
  59. $('#mainContent').addClass('has-affixed-region');
  60. }
  61. else
  62. {
  63. $('#mainContent').removeClass('has-affixed-region');
  64. }
  65. }
  66. });
  67. $(document).on('click', '.chosen-with-drop', function()
  68. {
  69. var select = $(this).prev('select');
  70. if($(select).val() == 'ditto')
  71. {
  72. if($(select).attr('id').substr(0, 7) == 'visions')
  73. {
  74. /* Fix bug #19960. */
  75. var value = '';
  76. }
  77. else
  78. {
  79. var index = $(select).closest('td').index();
  80. var row = $(select).closest('tr').index();
  81. var table = $(select).closest('tr').parent();
  82. var value = '';
  83. for(i = row - 1; i >= 0; i--)
  84. {
  85. value = $(table).find('tr').eq(i).find('td').eq(index).find('select').val();
  86. if(value != 'ditto') break;
  87. }
  88. }
  89. $(select).val(value);
  90. $(select).trigger("chosen:updated");
  91. }
  92. })
  93. $(document).on('change', '[id^=visions]', function()
  94. {
  95. if($.inArray('ditto', $(this).val()) >= 0)
  96. {
  97. $(this).val('ditto');
  98. $(this).trigger("chosen:updated");
  99. }
  100. })
  101. function initGroup(data)
  102. {
  103. $('select[id^="visions"]').each(function()
  104. {
  105. var i = $(this).attr('id').replace(/[^0-9]/ig, '');
  106. var groupVal = $('#group' + i).val();
  107. var dataObj = $(data);
  108. var dataHtml = $(dataObj).attr('id', 'group' + i).attr('name', 'group[' + i + '][]').prop('outerHTML');
  109. $('#group' + i).replaceWith(dataHtml);
  110. $('#group' + i + '_chosen').remove();
  111. if(i == 1) $('#group' + i).find('option[value="ditto"]').remove();
  112. $('#group' + i).val(groupVal);
  113. $('#group' + i).chosen();
  114. $('#role' + i).trigger('change');
  115. })
  116. }
  117. $(document).on('change', "select[id^='visions']", function()
  118. {
  119. var visionsDom = $(this);
  120. var visionsParam = visionsDom.val() instanceof Array ? visionsDom.val().join() : '-';
  121. var importRow = parseInt(visionsDom.attr('id').replace(/[^0-9]/ig, ''));
  122. $.post(createLink('user', 'ajaxGetGroup', "visions=" + visionsParam + "&i=2"), function(data)
  123. {
  124. for(var n = importRow; n <= batchCreateCount; n++)
  125. {
  126. if(n != importRow && $.inArray('ditto', $('select[id="visions' + n + '"]').val()) < 0) break;
  127. ((function(n)
  128. {
  129. var groupVal = $('#group' + n).val();
  130. var dataHtml = $(data).attr('id', 'group' + n).attr('name', 'group[' + n + '][]').prop('outerHTML');
  131. $('#group' + n).replaceWith(dataHtml);
  132. $('#group' + n + '_chosen').remove();
  133. $('#group' + n).val(groupVal);
  134. $('#group' + n).chosen();
  135. }(n)));
  136. }
  137. });
  138. });
  139. /**
  140. * Affix Region Scrollbar.
  141. *
  142. * @param dom $region
  143. * @access public
  144. * @return void
  145. */
  146. function affixRegionScrollbar($region)
  147. {
  148. $region.addClass('region-affixed');
  149. var $container = $region.parent();
  150. var $scrollbar = $container.find('.region-affixed-scrollbar');
  151. if(!$scrollbar.length)
  152. {
  153. $scrollbar = $('<div class="region-affixed-scrollbar"><div class="region-affixed-holder"></div></div>').css('height', $.zui.getScrollbarSize() + 1).appendTo($container).on('scroll', function()
  154. {
  155. $('.table-responsive').scrollLeft($scrollbar.scrollLeft());
  156. });
  157. }
  158. var $userform = $region.find('.table-responsive');
  159. $scrollbar.width($region.outerWidth());
  160. $scrollbar.find('.region-affixed-holder').width($userform[0].scrollWidth);
  161. var scrollLeft = $userform.scrollLeft();
  162. if(scrollLeft !== $scrollbar.scrollLeft()) $scrollbar.scrollLeft(scrollLeft);
  163. }
  164. if($('#batchCreateForm').length > 0) affixRegionScrollbar($('#batchCreateForm'));