forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.package.js
More file actions
79 lines (70 loc) · 2.34 KB
/
Copy pathadd.package.js
File metadata and controls
79 lines (70 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
App.Actions.PACKAGE.enable_unlimited = function(elm, source_elm) {
$(elm).data('checked', true);
$(elm).data('prev_value', $(elm).val()); // save prev value in order to restore if needed
$(elm).val(App.Constants.UNLIM_TRANSLATED_VALUE);
$(elm).attr('disabled', true);
$(source_elm).css('opacity', '1');
}
App.Actions.PACKAGE.disable_unlimited = function(elm, source_elm) {
$(elm).data('checked', false);
if ($(elm).data('prev_value') && $(elm).data('prev_value').trim() != '') {
var prev_value = $(elm).data('prev_value').trim();
$(elm).val(prev_value);
if (App.Helpers.isUnlimitedValue(prev_value)) {
$(elm).val('0');
}
}
else {
if (App.Helpers.isUnlimitedValue($(elm).val())) {
$(elm).val('0');
}
}
$(elm).attr('disabled', false);
$(source_elm).css('opacity', '0.5');
}
//
App.Actions.PACKAGE.toggle_unlimited_feature = function(evt) {
var elm = $(evt.target);
var ref = elm.prev('.vst-input');
if (!$(ref).data('checked')) {
App.Actions.PACKAGE.enable_unlimited(ref, elm);
}
else {
App.Actions.PACKAGE.disable_unlimited(ref, elm);
}
}
App.Listeners.PACKAGE.checkbox_unlimited_feature = function() {
$('.unlim-trigger').on('click', App.Actions.PACKAGE.toggle_unlimited_feature);
}
App.Listeners.PACKAGE.init = function() {
$('.unlim-trigger').each(function(i, elm) {
var ref = $(elm).prev('.vst-input');
if (App.Helpers.isUnlimitedValue($(ref).val())) {
App.Actions.PACKAGE.enable_unlimited(ref, elm);
}
else {
$(ref).data('prev_value', $(ref).val());
App.Actions.PACKAGE.disable_unlimited(ref, elm);
}
});
}
App.Helpers.isUnlimitedValue = function(value) {
var value = value.trim();
if (value == App.Constants.UNLIM_VALUE || value == App.Constants.UNLIM_TRANSLATED_VALUE) {
return true;
}
return false;
}
//
// Page entry point
// Trigger listeners
App.Listeners.PACKAGE.init();
App.Listeners.PACKAGE.checkbox_unlimited_feature();
$('form[name="v_add_package"]').bind('submit', function(evt) {
$('input:disabled').each(function(i, elm) {
$(elm).attr('disabled', false);
if (App.Helpers.isUnlimitedValue($(elm).val())) {
$(elm).val(App.Constants.UNLIM_VALUE);
}
});
});