blob: 9d7968f19a3baed1071dd830b8acd53eb49e2ecb [file] [log] [blame]
Akron537bc522018-07-13 19:06:27 +02001/**
2 * Create a panel for a certain aspect of the system, like
3 * the result, a match, or the VC.
Akron4d926f12018-07-16 15:30:25 +02004 *
5 * The buttons are associated with the panel's views,
6 * though they are integrated independently
Akron537bc522018-07-13 19:06:27 +02007 */
8define(['buttongroup', 'util'], function (buttonGroupClass) {
9
10 return {
Akron4d926f12018-07-16 15:30:25 +020011 create : function (classes) {
12 return Object.create(this)._init(classes);
Akron537bc522018-07-13 19:06:27 +020013 },
14
Akron4d926f12018-07-16 15:30:25 +020015
16 // Override by inheriting object
17 _init : function (classes) {
Akron537bc522018-07-13 19:06:27 +020018 this.views = [];
19
Akron537bc522018-07-13 19:06:27 +020020 /**
21 * Main action buttons for the panel,
22 * may be at the bottom (for matches)
23 * or as tabs (for the result).
24 */
Akron4d926f12018-07-16 15:30:25 +020025
26 this._classes = classes;
27 var c = ['action', 'button-panel'];
28 if (classes)
29 c.push.apply(c,classes);
30 this.actions = buttonGroupClass.create(c).bind(this);
31
32 // Warning: This is circular
33 this.actions.panel = this;
Akron537bc522018-07-13 19:06:27 +020034 return this;
35 },
36
Akron4d926f12018-07-16 15:30:25 +020037
Akron537bc522018-07-13 19:06:27 +020038 /**
39 * The element of the panel
40 */
41 element : function () {
42 if (this._element)
43 return this._element;
44
45 // Create panel element
46 var e = document.createElement('div');
Akron4d926f12018-07-16 15:30:25 +020047 var cl = e.classList;
48 cl.add('panel');
49
50 if (this._classes)
51 cl.add.apply(cl, this._classes);
Akron537bc522018-07-13 19:06:27 +020052
Akron4d926f12018-07-16 15:30:25 +020053 this._viewE = e.addE('div');
Akron3967d342018-07-14 08:35:12 +020054
Akron4d926f12018-07-16 15:30:25 +020055 // Per default the action buttons are below the view
56 // and integrated
57 var aElem = this.actions.element();
58 if (!aElem.parentNode)
59 e.appendChild(aElem);
Akron3967d342018-07-14 08:35:12 +020060
Akron537bc522018-07-13 19:06:27 +020061 this._element = e;
62 return e;
63 },
64
65
Akron4d926f12018-07-16 15:30:25 +020066 /*
Akron3967d342018-07-14 08:35:12 +020067 * The element of the views
68 */
Akron4d926f12018-07-16 15:30:25 +020069 _viewElement : function () {
Akron3967d342018-07-14 08:35:12 +020070 this.element();
71 return this._viewE;
72 },
73
Akron3967d342018-07-14 08:35:12 +020074 /**
Akron537bc522018-07-13 19:06:27 +020075 * Add a view to the panel
76 */
77 add : function (view) {
78
79 // Add view to views list
80 this.views.push(view);
81
82 // Append element to panel element
83
Akron4d926f12018-07-16 15:30:25 +020084 this._viewElement().appendChild(
Akron537bc522018-07-13 19:06:27 +020085 view.element()
86 );
87
88 view.panel = this;
89 },
90
91 /**
92 * Delete a closed view from panel
93 */
94 delView : function (view) {
95 for (i in this.views) {
96 if (this.views[i] === view) {
97 this.views[i] = undefined;
98 }
99 }
100 },
Akron537bc522018-07-13 19:06:27 +0200101 }
102});