@osimatic/helpers-js 1.0.78 → 1.0.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/form_helper.js +91 -73
- package/multiple_action_in_table.js +6 -4
- package/package.json +1 -1
package/form_helper.js
CHANGED
|
@@ -1,33 +1,54 @@
|
|
|
1
1
|
class FormHelper {
|
|
2
|
-
static
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
FormHelper.setSelectedSelectOption(form, selectName, id);
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
static disableSelectOption(form, selectName, optionValue) {
|
|
14
|
-
form.find('select[name="'+selectName+'"] option[value="'+optionValue+'"]').prop('disabled', true);
|
|
15
|
-
}
|
|
16
|
-
static disableSelectOptions(form, selectName, optionValues) {
|
|
17
|
-
$.each(optionValues, function(idx, id) {
|
|
18
|
-
FormHelper.disableSelectOption(form, selectName, id);
|
|
2
|
+
static init(form, onSubmitCallback, submitButton) {
|
|
3
|
+
FormHelper.reset(form, submitButton);
|
|
4
|
+
submitButton = typeof submitButton != 'undefined' && null != submitButton ? submitButton : form.find('button[name="validate"]');
|
|
5
|
+
submitButton.off('click').click(function(e) {
|
|
6
|
+
e.preventDefault();
|
|
7
|
+
FormHelper.buttonLoader($(this), 'loading');
|
|
8
|
+
FormHelper.hideFormErrors(form);
|
|
9
|
+
onSubmitCallback(form, submitButton);
|
|
19
10
|
});
|
|
20
11
|
}
|
|
21
|
-
static countSelectOptions(form, selectName) {
|
|
22
|
-
return form.find('select[name="'+selectName+'"] option:not([disabled])').length;
|
|
23
|
-
}
|
|
24
12
|
|
|
25
13
|
static reset(form) {
|
|
26
14
|
form.find('[name]').each((idx, el) => $(el).val(''));
|
|
15
|
+
FormHelper.buttonLoader(form.find('button'), 'reset');
|
|
27
16
|
FormHelper.hideFormErrors(form);
|
|
28
17
|
return form;
|
|
29
18
|
}
|
|
30
19
|
|
|
20
|
+
static populateForm(form, data) {
|
|
21
|
+
form.find('[name="employees_display_type"][value="NONE"]').prop('checked', true); //todo à retirer
|
|
22
|
+
|
|
23
|
+
$.each(data, function(key, value) {
|
|
24
|
+
if (value == null) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof value == 'object') {
|
|
29
|
+
var select = form.find('[name="'+key+'[]"]');
|
|
30
|
+
select.find('option').prop('selected', false);
|
|
31
|
+
select.data('default_id', value.join(','));
|
|
32
|
+
$.each(value, function(key, val) {
|
|
33
|
+
select.find('option[value="'+val+'"]').prop('selected', true);
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var input = form.find('[name="'+key+'"]');
|
|
39
|
+
|
|
40
|
+
if (input.prop('type') === 'radio' || input.prop('type') === 'checkbox') {
|
|
41
|
+
input.prop('checked', false);
|
|
42
|
+
input.filter('[value="'+value+'"]').prop('checked', true);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
input.val(value);
|
|
47
|
+
// console.log(form.find('[name="'+key+'"]').length);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
31
52
|
static getFormData(form) {
|
|
32
53
|
// var formElement = document.getElementById("myFormElement");
|
|
33
54
|
return new FormData(form[0]);
|
|
@@ -54,36 +75,57 @@ class FormHelper {
|
|
|
54
75
|
}
|
|
55
76
|
|
|
56
77
|
|
|
57
|
-
static populateForm(form, data) {
|
|
58
|
-
form.find('[name="employees_display_type"][value="NONE"]').prop('checked', true); //todo à retirer
|
|
59
|
-
|
|
60
|
-
$.each(data, function(key, value) {
|
|
61
|
-
if (value == null) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
78
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
select.data('default_id', value.join(','));
|
|
69
|
-
$.each(value, function(key, val) {
|
|
70
|
-
select.find('option[value="'+val+'"]').prop('selected', true);
|
|
71
|
-
});
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
79
|
+
// ------------------------------------------------------------
|
|
80
|
+
// Input text
|
|
81
|
+
// ------------------------------------------------------------
|
|
74
82
|
|
|
75
|
-
|
|
83
|
+
static getInputValue(input) {
|
|
84
|
+
if (typeof input == 'undefined') {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
let value = $(input).val();
|
|
88
|
+
if (value === null || value === '') {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
76
93
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
94
|
+
static getLinesOfTextarea(textarea) {
|
|
95
|
+
return textarea.val().replace(/(\r\n|\n|\r)/g, "\n").split("\n").filter(word => word.length > 0);
|
|
96
|
+
}
|
|
82
97
|
|
|
83
|
-
|
|
84
|
-
|
|
98
|
+
// ------------------------------------------------------------
|
|
99
|
+
// Select
|
|
100
|
+
// ------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
static resetSelectOption(form, selectName) {
|
|
103
|
+
form.find('select[name="'+selectName+'"] option').prop('disabled', false).prop('selected', false);
|
|
104
|
+
}
|
|
105
|
+
static setSelectedSelectOption(form, selectName, optionValue) {
|
|
106
|
+
form.find('select[name="'+selectName+'"] option[value="'+optionValue+'"]').prop('selected', true);
|
|
107
|
+
}
|
|
108
|
+
static setSelectedSelectOptions(form, selectName, optionValues) {
|
|
109
|
+
$.each(optionValues, function(idx, id) {
|
|
110
|
+
FormHelper.setSelectedSelectOption(form, selectName, id);
|
|
85
111
|
});
|
|
86
112
|
}
|
|
113
|
+
static disableSelectOption(form, selectName, optionValue) {
|
|
114
|
+
form.find('select[name="'+selectName+'"] option[value="'+optionValue+'"]').prop('disabled', true);
|
|
115
|
+
}
|
|
116
|
+
static disableSelectOptions(form, selectName, optionValues) {
|
|
117
|
+
$.each(optionValues, function(idx, id) {
|
|
118
|
+
FormHelper.disableSelectOption(form, selectName, id);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
static countSelectOptions(form, selectName) {
|
|
122
|
+
return form.find('select[name="'+selectName+'"] option:not([disabled])').length;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
// ------------------------------------------------------------
|
|
127
|
+
// Checkbox
|
|
128
|
+
// ------------------------------------------------------------
|
|
87
129
|
|
|
88
130
|
static getCheckedValues(inputs) {
|
|
89
131
|
return inputs.map(function() {
|
|
@@ -105,21 +147,6 @@ class FormHelper {
|
|
|
105
147
|
}).get().filter(word => word.length > 0);
|
|
106
148
|
}
|
|
107
149
|
|
|
108
|
-
static getInputValue(input) {
|
|
109
|
-
if (typeof input == 'undefined') {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
let value = $(input).val();
|
|
113
|
-
if (value === null || value === '') {
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
return value;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
static getLinesOfTextarea(textarea) {
|
|
120
|
-
return textarea.val().replace(/(\r\n|\n|\r)/g, "\n").split("\n").filter(word => word.length > 0);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
150
|
|
|
124
151
|
// ------------------------------------------------------------
|
|
125
152
|
// Champs
|
|
@@ -171,7 +198,7 @@ class FormHelper {
|
|
|
171
198
|
}
|
|
172
199
|
|
|
173
200
|
// ------------------------------------------------------------
|
|
174
|
-
// Messages
|
|
201
|
+
// Messages erreur
|
|
175
202
|
// ------------------------------------------------------------
|
|
176
203
|
|
|
177
204
|
static extractErrorKeyOfJson(json, onlyIfUniqueError) {
|
|
@@ -259,6 +286,10 @@ class FormHelper {
|
|
|
259
286
|
}
|
|
260
287
|
|
|
261
288
|
|
|
289
|
+
// ------------------------------------------------------------
|
|
290
|
+
// Bouton valider
|
|
291
|
+
// ------------------------------------------------------------
|
|
292
|
+
|
|
262
293
|
static buttonLoader(button, action) {
|
|
263
294
|
button = $(button);
|
|
264
295
|
if (action === 'start' || action === 'loading') {
|
|
@@ -287,19 +318,6 @@ class FormHelper {
|
|
|
287
318
|
return button;
|
|
288
319
|
}
|
|
289
320
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
/** @deprecated **/
|
|
295
|
-
static logRequestFailure(status, exception) {
|
|
296
|
-
console.log('request failure. Status: '+status+' ; Exception: '+exception);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/** @deprecated **/
|
|
300
|
-
static displayFormErrorsFromXhr(form, btnSubmit, xhr) {
|
|
301
|
-
this.displayFormErrors(form, btnSubmit, xhr.responseJSON);
|
|
302
|
-
}
|
|
303
321
|
|
|
304
322
|
}
|
|
305
323
|
|
|
@@ -110,13 +110,15 @@ class MultipleActionInTable {
|
|
|
110
110
|
class MultipleActionInDivList {
|
|
111
111
|
// init checkbox
|
|
112
112
|
static init(contentDiv) {
|
|
113
|
-
|
|
114
|
-
if (
|
|
113
|
+
let buttonsDiv = MultipleActionInDivList.getButtonsDiv(contentDiv);
|
|
114
|
+
if (buttonsDiv == null) {
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
buttonsDiv.addClass('hide');
|
|
119
|
+
|
|
120
|
+
// Si aucune div sélectionnable, on n'applique pas le plugin
|
|
121
|
+
if (!contentDiv.find('.multiple_action').length) {
|
|
120
122
|
return;
|
|
121
123
|
}
|
|
122
124
|
|