@hotstaq/admin-panel 0.3.1 → 0.3.2

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.
@@ -26,10 +26,34 @@ export class AdminEdit extends HotComponent
26
26
  * The modal id.
27
27
  */
28
28
  modalId: string;
29
+ /**
30
+ * The text for the add button.
31
+ */
32
+ add_text: string;
33
+ /**
34
+ * The location to put the add button.
35
+ */
36
+ add_place_here: string;
37
+ /**
38
+ * The text for the edit button.
39
+ */
40
+ edit_text: string;
41
+ /**
42
+ * The location to put the edit button.
43
+ */
44
+ edit_place_here: string;
45
+ /**
46
+ * The text for the remove button.
47
+ */
48
+ remove_text: string;
49
+ /**
50
+ * The location to put the remove button.
51
+ */
52
+ remove_place_here: string;
29
53
  /**
30
54
  * The hot-class attribute to pass to add to the modal's classes.
31
55
  */
32
- class: string;
56
+ css_class: string;
33
57
  /**
34
58
  * The bootstrap modal instance.
35
59
  */
@@ -77,7 +101,13 @@ export class AdminEdit extends HotComponent
77
101
  this.schema = "";
78
102
 
79
103
  this.modalId = "";
80
- this.class = "";
104
+ this.add_text = "Add";
105
+ this.add_place_here = "dashboardHeader";
106
+ this.edit_text = "Edit";
107
+ this.edit_place_here = "dashboardHeader";
108
+ this.remove_text = "Remove";
109
+ this.remove_place_here = "dashboardHeader";
110
+ this.css_class = "";
81
111
  this.modal = null;
82
112
  this.modalType = "add";
83
113
  this.closeOnSave = true;
@@ -176,42 +206,48 @@ export class AdminEdit extends HotComponent
176
206
  }
177
207
 
178
208
  this.modalType = "edit";
179
- let attachedList = document.getElementById (this.attached_list);
180
209
 
181
- // @ts-ignore
182
- let hotComponent: AdminTable = attachedList.hotComponent;
183
- let selectedField = hotComponent.getSelected ();
210
+ this.selectedFields = [];
184
211
 
185
- if (selectedField != null)
212
+ if (this.attached_list !== "")
186
213
  {
187
- await this.processHotFields (
188
- async (htmlElement: Element, field: { name: string; type: string; }) =>
189
- {
190
- // @ts-ignore
191
- const value = selectedField[field.name];
192
-
193
- if (value != null)
194
- $(htmlElement).val (value);
195
- });
214
+ let attachedList = document.getElementById (this.attached_list);
196
215
 
197
- this.selectedFields = [selectedField];
216
+ // @ts-ignore
217
+ let hotComponent: AdminTable = attachedList.hotComponent;
218
+ let selectedField = hotComponent.getSelected ();
198
219
 
199
- if (this.onedit != null)
220
+ if (selectedField != null)
200
221
  {
201
- if (typeof (this.onedit) === "string")
202
- this.onedit = (<(modalType: string, selectedFields: any[]) => Promise<boolean>>new Function (this.onedit));
222
+ await this.processHotFields (
223
+ async (htmlElement: Element, field: { name: string; type: string; }) =>
224
+ {
225
+ // @ts-ignore
226
+ const value = selectedField[field.name];
203
227
 
204
- let result = await this.onedit (this.modalType, this.selectedFields);
228
+ if (value != null)
229
+ $(htmlElement).val (value);
230
+ });
205
231
 
206
- if (result != null)
207
- {
208
- if (result === false)
209
- return;
210
- }
232
+ this.selectedFields = [selectedField];
211
233
  }
234
+ }
235
+
236
+ if (this.onedit != null)
237
+ {
238
+ if (typeof (this.onedit) === "string")
239
+ this.onedit = (<(modalType: string, selectedFields: any[]) => Promise<boolean>>new Function (this.onedit));
212
240
 
213
- bootstrap.Modal.getInstance (`#${this.modalId}`).show ();
241
+ let result = await this.onedit (this.modalType, this.selectedFields);
242
+
243
+ if (result != null)
244
+ {
245
+ if (result === false)
246
+ return;
247
+ }
214
248
  }
249
+
250
+ bootstrap.Modal.getInstance (`#${this.modalId}`).show ();
215
251
  }
216
252
 
217
253
  /**
@@ -235,36 +271,41 @@ export class AdminEdit extends HotComponent
235
271
 
236
272
  this.modalType = "remove";
237
273
 
238
- let attachedList = document.getElementById (this.attached_list);
239
- // @ts-ignore
240
- let hotComponent: AdminTable = attachedList.hotComponent;
241
- let checkedRows = hotComponent.getCheckedRows ();
242
274
  let whereFields: any[] = [];
275
+ let hotComponent: AdminTable = null;
243
276
 
244
- if (checkedRows.length > 0)
277
+ if (this.attached_list !== "")
245
278
  {
246
- for (let i = 0; i < checkedRows.length; i++)
279
+ let attachedList = document.getElementById (this.attached_list);
280
+ // @ts-ignore
281
+ hotComponent = attachedList.hotComponent;
282
+ let checkedRows = hotComponent.getCheckedRows ();
283
+
284
+ if (checkedRows.length > 0)
247
285
  {
248
- let checkedRow = checkedRows[i];
249
- whereFields.push (checkedRow);
286
+ for (let i = 0; i < checkedRows.length; i++)
287
+ {
288
+ let checkedRow = checkedRows[i];
289
+ whereFields.push (checkedRow);
290
+ }
250
291
  }
251
- }
252
292
 
253
- let selectedField = hotComponent.getSelected ();
293
+ let selectedField = hotComponent.getSelected ();
254
294
 
255
- if (selectedField != null)
256
- whereFields = [selectedField];
295
+ if (selectedField != null)
296
+ whereFields = [selectedField];
297
+ }
257
298
 
258
- if (whereFields.length > 0)
259
- {
260
- const confirmed: boolean = confirm ("Are you sure you want to remove this item?");
299
+ const confirmed: boolean = confirm ("Are you sure you want to remove this item?");
261
300
 
262
- if (confirmed === true)
301
+ if (confirmed === true)
302
+ {
303
+ for (let i = 0; i < whereFields.length; i++)
263
304
  {
264
- for (let i = 0; i < whereFields.length; i++)
265
- {
266
- let whereField = whereFields[i];
305
+ let whereField = whereFields[i];
267
306
 
307
+ if (hotComponent != null)
308
+ {
268
309
  // Remove any fields that are marked as remove.
269
310
  for (let key in whereField)
270
311
  {
@@ -276,27 +317,48 @@ export class AdminEdit extends HotComponent
276
317
  delete whereField[key];
277
318
  }
278
319
  }
320
+ }
279
321
 
280
- if (this.ondelete != null)
281
- {
282
- if (typeof (this.ondelete) === "string")
283
- this.ondelete = (<(selectedField: any) => Promise<void>>new Function (this.ondelete));
322
+ if (this.ondelete != null)
323
+ {
324
+ if (typeof (this.ondelete) === "string")
325
+ this.ondelete = (<(selectedField: any) => Promise<void>>new Function (this.ondelete));
284
326
 
285
- await this.ondelete (whereField);
286
- }
287
- else
288
- {
289
- let removeUrl: string = Hot.Data.AdminPanel.removeUrl;
327
+ await this.ondelete (whereField);
328
+ }
329
+ else
330
+ {
331
+ let removeUrl: string = Hot.Data.AdminPanel.removeUrl;
290
332
 
291
- await Hot.jsonRequest (removeUrl, {
292
- schema: this.schema,
293
- whereFields: whereField
294
- });
295
- }
333
+ await Hot.jsonRequest (removeUrl, {
334
+ schema: this.schema,
335
+ whereFields: whereField
336
+ });
296
337
  }
297
-
298
- await hotComponent.refreshList ();
299
338
  }
339
+
340
+ if (whereFields.length === 0)
341
+ {
342
+ if (this.ondelete != null)
343
+ {
344
+ if (typeof (this.ondelete) === "string")
345
+ this.ondelete = (<(selectedField: any) => Promise<void>>new Function (this.ondelete));
346
+
347
+ await this.ondelete (null);
348
+ }
349
+ else
350
+ {
351
+ let removeUrl: string = Hot.Data.AdminPanel.removeUrl;
352
+
353
+ await Hot.jsonRequest (removeUrl, {
354
+ schema: this.schema,
355
+ whereFields: null
356
+ });
357
+ }
358
+ }
359
+
360
+ if (hotComponent != null)
361
+ await hotComponent.refreshList ();
300
362
  }
301
363
  }
302
364
 
@@ -312,7 +374,22 @@ export class AdminEdit extends HotComponent
312
374
  if (field.type === "remove")
313
375
  return;
314
376
 
315
- values[field.name] = $(htmlElement).val ();
377
+ let value = $(htmlElement).val ();
378
+
379
+ if ($(htmlElement).attr ("hot-value") != null)
380
+ value = $(htmlElement).attr ("hot-value");
381
+
382
+ if (field.type === "array")
383
+ {
384
+ if (values[field.name] == null)
385
+ values[field.name] = [];
386
+
387
+ values[field.name].push (value);
388
+
389
+ return;
390
+ }
391
+
392
+ values[field.name] = value;
316
393
  });
317
394
 
318
395
  if (this.onsave != null)
@@ -349,8 +426,23 @@ export class AdminEdit extends HotComponent
349
426
  {
350
427
  if (field.type === "remove")
351
428
  return;
352
-
353
- whereFields[field.name] = $(htmlElement).val ();
429
+
430
+ let value = $(htmlElement).val ();
431
+
432
+ if ($(htmlElement).attr ("hot-value") != null)
433
+ value = $(htmlElement).attr ("hot-value");
434
+
435
+ if (field.type === "array")
436
+ {
437
+ if (whereFields[field.name] == null)
438
+ whereFields[field.name] = [];
439
+
440
+ whereFields[field.name].push (value);
441
+
442
+ return;
443
+ }
444
+
445
+ whereFields[field.name] = value;
354
446
  });
355
447
 
356
448
  let editUrl: string = Hot.Data.AdminPanel.editUrl;
@@ -363,11 +455,14 @@ export class AdminEdit extends HotComponent
363
455
  }
364
456
  }
365
457
 
366
- let attachedList = document.getElementById (this.attached_list);
367
- // @ts-ignore
368
- let table: AdminTable = attachedList.hotComponent;
458
+ if (this.attached_list !== "")
459
+ {
460
+ let attachedList = document.getElementById (this.attached_list);
461
+ // @ts-ignore
462
+ let table: AdminTable = attachedList.hotComponent;
369
463
 
370
- await table.refreshList ();
464
+ await table.refreshList ();
465
+ }
371
466
 
372
467
  if (this.closeOnSave === true)
373
468
  {
@@ -396,10 +491,10 @@ export class AdminEdit extends HotComponent
396
491
 
397
492
  this.modalId = `${this.name}Modal`;
398
493
 
399
- return ([{
494
+ let outputObj = [{
400
495
  html: `
401
496
  <!-- ${this.title} Modal Start -->
402
- <div class="modal fade ${this.class}" id="${this.modalId}" tabindex="-1" aria-labelledby="${this.name}ModalLabel" aria-hidden="true">
497
+ <div class="modal fade ${this.css_class}" id="${this.modalId}" tabindex="-1" aria-labelledby="${this.name}ModalLabel" aria-hidden="true">
403
498
  <div class="modal-dialog">
404
499
  <div class="modal-content">
405
500
  <div class="modal-header">
@@ -418,18 +513,32 @@ export class AdminEdit extends HotComponent
418
513
  </div>
419
514
  <!-- ${this.title} Modal End -->`,
420
515
  documentSelector: "body"
421
- },
516
+ }];
517
+
518
+ if (this.add_place_here !== "")
422
519
  {
423
- html: `<button id = "${this.modalId}-add-btn" type="button" class="btn btn-sm btn-outline-secondary" onclick = "this.addClicked ();">Add</button>`,
424
- documentSelector: `hot-place-here[name="dashboardHeader"]`
425
- },
520
+ outputObj.push ({
521
+ html: `<button id = "${this.modalId}-add-btn" type="button" class="btn btn-sm btn-outline-secondary" onclick = "this.addClicked ();">${this.add_text}</button>`,
522
+ documentSelector: `hot-place-here[name="${this.add_place_here}"]`
523
+ });
524
+ }
525
+
526
+ if (this.edit_place_here !== "")
426
527
  {
427
- html: `<button id = "${this.modalId}-edit-btn" type="button" class="btn btn-sm btn-outline-secondary" onclick = "this.editClicked ();">Edit</button>`,
428
- documentSelector: `hot-place-here[name="dashboardHeader"]`
429
- },
528
+ outputObj.push ({
529
+ html: `<button id = "${this.modalId}-edit-btn" type="button" class="btn btn-sm btn-outline-secondary" onclick = "this.editClicked ();">${this.edit_text}</button>`,
530
+ documentSelector: `hot-place-here[name="${this.edit_place_here}"]`
531
+ });
532
+ }
533
+
534
+ if (this.remove_place_here !== "")
430
535
  {
431
- html: `<button id = "${this.modalId}-remove-btn" type="button" class="btn btn-sm btn-outline-secondary" onclick = "this.removeClicked ();">Remove</button>`,
432
- documentSelector: `hot-place-here[name="dashboardHeader"]`
433
- }]);
536
+ outputObj.push ({
537
+ html: `<button id = "${this.modalId}-remove-btn" type="button" class="btn btn-sm btn-outline-secondary" onclick = "this.removeClicked ();">${this.remove_text}</button>`,
538
+ documentSelector: `hot-place-here[name="${this.remove_place_here}"]`
539
+ });
540
+ }
541
+
542
+ return (outputObj);
434
543
  }
435
544
  }
@@ -277,6 +277,12 @@ export class AdminTable extends HotComponent
277
277
  */
278
278
  addRow (fields: { [name: string]: any }[])
279
279
  {
280
+ if (fields == null)
281
+ return;
282
+
283
+ if (fields.length == 0)
284
+ return;
285
+
280
286
  let tbody = this.htmlElements[1].getElementsByTagName ("tbody")[0];
281
287
  let index: number = this.rowElements.length;
282
288
  let rowStr = `<tr onclick = "this.parentNode.parentNode.parentNode.parentNode.hotComponent.selectRow (this, ${index});">`;
@@ -10,7 +10,7 @@ export class AdminText extends HotComponent
10
10
  * The classes to set for the input.
11
11
  * @default "form-control"
12
12
  */
13
- class: string;
13
+ css_class: string;
14
14
 
15
15
  constructor (copy: HotComponent | HotStaq, api: HotAPI)
16
16
  {
@@ -18,7 +18,7 @@ export class AdminText extends HotComponent
18
18
 
19
19
  this.tag = "admin-text";
20
20
  this.no_output = "0";
21
- this.class = "form-control"
21
+ this.css_class = "form-control"
22
22
  }
23
23
 
24
24
  /**
@@ -46,7 +46,7 @@ export class AdminText extends HotComponent
46
46
  value = this.value;
47
47
 
48
48
  if (this.no_output === "1")
49
- return (`<div><input class="${this.class}" type = "hidden" value = "${value}" /></div>`);
49
+ return (`<div><input class="${this.css_class}" type = "hidden" value = "${value}" /></div>`);
50
50
 
51
51
  const field = this.htmlElements[0].getAttribute ("hot-field");
52
52
  let field_type = this.htmlElements[0].getAttribute ("hot-field-type");
@@ -56,7 +56,7 @@ export class AdminText extends HotComponent
56
56
 
57
57
  return (`<div>
58
58
  <label class="form-label">${this.inner}</label>
59
- <input class="${this.class}" type = "text" hot-field = "${field}" hot-field-type = "${field_type}" value = "${value}" />
59
+ <input class="${this.css_class}" type = "text" hot-field = "${field}" hot-field-type = "${field_type}" value = "${value}" />
60
60
  </div>`);
61
61
  }
62
62
  }