edit_package.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. App.Actions.PACKAGE.enable_unlimited = function(elm, source_elm) {
  2. $(elm).data('checked', true);
  3. $(elm).data('prev_value', $(elm).val()); // save prev value in order to restore if needed
  4. $(elm).val(App.Constants.UNLIM_TRANSLATED_VALUE);
  5. $(elm).attr('disabled', true);
  6. $(source_elm).css('opacity', '1');
  7. }
  8. App.Actions.PACKAGE.disable_unlimited = function(elm, source_elm) {
  9. $(elm).data('checked', false);
  10. if ($(elm).data('prev_value') && $(elm).data('prev_value').trim() != '') {
  11. var prev_value = $(elm).data('prev_value').trim();
  12. $(elm).val(prev_value);
  13. if (App.Helpers.isUnlimitedValue(prev_value)) {
  14. $(elm).val('0');
  15. }
  16. }
  17. else {
  18. if (App.Helpers.isUnlimitedValue($(elm).val())) {
  19. $(elm).val('0');
  20. }
  21. }
  22. $(elm).attr('disabled', false);
  23. $(source_elm).css('opacity', '0.5');
  24. }
  25. //
  26. App.Actions.PACKAGE.toggle_unlimited_feature = function(evt) {
  27. var elm = $(evt.target);
  28. var ref = elm.prev('.vst-input');
  29. if (!$(ref).data('checked')) {
  30. App.Actions.PACKAGE.enable_unlimited(ref, elm);
  31. }
  32. else {
  33. App.Actions.PACKAGE.disable_unlimited(ref, elm);
  34. }
  35. }
  36. App.Listeners.PACKAGE.checkbox_unlimited_feature = function() {
  37. $('.unlim-trigger').on('click', App.Actions.PACKAGE.toggle_unlimited_feature);
  38. }
  39. App.Listeners.PACKAGE.init = function() {
  40. $('.unlim-trigger').each(function(i, elm) {
  41. var ref = $(elm).prev('.vst-input');
  42. if (App.Helpers.isUnlimitedValue($(ref).val())) {
  43. App.Actions.PACKAGE.enable_unlimited(ref, elm);
  44. }
  45. else {
  46. $(ref).data('prev_value', $(ref).val());
  47. App.Actions.PACKAGE.disable_unlimited(ref, elm);
  48. }
  49. });
  50. }
  51. App.Helpers.isUnlimitedValue = function(value) {
  52. var value = value.trim();
  53. if (value == App.Constants.UNLIM_VALUE || value == App.Constants.UNLIM_TRANSLATED_VALUE) {
  54. return true;
  55. }
  56. return false;
  57. }
  58. //
  59. // Page entry point
  60. // Trigger listeners
  61. App.Listeners.PACKAGE.init();
  62. App.Listeners.PACKAGE.checkbox_unlimited_feature();
  63. $('form[name="v_edit_package"]').bind('submit', function(evt) {
  64. $('input:disabled').each(function(i, elm) {
  65. $(elm).attr('disabled', false);
  66. if (App.Helpers.isUnlimitedValue($(elm).val())) {
  67. $(elm).val(App.Constants.UNLIM_VALUE);
  68. }
  69. });
  70. });
  71. $(document).ready(function(){
  72. $('.add-ns-button').click(function(){
  73. var n = $('input[name^=v_ns]').length;
  74. if(n < 8){
  75. var t = $($('input[name=v_ns1]').parents('tr')[0]).clone(true, true);
  76. t.find('input').attr({value:'', name:'v_ns'+(n+1)});
  77. t.find('span').show();
  78. $('tr.add-ns').before(t);
  79. }
  80. if( n == 7 ) {
  81. $('.add-ns').hide();
  82. }
  83. });
  84. $('.remove-ns').click(function(){
  85. $(this).parents('tr')[0].remove();
  86. $('input[name^=v_ns]').each(function(i, ns){
  87. $(ns).attr({name: 'v_ns'+(i+1)});
  88. i < 2 ? $(ns).parent().find('span').hide() : $(ns).parent().find('span').show();
  89. });
  90. $('.add-ns').show();
  91. });
  92. $('input[name^=v_ns]').each(function(i, ns){
  93. i < 2 ? $(ns).parent().find('span').hide() : $(ns).parent().find('span').show();
  94. });
  95. });