v1.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. window.importLines = function(target, field)
  2. {
  3. const $modal = $(target).closest('.modal');
  4. const $dialog = $modal.find('.modal-dialog');
  5. const $lines = $modal.find('textarea');
  6. const $form = $modal.closest('body').find('form.form-batch[data-zui-batchform]');
  7. const modalID = $modal.attr('id');
  8. $dialog.addClass('loading');
  9. setTimeout(function()
  10. {
  11. let $currentRow;
  12. const lines = $lines.val().split('\n');
  13. $.each(lines, function(index, line)
  14. {
  15. line = line.trim();
  16. if(!line.length) return true;
  17. if($currentRow)
  18. {
  19. $row = $currentRow.next();
  20. }
  21. else
  22. {
  23. $row = $form.find('tbody>tr [name^=' + field + ']').first().closest('tr');
  24. }
  25. while($row.length && $row.find('[name^=' + field + ']').val().length)
  26. {
  27. $row = $row.next();
  28. }
  29. if(!$row || !$row.length)
  30. {
  31. $form.data('zui.BatchForm').addRow();
  32. $row = $form.find('tbody>tr [name^=' + field + ']').last().closest('tr');
  33. }
  34. $row.find('[name^=' + field + ']').val(line).addClass('highlight');
  35. $currentRow = $row;
  36. });
  37. $lines.val('');
  38. $dialog.removeClass('loading');
  39. $modal.on('hidden.Modal.zui', function()
  40. {
  41. const $firstRow = $form.find('tbody>tr [name^=' + field + ']').first().closest('tr');
  42. $firstRow[0].scrollIntoView();
  43. });
  44. zui.Modal.hide('#' + modalID);
  45. setTimeout(function()
  46. {
  47. $form.find('[name^=' + field + '].highlight').removeClass('highlight');
  48. }, 3000);
  49. }, 200);
  50. };