djgentelella 0.4.3__py3-none-any.whl → 0.4.4__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/datatables.js +15 -0
- djgentelella/static/gentelella/js/obj_api_management.js +396 -343
- {djgentelella-0.4.3.dist-info → djgentelella-0.4.4.dist-info}/METADATA +1 -1
- {djgentelella-0.4.3.dist-info → djgentelella-0.4.4.dist-info}/RECORD +9 -9
- {djgentelella-0.4.3.dist-info → djgentelella-0.4.4.dist-info}/AUTHORS +0 -0
- {djgentelella-0.4.3.dist-info → djgentelella-0.4.4.dist-info}/LICENSE.txt +0 -0
- {djgentelella-0.4.3.dist-info → djgentelella-0.4.4.dist-info}/WHEEL +0 -0
- {djgentelella-0.4.3.dist-info → djgentelella-0.4.4.dist-info}/top_level.txt +0 -0
djgentelella/__init__.py
CHANGED
|
@@ -274,3 +274,18 @@ function createDataTable(id, url, extraoptions={}, addfilter=false, formatDataTa
|
|
|
274
274
|
}, extraoptions);
|
|
275
275
|
return gtCreateDataTable(id, url, options);
|
|
276
276
|
}
|
|
277
|
+
|
|
278
|
+
function truncateTextRenderer(maxChars = 100) {
|
|
279
|
+
return (data, type, row, meta)=> {
|
|
280
|
+
if (type === 'display' && typeof data === 'string') {
|
|
281
|
+
const text = data.trim();
|
|
282
|
+
if (text.length > maxChars) {
|
|
283
|
+
return `<span title="${text.replace(/"/g, '"')}" style="display:inline; line-height:1; margin:0; padding:0;">${text.substring(0, maxChars)}...</span>`;
|
|
284
|
+
}
|
|
285
|
+
return text
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return data;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
@@ -1,48 +1,54 @@
|
|
|
1
|
-
function get_selected_items(dt, table){
|
|
1
|
+
function get_selected_items(dt, table) {
|
|
2
2
|
let values = [];
|
|
3
|
-
$(table).find(".gtcheckable:checked").each(function() {
|
|
3
|
+
$(table).find(".gtcheckable:checked").each(function () {
|
|
4
4
|
values.push(this.value);
|
|
5
5
|
});
|
|
6
6
|
return values;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
|
|
9
|
+
function gt_show_actions(crud_name) {
|
|
10
|
+
return function (data, type, row, meta) {
|
|
11
|
+
var html = "";
|
|
12
|
+
if (data != null) {
|
|
13
|
+
if (data.title != undefined) {
|
|
14
|
+
html += data.title + " ";
|
|
15
|
+
}
|
|
16
|
+
for (var x = 0; x < data.actions.length; x++) {
|
|
16
17
|
let action = data.actions[x];
|
|
17
|
-
html += '<i onclick="javascript:call_obj_crud_event(\''+crud_name+'\', \''+action.name+'\', '+meta.row+');" class="'+action.i_class+'"></i>';
|
|
18
|
+
html += '<i onclick="javascript:call_obj_crud_event(\'' + crud_name + '\', \'' + action.name + '\', ' + meta.row + ');" class="' + action.i_class + '"></i>';
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
return html;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
function GTBaseFormModal(modal_id, datatable_element,
|
|
25
|
+
function GTBaseFormModal(modal_id, datatable_element, form_config) {
|
|
25
26
|
var modal = $(modal_id);
|
|
26
27
|
var form = modal.find('form');
|
|
27
28
|
var prefix = form.find(".form_prefix").val();
|
|
28
|
-
if(prefix.length != 0){
|
|
29
|
-
prefix = prefix+"-"
|
|
29
|
+
if (prefix.length != 0) {
|
|
30
|
+
prefix = prefix + "-"
|
|
30
31
|
}
|
|
31
32
|
const default_config = {
|
|
32
33
|
"btn_class": ".formadd",
|
|
33
34
|
"type": "POST",
|
|
34
35
|
"reload_table": true,
|
|
35
|
-
"events": {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
"events": {
|
|
37
|
+
'form_submit': function (instance) {
|
|
38
|
+
return {}
|
|
39
|
+
},
|
|
40
|
+
'success_form': function (data) {
|
|
41
|
+
},
|
|
42
|
+
'error_form': function (errors) {
|
|
43
|
+
}
|
|
38
44
|
|
|
39
|
-
|
|
45
|
+
},
|
|
40
46
|
"relation_render": {},
|
|
41
47
|
"parentdiv": ".gtformfield"
|
|
42
|
-
|
|
48
|
+
}
|
|
43
49
|
|
|
44
50
|
|
|
45
|
-
const config =
|
|
51
|
+
const config = Object.assign({}, default_config, form_config);
|
|
46
52
|
|
|
47
53
|
return {
|
|
48
54
|
"instance": modal,
|
|
@@ -55,34 +61,36 @@ function GTBaseFormModal(modal_id, datatable_element, form_config) {
|
|
|
55
61
|
"type": config.type,
|
|
56
62
|
"btn_class": config.btn_class,
|
|
57
63
|
"parentdiv": config.parentdiv,
|
|
58
|
-
"init": function(){
|
|
64
|
+
"init": function () {
|
|
59
65
|
var myModalEl = this.instance[0];
|
|
60
66
|
myModalEl.addEventListener('hidden.bs.modal', this.hide_modalevent(this))
|
|
61
67
|
this.instance.find(this.btn_class).on('click', this.add_btn_form(this));
|
|
62
|
-
$(this.form).on('submit', (e)=>{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
$(this.form).on('submit', (e) => {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
})
|
|
71
|
+
},
|
|
72
|
+
"add_btn_form": function (instance) {
|
|
73
|
+
return function (event) {
|
|
74
|
+
convertToStringJson(instance.form, prefix = instance.prefix,
|
|
75
|
+
extras = instance.config.events.form_submit(instance)).then((result) => {
|
|
76
|
+
fetch(instance.url, {
|
|
77
|
+
method: instance.type,
|
|
78
|
+
body: result,
|
|
79
|
+
headers: {'X-CSRFToken': getCookie('csrftoken'), 'Content-Type': 'application/json'}
|
|
80
|
+
}
|
|
73
81
|
).then(response_manage_type_data(instance, instance.error, instance.error_text))
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
.then(instance.fn_success(instance))
|
|
83
|
+
.catch(error => instance.handle_error(instance, error));
|
|
84
|
+
});
|
|
77
85
|
}
|
|
78
86
|
},
|
|
79
|
-
"success": function(instance, data){
|
|
87
|
+
"success": function (instance, data) {
|
|
80
88
|
},
|
|
81
|
-
"fn_success": function(instance){
|
|
82
|
-
|
|
83
|
-
if(data !== false){
|
|
89
|
+
"fn_success": function (instance) {
|
|
90
|
+
return function (data) {
|
|
91
|
+
if (data !== false) {
|
|
84
92
|
instance.config.events.success_form(data)
|
|
85
|
-
if (instance.reload_table){
|
|
93
|
+
if (instance.reload_table) {
|
|
86
94
|
datatable_element.ajax.reload();
|
|
87
95
|
}
|
|
88
96
|
instance.hide_modal();
|
|
@@ -94,87 +102,87 @@ function GTBaseFormModal(modal_id, datatable_element, form_config) {
|
|
|
94
102
|
});
|
|
95
103
|
instance.success(instance, data);
|
|
96
104
|
}
|
|
97
|
-
|
|
105
|
+
}
|
|
98
106
|
},
|
|
99
|
-
"error_text": function(instance, message){
|
|
100
|
-
Swal.fire({icon: 'error',
|
|
107
|
+
"error_text": function (instance, message) {
|
|
108
|
+
Swal.fire({icon: 'error', title: gettext('Error'), text: message});
|
|
101
109
|
},
|
|
102
|
-
"error": function(instance, errors){
|
|
110
|
+
"error": function (instance, errors) {
|
|
103
111
|
instance.config.events.error_form(errors)
|
|
104
|
-
if(errors.hasOwnProperty('detail') && Object.keys(errors).length == 1){
|
|
105
|
-
Swal.fire({
|
|
112
|
+
if (errors.hasOwnProperty('detail') && Object.keys(errors).length == 1) {
|
|
113
|
+
Swal.fire({icon: 'error', title: gettext('Error'), text: errors.detail});
|
|
106
114
|
}
|
|
107
115
|
instance.form.find('ul.form_errors').remove();
|
|
108
116
|
form_field_errors(instance.form, errors, instance.prefix, instance.parentdiv);
|
|
109
117
|
},
|
|
110
|
-
"handle_error": function(instance, error){
|
|
111
|
-
Swal.fire({
|
|
118
|
+
"handle_error": function (instance, error) {
|
|
119
|
+
Swal.fire({icon: 'error', title: gettext('Error'), text: error.message});
|
|
112
120
|
},
|
|
113
|
-
"hide_modal": function(){
|
|
121
|
+
"hide_modal": function () {
|
|
114
122
|
this.instance.modal('hide');
|
|
115
123
|
},
|
|
116
|
-
"hide_modalevent": function(instance){
|
|
117
|
-
return function(event){
|
|
124
|
+
"hide_modalevent": function (instance) {
|
|
125
|
+
return function (event) {
|
|
118
126
|
clear_action_form(instance.form);
|
|
119
127
|
instance.hide_modal();
|
|
120
128
|
}
|
|
121
129
|
},
|
|
122
|
-
"show_modal": function(btninstance){
|
|
130
|
+
"show_modal": function (btninstance) {
|
|
123
131
|
this.instance.modal('show');
|
|
124
132
|
},
|
|
125
|
-
"fill_form": function(datainstance){
|
|
126
|
-
var keys
|
|
133
|
+
"fill_form": function (datainstance) {
|
|
134
|
+
var keys = Object.keys(datainstance);
|
|
127
135
|
var select2Items = [];
|
|
128
136
|
var instance = this;
|
|
129
|
-
$.each(keys, function(i, e){
|
|
130
|
-
if($("#id_"+instance.prefix+e).data('select2-id') != undefined
|
|
131
|
-
|
|
132
|
-
}else{
|
|
133
|
-
|
|
137
|
+
$.each(keys, function (i, e) {
|
|
138
|
+
if ($("#id_" + instance.prefix + e).data('select2-id') != undefined) {
|
|
139
|
+
select2Items.push(e);
|
|
140
|
+
} else {
|
|
141
|
+
instance.updateInstanceForm(instance.prefix + e, datainstance[e]);
|
|
134
142
|
}
|
|
135
143
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
}else{
|
|
152
|
-
if($('#id_'+instance.prefix+e+' option[value="'+datainstance[e]['id']+'"]').length>0){
|
|
153
|
-
$('#id_'+instance.prefix+e).val(datainstance[e]['id']);
|
|
154
|
-
}else{
|
|
155
|
-
var newOption = new Option(datainstance[e][display_name_key], datainstance[e]['id'], true, true);
|
|
156
|
-
$('#id_'+instance.prefix+e).append(newOption);
|
|
157
|
-
}
|
|
144
|
+
});
|
|
145
|
+
// do select 2 items
|
|
146
|
+
$.each(select2Items, function (i, e) {
|
|
147
|
+
var display_name_key = 'text';
|
|
148
|
+
if (instance.relation_render.hasOwnProperty(e)) {
|
|
149
|
+
display_name_key = instance.relation_render[e];
|
|
150
|
+
}
|
|
151
|
+
$('#id_' + instance.prefix + e).val(null).trigger('change');
|
|
152
|
+
if (datainstance[e]) {
|
|
153
|
+
if (Array.isArray(datainstance[e])) {
|
|
154
|
+
for (var x = 0; x < datainstance[e].length; x++) {
|
|
155
|
+
$('#id_' + instance.prefix + e + ' option[value="' + datainstance[e][x]['id'] + '"]').remove();
|
|
156
|
+
var newOption = new Option(datainstance[e][x][display_name_key], datainstance[e][x]['id'], true, true);
|
|
157
|
+
$('#id_' + instance.prefix + e).append(newOption);
|
|
158
158
|
}
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
} else {
|
|
160
|
+
if ($('#id_' + instance.prefix + e + ' option[value="' + datainstance[e]['id'] + '"]').length > 0) {
|
|
161
|
+
$('#id_' + instance.prefix + e).val(datainstance[e]['id']);
|
|
162
|
+
} else {
|
|
163
|
+
var newOption = new Option(datainstance[e][display_name_key], datainstance[e]['id'], true, true);
|
|
164
|
+
$('#id_' + instance.prefix + e).append(newOption);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
$('#id_' + instance.prefix + e).trigger('change')
|
|
168
|
+
}
|
|
161
169
|
});
|
|
162
170
|
},
|
|
163
|
-
"updateInstanceForm": function (name, value){
|
|
164
|
-
var item = this.form.find('input[name="'+name+'"], textarea[name="'+name+'"]');
|
|
165
|
-
var parent=this;
|
|
166
|
-
item.each(function(i, inputfield){
|
|
167
|
-
let done=false;
|
|
168
|
-
inputfield
|
|
169
|
-
|
|
170
|
-
if(inputfield.attr('class') === "chunkedvalue"){
|
|
171
|
-
if(value){
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
"updateInstanceForm": function (name, value) {
|
|
172
|
+
var item = this.form.find('input[name="' + name + '"], textarea[name="' + name + '"]');
|
|
173
|
+
var parent = this;
|
|
174
|
+
item.each(function (i, inputfield) {
|
|
175
|
+
let done = false;
|
|
176
|
+
inputfield = $(inputfield);
|
|
177
|
+
|
|
178
|
+
if (inputfield.attr('class') === "chunkedvalue") {
|
|
179
|
+
if (value) {
|
|
180
|
+
var chunked = parent.form.find('input[name="' + name + '_widget"]').data('fileUploadWidget');
|
|
181
|
+
chunked.addRemote(value);
|
|
174
182
|
}
|
|
175
|
-
done=true;
|
|
176
|
-
} else if(inputfield.attr('type') === 'file'){
|
|
177
|
-
if(value){
|
|
183
|
+
done = true;
|
|
184
|
+
} else if (inputfield.attr('type') === 'file') {
|
|
185
|
+
if (value) {
|
|
178
186
|
var newlink = document.createElement('a');
|
|
179
187
|
newlink.href = value.url;
|
|
180
188
|
newlink.textContent = value.name;
|
|
@@ -184,54 +192,59 @@ function GTBaseFormModal(modal_id, datatable_element, form_config) {
|
|
|
184
192
|
newlink.classList.add("d-block");
|
|
185
193
|
inputfield.before(newlink)
|
|
186
194
|
}
|
|
187
|
-
done=true;
|
|
188
|
-
} else if(inputfield.attr('type') === "checkbox"
|
|
189
|
-
if (inputfield.data().widget === "YesNoInput"){
|
|
190
|
-
inputfield.prop(
|
|
195
|
+
done = true;
|
|
196
|
+
} else if (inputfield.attr('type') === "checkbox") {
|
|
197
|
+
if (inputfield.data().widget === "YesNoInput") {
|
|
198
|
+
inputfield.prop("checked", !value);
|
|
191
199
|
inputfield.trigger("click");
|
|
192
|
-
done=true;
|
|
193
|
-
}else{
|
|
194
|
-
inputfield.prop(
|
|
200
|
+
done = true;
|
|
201
|
+
} else {
|
|
202
|
+
inputfield.prop("checked", value);
|
|
195
203
|
}
|
|
196
|
-
done=true;
|
|
197
|
-
} else if(inputfield.attr('type') === "radio"){
|
|
204
|
+
done = true;
|
|
205
|
+
} else if (inputfield.attr('type') === "radio") {
|
|
198
206
|
var is_icheck = inputfield.closest('.gtradio').length > 0;
|
|
199
|
-
var sel = inputfield.filter(function() {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
207
|
+
var sel = inputfield.filter(function () {
|
|
208
|
+
return this.value === value.toString()
|
|
209
|
+
});
|
|
210
|
+
if (sel.length > 0) {
|
|
211
|
+
sel.prop("checked", true);
|
|
212
|
+
if (is_icheck) {
|
|
203
213
|
sel.iCheck('update');
|
|
204
214
|
sel.iCheck('check');
|
|
205
215
|
}
|
|
206
216
|
|
|
207
|
-
}else{
|
|
208
|
-
inputfield.prop(
|
|
209
|
-
if(is_icheck){
|
|
217
|
+
} else {
|
|
218
|
+
inputfield.prop("checked", false);
|
|
219
|
+
if (is_icheck) {
|
|
210
220
|
inputfield.iCheck('update');
|
|
211
221
|
inputfield.iCheck('uncheck');
|
|
212
222
|
}
|
|
213
223
|
}
|
|
214
|
-
done=true;
|
|
224
|
+
done = true;
|
|
215
225
|
}
|
|
216
|
-
if (inputfield.data().widget === "EditorTinymce" || inputfield.data().widget === "TextareaWysiwyg"){
|
|
217
|
-
|
|
218
|
-
|
|
226
|
+
if (inputfield.data().widget === "EditorTinymce" || inputfield.data().widget === "TextareaWysiwyg") {
|
|
227
|
+
tinymce.get(inputfield.attr('id')).setContent(value);
|
|
228
|
+
done = true;
|
|
219
229
|
}
|
|
220
|
-
if (inputfield.data().widget === "TaggingInput" || inputfield.data().widget === "EmailTaggingInput"){
|
|
221
|
-
var tagifyelement=inputfield.data().tagify;
|
|
230
|
+
if (inputfield.data().widget === "TaggingInput" || inputfield.data().widget === "EmailTaggingInput") {
|
|
231
|
+
var tagifyelement = inputfield.data().tagify;
|
|
222
232
|
tagifyelement.removeAllTags();
|
|
223
233
|
tagifyelement.loadOriginalValues(value);
|
|
224
|
-
done=true;
|
|
234
|
+
done = true;
|
|
235
|
+
}
|
|
236
|
+
if (!done) {
|
|
237
|
+
inputfield.val(value);
|
|
225
238
|
}
|
|
226
|
-
if(!done) { inputfield.val(value); }
|
|
227
239
|
});
|
|
228
|
-
|
|
240
|
+
}
|
|
229
241
|
}
|
|
230
242
|
}
|
|
243
|
+
|
|
231
244
|
/**
|
|
232
|
-
**/
|
|
245
|
+
**/
|
|
233
246
|
|
|
234
|
-
function BaseDetailModal(modalid, base_detail_url, template_url, form_config={}){
|
|
247
|
+
function BaseDetailModal(modalid, base_detail_url, template_url, form_config = {}) {
|
|
235
248
|
const default_config = {
|
|
236
249
|
"base_template": "<% it.display_text %>",
|
|
237
250
|
"title": "<% it.title %>",
|
|
@@ -240,20 +253,28 @@ function BaseDetailModal(modalid, base_detail_url, template_url, form_config={})
|
|
|
240
253
|
"headers": {'X-CSRFToken': getCookie('csrftoken'), 'Content-Type': 'application/json'},
|
|
241
254
|
"method": "get",
|
|
242
255
|
"events": {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
256
|
+
'update_detail_event': function (data) {
|
|
257
|
+
return data
|
|
258
|
+
},
|
|
259
|
+
'form_submit_template': function (data) {
|
|
260
|
+
return data
|
|
261
|
+
},
|
|
262
|
+
'form_submit_instance': function (data) {
|
|
263
|
+
return data
|
|
264
|
+
},
|
|
265
|
+
'form_error_instance': function (errors) {
|
|
266
|
+
},
|
|
267
|
+
'form_error_template': function (errors) {
|
|
268
|
+
}
|
|
248
269
|
}
|
|
249
|
-
|
|
270
|
+
}
|
|
250
271
|
|
|
251
272
|
|
|
252
|
-
const config =
|
|
273
|
+
const config = Object.assign({}, default_config, form_config);
|
|
253
274
|
return {
|
|
254
275
|
"modal": $(modalid),
|
|
255
276
|
"modalid": modalid,
|
|
256
|
-
"config"
|
|
277
|
+
"config": config,
|
|
257
278
|
"instanceid": null,
|
|
258
279
|
"template_url": template_url,
|
|
259
280
|
"base_detail_url": base_detail_url,
|
|
@@ -264,96 +285,98 @@ function BaseDetailModal(modalid, base_detail_url, template_url, form_config={})
|
|
|
264
285
|
"template_tries": 0,
|
|
265
286
|
"detail_tries": 0,
|
|
266
287
|
"title": config.title,
|
|
267
|
-
"init": function(){
|
|
288
|
+
"init": function () {
|
|
268
289
|
this.get_template();
|
|
269
290
|
},
|
|
270
|
-
"show": function(){
|
|
291
|
+
"show": function () {
|
|
271
292
|
this.modal.modal('show');
|
|
272
293
|
},
|
|
273
|
-
"hide": function(){
|
|
294
|
+
"hide": function () {
|
|
274
295
|
this.modal.modal('hide');
|
|
275
296
|
},
|
|
276
|
-
"update_template": function(instance){
|
|
277
|
-
return function(data){
|
|
278
|
-
instance.template_tries=0;
|
|
279
|
-
instance.template= 'template' in data ? data['template'] : instance.template;
|
|
297
|
+
"update_template": function (instance) {
|
|
298
|
+
return function (data) {
|
|
299
|
+
instance.template_tries = 0;
|
|
300
|
+
instance.template = 'template' in data ? data['template'] : instance.template;
|
|
280
301
|
instance.title = 'title' in data ? data['title'] : instance.title;
|
|
281
302
|
}
|
|
282
303
|
},
|
|
283
|
-
"update_detail": function(instance){
|
|
284
|
-
return function(data){
|
|
285
|
-
|
|
286
|
-
|
|
304
|
+
"update_detail": function (instance) {
|
|
305
|
+
return function (data) {
|
|
306
|
+
data = instance.config.events.update_detail_event(data);
|
|
307
|
+
instance.detail_tries = 0;
|
|
287
308
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
309
|
+
var result = Sqrl.render(instance.template, data, Sqrl.getConfig({tags: ["<%", "%>"]}));
|
|
310
|
+
instance.modal.find(".modal-body").html(result);
|
|
311
|
+
var result = Sqrl.render(instance.title, data, Sqrl.getConfig({tags: ["<%", "%>"]}));
|
|
312
|
+
instance.modal.find(".modal-title").html(result);
|
|
313
|
+
instance.show();
|
|
293
314
|
}
|
|
294
315
|
},
|
|
295
|
-
"recall_get_template": function(instance){
|
|
296
|
-
return function(response) {
|
|
297
|
-
if(instance.template_tries<instance.template_max_tries){
|
|
298
|
-
instance.template_tries = instance.template_tries+ 1;
|
|
316
|
+
"recall_get_template": function (instance) {
|
|
317
|
+
return function (response) {
|
|
318
|
+
if (instance.template_tries < instance.template_max_tries) {
|
|
319
|
+
instance.template_tries = instance.template_tries + 1;
|
|
299
320
|
instance.get_template();
|
|
300
|
-
}else{
|
|
321
|
+
} else {
|
|
301
322
|
instance.config.events.form_error_template(response);
|
|
302
323
|
}
|
|
303
324
|
}
|
|
304
325
|
},
|
|
305
|
-
"recall_get_detail": function(instance){
|
|
306
|
-
return function(response) {
|
|
307
|
-
if(instance.detail_tries<instance.detail_max_tries){
|
|
308
|
-
instance.detail_tries = instance.detail_tries+1;
|
|
326
|
+
"recall_get_detail": function (instance) {
|
|
327
|
+
return function (response) {
|
|
328
|
+
if (instance.detail_tries < instance.detail_max_tries) {
|
|
329
|
+
instance.detail_tries = instance.detail_tries + 1;
|
|
309
330
|
instance.show_instance(instance.instanceid);
|
|
310
|
-
}else{
|
|
331
|
+
} else {
|
|
311
332
|
instance.config.events.form_error_instance(response);
|
|
312
333
|
}
|
|
313
334
|
}
|
|
314
335
|
|
|
315
336
|
},
|
|
316
|
-
"get_template": function(){
|
|
337
|
+
"get_template": function () {
|
|
317
338
|
var instance = this;
|
|
318
339
|
let params = {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
340
|
+
method: instance.config.method,
|
|
341
|
+
headers: instance.config.headers
|
|
342
|
+
}
|
|
322
343
|
params = instance.config.events.form_submit_template(params);
|
|
323
344
|
|
|
324
345
|
fetch(instance.template_url, params
|
|
325
|
-
|
|
346
|
+
).then(response_manage_type_data(instance, instance.error, instance.handle_error))
|
|
326
347
|
.then(instance.update_template(instance))
|
|
327
348
|
.catch(instance.recall_get_template(instance));
|
|
328
349
|
},
|
|
329
|
-
"show_instance": function(instanceid){
|
|
350
|
+
"show_instance": function (instanceid) {
|
|
330
351
|
var instance = this;
|
|
331
|
-
if(this.instanceid != instanceid){
|
|
352
|
+
if (this.instanceid != instanceid) {
|
|
353
|
+
instance.detail_tries = 0;
|
|
354
|
+
}
|
|
332
355
|
this.instanceid = instanceid
|
|
333
|
-
var url = this.base_detail_url.replace('/0/', '/'+instanceid+'/');
|
|
356
|
+
var url = this.base_detail_url.replace('/0/', '/' + instanceid + '/');
|
|
334
357
|
|
|
335
358
|
let params = {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
359
|
+
method: instance.config.method,
|
|
360
|
+
headers: instance.config.headers
|
|
361
|
+
}
|
|
339
362
|
params = instance.config.events.form_submit_instance(params);
|
|
340
363
|
fetch(url, params
|
|
341
|
-
|
|
364
|
+
).then(response_manage_type_data(instance, instance.error, instance.handle_error))
|
|
342
365
|
.then(instance.update_detail(instance))
|
|
343
366
|
.catch(instance.recall_get_detail(instance));
|
|
344
367
|
|
|
345
368
|
},
|
|
346
|
-
"error": function(instance, errors){
|
|
347
|
-
Swal.fire({
|
|
369
|
+
"error": function (instance, errors) {
|
|
370
|
+
Swal.fire({icon: 'error', title: gettext('Error'), text: errors.detail});
|
|
348
371
|
},
|
|
349
|
-
"handle_error": function(instance, error){
|
|
350
|
-
Swal.fire({
|
|
372
|
+
"handle_error": function (instance, error) {
|
|
373
|
+
Swal.fire({icon: 'error', title: gettext('Error'), text: error.message});
|
|
351
374
|
},
|
|
352
375
|
|
|
353
376
|
}
|
|
354
377
|
}
|
|
355
378
|
|
|
356
|
-
function ObjectCRUD(uniqueid, objconfig={}){
|
|
379
|
+
function ObjectCRUD(uniqueid, objconfig = {}) {
|
|
357
380
|
|
|
358
381
|
var default_config = {
|
|
359
382
|
uls: null,
|
|
@@ -361,14 +384,17 @@ function ObjectCRUD(uniqueid, objconfig={}){
|
|
|
361
384
|
modal_ids: null,
|
|
362
385
|
checkable: false,
|
|
363
386
|
events: {
|
|
364
|
-
|
|
387
|
+
'update_data': function (data) {
|
|
388
|
+
return data;
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
actions: {
|
|
392
|
+
table_actions: [], object_actions: [],
|
|
393
|
+
title: gettext('Actions'),
|
|
394
|
+
className: "no-export-col"
|
|
365
395
|
},
|
|
366
|
-
actions: { table_actions: [], object_actions: [],
|
|
367
|
-
title: gettext('Actions'),
|
|
368
|
-
className: "no-export-col"
|
|
369
|
-
},
|
|
370
396
|
datatable_inits: {},
|
|
371
|
-
replace_as_detail: {create: false,
|
|
397
|
+
replace_as_detail: {create: false, update: true, destroy: true, list: false},
|
|
372
398
|
relation_render: {},
|
|
373
399
|
headers: {'X-CSRFToken': getCookie('csrftoken'), 'Content-Type': 'application/json'},
|
|
374
400
|
btn_class: {
|
|
@@ -382,7 +408,9 @@ function ObjectCRUD(uniqueid, objconfig={}){
|
|
|
382
408
|
update: 'fa fa-edit',
|
|
383
409
|
destroy: 'fa fa-trash'
|
|
384
410
|
},
|
|
385
|
-
delete_display: function(data){
|
|
411
|
+
delete_display: function (data) {
|
|
412
|
+
return gettext("This Object");
|
|
413
|
+
},
|
|
386
414
|
gt_form_modals: {
|
|
387
415
|
'create': {},
|
|
388
416
|
'detail': {},
|
|
@@ -392,25 +420,25 @@ function ObjectCRUD(uniqueid, objconfig={}){
|
|
|
392
420
|
|
|
393
421
|
}
|
|
394
422
|
|
|
395
|
-
const config =
|
|
423
|
+
const config = Object.assign({}, default_config, objconfig);
|
|
396
424
|
|
|
397
425
|
per_table_actions = []
|
|
398
426
|
per_object_actions = []
|
|
399
|
-
if(
|
|
400
|
-
per_table_actions=objconfig.actions.table_actions;
|
|
427
|
+
if ("table_actions" in objconfig.actions) {
|
|
428
|
+
per_table_actions = objconfig.actions.table_actions;
|
|
401
429
|
}
|
|
402
|
-
if(
|
|
430
|
+
if ("object_actions" in objconfig.actions) {
|
|
403
431
|
per_object_actions = objconfig.actions.object_actions;
|
|
404
432
|
}
|
|
405
|
-
obj={
|
|
433
|
+
obj = {
|
|
406
434
|
"uniqueid": uniqueid,
|
|
407
435
|
"config": config,
|
|
408
436
|
"relation_render": config.relation_render,
|
|
409
437
|
"can_create": config.modal_ids.hasOwnProperty("create"),
|
|
410
|
-
"can_destroy": config.urls.hasOwnProperty("destroy_url") && config.modal_ids.hasOwnProperty("destroy")
|
|
438
|
+
"can_destroy": config.urls.hasOwnProperty("destroy_url") && config.modal_ids.hasOwnProperty("destroy"),
|
|
411
439
|
"can_list": config.urls.hasOwnProperty("list_url"),
|
|
412
440
|
"can_detail": objconfig.urls.hasOwnProperty("detail_url") && config.modal_ids.hasOwnProperty("detail")
|
|
413
|
-
|
|
441
|
+
&& config.urls.hasOwnProperty("detail_template_url"),
|
|
414
442
|
"can_update": config.modal_ids.hasOwnProperty("update"),
|
|
415
443
|
"use_get_values_for_update": config.urls.hasOwnProperty("get_values_for_update_url"),
|
|
416
444
|
"create_btn_class": config.btn_class.create,
|
|
@@ -421,33 +449,33 @@ function ObjectCRUD(uniqueid, objconfig={}){
|
|
|
421
449
|
"delete_form": null,
|
|
422
450
|
"data_extras": config.data_extras,
|
|
423
451
|
"detail_modal": null,
|
|
424
|
-
"base_update_url":null,
|
|
452
|
+
"base_update_url": null,
|
|
425
453
|
"table_actions": per_table_actions,
|
|
426
454
|
"object_actions": per_object_actions,
|
|
427
|
-
"init": function(){
|
|
428
|
-
if(this.can_list) this.list();
|
|
429
|
-
if(this.can_create){
|
|
455
|
+
"init": function () {
|
|
456
|
+
if (this.can_list) this.list();
|
|
457
|
+
if (this.can_create) {
|
|
430
458
|
let create_conf = Object.assign({}, {}, this.config.gt_form_modals.create);
|
|
431
459
|
this.create_form = GTBaseFormModal(this.config.modal_ids.create, this.datatable, create_conf);
|
|
432
460
|
this.create_form.init();
|
|
433
461
|
}
|
|
434
|
-
if(this.can_update){
|
|
462
|
+
if (this.can_update) {
|
|
435
463
|
let update_conf = Object.assign({}, {
|
|
436
|
-
type: "PUT",
|
|
464
|
+
type: "PUT", relation_render: this.relation_render
|
|
437
465
|
}, this.config.gt_form_modals.update);
|
|
438
466
|
this.update_form = GTBaseFormModal(this.config.modal_ids.update, this.datatable, update_conf);
|
|
439
467
|
this.base_update_url = this.update_form.url;
|
|
440
468
|
this.update_form.init();
|
|
441
469
|
}
|
|
442
|
-
if(this.can_detail){
|
|
470
|
+
if (this.can_detail) {
|
|
443
471
|
let detail_conf = Object.assign({}, {}, this.config.gt_form_modals.detail);
|
|
444
472
|
this.detail_modal = BaseDetailModal(this.config.modal_ids.detail,
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
473
|
+
this.config.urls.detail_url,
|
|
474
|
+
this.config.urls.detail_template_url,
|
|
475
|
+
detail_conf)
|
|
448
476
|
this.detail_modal.init()
|
|
449
477
|
}
|
|
450
|
-
if(this.can_destroy){
|
|
478
|
+
if (this.can_destroy) {
|
|
451
479
|
let destroy_conf = Object.assign({}, {
|
|
452
480
|
type: "DELETE", relation_render: this.relation_render, btn_class: ".delbtn"
|
|
453
481
|
}, this.config.gt_form_modals.destroy);
|
|
@@ -455,13 +483,13 @@ function ObjectCRUD(uniqueid, objconfig={}){
|
|
|
455
483
|
this.destroy_form.init();
|
|
456
484
|
}
|
|
457
485
|
},
|
|
458
|
-
"create":
|
|
459
|
-
return function(e, dt, node, config){
|
|
486
|
+
"create": function (instance) {
|
|
487
|
+
return function (e, dt, node, config) {
|
|
460
488
|
instance.create_form.show_modal();
|
|
461
489
|
}
|
|
462
490
|
},
|
|
463
|
-
"success": function(instance){
|
|
464
|
-
return function(data){
|
|
491
|
+
"success": function (instance) {
|
|
492
|
+
return function (data) {
|
|
465
493
|
Swal.fire({
|
|
466
494
|
title: gettext('Success'),
|
|
467
495
|
text: data['detail'],
|
|
@@ -472,20 +500,20 @@ function ObjectCRUD(uniqueid, objconfig={}){
|
|
|
472
500
|
}
|
|
473
501
|
|
|
474
502
|
},
|
|
475
|
-
"destroy": function(data, action) {
|
|
476
|
-
let url =
|
|
503
|
+
"destroy": function (data, action) {
|
|
504
|
+
let url = this.config.urls.destroy_url.replace('/0/', '/' + data.id + '/');
|
|
477
505
|
let text = this.config.delete_display(data)
|
|
478
506
|
this.destroy_form.url = url;
|
|
479
507
|
this.destroy_form.instance.find(".objtext").html(text)
|
|
480
508
|
this.destroy_form.show_modal();
|
|
481
509
|
},
|
|
482
|
-
"list": function(){
|
|
510
|
+
"list": function () {
|
|
483
511
|
/**
|
|
484
|
-
|
|
485
|
-
|
|
512
|
+
This function initialize datatable
|
|
513
|
+
*/
|
|
486
514
|
var instance = this;
|
|
487
515
|
|
|
488
|
-
if(this.can_create){
|
|
516
|
+
if (this.can_create) {
|
|
489
517
|
this.table_actions.push({
|
|
490
518
|
action: this.create(this),
|
|
491
519
|
text: this.config.icons.create,
|
|
@@ -493,207 +521,218 @@ function ObjectCRUD(uniqueid, objconfig={}){
|
|
|
493
521
|
className: this.config.btn_class.create
|
|
494
522
|
})
|
|
495
523
|
}
|
|
496
|
-
if(this.can_list){
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
524
|
+
if (this.can_list) {
|
|
525
|
+
this.table_actions.unshift({
|
|
526
|
+
action: function (e, dt, node, config) {
|
|
527
|
+
clearDataTableFilters(dt, instance.config.datatable_element)
|
|
528
|
+
},
|
|
529
|
+
text: this.config.icons.clear,
|
|
530
|
+
titleAttr: gettext('Clear Filters'),
|
|
531
|
+
className: this.config.btn_class.clear_filters
|
|
532
|
+
})
|
|
503
533
|
}
|
|
504
|
-
if(!config.datatable_inits.hasOwnProperty("buttons")){
|
|
534
|
+
if (!config.datatable_inits.hasOwnProperty("buttons")) {
|
|
505
535
|
config.datatable_inits['buttons'] = this.table_actions;
|
|
506
536
|
}
|
|
507
|
-
if(this.can_detail){
|
|
537
|
+
if (this.can_detail) {
|
|
508
538
|
instance.object_actions.push(
|
|
509
539
|
{
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
540
|
+
'name': "detail",
|
|
541
|
+
'action': 'detail',
|
|
542
|
+
'title': gettext('Detail'),
|
|
543
|
+
'url': null,
|
|
544
|
+
'i_class': this.config.icons.detail,
|
|
515
545
|
}
|
|
516
546
|
)
|
|
517
547
|
}
|
|
518
|
-
if(this.can_update){
|
|
548
|
+
if (this.can_update) {
|
|
519
549
|
instance.object_actions.push(
|
|
520
550
|
{
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
551
|
+
'name': "update",
|
|
552
|
+
'action': 'update',
|
|
553
|
+
'title': gettext("Update"),
|
|
554
|
+
'url': null,
|
|
555
|
+
'i_class': this.config.icons.update,
|
|
526
556
|
}
|
|
527
557
|
)
|
|
528
558
|
}
|
|
529
|
-
if(this.can_destroy){
|
|
559
|
+
if (this.can_destroy) {
|
|
530
560
|
instance.object_actions.push(
|
|
531
561
|
{
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
562
|
+
'name': 'destroy',
|
|
563
|
+
'action': 'destroy',
|
|
564
|
+
'title': gettext('Delete'),
|
|
565
|
+
'url': null,
|
|
566
|
+
'i_class': this.config.icons.destroy,
|
|
537
567
|
}
|
|
538
568
|
)
|
|
539
569
|
}
|
|
540
|
-
if(!config.datatable_inits.hasOwnProperty("columns")){
|
|
541
|
-
config.datatable_inits.columns=[];
|
|
570
|
+
if (!config.datatable_inits.hasOwnProperty("columns")) {
|
|
571
|
+
config.datatable_inits.columns = [];
|
|
542
572
|
}
|
|
543
|
-
if(!config.datatable_inits.hasOwnProperty("columnDefs")){
|
|
573
|
+
if (!config.datatable_inits.hasOwnProperty("columnDefs")) {
|
|
544
574
|
config.datatable_inits['columnDefs'] = [
|
|
545
575
|
{
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
576
|
+
targets: -1,
|
|
577
|
+
title: this.config.actions.title,
|
|
578
|
+
type: 'actions',
|
|
579
|
+
className: this.config.actions.className,
|
|
580
|
+
orderable: false,
|
|
581
|
+
render: function (data, type, full, meta) {
|
|
552
582
|
var edittext = '<div class="d-flex mt-1">';
|
|
553
|
-
let do_action=true;
|
|
554
|
-
for(var x=0; x<instance.object_actions.length; x++){
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
do_action=data[action.name];
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
display_in_column=action.in_action_column;
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
583
|
+
let do_action = true;
|
|
584
|
+
for (var x = 0; x < instance.object_actions.length; x++) {
|
|
585
|
+
let action = instance.object_actions[x];
|
|
586
|
+
let display_in_column = true;
|
|
587
|
+
do_action = true
|
|
588
|
+
if (action.name in data) {
|
|
589
|
+
do_action = data[action.name];
|
|
590
|
+
}
|
|
591
|
+
if (do_action) {
|
|
592
|
+
if ('in_action_column' in action) {
|
|
593
|
+
display_in_column = action.in_action_column;
|
|
594
|
+
}
|
|
595
|
+
if (display_in_column) {
|
|
596
|
+
let params = "'" + instance.uniqueid + "', '" + action.name + "', " + meta.row;
|
|
597
|
+
edittext += '<i onclick="javascript:call_obj_crud_event(' + params + ');"';
|
|
598
|
+
edittext += 'title="' + action.title + '"';
|
|
599
|
+
edittext += ' class="' + instance.object_actions[x].i_class + '" ></i>';
|
|
600
|
+
}
|
|
601
|
+
}
|
|
572
602
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
603
|
+
edittext += '</div>';
|
|
604
|
+
return edittext;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
577
607
|
]
|
|
578
|
-
if(this.checkable){
|
|
608
|
+
if (this.checkable) {
|
|
579
609
|
config.datatable_inits['columnDefs'].push(
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
610
|
+
{
|
|
611
|
+
targets: 0,
|
|
612
|
+
title: "Checkable",
|
|
613
|
+
type: 'checkable',
|
|
614
|
+
className: "no-export-col",
|
|
615
|
+
orderable: false,
|
|
616
|
+
render: function (data, type, full, meta) {
|
|
617
|
+
return '<input type="checkbox" class="gtcheckable" name="checkable" value="' + full.id + '" title="' + full.name + '"/>'
|
|
618
|
+
}
|
|
619
|
+
})
|
|
590
620
|
|
|
591
621
|
config.datatable_inits.columns.unshift(
|
|
592
|
-
{
|
|
622
|
+
{
|
|
623
|
+
data: "id",
|
|
624
|
+
name: "checkable",
|
|
625
|
+
title: '<input type="checkbox" class="checkableall"> ',
|
|
626
|
+
type: "checkable",
|
|
627
|
+
visible: true
|
|
628
|
+
}
|
|
593
629
|
)
|
|
594
630
|
}
|
|
595
631
|
}
|
|
596
|
-
|
|
597
|
-
|
|
632
|
+
this.datatable = gtCreateDataTable(this.config.datatable_element, this.config.urls.list_url,
|
|
633
|
+
this.config.datatable_inits);
|
|
598
634
|
},
|
|
599
|
-
"detail":
|
|
600
|
-
|
|
635
|
+
"detail": function (instance, action) {
|
|
636
|
+
this.detail_modal.show_instance(instance.id);
|
|
601
637
|
},
|
|
602
|
-
"update": function(instance, action){
|
|
603
|
-
if(this.use_get_values_for_update){
|
|
604
|
-
let url =
|
|
638
|
+
"update": function (instance, action) {
|
|
639
|
+
if (this.use_get_values_for_update) {
|
|
640
|
+
let url = this.config.urls.get_values_for_update_url.replace('/0/', '/' + instance.id + '/');
|
|
605
641
|
this.retrieve_data(url, 'GET', this.update_value_success(this, instance));
|
|
606
|
-
}else{
|
|
642
|
+
} else {
|
|
607
643
|
this.update_value_success(this, instance)(instance);
|
|
608
644
|
}
|
|
609
645
|
},
|
|
610
|
-
"update_value_success": function(instance, element){
|
|
611
|
-
return function(data){
|
|
646
|
+
"update_value_success": function (instance, element) {
|
|
647
|
+
return function (data) {
|
|
612
648
|
data = instance.config.events.update_data(data);
|
|
613
649
|
instance.update_form.fill_form(data);
|
|
614
|
-
instance.update_form.url = instance.base_update_url.replace('/0/', '/'+data.id+'/');
|
|
650
|
+
instance.update_form.url = instance.base_update_url.replace('/0/', '/' + data.id + '/');
|
|
615
651
|
instance.update_form.show_modal();
|
|
616
652
|
}
|
|
617
653
|
},
|
|
618
|
-
"action_update": function(action, data){
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
654
|
+
"action_update": function (action, data) {
|
|
655
|
+
},
|
|
656
|
+
"action_destroy": function (action, data) {
|
|
657
|
+
},
|
|
658
|
+
'do_table_actions': function (action_position) {
|
|
659
|
+
var instance = this;
|
|
660
|
+
if (action_position >= 0 && action_position < instance.table_actions.length) {
|
|
661
|
+
let action = instance.table_actions[action_position];
|
|
662
|
+
if (action.name in this) {
|
|
625
663
|
this[action.name]({}, action);
|
|
626
|
-
}else{
|
|
664
|
+
} else {
|
|
627
665
|
this.do_action({}, action);
|
|
628
666
|
}
|
|
629
|
-
|
|
630
|
-
},
|
|
631
|
-
'do_object_actions': function(action_position, instance_id){
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
'do_object_actions': function (action_position, instance_id) {
|
|
670
|
+
var instance = this;
|
|
671
|
+
var data = this.datatable.row(instance_id).data();
|
|
672
|
+
;
|
|
673
|
+
if (action_position >= 0 && action_position < instance.object_actions.length) {
|
|
674
|
+
let action = instance.object_actions[action_position];
|
|
675
|
+
if (action.name in this) {
|
|
637
676
|
this[action.name](data, action);
|
|
638
|
-
}else{
|
|
677
|
+
} else {
|
|
639
678
|
this.do_action(data, action);
|
|
640
679
|
}
|
|
641
|
-
|
|
680
|
+
}
|
|
642
681
|
},
|
|
643
|
-
'do_action': function(data, action){
|
|
682
|
+
'do_action': function (data, action) {
|
|
644
683
|
var instance = this;
|
|
645
684
|
let method = 'method' in action ? action.method : 'POST';
|
|
646
685
|
let body = 'data_fn' in action ? JSON.stringify(action.data_fn(data)) : '';
|
|
647
686
|
let url = 'url_fn' in action ? action.url_fn(data) : null;
|
|
648
687
|
let error_fn = 'error_fn' in action ? action.error_fn : instance.error;
|
|
649
|
-
if(url == null && 'url' in action
|
|
650
|
-
|
|
688
|
+
if (url == null && 'url' in action && action.url !== null) {
|
|
689
|
+
url = action.url;
|
|
651
690
|
}
|
|
652
|
-
if(
|
|
691
|
+
if (url !== null) {
|
|
653
692
|
fetch(url, {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
693
|
+
method: method,
|
|
694
|
+
body: body,
|
|
695
|
+
headers: this.config.headers
|
|
657
696
|
}
|
|
658
697
|
).then(response_manage_type_data(instance, error_fn, instance.error_text))
|
|
659
|
-
|
|
660
|
-
|
|
698
|
+
.then(instance.success(instance))
|
|
699
|
+
.catch(error => instance.handle_error(instance, error));
|
|
661
700
|
}
|
|
662
701
|
},
|
|
663
|
-
'retrieve_data': function(url, method, success){
|
|
702
|
+
'retrieve_data': function (url, method, success) {
|
|
664
703
|
var instance = this;
|
|
665
704
|
fetch(url, {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
705
|
+
method: method,
|
|
706
|
+
headers: this.config.headers
|
|
707
|
+
}).then(response_manage_type_data(instance, instance.error, instance.error_text))
|
|
669
708
|
.then(success)
|
|
670
709
|
.catch(error => instance.handle_error(instance, error));
|
|
671
710
|
},
|
|
672
|
-
"error_text": function(instance, message){
|
|
673
|
-
Swal.fire({icon: 'error',
|
|
711
|
+
"error_text": function (instance, message) {
|
|
712
|
+
Swal.fire({icon: 'error', title: gettext('Error'), text: message});
|
|
674
713
|
},
|
|
675
|
-
"error": function(instance, errors){
|
|
676
|
-
if(errors.hasOwnProperty('detail') && Object.keys(errors).length == 1){
|
|
677
|
-
Swal.fire({
|
|
714
|
+
"error": function (instance, errors) {
|
|
715
|
+
if (errors.hasOwnProperty('detail') && Object.keys(errors).length == 1) {
|
|
716
|
+
Swal.fire({icon: 'error', title: gettext('Error'), text: errors.detail});
|
|
678
717
|
}
|
|
679
718
|
//instance.form.find('ul.form_errors').remove();
|
|
680
719
|
//form_field_errors(instance.form, errors, instance.prefix);
|
|
681
720
|
},
|
|
682
|
-
"handle_error": function(instance, error){
|
|
721
|
+
"handle_error": function (instance, error) {
|
|
683
722
|
let error_msg = gettext('There was a problem performing your request. Please try again later or contact the administrator.');
|
|
684
|
-
Swal.fire({
|
|
723
|
+
Swal.fire({icon: 'error', title: error_msg, text: error.message});
|
|
685
724
|
},
|
|
686
|
-
'find_table_action_by_name': function(name){
|
|
687
|
-
for(var x=0; x<this.table_actions.length; x++){
|
|
688
|
-
if(this.table_actions[x].name === name){
|
|
725
|
+
'find_table_action_by_name': function (name) {
|
|
726
|
+
for (var x = 0; x < this.table_actions.length; x++) {
|
|
727
|
+
if (this.table_actions[x].name === name) {
|
|
689
728
|
return x;
|
|
690
729
|
}
|
|
691
730
|
}
|
|
692
731
|
return undefined;
|
|
693
732
|
},
|
|
694
|
-
'find_object_action_by_name': function(name){
|
|
695
|
-
for(var x=0; x<this.object_actions.length; x++){
|
|
696
|
-
if(this.object_actions[x].name === name){
|
|
733
|
+
'find_object_action_by_name': function (name) {
|
|
734
|
+
for (var x = 0; x < this.object_actions.length; x++) {
|
|
735
|
+
if (this.object_actions[x].name === name) {
|
|
697
736
|
return x;
|
|
698
737
|
}
|
|
699
738
|
}
|
|
@@ -705,21 +744,35 @@ function ObjectCRUD(uniqueid, objconfig={}){
|
|
|
705
744
|
return obj;
|
|
706
745
|
}
|
|
707
746
|
|
|
708
|
-
function call_obj_crud_event(uniqueid, action_name, row_id){
|
|
709
|
-
if(uniqueid in gt_crud_objs){
|
|
747
|
+
function call_obj_crud_event(uniqueid, action_name, row_id) {
|
|
748
|
+
if (uniqueid in gt_crud_objs) {
|
|
710
749
|
let position = gt_crud_objs[uniqueid].find_object_action_by_name(action_name);
|
|
711
|
-
if(position != undefined){
|
|
750
|
+
if (position != undefined) {
|
|
712
751
|
gt_crud_objs[uniqueid].do_object_actions(position, row_id);
|
|
713
752
|
}
|
|
714
753
|
}
|
|
715
754
|
}
|
|
716
755
|
|
|
717
|
-
function call_table_crud_event(uniqueid, action_name){
|
|
718
|
-
if(uniqueid in gt_crud_objs){
|
|
719
|
-
|
|
720
|
-
|
|
756
|
+
function call_table_crud_event(uniqueid, action_name) {
|
|
757
|
+
if (uniqueid in gt_crud_objs) {
|
|
758
|
+
let position = gt_crud_objs[uniqueid].find_table_action_by_name(action_name);
|
|
759
|
+
if (position != undefined) {
|
|
721
760
|
gt_crud_objs[uniqueid].do_table_actions(position, 0);
|
|
722
|
-
|
|
761
|
+
}
|
|
723
762
|
}
|
|
724
763
|
}
|
|
725
764
|
|
|
765
|
+
function truncateText(data, maxChars = 100) {
|
|
766
|
+
|
|
767
|
+
if (typeof data === 'string') {
|
|
768
|
+
const text = data.trim();
|
|
769
|
+
if (text.length > maxChars) {
|
|
770
|
+
return `<span title="${text.replace(/"/g, '"')}" style="display:inline; line-height:1; margin:0; padding:0;">${text.substring(0, maxChars)}...</span>`;
|
|
771
|
+
}
|
|
772
|
+
return text
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
return data;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: djgentelella
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: Help building extra widgets for forms and speciall methods to render forms in templates
|
|
5
5
|
Author-email: Solvosoft <info@solvosoft.com>
|
|
6
6
|
Maintainer-email: Luis Zarate Montero <luis.zarate@solvosoft.com>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
djgentelella/__init__.py,sha256=
|
|
1
|
+
djgentelella/__init__.py,sha256=SZ45PeABDxCAv7VZI4emwNNgGIkc2K-9QlgBEXYY9m0,73
|
|
2
2
|
djgentelella/admin.py,sha256=hFPWtRyTZWYtuKEv-SZ3r6lHw3aissX0ObqxYmxblY0,1531
|
|
3
3
|
djgentelella/apps.py,sha256=5VEbpUv4b1Jh7gCRAQCe5TvpakRyndKwafjVj0z-Xfo,153
|
|
4
4
|
djgentelella/chartjs.py,sha256=iNYoFnaIQoXsYInJFbSE2quWpjmDz5CuMKpVsvt4pRM,8572
|
|
@@ -143,8 +143,8 @@ djgentelella/static/gentelella/images/forward_enabled_hover.png,sha256=T6LWiaYzc
|
|
|
143
143
|
djgentelella/static/gentelella/images/loading.gif,sha256=dyCz9kckQBZKy7DpKpR3hL4xgQgnShbMue3Ao9h_lK0,30269
|
|
144
144
|
djgentelella/static/gentelella/js/base.js,sha256=511G19fPkbF-XFgd5D0heRICSIkT8qcfSSVmWAFmhOw,125743
|
|
145
145
|
djgentelella/static/gentelella/js/custom.js,sha256=O9GWx1FbkMYzbUSzlYw3SrfZrf9xPdMokPh91xMtdUY,14922
|
|
146
|
-
djgentelella/static/gentelella/js/datatables.js,sha256=
|
|
147
|
-
djgentelella/static/gentelella/js/obj_api_management.js,sha256=
|
|
146
|
+
djgentelella/static/gentelella/js/datatables.js,sha256=ZmEBPhoj8jDgl_1g14J9tKtiMknyzBekp1_NqAlxjuU,13743
|
|
147
|
+
djgentelella/static/gentelella/js/obj_api_management.js,sha256=wAVqz9hp5NdJC2dxA_l3mxIeUA2N3fSXuTRADJDCyR4,32127
|
|
148
148
|
djgentelella/static/gentelella/js/permissionmanagement.js,sha256=Y6n0jRtVr6LVadA3frJ6Ec7FXeuEUS6EsZ2ZgSIj7Y0,8211
|
|
149
149
|
djgentelella/static/gentelella/js/widgets.js,sha256=l6nQvotvoMeneNupSXjUqNb6LPKXrMOkQz010e3hRpc,12794
|
|
150
150
|
djgentelella/static/gentelella/js/base/api_list.js,sha256=jhhsWJ9VsZiZiHzusxMqDq9IDPbt14b3u9tTHIgLqvU,3942
|
|
@@ -1030,9 +1030,9 @@ djgentelella/widgets/trees.py,sha256=bV6s-w1cgYahS0aNU6xBrx-aISdlzDZ23BFt3_3hAu4
|
|
|
1030
1030
|
djgentelella/widgets/wysiwyg.py,sha256=wHeMyYNVE8-lKJ06A-0DLDAcRNv3TOAOG_Wl9DYZqS0,609
|
|
1031
1031
|
djgentelella/wysiwyg/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
1032
1032
|
djgentelella/wysiwyg/views.py,sha256=tI7LjLhCnohdvIEOEEhB2Cu1zxRmdcOhYJJX4LBIZaA,1159
|
|
1033
|
-
djgentelella-0.4.
|
|
1034
|
-
djgentelella-0.4.
|
|
1035
|
-
djgentelella-0.4.
|
|
1036
|
-
djgentelella-0.4.
|
|
1037
|
-
djgentelella-0.4.
|
|
1038
|
-
djgentelella-0.4.
|
|
1033
|
+
djgentelella-0.4.4.dist-info/AUTHORS,sha256=HyQoO-q7oXtavpNm7jaBVv8Vxx3c7yo33xkFkt4blkY,118
|
|
1034
|
+
djgentelella-0.4.4.dist-info/LICENSE.txt,sha256=wDzqAntLQORAL6vQhVdzZyfsPVvFStZKtkct5DIZjK0,18047
|
|
1035
|
+
djgentelella-0.4.4.dist-info/METADATA,sha256=iKgO9iJZjRE8qTE2A6wrnlzbqGYdOKPnaLEBa_1OaY0,27544
|
|
1036
|
+
djgentelella-0.4.4.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
1037
|
+
djgentelella-0.4.4.dist-info/top_level.txt,sha256=88JbODVPV-P5q7ic25yMHt_FuuizaLzMyIaegpFa7Qk,13
|
|
1038
|
+
djgentelella-0.4.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|