pastetext.html.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <div id="importLinesModal" class="modal fade">
  2. <div class="modal-dialog modal-lg modal-simple load-indicator">
  3. <div class="modal-content">
  4. <div class="modal-header">
  5. <button type="button" class="close" data-dismiss="modal"><i class="icon icon-close"></i></button>
  6. <h4 class="modal-title"><?php echo $lang->pasteText;?></h4>
  7. </div>
  8. <div class="modal-body">
  9. <?php echo html::textarea('importLines', '', "class='form-control mgb-10' rows='10' placeholder='$lang->pasteTextInfo'")?>
  10. </div>
  11. <div class="modal-footer text-left">
  12. <button type="button" class="btn btn-primary btn-wide" id="importLinesBtn"><?php echo $lang->save;?></button>
  13. </div>
  14. </div>
  15. </div>
  16. </div>
  17. <script>
  18. $(function()
  19. {
  20. var $form = $('#batchCreateForm');
  21. var batchForm = $form.data('zui.batchActionForm');
  22. var rowTpl, $formTbody;
  23. var createRow = function()
  24. {
  25. if(!rowTpl) rowTpl = $('#trTemp tbody').html();
  26. if(!$formTbody) $formTbody = $form.find('table > tbody');
  27. var lastIndex = parseInt($formTbody.find('tr:last > td:first').text());
  28. var moduleArr = ['task', 'story', 'bug', 'testcase'];
  29. if($.inArray(config.currentModule, moduleArr) >= 0 && config.currentMethod == 'batchcreate')
  30. {
  31. lastIndex = rowIndex;
  32. rowIndex ++;
  33. }
  34. var $newRow = $(rowTpl.replace(/%s/g, lastIndex + 1));
  35. $newRow.find('.chosen').chosen();
  36. $newRow.find('.picker').remove()
  37. $newRow.find('.picker-select').picker();
  38. $newRow.find('.iframe').modalTrigger({iframe:true});
  39. $newRow.find('[data-provide="colorpicker-later"]').colorPicker();
  40. $newRow.datepickerAll();
  41. $formTbody.append($newRow);
  42. return $newRow;
  43. };
  44. var $importLines = $('#importLines');
  45. $('#importLinesBtn').on('click', function()
  46. {
  47. var $modal = $('#importLinesModal');
  48. var $dialog = $modal.find('.modal-dialog').addClass('loading');
  49. setTimeout(function()
  50. {
  51. var importText = $importLines.val();
  52. var lines = importText.split('\n');
  53. var $lastRow, $firstRow;
  54. $.each(lines, function(index, line)
  55. {
  56. line = $.trim(line);
  57. if (!line.length) return;
  58. if (!$lastRow)
  59. {
  60. $row = $form.find('tbody>tr .title-import').first().closest('tr');
  61. if(!$row && batchForm) $row = batchForm.createRow();
  62. }
  63. else $row = $lastRow.next();
  64. while ($row.length && $row.find('.title-import').val().length)
  65. {
  66. $row = $row.next();
  67. }
  68. if (!$row || !$row.length)
  69. {
  70. if (batchForm) $row = batchForm.createRow();
  71. else $row = createRow();
  72. }
  73. $row.find('.title-import').val(line).addClass('highlight');
  74. $lastRow = $row;
  75. if(!$firstRow) $firstRow = $row;
  76. });
  77. $importLines.val('');
  78. $dialog.removeClass('loading');
  79. $modal.on('hidden.zui.modal', function()
  80. {
  81. $firstRow[0].scrollIntoView();
  82. }).modal('hide');
  83. setTimeout(function()
  84. {
  85. $form.find('.title-import.highlight').removeClass('highlight');
  86. }, 3000);
  87. }, 200);
  88. });
  89. $importLines.on('scroll', function()
  90. {
  91. $importLines.css('background-position-y', -$importLines.scrollTop() + 6);
  92. });
  93. });
  94. </script>