batchcreate.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. function updateAction(date)
  2. {
  3. date = date.replace(/\-/g, '');
  4. link = createLink('effort', 'batchCreate', 'date=' + date);
  5. var hasContent = false;
  6. $('#objectTable tr.effortBox.new input[id^=work]').each(function(){if($(this).val().length > 0) hasContent = true});
  7. if(!hasContent) return location.href=link;
  8. cleanEffort();
  9. }
  10. function addEffort(clickedButton)
  11. {
  12. effortRow = '<tr class="effortBox new">' + $(clickedButton).closest('tr').html() + '</tr>';
  13. $(clickedButton).closest('tr').after(effortRow);
  14. var nextBox = $(clickedButton).closest('tr').next('.effortBox');
  15. $(nextBox).find('input[id^=id]').val(num);
  16. $(nextBox).find('.chosen-container, .picker').remove();
  17. $(nextBox).find('select').chosen();
  18. $(nextBox).find('input[id^="left"]').attr('name', "left[" + num + "]").attr('id', "left[" + num + "]");
  19. $(nextBox).find('select[id^=execution]').attr('name', "execution[" + num + "]").attr('id', "execution" + num);
  20. if($(nextBox).find('select#objectType').val().indexOf('task_') < 0) $(nextBox).find('input[id^="left"]').attr('disabled', 'disabled');
  21. num++;
  22. updateID();
  23. }
  24. function deleteEffort(clickedButton)
  25. {
  26. if($('.effortBox').size() == 1) return;
  27. $(clickedButton).parent().parent().remove();
  28. updateID();
  29. }
  30. function cleanEffort()
  31. {
  32. $('#objectTable tbody tr.computed').remove();
  33. updateID();
  34. }
  35. function updateID()
  36. {
  37. i = 1;
  38. $('.effortID').each(function(){$(this).html(i ++)});
  39. }
  40. $(function()
  41. {
  42. $('select#objectType').each(function()
  43. {
  44. var value = $(this).val();
  45. var $leftInput = $(this).closest('td').next().next().next().find('input');
  46. if(value.indexOf('task_') >= 0)
  47. {
  48. $leftInput.removeAttr('disabled').removeAttr('title');
  49. }
  50. });
  51. $(document).on('change', 'select#objectType', function()
  52. {
  53. var value = $(this).val();
  54. var executionID = value.indexOf('task') > -1 ? (executionTask[value] ? executionTask[value] : 0) : (executionBug[value] ? executionBug[value] : 0);
  55. var id = $(this).closest('tr').find('#id').val();
  56. var selectName = 'execution[' + id + ']';
  57. var selectID = 'execution' + id;
  58. if(value == '')
  59. {
  60. var executionTpl = $('#executionTpl').html();
  61. }
  62. else
  63. {
  64. var executionName = executions[executionID] ? executions[executionID] : '';
  65. var executionTpl = '<select name="' + selectName + '" id="' + selectID + '" tabindex="9999" class="form-control">';
  66. executionTpl += '<option value="" title="" data-keys=" "></option>';
  67. if(executionName) executionTpl += '<option value="' + executionID + '" title="' + executionName + '" data-keys=" ">' + executionName + '</option>';
  68. }
  69. var $executionTd = $(this).parent().next();
  70. $executionTd.empty();
  71. $executionTd.append(executionTpl);
  72. var $execution = $(this).parent().next().find('select');
  73. $execution.chosen();
  74. $execution.val(executionID);
  75. $execution.trigger("chosen:updated");
  76. var $leftInput = $(this).closest('td').next().next().next().find('input');
  77. if(value.indexOf('task_') >= 0)
  78. {
  79. $leftInput.removeAttr('disabled').removeAttr('title');
  80. }
  81. else
  82. {
  83. $execution.val(0);
  84. $leftInput.attr('disabled', true).attr('title', leftTip);
  85. }
  86. });
  87. });