blob: c2c229309a32bc3650e2cf08128b0146e60406ff [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
Akron3967d342018-07-14 08:35:12 +020011 create : function (viewpos) {
12 return Object.create(this)._init(viewpos);
Akron537bc522018-07-13 19:06:27 +020013 },
14
Akron3967d342018-07-14 08:35:12 +020015 _init : function (viewpos) {
Akron537bc522018-07-13 19:06:27 +020016 this.views = [];
17
Akron3967d342018-07-14 08:35:12 +020018 this._viewpos = (viewpos == 'down' ? viewpos : 'up');
19
Akron537bc522018-07-13 19:06:27 +020020
21 /**
22 * Main action buttons for the panel,
23 * may be at the bottom (for matches)
24 * or as tabs (for the result).
25 */
26 this.actions = buttonGroupClass.create(['action', 'panel']);
27 return this;
28 },
29
30 /**
31 * The element of the panel
32 */
33 element : function () {
34 if (this._element)
35 return this._element;
36
37 // Create panel element
38 var e = document.createElement('div');
39 e.classList.add('panel');
40
Akron3967d342018-07-14 08:35:12 +020041 if (this._viewpos == 'up') {
42 this._viewE = e.addE('div');
43 };
44
Akron537bc522018-07-13 19:06:27 +020045 e.appendChild(this.actions.element());
46
Akron3967d342018-07-14 08:35:12 +020047 if (this._viewpos == 'down') {
48 this._viewE = e.addE('div');
49 };
50
Akron537bc522018-07-13 19:06:27 +020051 this._element = e;
52 return e;
53 },
54
55
56 /**
Akron3967d342018-07-14 08:35:12 +020057 * The element of the views
58 */
59 viewElement : function () {
60 this.element();
61 return this._viewE;
62 },
63
64
65 /**
Akron537bc522018-07-13 19:06:27 +020066 * Add a view to the panel
67 */
68 add : function (view) {
69
70 // Add view to views list
71 this.views.push(view);
72
73 // Append element to panel element
74
Akron3967d342018-07-14 08:35:12 +020075 this.viewElement().appendChild(
Akron537bc522018-07-13 19:06:27 +020076 view.element()
77 );
78
79 view.panel = this;
80 },
81
82 /**
83 * Delete a closed view from panel
84 */
85 delView : function (view) {
86 for (i in this.views) {
87 if (this.views[i] === view) {
88 this.views[i] = undefined;
89 }
90 }
91 },
92
93 /**
94 * Elements before the action buttons
Akron3967d342018-07-14 08:35:12 +020095 * TODO:
96 * Maybe rename actionLine?
Akron537bc522018-07-13 19:06:27 +020097 */
98 beforeActions : function (element) {
99 if (arguments.length > 0)
100 this._beforeActions = element;
101
102 return this._beforeActions;
103 },
104
105 /**
106 * Element after the action buttons
107 */
108 afterActions : function (element) {
109 if (arguments.length > 0)
110 this._afterActions = element;
111
112 return this._afterActions;
113 }
114 }
115});