|
| 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_VALUE); |
| 5 | + $(elm).attr('disabled', true); |
| 6 | + $(source_elm).css('opacity', '1'); |
| 7 | +} |
| 8 | + |
| 9 | +App.Actions.PACKAGE.disable_unlimited = function(elm, source_elm) { |
| 10 | + $(elm).data('checked', false); |
| 11 | + if ($(elm).data('prev_value') && $(elm).data('prev_value').trim() != '') { |
| 12 | + var prev_value = $(elm).data('prev_value').trim(); |
| 13 | + $(elm).val(prev_value); |
| 14 | + } |
| 15 | + else { |
| 16 | + $(elm).val('0'); |
| 17 | + } |
| 18 | + $(elm).attr('disabled', false); |
| 19 | + $(source_elm).css('opacity', '0.5'); |
| 20 | +} |
| 21 | + |
| 22 | +// |
| 23 | +App.Actions.PACKAGE.toggle_unlimited_feature = function(evt) { |
| 24 | + var elm = $(evt.target); |
| 25 | + var ref = elm.prev('.vst-input'); |
| 26 | + if (!$(ref).data('checked')) { |
| 27 | + App.Actions.PACKAGE.enable_unlimited(ref, elm); |
| 28 | + } |
| 29 | + else { |
| 30 | + App.Actions.PACKAGE.disable_unlimited(ref, elm); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +App.Listeners.PACKAGE.checkbox_unlimited_feature = function() { |
| 35 | + $('.unlim-trigger').on('click', App.Actions.PACKAGE.toggle_unlimited_feature); |
| 36 | +} |
| 37 | + |
| 38 | +App.Listeners.PACKAGE.init = function() { |
| 39 | + $('.unlim-trigger').each(function(i, elm) { |
| 40 | + var ref = $(elm).prev('.vst-input'); |
| 41 | + if ($(ref).val().trim() == App.Constants.UNLIM_VALUE || $(ref).val().trim() == App.Constants.UNLIM_TRANSLATED_VALUE) { |
| 42 | + $(ref).val('0'); |
| 43 | + App.Actions.PACKAGE.enable_unlimited(ref, elm); |
| 44 | + //$(elm).attr('checked', true); |
| 45 | + } |
| 46 | + else { |
| 47 | + App.Actions.PACKAGE.disable_unlimited(ref, elm); |
| 48 | + } |
| 49 | + }); |
| 50 | +} |
| 51 | + |
| 52 | +// |
| 53 | +// Page entry point |
| 54 | +// Trigger listeners |
| 55 | +App.Listeners.PACKAGE.init(); |
| 56 | +App.Listeners.PACKAGE.checkbox_unlimited_feature(); |
| 57 | +$('form[name="v_edit_package"]').bind('submit', function(evt) { |
| 58 | + $('input:disabled').each(function(i, elm) { |
| 59 | + $(elm).attr('disabled', false); |
| 60 | + }); |
| 61 | +}); |
| 62 | + |
| 63 | + |
0 commit comments