common.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. $(function()
  2. {
  3. if(config.currentMethod == 'create' || config.currentMethod == 'edit' || config.currentMethod == 'track')
  4. {
  5. computeIndex();
  6. $('#impact, #chance').change(function(){computeIndex()});
  7. }
  8. if(config.currentMethod == 'batchcreate')
  9. {
  10. $("[id^=impact]").each(function()
  11. {
  12. if(this.id != 'impact%s') computeIndex(this);
  13. })
  14. }
  15. if(config.currentMethod == 'batchedit')
  16. {
  17. $("[id^=impact]").each(function()
  18. {
  19. computeIndex(this);
  20. })
  21. $("[id^='impact'], [id^='chance']").change(function(){computeIndex(this)});
  22. }
  23. })
  24. $('#importLinesBtn').on('click', function()
  25. {
  26. setTimeout(function()
  27. {
  28. $("[id^=priValue]").each(function()
  29. {
  30. $('select[id^=pri]').trigger('chosen:updated');
  31. $(this).find("[id$='_chosen']").find('span').addClass('pri-middle');
  32. })
  33. }, 500);
  34. });
  35. /**
  36. * computeIndex
  37. *
  38. * @param object obj
  39. * @param int number
  40. * @access public
  41. * @return void
  42. */
  43. function computeIndex(obj = '', number = '')
  44. {
  45. if(obj)
  46. {
  47. var selectID = obj.id;
  48. if(!number) var number = $('#' + selectID).attr('data-number');
  49. var impact = $('#impact' + number).val();
  50. var chance = $('#chance' + number).val();
  51. }
  52. else
  53. {
  54. var impact = $('#impact').val();
  55. var chance = $('#chance').val();
  56. }
  57. var ratio = parseInt(impact * chance);
  58. var pri = '';
  59. var priColor = '';
  60. if(0 < ratio && ratio <= 5) pri = 'low';
  61. if(5 < ratio && ratio <= 12) pri = 'middle';
  62. if(15 <= ratio && ratio <= 25) pri = 'high';
  63. if(pri == 'low') priColor = 'pri-low';
  64. if(pri == 'middle') priColor = 'pri-middle';
  65. if(pri == 'high') priColor = 'pri-high';
  66. if(obj)
  67. {
  68. $('#ratio' + number).val(ratio);
  69. $('#pri' + number).val(pri);
  70. $('#pri' + number).trigger("chosen:updated")
  71. $('#pri' + number).chosen();
  72. $('#pri' + number).attr('disabled', true);
  73. $('#priValue' + number +' .chosen-container-single .chosen-single>span').attr("class", priColor);
  74. $('input[name="pri[' + number + ']"]').remove();
  75. $('#pri' + number).after("<input type='hidden' name='pri[" + number + "]' value='" + pri + "'/>");
  76. }
  77. else
  78. {
  79. $('#ratio').val(ratio);
  80. $('#pri').val(pri);
  81. $('#pri').trigger("chosen:updated")
  82. $('#pri').chosen();
  83. $('#pri').attr('disabled', true);
  84. $('#priValue .chosen-container-single .chosen-single>span').attr("class", priColor);
  85. $('input[name="pri"]').remove();
  86. $('#pri').after("<input type='hidden' name='pri' value='" + pri + "'/>");
  87. }
  88. }