djgentelella 0.3.25__py3-none-any.whl → 0.3.26__py3-none-any.whl
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.
- djgentelella/__init__.py +1 -1
- djgentelella/static/gentelella/js/base/form.common.js +195 -82
- djgentelella/static/gentelella/js/base/formset.js +102 -83
- djgentelella/static/gentelella/js/base.js +294 -162
- {djgentelella-0.3.25.dist-info → djgentelella-0.3.26.dist-info}/METADATA +1 -1
- {djgentelella-0.3.25.dist-info → djgentelella-0.3.26.dist-info}/RECORD +10 -10
- {djgentelella-0.3.25.dist-info → djgentelella-0.3.26.dist-info}/AUTHORS +0 -0
- {djgentelella-0.3.25.dist-info → djgentelella-0.3.26.dist-info}/LICENSE.txt +0 -0
- {djgentelella-0.3.25.dist-info → djgentelella-0.3.26.dist-info}/WHEEL +0 -0
- {djgentelella-0.3.25.dist-info → djgentelella-0.3.26.dist-info}/top_level.txt +0 -0
djgentelella/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = '0.3.
|
|
1
|
+
__version__ = '0.3.26'
|
|
@@ -1,111 +1,114 @@
|
|
|
1
1
|
function convertFileToBase64(file) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
const reader = new FileReader();
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
reader.onload = () => {
|
|
6
|
+
const base64String = reader.result.split(',')[1];
|
|
7
|
+
resolve(base64String);
|
|
8
|
+
};
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
reader.onerror = (error) => {
|
|
11
|
+
reject(error);
|
|
12
|
+
};
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
reader.readAsDataURL(file);
|
|
15
|
+
});
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
async function obtainFormAsJSON(form, prefix = '', extras={}) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
for (let i = 0; i < fields.length; i++) {
|
|
31
|
-
const field = fields[i];
|
|
32
|
-
|
|
33
|
-
if (field.type !== 'submit' && field.type !== 'button') {
|
|
34
|
-
const fieldName = field.name.replace(prefix, '');
|
|
35
|
-
if(field.type === 'textarea'){
|
|
36
|
-
formData[fieldName] = $(field).val();
|
|
37
|
-
}else if(field.type === 'checkbox'){
|
|
38
|
-
formData[fieldName] = field.checked;
|
|
39
|
-
}else if (field.type === 'radio') {
|
|
40
|
-
if(field.checked){
|
|
41
|
-
formData[fieldName] = $(field).val();
|
|
18
|
+
async function obtainFormAsJSON(form, prefix = '', extras = {}, format = true) {
|
|
19
|
+
const fields = form.elements;
|
|
20
|
+
const formData = {};
|
|
21
|
+
// typeof variable === 'function'
|
|
22
|
+
for (let key in extras) {
|
|
23
|
+
if (typeof extras[key] === 'function') {
|
|
24
|
+
formData[key] = extras[key](form, key, prefix);
|
|
25
|
+
} else {
|
|
26
|
+
formData[key] = extras[key];
|
|
42
27
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < fields.length; i++) {
|
|
31
|
+
const field = fields[i];
|
|
32
|
+
|
|
33
|
+
if (field.type !== 'submit' && field.type !== 'button') {
|
|
34
|
+
const fieldName = field.name.replace(prefix, '');
|
|
35
|
+
if (field.type === 'textarea') {
|
|
36
|
+
formData[fieldName] = $(field).val();
|
|
37
|
+
} else if (field.type === 'checkbox') {
|
|
38
|
+
formData[fieldName] = field.checked;
|
|
39
|
+
} else if (field.type === 'radio') {
|
|
40
|
+
if (field.checked) {
|
|
41
|
+
formData[fieldName] = $(field).val();
|
|
42
|
+
}
|
|
43
|
+
} else if (field.type === 'file') {
|
|
44
|
+
const files = Array.from(field.files);
|
|
45
|
+
const filesBase64 = [];
|
|
46
|
+
|
|
47
|
+
for (let j = 0; j < files.length; j++) {
|
|
48
|
+
const file = files[j];
|
|
49
|
+
try {
|
|
50
|
+
const base64String = await convertFileToBase64(file);
|
|
51
|
+
filesBase64.push({name: file.name, value: base64String});
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('Error converting file:', error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
formData[fieldName] = filesBase64;
|
|
58
|
+
} else if (field.multiple) {
|
|
59
|
+
const selectedOptions = Array.from(field.selectedOptions);
|
|
60
|
+
const selectedValues = selectedOptions.map((option) => option.value);
|
|
61
|
+
formData[fieldName] = selectedValues;
|
|
62
|
+
} else {
|
|
63
|
+
formData[fieldName] = field.value;
|
|
64
|
+
}
|
|
55
65
|
}
|
|
66
|
+
}
|
|
56
67
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const selectedOptions = Array.from(field.selectedOptions);
|
|
60
|
-
const selectedValues = selectedOptions.map((option) => option.value);
|
|
61
|
-
formData[fieldName] = selectedValues;
|
|
62
|
-
} else {
|
|
63
|
-
formData[fieldName] = field.value;
|
|
64
|
-
}
|
|
68
|
+
if (format) {
|
|
69
|
+
return JSON.stringify(formData);
|
|
65
70
|
}
|
|
66
|
-
}
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
return formData;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
|
-
function convertToStringJson(form, prefix="", extras={}){
|
|
72
|
-
|
|
73
|
-
return result;
|
|
75
|
+
function convertToStringJson(form, prefix = "", extras = {}, format = true) {
|
|
76
|
+
return obtainFormAsJSON(form[0], prefix, extras, format);
|
|
74
77
|
}
|
|
75
78
|
|
|
76
|
-
function load_errors(error_list, obj, parentdiv){
|
|
79
|
+
function load_errors(error_list, obj, parentdiv) {
|
|
77
80
|
ul_obj = "<ul class='errorlist form_errors d-flex justify-content-center'>";
|
|
78
|
-
error_list.forEach((item)=>{
|
|
79
|
-
ul_obj += "<li>"+item+"</li>";
|
|
81
|
+
error_list.forEach((item) => {
|
|
82
|
+
ul_obj += "<li>" + item + "</li>";
|
|
80
83
|
});
|
|
81
84
|
ul_obj += "</ul>"
|
|
82
85
|
$(obj).parents(parentdiv).prepend(ul_obj);
|
|
83
86
|
return ul_obj;
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
function form_field_errors(target_form, form_errors, prefix, parentdiv){
|
|
89
|
+
function form_field_errors(target_form, form_errors, prefix, parentdiv) {
|
|
87
90
|
var item = "";
|
|
88
91
|
for (const [key, value] of Object.entries(form_errors)) {
|
|
89
|
-
item = " #id_" +prefix+key;
|
|
90
|
-
if(target_form.find(item).length > 0){
|
|
92
|
+
item = " #id_" + prefix + key;
|
|
93
|
+
if (target_form.find(item).length > 0) {
|
|
91
94
|
load_errors(form_errors[key], item, parentdiv);
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
function response_manage_type_data(instance, err_json_fn, error_text_fn){
|
|
97
|
-
return function(response) {
|
|
99
|
+
function response_manage_type_data(instance, err_json_fn, error_text_fn) {
|
|
100
|
+
return function (response) {
|
|
98
101
|
const contentType = response.headers.get("content-type");
|
|
99
|
-
if(response.ok){
|
|
100
|
-
|
|
102
|
+
if (response.ok) {
|
|
103
|
+
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
101
104
|
return response.json();
|
|
102
|
-
}else{
|
|
105
|
+
} else {
|
|
103
106
|
return response.text();
|
|
104
107
|
}
|
|
105
|
-
}else{
|
|
108
|
+
} else {
|
|
106
109
|
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
107
110
|
response.json().then(data => err_json_fn(instance, data));
|
|
108
|
-
}else{
|
|
111
|
+
} else {
|
|
109
112
|
response.text().then(data => error_text_fn(instance, data));
|
|
110
113
|
}
|
|
111
114
|
return Promise.resolve(false);
|
|
@@ -115,20 +118,20 @@ function response_manage_type_data(instance, err_json_fn, error_text_fn){
|
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
120
|
|
|
118
|
-
function clear_action_form(form){
|
|
121
|
+
function clear_action_form(form) {
|
|
119
122
|
// clear switchery before the form reset so the check status doesn't get changed before the validation
|
|
120
|
-
$(form).find("input[data-switchery=true]").each(function() {
|
|
121
|
-
if($(this).prop("checked")){ // only reset it if it is checked
|
|
123
|
+
$(form).find("input[data-switchery=true]").each(function () {
|
|
124
|
+
if ($(this).prop("checked")) { // only reset it if it is checked
|
|
122
125
|
$(this).trigger("click").prop("checked", false);
|
|
123
126
|
}
|
|
124
127
|
});
|
|
125
|
-
$(form).find('[data-widget="TaggingInput"],[data-widget="EmailTaggingInput"]').each(function(i, e) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
$(form).find('[data-widget="TaggingInput"],[data-widget="EmailTaggingInput"]').each(function (i, e) {
|
|
129
|
+
var tg = $(e).data().tagify;
|
|
130
|
+
tg.removeAllTags();
|
|
128
131
|
});
|
|
129
|
-
$(form).find('[data-widget="FileChunkedUpload"],[data-widget="FileInput"]').each(function(i, e) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
$(form).find('[data-widget="FileChunkedUpload"],[data-widget="FileInput"]').each(function (i, e) {
|
|
133
|
+
var tg = $(e).data().fileUploadWidget;
|
|
134
|
+
tg.resetEmpty();
|
|
132
135
|
});
|
|
133
136
|
$(form).trigger('reset');
|
|
134
137
|
$(form).find("select option:selected").prop("selected", false);
|
|
@@ -140,3 +143,113 @@ function clear_action_form(form){
|
|
|
140
143
|
var gt_form_modals = {}
|
|
141
144
|
var gt_detail_modals = {}
|
|
142
145
|
var gt_crud_objs = {};
|
|
146
|
+
|
|
147
|
+
function updateInstanceValuesForm(form, name, value) {
|
|
148
|
+
var item = form.find(
|
|
149
|
+
'input[name="' + name + '"], ' +
|
|
150
|
+
'textarea[name="' + name + '"], ' +
|
|
151
|
+
'select[name="' + name + '"]'
|
|
152
|
+
);
|
|
153
|
+
item.each(function (i, inputfield) {
|
|
154
|
+
let done = false;
|
|
155
|
+
inputfield = $(inputfield);
|
|
156
|
+
|
|
157
|
+
if (inputfield.attr('class') === "chunkedvalue") {
|
|
158
|
+
if (value) {
|
|
159
|
+
var chunked = form.find('input[name="' + name + '_widget"]').data('fileUploadWidget');
|
|
160
|
+
chunked.addRemote(value);
|
|
161
|
+
}
|
|
162
|
+
done = true;
|
|
163
|
+
} else if (inputfield.attr('type') === 'file') {
|
|
164
|
+
if (value) {
|
|
165
|
+
var newlink = document.createElement('a');
|
|
166
|
+
newlink.href = value.url;
|
|
167
|
+
newlink.textContent = value.name;
|
|
168
|
+
newlink.target = "_blank";
|
|
169
|
+
newlink.classList.add("link-primary");
|
|
170
|
+
newlink.classList.add("file-link");
|
|
171
|
+
newlink.classList.add("d-block");
|
|
172
|
+
inputfield.before(newlink)
|
|
173
|
+
}
|
|
174
|
+
done = true;
|
|
175
|
+
} else if (inputfield.attr('type') === "checkbox") {
|
|
176
|
+
if (inputfield.data().widget === "YesNoInput") {
|
|
177
|
+
inputfield.prop("checked", !value);
|
|
178
|
+
inputfield.trigger("click");
|
|
179
|
+
done = true;
|
|
180
|
+
} else {
|
|
181
|
+
inputfield.prop("checked", value);
|
|
182
|
+
}
|
|
183
|
+
done = true;
|
|
184
|
+
} else if (inputfield.attr('type') === "radio") {
|
|
185
|
+
var is_icheck = inputfield.closest('.gtradio').length > 0;
|
|
186
|
+
var sel = inputfield.filter(function () {
|
|
187
|
+
return this.value === value.toString()
|
|
188
|
+
});
|
|
189
|
+
if (sel.length > 0) {
|
|
190
|
+
sel.prop("checked", true);
|
|
191
|
+
if (is_icheck) {
|
|
192
|
+
sel.iCheck('update');
|
|
193
|
+
sel.iCheck('check');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
} else {
|
|
197
|
+
inputfield.prop("checked", false);
|
|
198
|
+
if (is_icheck) {
|
|
199
|
+
inputfield.iCheck('update');
|
|
200
|
+
inputfield.iCheck('uncheck');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
done = true;
|
|
204
|
+
}
|
|
205
|
+
if (inputfield.data().widget === "EditorTinymce" || inputfield.data().widget === "TextareaWysiwyg") {
|
|
206
|
+
tinymce.get(inputfield.attr('id')).setContent(value);
|
|
207
|
+
done = true;
|
|
208
|
+
}
|
|
209
|
+
if (inputfield.data().widget === "TaggingInput" || inputfield.data().widget === "EmailTaggingInput") {
|
|
210
|
+
var tagifyelement = inputfield.data().tagify;
|
|
211
|
+
tagifyelement.removeAllTags();
|
|
212
|
+
tagifyelement.loadOriginalValues(value);
|
|
213
|
+
done = true;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// New code for testing (*** start ***)
|
|
217
|
+
// data loading in select, autocompleteselect, autocompletemultiselect
|
|
218
|
+
else if (inputfield.is('select') && inputfield.data().widget === "Select") {
|
|
219
|
+
inputfield.val(value).trigger('change');
|
|
220
|
+
done = true;
|
|
221
|
+
} else if (inputfield.is('select') && inputfield.data().widget === "AutocompleteSelect") {
|
|
222
|
+
let data = value;
|
|
223
|
+
let select2Obj = inputfield.data('select2');
|
|
224
|
+
if (select2Obj) {
|
|
225
|
+
inputfield.select2('trigger', 'select', {
|
|
226
|
+
data: data
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
done = true;
|
|
230
|
+
} else if (inputfield.is('select') && inputfield.data().widget === "AutocompleteSelectMultiple") {
|
|
231
|
+
|
|
232
|
+
if (Array.isArray(value)) {
|
|
233
|
+
value.forEach(item => {
|
|
234
|
+
let newOption = new Option(item.text, item.id, true, true);
|
|
235
|
+
inputfield.append(newOption);
|
|
236
|
+
});
|
|
237
|
+
inputfield.trigger('change');
|
|
238
|
+
}
|
|
239
|
+
done = true;
|
|
240
|
+
}
|
|
241
|
+
// New code for testing (*** end ***)
|
|
242
|
+
|
|
243
|
+
if (!done) {
|
|
244
|
+
inputfield.val(value);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function updateInstanceForm(form, data) {
|
|
250
|
+
for (let key in data) {
|
|
251
|
+
if (data.hasOwnProperty(key)) {
|
|
252
|
+
updateInstanceValuesForm(form, key, data[key])
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
function gtforms(index,manager, formList, extra=true)
|
|
1
|
+
function gtforms(index, manager, formList, extra = true) {
|
|
2
2
|
return {
|
|
3
3
|
index: index,
|
|
4
4
|
order: index,
|
|
5
|
+
deleted: false,
|
|
5
6
|
manager: manager,
|
|
6
7
|
formList: formList,
|
|
7
8
|
extra: extra,
|
|
8
9
|
instance: null,
|
|
9
|
-
deleteForm: function(){
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
deleteForm: function () {
|
|
11
|
+
if (!this.manager.validateDeleteForm()) {
|
|
12
|
+
this.manager.notify('error', 'You can not delete this form, minimum form validation failed')
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.deleted = true;
|
|
14
16
|
this.instance.hide();
|
|
15
|
-
this.instance.find('input[name="'+this.manager.prefix+'-'+this.index+'-DELETE"]').prop(
|
|
17
|
+
this.instance.find('input[name="' + this.manager.prefix + '-' + this.index + '-DELETE"]').prop("checked", true);
|
|
16
18
|
this.manager.deleteForm(this.order);
|
|
17
19
|
},
|
|
18
|
-
render: function(){
|
|
20
|
+
render: function () {
|
|
19
21
|
var html = this.manager.template.replace(/__prefix__/gi, this.index);
|
|
20
22
|
this.instance = $(html);
|
|
21
23
|
formList.append(this.instance);
|
|
@@ -23,37 +25,42 @@ function gtforms(index,manager, formList, extra=true) {
|
|
|
23
25
|
this.registerBtns();
|
|
24
26
|
|
|
25
27
|
},
|
|
26
|
-
reorder: function(oper){
|
|
27
|
-
var brother = this.manager.getForm(this.order+oper);
|
|
28
|
-
this.manager.switchFrom(this.order, this.order+oper);
|
|
29
|
-
if(brother != null){
|
|
30
|
-
if(oper == 1
|
|
28
|
+
reorder: function (oper) {
|
|
29
|
+
var brother = this.manager.getForm(this.order + oper);
|
|
30
|
+
this.manager.switchFrom(this.order, this.order + oper);
|
|
31
|
+
if (brother != null) {
|
|
32
|
+
if (oper == 1) {
|
|
31
33
|
this.instance.before(brother.instance);
|
|
32
|
-
}else{
|
|
34
|
+
} else {
|
|
33
35
|
brother.instance.before(this.instance);
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
},
|
|
37
|
-
registerBtns: function(){
|
|
39
|
+
registerBtns: function () {
|
|
38
40
|
this.instance.find('.deletebtn').on('click', this.callDelete(this));
|
|
39
41
|
// down increment order and up decrement order when forms are inserted in bottom
|
|
40
42
|
this.instance.find('.btndown').on('click', this.callReorder(this, 1));
|
|
41
43
|
this.instance.find('.btnup').on('click', this.callReorder(this, -1));
|
|
42
44
|
},
|
|
43
|
-
callDelete: function(instance){
|
|
44
|
-
return () => {
|
|
45
|
+
callDelete: function (instance) {
|
|
46
|
+
return () => {
|
|
47
|
+
instance.deleteForm()
|
|
48
|
+
};
|
|
45
49
|
},
|
|
46
|
-
initializeWidgets: function(instance){
|
|
50
|
+
initializeWidgets: function (instance) {
|
|
47
51
|
gt_find_initialize(instance);
|
|
48
52
|
},
|
|
49
|
-
callReorder: function(instance, oper){
|
|
50
|
-
return () => {
|
|
53
|
+
callReorder: function (instance, oper) {
|
|
54
|
+
return () => {
|
|
55
|
+
instance.reorder(oper)
|
|
56
|
+
}
|
|
51
57
|
},
|
|
52
|
-
updateOrder: function(){
|
|
53
|
-
this.instance.find('input[name="'+this.manager.prefix+'-'+this.index+'-ORDER"]').val(this.order);
|
|
58
|
+
updateOrder: function () {
|
|
59
|
+
this.instance.find('input[name="' + this.manager.prefix + '-' + this.index + '-ORDER"]').val(this.order);
|
|
54
60
|
}
|
|
55
61
|
}
|
|
56
62
|
}
|
|
63
|
+
|
|
57
64
|
function gtformSetManager(instance) {
|
|
58
65
|
var obj = {
|
|
59
66
|
index: 0,
|
|
@@ -70,49 +77,61 @@ function gtformSetManager(instance) {
|
|
|
70
77
|
formList: instance.find('.formlist'),
|
|
71
78
|
template: '',
|
|
72
79
|
prefix: 'form-',
|
|
73
|
-
initialize: function(){
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
},
|
|
82
|
-
addBtnForm: function(instance){
|
|
83
|
-
return () => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
initialize: function () {
|
|
81
|
+
this.template = this.formsetControl.find(".formsettemplate").contents()[0].data;
|
|
82
|
+
this.prefix = this.formsetControl.data('prefix');
|
|
83
|
+
this.validateMax = this.formsetControl.data('validate-max') == '1';
|
|
84
|
+
this.validateMin = this.formsetControl.data('validate-min') == '1';
|
|
85
|
+
this.loadManagementForm();
|
|
86
|
+
this.instance.find('.formsetadd').on('click', this.addBtnForm(this));
|
|
87
|
+
this.addFormDom();
|
|
88
|
+
},
|
|
89
|
+
addBtnForm: function (instance) {
|
|
90
|
+
return (e) => {
|
|
91
|
+
instance.addEmtpyForm(e)
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
addEmtpyForm: function (e) {
|
|
95
|
+
if (this.validateAddForm()) {
|
|
96
|
+
this.activeForms += 1;
|
|
87
97
|
var form = gtforms(this.index, this, this.formList);
|
|
88
98
|
form.render();
|
|
89
99
|
this.forms.push(form);
|
|
100
|
+
this.addForm(this, form, true, e);
|
|
90
101
|
this.index += 1;
|
|
91
102
|
this.updateTotalForms(+1);
|
|
92
|
-
}else{
|
|
103
|
+
} else {
|
|
93
104
|
this.notify('error', 'You cannot add new form, limit is exceded')
|
|
94
105
|
}
|
|
95
106
|
},
|
|
96
|
-
addForm: function(object){
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
addForm: function (parent, object, isempty, event) {
|
|
108
|
+
},
|
|
109
|
+
addFormDom: function () {
|
|
110
|
+
this.formList.children().each((i, element) => {
|
|
111
|
+
this.activeForms += 1;
|
|
112
|
+
var form = gtforms(this.index, this, this.formList, extra = false);
|
|
113
|
+
form.instance = $(element);
|
|
114
|
+
form.registerBtns();
|
|
115
|
+
this.forms.push(form);
|
|
116
|
+
this.addForm(this, form, false, null);
|
|
117
|
+
this.index += 1;
|
|
104
118
|
});
|
|
105
119
|
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
120
|
+
delForm: function (parent, index, form) {
|
|
121
|
+
},
|
|
122
|
+
deleteForm: function (index) {
|
|
123
|
+
if (!this.validateDeleteForm()) return;
|
|
124
|
+
this.activeForms = Math.max(0, this.activeForms - 1);
|
|
125
|
+
|
|
126
|
+
if (index >= 0 && index < this.forms.length) {
|
|
127
|
+
this.delForm(this, index, this.forms[index]);
|
|
128
|
+
if (this.forms[index].extra) {
|
|
110
129
|
this.forms.splice(index, 1);
|
|
111
130
|
this.updateTotalForms(-1);
|
|
112
|
-
if(index == this.forms.length){
|
|
131
|
+
if (index == this.forms.length) {
|
|
113
132
|
this.index -= 1;
|
|
114
|
-
}else{
|
|
115
|
-
for(var x=0; x<this.forms.length; x++){
|
|
133
|
+
} else {
|
|
134
|
+
for (var x = 0; x < this.forms.length; x++) {
|
|
116
135
|
this.forms[x].order = x;
|
|
117
136
|
this.forms[x].updateOrder();
|
|
118
137
|
}
|
|
@@ -121,40 +140,40 @@ function gtformSetManager(instance) {
|
|
|
121
140
|
|
|
122
141
|
}
|
|
123
142
|
},
|
|
124
|
-
validateAddForm: function(){
|
|
125
|
-
if(!this.validateMax) return true;
|
|
143
|
+
validateAddForm: function () {
|
|
144
|
+
if (!this.validateMax) return true;
|
|
126
145
|
return this.MAX_NUM_FORMS == -1 || this.TOTAL_FORMS < this.MAX_NUM_FORMS;
|
|
127
146
|
},
|
|
128
|
-
validateDeleteForm: function(){
|
|
129
|
-
if(!this.validateMin) return true;
|
|
147
|
+
validateDeleteForm: function () {
|
|
148
|
+
if (!this.validateMin) return true;
|
|
130
149
|
return this.MIN_NUM_FORMS == -1 || this.TOTAL_FORMS > this.MIN_NUM_FORMS;
|
|
131
150
|
},
|
|
132
|
-
loadManagementForm: function(){
|
|
133
|
-
this.TOTAL_FORMS = parseInt(this.formsetControl.find('input[name="'+this.prefix+'-TOTAL_FORMS"]').val());
|
|
134
|
-
this.INITIAL_FORMS = parseInt(this.formsetControl.find('input[name="'+this.prefix+'-INITIAL_FORMS"]').val());
|
|
135
|
-
this.MIN_NUM_FORMS = parseInt(this.formsetControl.find('input[name="'+this.prefix+'-MIN_NUM_FORMS"]').val());
|
|
136
|
-
this.MAX_NUM_FORMS = parseInt(this.formsetControl.find('input[name="'+this.prefix+'-MAX_NUM_FORMS"]').val());
|
|
151
|
+
loadManagementForm: function () {
|
|
152
|
+
this.TOTAL_FORMS = parseInt(this.formsetControl.find('input[name="' + this.prefix + '-TOTAL_FORMS"]').val());
|
|
153
|
+
this.INITIAL_FORMS = parseInt(this.formsetControl.find('input[name="' + this.prefix + '-INITIAL_FORMS"]').val());
|
|
154
|
+
this.MIN_NUM_FORMS = parseInt(this.formsetControl.find('input[name="' + this.prefix + '-MIN_NUM_FORMS"]').val());
|
|
155
|
+
this.MAX_NUM_FORMS = parseInt(this.formsetControl.find('input[name="' + this.prefix + '-MAX_NUM_FORMS"]').val());
|
|
137
156
|
},
|
|
138
|
-
updateManagementForm: function(){
|
|
139
|
-
this.formsetControl.find('input[name="'+this.prefix+'-TOTAL_FORMS"]').val(this.TOTAL_FORMS);
|
|
140
|
-
this.formsetControl.find('input[name="'+this.prefix+'-INITIAL_FORMS"]').val(this.INITIAL_FORMS);
|
|
141
|
-
this.formsetControl.find('input[name="'+this.prefix+'-MIN_NUM_FORMS"]').val(this.MIN_NUM_FORMS);
|
|
142
|
-
this.formsetControl.find('input[name="'+this.prefix+'-MAX_NUM_FORMS"]').val(this.MAX_NUM_FORMS);
|
|
157
|
+
updateManagementForm: function () {
|
|
158
|
+
this.formsetControl.find('input[name="' + this.prefix + '-TOTAL_FORMS"]').val(this.TOTAL_FORMS);
|
|
159
|
+
this.formsetControl.find('input[name="' + this.prefix + '-INITIAL_FORMS"]').val(this.INITIAL_FORMS);
|
|
160
|
+
this.formsetControl.find('input[name="' + this.prefix + '-MIN_NUM_FORMS"]').val(this.MIN_NUM_FORMS);
|
|
161
|
+
this.formsetControl.find('input[name="' + this.prefix + '-MAX_NUM_FORMS"]').val(this.MAX_NUM_FORMS);
|
|
143
162
|
},
|
|
144
|
-
updateTotalForms: function(oper){
|
|
145
|
-
this.TOTAL_FORMS = this.TOTAL_FORMS+oper;
|
|
146
|
-
this.formsetControl.find('input[name="'+this.prefix+'-TOTAL_FORMS"]').val(this.TOTAL_FORMS);
|
|
163
|
+
updateTotalForms: function (oper) {
|
|
164
|
+
this.TOTAL_FORMS = this.TOTAL_FORMS + oper;
|
|
165
|
+
this.formsetControl.find('input[name="' + this.prefix + '-TOTAL_FORMS"]').val(this.TOTAL_FORMS);
|
|
147
166
|
},
|
|
148
|
-
getForm: function(index){
|
|
149
|
-
if(index>=0 && index < this.forms.length){
|
|
167
|
+
getForm: function (index) {
|
|
168
|
+
if (index >= 0 && index < this.forms.length) {
|
|
150
169
|
return this.forms[index];
|
|
151
170
|
}
|
|
152
171
|
return null;
|
|
153
172
|
},
|
|
154
|
-
switchFrom: function(fref, fswap){
|
|
173
|
+
switchFrom: function (fref, fswap) {
|
|
155
174
|
var freform = this.getForm(fref);
|
|
156
175
|
var fswapform = this.getForm(fswap);
|
|
157
|
-
if(freform != null && fswapform != null){
|
|
176
|
+
if (freform != null && fswapform != null) {
|
|
158
177
|
var tmporder = freform.order;
|
|
159
178
|
freform.order = fswapform.order;
|
|
160
179
|
fswapform.order = tmporder;
|
|
@@ -166,23 +185,23 @@ function gtformSetManager(instance) {
|
|
|
166
185
|
}
|
|
167
186
|
|
|
168
187
|
},
|
|
169
|
-
redrawOrdering: function(){
|
|
170
|
-
for(var x=0; x<this.forms.length; x++){
|
|
171
|
-
|
|
188
|
+
redrawOrdering: function () {
|
|
189
|
+
for (var x = 0; x < this.forms.length; x++) {
|
|
190
|
+
this.formList.append(this.forms[x].instance);
|
|
172
191
|
}
|
|
173
192
|
},
|
|
174
|
-
notify: function(type, text){
|
|
193
|
+
notify: function (type, text) {
|
|
175
194
|
console.log(text);
|
|
176
195
|
},
|
|
177
|
-
clean: function(){
|
|
178
|
-
while(this.forms.length>0){
|
|
196
|
+
clean: function () {
|
|
197
|
+
while (this.forms.length > 0) {
|
|
179
198
|
var f = this.forms.pop();
|
|
180
199
|
f.instance.remove();
|
|
181
200
|
}
|
|
182
|
-
this.TOTAL_FORMS=0;
|
|
183
|
-
this.INITIAL_FORMS=0;
|
|
184
|
-
this.TOTAL_FORMS=0;
|
|
185
|
-
this.index=0;
|
|
201
|
+
this.TOTAL_FORMS = 0;
|
|
202
|
+
this.INITIAL_FORMS = 0;
|
|
203
|
+
this.TOTAL_FORMS = 0;
|
|
204
|
+
this.index = 0;
|
|
186
205
|
this.updateManagementForm();
|
|
187
206
|
}
|
|
188
207
|
}
|
|
@@ -700,113 +700,116 @@ $.fn.select2related = function(action, relatedobjs=[]) {
|
|
|
700
700
|
})(jQuery)
|
|
701
701
|
|
|
702
702
|
function convertFileToBase64(file) {
|
|
703
|
-
|
|
704
|
-
|
|
703
|
+
return new Promise((resolve, reject) => {
|
|
704
|
+
const reader = new FileReader();
|
|
705
705
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
706
|
+
reader.onload = () => {
|
|
707
|
+
const base64String = reader.result.split(',')[1];
|
|
708
|
+
resolve(base64String);
|
|
709
|
+
};
|
|
710
710
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
711
|
+
reader.onerror = (error) => {
|
|
712
|
+
reject(error);
|
|
713
|
+
};
|
|
714
714
|
|
|
715
|
-
|
|
716
|
-
|
|
715
|
+
reader.readAsDataURL(file);
|
|
716
|
+
});
|
|
717
717
|
}
|
|
718
718
|
|
|
719
|
-
async function obtainFormAsJSON(form, prefix = '', extras={}) {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
719
|
+
async function obtainFormAsJSON(form, prefix = '', extras = {}, format = true) {
|
|
720
|
+
const fields = form.elements;
|
|
721
|
+
const formData = {};
|
|
722
|
+
// typeof variable === 'function'
|
|
723
|
+
for (let key in extras) {
|
|
724
|
+
if (typeof extras[key] === 'function') {
|
|
725
|
+
formData[key] = extras[key](form, key, prefix);
|
|
726
|
+
} else {
|
|
727
|
+
formData[key] = extras[key];
|
|
728
|
+
}
|
|
728
729
|
}
|
|
729
|
-
}
|
|
730
730
|
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
731
|
+
for (let i = 0; i < fields.length; i++) {
|
|
732
|
+
const field = fields[i];
|
|
733
|
+
|
|
734
|
+
if (field.type !== 'submit' && field.type !== 'button') {
|
|
735
|
+
const fieldName = field.name.replace(prefix, '');
|
|
736
|
+
if (field.type === 'textarea') {
|
|
737
|
+
formData[fieldName] = $(field).val();
|
|
738
|
+
} else if (field.type === 'checkbox') {
|
|
739
|
+
formData[fieldName] = field.checked;
|
|
740
|
+
} else if (field.type === 'radio') {
|
|
741
|
+
if (field.checked) {
|
|
742
|
+
formData[fieldName] = $(field).val();
|
|
743
|
+
}
|
|
744
|
+
} else if (field.type === 'file') {
|
|
745
|
+
const files = Array.from(field.files);
|
|
746
|
+
const filesBase64 = [];
|
|
747
|
+
|
|
748
|
+
for (let j = 0; j < files.length; j++) {
|
|
749
|
+
const file = files[j];
|
|
750
|
+
try {
|
|
751
|
+
const base64String = await convertFileToBase64(file);
|
|
752
|
+
filesBase64.push({name: file.name, value: base64String});
|
|
753
|
+
} catch (error) {
|
|
754
|
+
console.error('Error converting file:', error);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
formData[fieldName] = filesBase64;
|
|
759
|
+
} else if (field.multiple) {
|
|
760
|
+
const selectedOptions = Array.from(field.selectedOptions);
|
|
761
|
+
const selectedValues = selectedOptions.map((option) => option.value);
|
|
762
|
+
formData[fieldName] = selectedValues;
|
|
763
|
+
} else {
|
|
764
|
+
formData[fieldName] = field.value;
|
|
765
|
+
}
|
|
756
766
|
}
|
|
767
|
+
}
|
|
757
768
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
const selectedOptions = Array.from(field.selectedOptions);
|
|
761
|
-
const selectedValues = selectedOptions.map((option) => option.value);
|
|
762
|
-
formData[fieldName] = selectedValues;
|
|
763
|
-
} else {
|
|
764
|
-
formData[fieldName] = field.value;
|
|
765
|
-
}
|
|
769
|
+
if (format) {
|
|
770
|
+
return JSON.stringify(formData);
|
|
766
771
|
}
|
|
767
|
-
}
|
|
768
772
|
|
|
769
|
-
|
|
773
|
+
return formData;
|
|
770
774
|
}
|
|
771
775
|
|
|
772
|
-
function convertToStringJson(form, prefix="", extras={}){
|
|
773
|
-
|
|
774
|
-
return result;
|
|
776
|
+
function convertToStringJson(form, prefix = "", extras = {}, format = true) {
|
|
777
|
+
return obtainFormAsJSON(form[0], prefix, extras, format);
|
|
775
778
|
}
|
|
776
779
|
|
|
777
|
-
function load_errors(error_list, obj, parentdiv){
|
|
780
|
+
function load_errors(error_list, obj, parentdiv) {
|
|
778
781
|
ul_obj = "<ul class='errorlist form_errors d-flex justify-content-center'>";
|
|
779
|
-
error_list.forEach((item)=>{
|
|
780
|
-
ul_obj += "<li>"+item+"</li>";
|
|
782
|
+
error_list.forEach((item) => {
|
|
783
|
+
ul_obj += "<li>" + item + "</li>";
|
|
781
784
|
});
|
|
782
785
|
ul_obj += "</ul>"
|
|
783
786
|
$(obj).parents(parentdiv).prepend(ul_obj);
|
|
784
787
|
return ul_obj;
|
|
785
788
|
}
|
|
786
789
|
|
|
787
|
-
function form_field_errors(target_form, form_errors, prefix, parentdiv){
|
|
790
|
+
function form_field_errors(target_form, form_errors, prefix, parentdiv) {
|
|
788
791
|
var item = "";
|
|
789
792
|
for (const [key, value] of Object.entries(form_errors)) {
|
|
790
|
-
item = " #id_" +prefix+key;
|
|
791
|
-
if(target_form.find(item).length > 0){
|
|
793
|
+
item = " #id_" + prefix + key;
|
|
794
|
+
if (target_form.find(item).length > 0) {
|
|
792
795
|
load_errors(form_errors[key], item, parentdiv);
|
|
793
796
|
}
|
|
794
797
|
}
|
|
795
798
|
}
|
|
796
799
|
|
|
797
|
-
function response_manage_type_data(instance, err_json_fn, error_text_fn){
|
|
798
|
-
return function(response) {
|
|
800
|
+
function response_manage_type_data(instance, err_json_fn, error_text_fn) {
|
|
801
|
+
return function (response) {
|
|
799
802
|
const contentType = response.headers.get("content-type");
|
|
800
|
-
if(response.ok){
|
|
801
|
-
|
|
803
|
+
if (response.ok) {
|
|
804
|
+
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
802
805
|
return response.json();
|
|
803
|
-
}else{
|
|
806
|
+
} else {
|
|
804
807
|
return response.text();
|
|
805
808
|
}
|
|
806
|
-
}else{
|
|
809
|
+
} else {
|
|
807
810
|
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
808
811
|
response.json().then(data => err_json_fn(instance, data));
|
|
809
|
-
}else{
|
|
812
|
+
} else {
|
|
810
813
|
response.text().then(data => error_text_fn(instance, data));
|
|
811
814
|
}
|
|
812
815
|
return Promise.resolve(false);
|
|
@@ -816,20 +819,20 @@ function response_manage_type_data(instance, err_json_fn, error_text_fn){
|
|
|
816
819
|
}
|
|
817
820
|
}
|
|
818
821
|
|
|
819
|
-
function clear_action_form(form){
|
|
822
|
+
function clear_action_form(form) {
|
|
820
823
|
// clear switchery before the form reset so the check status doesn't get changed before the validation
|
|
821
|
-
$(form).find("input[data-switchery=true]").each(function() {
|
|
822
|
-
if($(this).prop("checked")){ // only reset it if it is checked
|
|
824
|
+
$(form).find("input[data-switchery=true]").each(function () {
|
|
825
|
+
if ($(this).prop("checked")) { // only reset it if it is checked
|
|
823
826
|
$(this).trigger("click").prop("checked", false);
|
|
824
827
|
}
|
|
825
828
|
});
|
|
826
|
-
$(form).find('[data-widget="TaggingInput"],[data-widget="EmailTaggingInput"]').each(function(i, e) {
|
|
827
|
-
|
|
828
|
-
|
|
829
|
+
$(form).find('[data-widget="TaggingInput"],[data-widget="EmailTaggingInput"]').each(function (i, e) {
|
|
830
|
+
var tg = $(e).data().tagify;
|
|
831
|
+
tg.removeAllTags();
|
|
829
832
|
});
|
|
830
|
-
$(form).find('[data-widget="FileChunkedUpload"],[data-widget="FileInput"]').each(function(i, e) {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
+
$(form).find('[data-widget="FileChunkedUpload"],[data-widget="FileInput"]').each(function (i, e) {
|
|
834
|
+
var tg = $(e).data().fileUploadWidget;
|
|
835
|
+
tg.resetEmpty();
|
|
833
836
|
});
|
|
834
837
|
$(form).trigger('reset');
|
|
835
838
|
$(form).find("select option:selected").prop("selected", false);
|
|
@@ -842,25 +845,137 @@ var gt_form_modals = {}
|
|
|
842
845
|
var gt_detail_modals = {}
|
|
843
846
|
var gt_crud_objs = {};
|
|
844
847
|
|
|
848
|
+
function updateInstanceValuesForm(form, name, value) {
|
|
849
|
+
var item = form.find(
|
|
850
|
+
'input[name="' + name + '"], ' +
|
|
851
|
+
'textarea[name="' + name + '"], ' +
|
|
852
|
+
'select[name="' + name + '"]'
|
|
853
|
+
);
|
|
854
|
+
item.each(function (i, inputfield) {
|
|
855
|
+
let done = false;
|
|
856
|
+
inputfield = $(inputfield);
|
|
857
|
+
|
|
858
|
+
if (inputfield.attr('class') === "chunkedvalue") {
|
|
859
|
+
if (value) {
|
|
860
|
+
var chunked = form.find('input[name="' + name + '_widget"]').data('fileUploadWidget');
|
|
861
|
+
chunked.addRemote(value);
|
|
862
|
+
}
|
|
863
|
+
done = true;
|
|
864
|
+
} else if (inputfield.attr('type') === 'file') {
|
|
865
|
+
if (value) {
|
|
866
|
+
var newlink = document.createElement('a');
|
|
867
|
+
newlink.href = value.url;
|
|
868
|
+
newlink.textContent = value.name;
|
|
869
|
+
newlink.target = "_blank";
|
|
870
|
+
newlink.classList.add("link-primary");
|
|
871
|
+
newlink.classList.add("file-link");
|
|
872
|
+
newlink.classList.add("d-block");
|
|
873
|
+
inputfield.before(newlink)
|
|
874
|
+
}
|
|
875
|
+
done = true;
|
|
876
|
+
} else if (inputfield.attr('type') === "checkbox") {
|
|
877
|
+
if (inputfield.data().widget === "YesNoInput") {
|
|
878
|
+
inputfield.prop("checked", !value);
|
|
879
|
+
inputfield.trigger("click");
|
|
880
|
+
done = true;
|
|
881
|
+
} else {
|
|
882
|
+
inputfield.prop("checked", value);
|
|
883
|
+
}
|
|
884
|
+
done = true;
|
|
885
|
+
} else if (inputfield.attr('type') === "radio") {
|
|
886
|
+
var is_icheck = inputfield.closest('.gtradio').length > 0;
|
|
887
|
+
var sel = inputfield.filter(function () {
|
|
888
|
+
return this.value === value.toString()
|
|
889
|
+
});
|
|
890
|
+
if (sel.length > 0) {
|
|
891
|
+
sel.prop("checked", true);
|
|
892
|
+
if (is_icheck) {
|
|
893
|
+
sel.iCheck('update');
|
|
894
|
+
sel.iCheck('check');
|
|
895
|
+
}
|
|
845
896
|
|
|
846
|
-
|
|
897
|
+
} else {
|
|
898
|
+
inputfield.prop("checked", false);
|
|
899
|
+
if (is_icheck) {
|
|
900
|
+
inputfield.iCheck('update');
|
|
901
|
+
inputfield.iCheck('uncheck');
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
done = true;
|
|
905
|
+
}
|
|
906
|
+
if (inputfield.data().widget === "EditorTinymce" || inputfield.data().widget === "TextareaWysiwyg") {
|
|
907
|
+
tinymce.get(inputfield.attr('id')).setContent(value);
|
|
908
|
+
done = true;
|
|
909
|
+
}
|
|
910
|
+
if (inputfield.data().widget === "TaggingInput" || inputfield.data().widget === "EmailTaggingInput") {
|
|
911
|
+
var tagifyelement = inputfield.data().tagify;
|
|
912
|
+
tagifyelement.removeAllTags();
|
|
913
|
+
tagifyelement.loadOriginalValues(value);
|
|
914
|
+
done = true;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// New code for testing (*** start ***)
|
|
918
|
+
// data loading in select, autocompleteselect, autocompletemultiselect
|
|
919
|
+
else if (inputfield.is('select') && inputfield.data().widget === "Select") {
|
|
920
|
+
inputfield.val(value).trigger('change');
|
|
921
|
+
done = true;
|
|
922
|
+
} else if (inputfield.is('select') && inputfield.data().widget === "AutocompleteSelect") {
|
|
923
|
+
let data = value;
|
|
924
|
+
let select2Obj = inputfield.data('select2');
|
|
925
|
+
if (select2Obj) {
|
|
926
|
+
inputfield.select2('trigger', 'select', {
|
|
927
|
+
data: data
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
done = true;
|
|
931
|
+
} else if (inputfield.is('select') && inputfield.data().widget === "AutocompleteSelectMultiple") {
|
|
932
|
+
|
|
933
|
+
if (Array.isArray(value)) {
|
|
934
|
+
value.forEach(item => {
|
|
935
|
+
let newOption = new Option(item.text, item.id, true, true);
|
|
936
|
+
inputfield.append(newOption);
|
|
937
|
+
});
|
|
938
|
+
inputfield.trigger('change');
|
|
939
|
+
}
|
|
940
|
+
done = true;
|
|
941
|
+
}
|
|
942
|
+
// New code for testing (*** end ***)
|
|
943
|
+
|
|
944
|
+
if (!done) {
|
|
945
|
+
inputfield.val(value);
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
function updateInstanceForm(form, data) {
|
|
951
|
+
for (let key in data) {
|
|
952
|
+
if (data.hasOwnProperty(key)) {
|
|
953
|
+
updateInstanceValuesForm(form, key, data[key])
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
function gtforms(index, manager, formList, extra = true) {
|
|
847
960
|
return {
|
|
848
961
|
index: index,
|
|
849
962
|
order: index,
|
|
963
|
+
deleted: false,
|
|
850
964
|
manager: manager,
|
|
851
965
|
formList: formList,
|
|
852
966
|
extra: extra,
|
|
853
967
|
instance: null,
|
|
854
|
-
deleteForm: function(){
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
968
|
+
deleteForm: function () {
|
|
969
|
+
if (!this.manager.validateDeleteForm()) {
|
|
970
|
+
this.manager.notify('error', 'You can not delete this form, minimum form validation failed')
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
this.deleted = true;
|
|
859
974
|
this.instance.hide();
|
|
860
|
-
this.instance.find('input[name="'+this.manager.prefix+'-'+this.index+'-DELETE"]').prop(
|
|
975
|
+
this.instance.find('input[name="' + this.manager.prefix + '-' + this.index + '-DELETE"]').prop("checked", true);
|
|
861
976
|
this.manager.deleteForm(this.order);
|
|
862
977
|
},
|
|
863
|
-
render: function(){
|
|
978
|
+
render: function () {
|
|
864
979
|
var html = this.manager.template.replace(/__prefix__/gi, this.index);
|
|
865
980
|
this.instance = $(html);
|
|
866
981
|
formList.append(this.instance);
|
|
@@ -868,37 +983,42 @@ function gtforms(index,manager, formList, extra=true) {
|
|
|
868
983
|
this.registerBtns();
|
|
869
984
|
|
|
870
985
|
},
|
|
871
|
-
reorder: function(oper){
|
|
872
|
-
var brother = this.manager.getForm(this.order+oper);
|
|
873
|
-
this.manager.switchFrom(this.order, this.order+oper);
|
|
874
|
-
if(brother != null){
|
|
875
|
-
if(oper == 1
|
|
986
|
+
reorder: function (oper) {
|
|
987
|
+
var brother = this.manager.getForm(this.order + oper);
|
|
988
|
+
this.manager.switchFrom(this.order, this.order + oper);
|
|
989
|
+
if (brother != null) {
|
|
990
|
+
if (oper == 1) {
|
|
876
991
|
this.instance.before(brother.instance);
|
|
877
|
-
}else{
|
|
992
|
+
} else {
|
|
878
993
|
brother.instance.before(this.instance);
|
|
879
994
|
}
|
|
880
995
|
}
|
|
881
996
|
},
|
|
882
|
-
registerBtns: function(){
|
|
997
|
+
registerBtns: function () {
|
|
883
998
|
this.instance.find('.deletebtn').on('click', this.callDelete(this));
|
|
884
999
|
// down increment order and up decrement order when forms are inserted in bottom
|
|
885
1000
|
this.instance.find('.btndown').on('click', this.callReorder(this, 1));
|
|
886
1001
|
this.instance.find('.btnup').on('click', this.callReorder(this, -1));
|
|
887
1002
|
},
|
|
888
|
-
callDelete: function(instance){
|
|
889
|
-
return () => {
|
|
1003
|
+
callDelete: function (instance) {
|
|
1004
|
+
return () => {
|
|
1005
|
+
instance.deleteForm()
|
|
1006
|
+
};
|
|
890
1007
|
},
|
|
891
|
-
initializeWidgets: function(instance){
|
|
1008
|
+
initializeWidgets: function (instance) {
|
|
892
1009
|
gt_find_initialize(instance);
|
|
893
1010
|
},
|
|
894
|
-
callReorder: function(instance, oper){
|
|
895
|
-
return () => {
|
|
1011
|
+
callReorder: function (instance, oper) {
|
|
1012
|
+
return () => {
|
|
1013
|
+
instance.reorder(oper)
|
|
1014
|
+
}
|
|
896
1015
|
},
|
|
897
|
-
updateOrder: function(){
|
|
898
|
-
this.instance.find('input[name="'+this.manager.prefix+'-'+this.index+'-ORDER"]').val(this.order);
|
|
1016
|
+
updateOrder: function () {
|
|
1017
|
+
this.instance.find('input[name="' + this.manager.prefix + '-' + this.index + '-ORDER"]').val(this.order);
|
|
899
1018
|
}
|
|
900
1019
|
}
|
|
901
1020
|
}
|
|
1021
|
+
|
|
902
1022
|
function gtformSetManager(instance) {
|
|
903
1023
|
var obj = {
|
|
904
1024
|
index: 0,
|
|
@@ -915,49 +1035,61 @@ function gtformSetManager(instance) {
|
|
|
915
1035
|
formList: instance.find('.formlist'),
|
|
916
1036
|
template: '',
|
|
917
1037
|
prefix: 'form-',
|
|
918
|
-
initialize: function(){
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
1038
|
+
initialize: function () {
|
|
1039
|
+
this.template = this.formsetControl.find(".formsettemplate").contents()[0].data;
|
|
1040
|
+
this.prefix = this.formsetControl.data('prefix');
|
|
1041
|
+
this.validateMax = this.formsetControl.data('validate-max') == '1';
|
|
1042
|
+
this.validateMin = this.formsetControl.data('validate-min') == '1';
|
|
1043
|
+
this.loadManagementForm();
|
|
1044
|
+
this.instance.find('.formsetadd').on('click', this.addBtnForm(this));
|
|
1045
|
+
this.addFormDom();
|
|
926
1046
|
},
|
|
927
|
-
addBtnForm: function(instance){
|
|
928
|
-
return () => {
|
|
1047
|
+
addBtnForm: function (instance) {
|
|
1048
|
+
return (e) => {
|
|
1049
|
+
instance.addEmtpyForm(e)
|
|
1050
|
+
};
|
|
929
1051
|
},
|
|
930
|
-
addEmtpyForm: function(){
|
|
931
|
-
if(this.validateAddForm()){
|
|
1052
|
+
addEmtpyForm: function (e) {
|
|
1053
|
+
if (this.validateAddForm()) {
|
|
1054
|
+
this.activeForms += 1;
|
|
932
1055
|
var form = gtforms(this.index, this, this.formList);
|
|
933
1056
|
form.render();
|
|
934
1057
|
this.forms.push(form);
|
|
1058
|
+
this.addForm(this, form, true, e);
|
|
935
1059
|
this.index += 1;
|
|
936
1060
|
this.updateTotalForms(+1);
|
|
937
|
-
}else{
|
|
1061
|
+
} else {
|
|
938
1062
|
this.notify('error', 'You cannot add new form, limit is exceded')
|
|
939
1063
|
}
|
|
940
1064
|
},
|
|
941
|
-
addForm: function(object){
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1065
|
+
addForm: function (parent, object, isempty, event) {
|
|
1066
|
+
},
|
|
1067
|
+
addFormDom: function () {
|
|
1068
|
+
this.formList.children().each((i, element) => {
|
|
1069
|
+
this.activeForms += 1;
|
|
1070
|
+
var form = gtforms(this.index, this, this.formList, extra = false);
|
|
1071
|
+
form.instance = $(element);
|
|
1072
|
+
form.registerBtns();
|
|
1073
|
+
this.forms.push(form);
|
|
1074
|
+
this.addForm(this, form, false, null);
|
|
1075
|
+
this.index += 1;
|
|
949
1076
|
});
|
|
950
1077
|
},
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1078
|
+
delForm: function (parent, index, form) {
|
|
1079
|
+
},
|
|
1080
|
+
deleteForm: function (index) {
|
|
1081
|
+
if (!this.validateDeleteForm()) return;
|
|
1082
|
+
this.activeForms = Math.max(0, this.activeForms - 1);
|
|
1083
|
+
|
|
1084
|
+
if (index >= 0 && index < this.forms.length) {
|
|
1085
|
+
this.delForm(this, index, this.forms[index]);
|
|
1086
|
+
if (this.forms[index].extra) {
|
|
955
1087
|
this.forms.splice(index, 1);
|
|
956
1088
|
this.updateTotalForms(-1);
|
|
957
|
-
if(index == this.forms.length){
|
|
1089
|
+
if (index == this.forms.length) {
|
|
958
1090
|
this.index -= 1;
|
|
959
|
-
}else{
|
|
960
|
-
for(var x=0; x<this.forms.length; x++){
|
|
1091
|
+
} else {
|
|
1092
|
+
for (var x = 0; x < this.forms.length; x++) {
|
|
961
1093
|
this.forms[x].order = x;
|
|
962
1094
|
this.forms[x].updateOrder();
|
|
963
1095
|
}
|
|
@@ -966,40 +1098,40 @@ function gtformSetManager(instance) {
|
|
|
966
1098
|
|
|
967
1099
|
}
|
|
968
1100
|
},
|
|
969
|
-
validateAddForm: function(){
|
|
970
|
-
if(!this.validateMax) return true;
|
|
1101
|
+
validateAddForm: function () {
|
|
1102
|
+
if (!this.validateMax) return true;
|
|
971
1103
|
return this.MAX_NUM_FORMS == -1 || this.TOTAL_FORMS < this.MAX_NUM_FORMS;
|
|
972
1104
|
},
|
|
973
|
-
validateDeleteForm: function(){
|
|
974
|
-
if(!this.validateMin) return true;
|
|
1105
|
+
validateDeleteForm: function () {
|
|
1106
|
+
if (!this.validateMin) return true;
|
|
975
1107
|
return this.MIN_NUM_FORMS == -1 || this.TOTAL_FORMS > this.MIN_NUM_FORMS;
|
|
976
1108
|
},
|
|
977
|
-
loadManagementForm: function(){
|
|
978
|
-
this.TOTAL_FORMS = parseInt(this.formsetControl.find('input[name="'+this.prefix+'-TOTAL_FORMS"]').val());
|
|
979
|
-
this.INITIAL_FORMS = parseInt(this.formsetControl.find('input[name="'+this.prefix+'-INITIAL_FORMS"]').val());
|
|
980
|
-
this.MIN_NUM_FORMS = parseInt(this.formsetControl.find('input[name="'+this.prefix+'-MIN_NUM_FORMS"]').val());
|
|
981
|
-
this.MAX_NUM_FORMS = parseInt(this.formsetControl.find('input[name="'+this.prefix+'-MAX_NUM_FORMS"]').val());
|
|
1109
|
+
loadManagementForm: function () {
|
|
1110
|
+
this.TOTAL_FORMS = parseInt(this.formsetControl.find('input[name="' + this.prefix + '-TOTAL_FORMS"]').val());
|
|
1111
|
+
this.INITIAL_FORMS = parseInt(this.formsetControl.find('input[name="' + this.prefix + '-INITIAL_FORMS"]').val());
|
|
1112
|
+
this.MIN_NUM_FORMS = parseInt(this.formsetControl.find('input[name="' + this.prefix + '-MIN_NUM_FORMS"]').val());
|
|
1113
|
+
this.MAX_NUM_FORMS = parseInt(this.formsetControl.find('input[name="' + this.prefix + '-MAX_NUM_FORMS"]').val());
|
|
982
1114
|
},
|
|
983
|
-
updateManagementForm: function(){
|
|
984
|
-
this.formsetControl.find('input[name="'+this.prefix+'-TOTAL_FORMS"]').val(this.TOTAL_FORMS);
|
|
985
|
-
this.formsetControl.find('input[name="'+this.prefix+'-INITIAL_FORMS"]').val(this.INITIAL_FORMS);
|
|
986
|
-
this.formsetControl.find('input[name="'+this.prefix+'-MIN_NUM_FORMS"]').val(this.MIN_NUM_FORMS);
|
|
987
|
-
this.formsetControl.find('input[name="'+this.prefix+'-MAX_NUM_FORMS"]').val(this.MAX_NUM_FORMS);
|
|
1115
|
+
updateManagementForm: function () {
|
|
1116
|
+
this.formsetControl.find('input[name="' + this.prefix + '-TOTAL_FORMS"]').val(this.TOTAL_FORMS);
|
|
1117
|
+
this.formsetControl.find('input[name="' + this.prefix + '-INITIAL_FORMS"]').val(this.INITIAL_FORMS);
|
|
1118
|
+
this.formsetControl.find('input[name="' + this.prefix + '-MIN_NUM_FORMS"]').val(this.MIN_NUM_FORMS);
|
|
1119
|
+
this.formsetControl.find('input[name="' + this.prefix + '-MAX_NUM_FORMS"]').val(this.MAX_NUM_FORMS);
|
|
988
1120
|
},
|
|
989
|
-
updateTotalForms: function(oper){
|
|
990
|
-
this.TOTAL_FORMS = this.TOTAL_FORMS+oper;
|
|
991
|
-
this.formsetControl.find('input[name="'+this.prefix+'-TOTAL_FORMS"]').val(this.TOTAL_FORMS);
|
|
1121
|
+
updateTotalForms: function (oper) {
|
|
1122
|
+
this.TOTAL_FORMS = this.TOTAL_FORMS + oper;
|
|
1123
|
+
this.formsetControl.find('input[name="' + this.prefix + '-TOTAL_FORMS"]').val(this.TOTAL_FORMS);
|
|
992
1124
|
},
|
|
993
|
-
getForm: function(index){
|
|
994
|
-
if(index>=0 && index < this.forms.length){
|
|
1125
|
+
getForm: function (index) {
|
|
1126
|
+
if (index >= 0 && index < this.forms.length) {
|
|
995
1127
|
return this.forms[index];
|
|
996
1128
|
}
|
|
997
1129
|
return null;
|
|
998
1130
|
},
|
|
999
|
-
switchFrom: function(fref, fswap){
|
|
1131
|
+
switchFrom: function (fref, fswap) {
|
|
1000
1132
|
var freform = this.getForm(fref);
|
|
1001
1133
|
var fswapform = this.getForm(fswap);
|
|
1002
|
-
if(freform != null && fswapform != null){
|
|
1134
|
+
if (freform != null && fswapform != null) {
|
|
1003
1135
|
var tmporder = freform.order;
|
|
1004
1136
|
freform.order = fswapform.order;
|
|
1005
1137
|
fswapform.order = tmporder;
|
|
@@ -1011,23 +1143,23 @@ function gtformSetManager(instance) {
|
|
|
1011
1143
|
}
|
|
1012
1144
|
|
|
1013
1145
|
},
|
|
1014
|
-
redrawOrdering: function(){
|
|
1015
|
-
for(var x=0; x<this.forms.length; x++){
|
|
1016
|
-
|
|
1146
|
+
redrawOrdering: function () {
|
|
1147
|
+
for (var x = 0; x < this.forms.length; x++) {
|
|
1148
|
+
this.formList.append(this.forms[x].instance);
|
|
1017
1149
|
}
|
|
1018
1150
|
},
|
|
1019
|
-
notify: function(type, text){
|
|
1151
|
+
notify: function (type, text) {
|
|
1020
1152
|
console.log(text);
|
|
1021
1153
|
},
|
|
1022
|
-
clean: function(){
|
|
1023
|
-
while(this.forms.length>0){
|
|
1154
|
+
clean: function () {
|
|
1155
|
+
while (this.forms.length > 0) {
|
|
1024
1156
|
var f = this.forms.pop();
|
|
1025
1157
|
f.instance.remove();
|
|
1026
1158
|
}
|
|
1027
|
-
this.TOTAL_FORMS=0;
|
|
1028
|
-
this.INITIAL_FORMS=0;
|
|
1029
|
-
this.TOTAL_FORMS=0;
|
|
1030
|
-
this.index=0;
|
|
1159
|
+
this.TOTAL_FORMS = 0;
|
|
1160
|
+
this.INITIAL_FORMS = 0;
|
|
1161
|
+
this.TOTAL_FORMS = 0;
|
|
1162
|
+
this.index = 0;
|
|
1031
1163
|
this.updateManagementForm();
|
|
1032
1164
|
}
|
|
1033
1165
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
djgentelella/__init__.py,sha256=
|
|
1
|
+
djgentelella/__init__.py,sha256=XivbflQHecymlyv-LOrn_VB6ZE5nGPpK5x8qk-cm_2s,23
|
|
2
2
|
djgentelella/admin.py,sha256=Wk-InJLUomexhr7Srw4dh3ZODB5i5RVyq1ukvoRvx-0,1304
|
|
3
3
|
djgentelella/apps.py,sha256=5VEbpUv4b1Jh7gCRAQCe5TvpakRyndKwafjVj0z-Xfo,153
|
|
4
4
|
djgentelella/chartjs.py,sha256=iNYoFnaIQoXsYInJFbSE2quWpjmDz5CuMKpVsvt4pRM,8572
|
|
@@ -121,7 +121,7 @@ djgentelella/static/gentelella/images/forward_disabled.png,sha256=7enxADzvJa3VzC
|
|
|
121
121
|
djgentelella/static/gentelella/images/forward_enabled.png,sha256=vLOxO1qvkBV2ev931iHx-VV63NjrgoTQbwtR4kdVVrA,1380
|
|
122
122
|
djgentelella/static/gentelella/images/forward_enabled_hover.png,sha256=T6LWiaYzcT2fuJAGEaZGxd8Lok3rlZerlVxiy6d647Q,1379
|
|
123
123
|
djgentelella/static/gentelella/images/loading.gif,sha256=dyCz9kckQBZKy7DpKpR3hL4xgQgnShbMue3Ao9h_lK0,30269
|
|
124
|
-
djgentelella/static/gentelella/js/base.js,sha256=
|
|
124
|
+
djgentelella/static/gentelella/js/base.js,sha256=g4B7NZdniNJmAb4rszA80WK4paP-ppIf20zRl3mcIoc,87448
|
|
125
125
|
djgentelella/static/gentelella/js/custom.js,sha256=O9GWx1FbkMYzbUSzlYw3SrfZrf9xPdMokPh91xMtdUY,14922
|
|
126
126
|
djgentelella/static/gentelella/js/datatables.js,sha256=cAp5D5OuN2oT-XW048XqkOZDJtPJefl2e36NNkrSN1M,12215
|
|
127
127
|
djgentelella/static/gentelella/js/obj_api_management.js,sha256=_RYQwzuB7QsNMCOQX4jKv9wGfTXIW0yFaaeTls4QqEo,29534
|
|
@@ -136,8 +136,8 @@ djgentelella/static/gentelella/js/base/custom.widgets.js,sha256=bMcE6gNNn9AABlZN
|
|
|
136
136
|
djgentelella/static/gentelella/js/base/dateranges_gridslider.js,sha256=TGR9Ko9MZVZGhPhe3ubvzMZcEWrlBLH2SA3E239LRyI,5571
|
|
137
137
|
djgentelella/static/gentelella/js/base/editorTinymce.js,sha256=2fT36ECHyQKLP0X74zYsSHZZ0Rqg-UywDMbG5LjJVac,1118
|
|
138
138
|
djgentelella/static/gentelella/js/base/fileupload.widget.js,sha256=MIniB9KLE8ozKuDqy5EovrZBbscqEYPMsS70ecgNB1w,10653
|
|
139
|
-
djgentelella/static/gentelella/js/base/form.common.js,sha256=
|
|
140
|
-
djgentelella/static/gentelella/js/base/formset.js,sha256=
|
|
139
|
+
djgentelella/static/gentelella/js/base/form.common.js,sha256=obPt6TS2Q-IgmnNUJeq6_FnDfLnv1ge5DprAj7_KS7Q,9199
|
|
140
|
+
djgentelella/static/gentelella/js/base/formset.js,sha256=FLgkWI3nhyIuSc22tiwyIDfwCkoILlU2zU34_-ohMmo,8430
|
|
141
141
|
djgentelella/static/gentelella/js/base/gigapixel_storymap.js,sha256=UaBtuOzHMaYeR-BabvrYiGyvvO2P1Yxykaa0vVYWKIg,627
|
|
142
142
|
djgentelella/static/gentelella/js/base/helper_widget.js,sha256=llwsuolL8zyr9GES0cpz3RHX--WXacmRNwS2Ccb3PO8,10836
|
|
143
143
|
djgentelella/static/gentelella/js/base/mapbased_storymap.js,sha256=i4Ef8ATjzpyNPSO5wSdDA0FHwc5qXqa2kZzTBWH9mY0,542
|
|
@@ -990,9 +990,9 @@ djgentelella/widgets/trees.py,sha256=bV6s-w1cgYahS0aNU6xBrx-aISdlzDZ23BFt3_3hAu4
|
|
|
990
990
|
djgentelella/widgets/wysiwyg.py,sha256=wHeMyYNVE8-lKJ06A-0DLDAcRNv3TOAOG_Wl9DYZqS0,609
|
|
991
991
|
djgentelella/wysiwyg/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
992
992
|
djgentelella/wysiwyg/views.py,sha256=tI7LjLhCnohdvIEOEEhB2Cu1zxRmdcOhYJJX4LBIZaA,1159
|
|
993
|
-
djgentelella-0.3.
|
|
994
|
-
djgentelella-0.3.
|
|
995
|
-
djgentelella-0.3.
|
|
996
|
-
djgentelella-0.3.
|
|
997
|
-
djgentelella-0.3.
|
|
998
|
-
djgentelella-0.3.
|
|
993
|
+
djgentelella-0.3.26.dist-info/AUTHORS,sha256=HyQoO-q7oXtavpNm7jaBVv8Vxx3c7yo33xkFkt4blkY,118
|
|
994
|
+
djgentelella-0.3.26.dist-info/LICENSE.txt,sha256=wDzqAntLQORAL6vQhVdzZyfsPVvFStZKtkct5DIZjK0,18047
|
|
995
|
+
djgentelella-0.3.26.dist-info/METADATA,sha256=hoOHND-Ojrdd1IocBTRgL1zu2tg84aaTkFU7_ivqzAo,27682
|
|
996
|
+
djgentelella-0.3.26.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
997
|
+
djgentelella-0.3.26.dist-info/top_level.txt,sha256=88JbODVPV-P5q7ic25yMHt_FuuizaLzMyIaegpFa7Qk,13
|
|
998
|
+
djgentelella-0.3.26.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|