blob: 5aa96ad83256289ebeb024bd11c601d61e2cd08c [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.
4 */
5define(['buttongroup', 'util'], function (buttonGroupClass) {
6
7 return {
8
9 // TODO:
10 // Support classes
11 create : function () {
12 return Object.create(this)._init();
13 },
14
15 _init : function () {
16 // ...
17 this.views = [];
18
19
20 /**
21 * Main action buttons for the panel,
22 * may be at the bottom (for matches)
23 * or as tabs (for the result).
24 */
25 this.actions = buttonGroupClass.create(['action', 'panel']);
26 return this;
27 },
28
29 /**
30 * The element of the panel
31 */
32 element : function () {
33 if (this._element)
34 return this._element;
35
36 // Create panel element
37 var e = document.createElement('div');
38 e.classList.add('panel');
39
40 e.appendChild(this.actions.element());
41
42 this._element = e;
43 return e;
44 },
45
46
47 /**
48 * Add a view to the panel
49 */
50 add : function (view) {
51
52 // Add view to views list
53 this.views.push(view);
54
55 // Append element to panel element
56
57 this.element().appendChild(
58 view.element()
59 );
60
61 view.panel = this;
62 },
63
64 /**
65 * Delete a closed view from panel
66 */
67 delView : function (view) {
68 for (i in this.views) {
69 if (this.views[i] === view) {
70 this.views[i] = undefined;
71 }
72 }
73 },
74
75 /**
76 * Elements before the action buttons
77 */
78 beforeActions : function (element) {
79 if (arguments.length > 0)
80 this._beforeActions = element;
81
82 return this._beforeActions;
83 },
84
85 /**
86 * Element after the action buttons
87 */
88 afterActions : function (element) {
89 if (arguments.length > 0)
90 this._afterActions = element;
91
92 return this._afterActions;
93 }
94 }
95});