djgentelella 0.4.3__py3-none-any.whl → 0.4.5__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.
@@ -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
- function gt_show_actions(crud_name){
9
- return function(data, type, row, meta){
10
- var html="";
11
- if(data != null ){
12
- if(data.title != undefined){
13
- html+= data.title+" ";
14
- }
15
- for(var x=0; x<data.actions.length; x++){
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, form_config) {
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": {'form_submit': function(instance){ return {} },
36
- 'success_form': function(data){},
37
- 'error_form': function(errors){}
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 = Object.assign({}, default_config, form_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)=>{e.preventDefault();})
63
- },
64
- "add_btn_form": function(instance){
65
- return function(event){
66
- convertToStringJson(instance.form, prefix=instance.prefix,
67
- extras=instance.config.events.form_submit(instance)).then((result) => {
68
- fetch(instance.url, {
69
- method: instance.type,
70
- body: result,
71
- headers: {'X-CSRFToken': getCookie('csrftoken'), 'Content-Type': 'application/json'}
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
- .then(instance.fn_success(instance))
75
- .catch(error => instance.handle_error(instance, error));
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
- return function(data){
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', title: gettext('Error'), text: message });
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({ icon: 'error', title: gettext('Error'), text: errors.detail });
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({ icon: 'error', title: gettext('Error'), text: error.message });
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 = Object.keys(datainstance);
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
- select2Items.push(e);
132
- }else{
133
- instance.updateInstanceForm(instance.prefix+e, datainstance[e]);
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
- // do select 2 items
138
- $.each(select2Items, function(i, e){
139
- var display_name_key = 'text';
140
- if(instance.relation_render.hasOwnProperty(e)){
141
- display_name_key=instance.relation_render[e];
142
- }
143
- $('#id_'+instance.prefix+e).val(null).trigger('change');
144
- if(datainstance[e]){
145
- if(Array.isArray(datainstance[e])){
146
- for(var x=0; x<datainstance[e].length; x++){
147
- $('#id_'+instance.prefix+e+' option[value="'+datainstance[e][x]['id']+'"]').remove();
148
- var newOption = new Option(datainstance[e][x][display_name_key], datainstance[e][x]['id'], true, true);
149
- $('#id_'+instance.prefix+e).append(newOption);
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
- $('#id_'+instance.prefix+e).trigger('change')
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=$(inputfield);
169
-
170
- if(inputfield.attr('class') === "chunkedvalue"){
171
- if(value){
172
- var chunked=parent.form.find('input[name="'+name+'_widget"]').data('fileUploadWidget');
173
- chunked.addRemote(value);
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( "checked", !value);
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( "checked", value);
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() { return this.value === value.toString() });
200
- if(sel.length>0){
201
- sel.prop( "checked", true);
202
- if(is_icheck){
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( "checked", false);
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
- tinymce.get(inputfield.attr('id')).setContent(value);
218
- done=true;
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
- 'update_detail_event': function(data){ return data},
244
- 'form_submit_template': function(data){ return data},
245
- 'form_submit_instance': function(data){ return data},
246
- 'form_error_instance': function(errors){},
247
- 'form_error_template': function(errors){}
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 = Object.assign({}, default_config, form_config);
273
+ const config = Object.assign({}, default_config, form_config);
253
274
  return {
254
275
  "modal": $(modalid),
255
276
  "modalid": modalid,
256
- "config" : 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
- data = instance.config.events.update_detail_event(data);
286
- instance.detail_tries=0;
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
- var result = Sqrl.render(instance.template, data, Sqrl.getConfig({ tags: ["<%", "%>"] }));
289
- instance.modal.find(".modal-body").html(result);
290
- var result = Sqrl.render(instance.title, data, Sqrl.getConfig({ tags: ["<%", "%>"] }));
291
- instance.modal.find(".modal-title").html(result);
292
- instance.show();
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
- method: instance.config.method,
320
- headers: instance.config.headers
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
- ).then(response_manage_type_data(instance, instance.error, instance.handle_error))
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){ instance.detail_tries = 0; }
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
- method: instance.config.method,
337
- headers: instance.config.headers
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
- ).then(response_manage_type_data(instance, instance.error, instance.handle_error))
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({ icon: 'error', title: gettext('Error'), text: errors.detail });
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({ icon: 'error', title: gettext('Error'), text: error.message });
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
- 'update_data': function(data){ return data; }
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, update: true, destroy: true, list: 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){ return gettext("This Object"); },
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 = Object.assign({}, default_config, objconfig);
423
+ const config = Object.assign({}, default_config, objconfig);
396
424
 
397
425
  per_table_actions = []
398
426
  per_object_actions = []
399
- if( "table_actions" in objconfig.actions){
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( "object_actions" in objconfig.actions){
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
- && config.urls.hasOwnProperty("detail_template_url"),
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", relation_render: this.relation_render
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
- this.config.urls.detail_url,
446
- this.config.urls.detail_template_url,
447
- detail_conf)
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": function(instance){
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 = this.config.urls.destroy_url.replace('/0/', '/'+data.id+'/');
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
- This function initialize datatable
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
- this.table_actions.unshift({
498
- action: function ( e, dt, node, config ) {clearDataTableFilters(dt, instance.config.datatable_element)},
499
- text: this.config.icons.clear,
500
- titleAttr: gettext('Clear Filters'),
501
- className: this.config.btn_class.clear_filters
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
- 'name': "detail",
511
- 'action': 'detail',
512
- 'title': gettext('Detail'),
513
- 'url': null,
514
- 'i_class': this.config.icons.detail,
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
- 'name': "update",
522
- 'action': 'update',
523
- 'title': gettext("Update"),
524
- 'url': null,
525
- 'i_class': this.config.icons.update,
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
- 'name': 'destroy',
533
- 'action': 'destroy',
534
- 'title': gettext('Delete'),
535
- 'url': null,
536
- 'i_class': this.config.icons.destroy,
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
- targets: -1,
547
- title: this.config.actions.title,
548
- type: 'actions',
549
- className: this.config.actions.className,
550
- orderable: false,
551
- render: function(data, type, full, meta){
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
- let action = instance.object_actions[x];
556
- let display_in_column = true;
557
- do_action=true
558
- if(action.name in data ){
559
- do_action=data[action.name];
560
- }
561
- if(do_action){
562
- if('in_action_column' in action ){
563
- display_in_column=action.in_action_column;
564
- }
565
- if(display_in_column){
566
- let params = "'"+instance.uniqueid+"', '"+action.name+"', "+meta.row;
567
- edittext += '<i onclick="javascript:call_obj_crud_event('+params+');"';
568
- edittext += 'title="'+action.title+'"';
569
- edittext += ' class="'+instance.object_actions[x].i_class+'" ></i>';
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
- edittext += '</div>';
574
- return edittext;
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
- targets: 0,
582
- title: "Checkable",
583
- type: 'checkable',
584
- className: "no-export-col",
585
- orderable: false,
586
- render: function(data, type, full, meta){
587
- return '<input type="checkbox" class="gtcheckable" name="checkable" value="'+full.id+'" title="'+full.name+'"/>'
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
- {data: "id", name: "checkable", title: '<input type="checkbox" class="checkableall"> ', type: "checkable", visible: true}
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
- this.datatable = gtCreateDataTable(this.config.datatable_element, this.config.urls.list_url,
597
- this.config.datatable_inits);
632
+ this.datatable = gtCreateDataTable(this.config.datatable_element, this.config.urls.list_url,
633
+ this.config.datatable_inits);
598
634
  },
599
- "detail": function(instance, action){
600
- this.detail_modal.show_instance(instance.id);
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 = this.config.urls.get_values_for_update_url.replace('/0/', '/'+instance.id+'/');
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
- "action_destroy": function(action, data){},
620
- 'do_table_actions': function(action_position){
621
- var instance = this;
622
- if(action_position>=0 && action_position<instance.table_actions.length){
623
- let action=instance.table_actions[action_position];
624
- if(action.name in this){
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
- var instance = this;
633
- var data = this.datatable.row(instance_id).data(); ;
634
- if(action_position>=0 && action_position<instance.object_actions.length){
635
- let action=instance.object_actions[action_position];
636
- if(action.name in this){
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 && action.url !== null){
650
- url = action.url;
688
+ if (url == null && 'url' in action && action.url !== null) {
689
+ url = action.url;
651
690
  }
652
- if( url !== null ){
691
+ if (url !== null) {
653
692
  fetch(url, {
654
- method: method,
655
- body: body,
656
- headers: this.config.headers
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
- .then(instance.success(instance))
660
- .catch(error => instance.handle_error(instance, error));
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
- method: method,
667
- headers:this.config.headers
668
- }).then(response_manage_type_data(instance, instance.error, instance.error_text))
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', title: gettext('Error'), text: message });
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({ icon: 'error', title: gettext('Error'), text: errors.detail });
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({ icon: 'error', title: error_msg, text: error.message });
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
- let position = gt_crud_objs[uniqueid].find_table_action_by_name(action_name);
720
- if(position != undefined){
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, '&quot;')}" 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
+