djgentelella 0.3.25__py3-none-any.whl → 0.3.27__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/blog/tests/test_entry_forms.py +4 -4
- 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/templates/gentelella/blocks/listcard_template.html +2 -2
- djgentelella/tests/Calendar_Test.py +3 -3
- djgentelella/tests/Notification_Test.py +13 -18
- djgentelella/tests/fields/files.py +3 -5
- djgentelella/views/listAreaViewset.py +17 -1
- {djgentelella-0.3.25.dist-info → djgentelella-0.3.27.dist-info}/METADATA +1 -3
- {djgentelella-0.3.25.dist-info → djgentelella-0.3.27.dist-info}/RECORD +16 -16
- {djgentelella-0.3.25.dist-info → djgentelella-0.3.27.dist-info}/WHEEL +1 -1
- {djgentelella-0.3.25.dist-info → djgentelella-0.3.27.dist-info}/AUTHORS +0 -0
- {djgentelella-0.3.25.dist-info → djgentelella-0.3.27.dist-info}/LICENSE.txt +0 -0
- {djgentelella-0.3.25.dist-info → djgentelella-0.3.27.dist-info}/top_level.txt +0 -0
djgentelella/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = '0.3.
|
|
1
|
+
__version__ = '0.3.27'
|
|
@@ -31,8 +31,8 @@ class TestEntryEditing(TestCase):
|
|
|
31
31
|
form.save()
|
|
32
32
|
|
|
33
33
|
actual = models.Entry.objects.get(pk=self.entry.pk)
|
|
34
|
-
self.
|
|
35
|
-
self.
|
|
34
|
+
self.assertEqual(actual.title, update['title'])
|
|
35
|
+
self.assertEqual(actual.content.raw, update['content'])
|
|
36
36
|
self.assertIsNotNone(actual.published_timestamp)
|
|
37
37
|
|
|
38
38
|
|
|
@@ -60,6 +60,6 @@ class TestEntryCreation(TestCase):
|
|
|
60
60
|
form.save()
|
|
61
61
|
|
|
62
62
|
actual = models.Entry.objects.get(slug='last-post-final')
|
|
63
|
-
self.
|
|
64
|
-
self.
|
|
63
|
+
self.assertEqual(actual.title, create['title'])
|
|
64
|
+
self.assertEqual(actual.content.raw, create['content'])
|
|
65
65
|
self.assertIsNone(actual.published_timestamp)
|
|
@@ -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
|
}
|