blob: 422f3d72ef25db9846e2be8ec50f46eaf466e977 [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001define(['menu/item'], function (itemClass) {
Akron671fdb92017-09-12 18:09:46 +02002 "use strict";
3
Nils Diewald0e6992a2015-04-14 20:13:52 +00004 /**
5 * Menu item for tree view choice.
6 */
7
8 return {
Nils Diewald7148c6f2015-05-04 15:07:53 +00009
10 /**
11 * Create new menu item
12 * for tree views.
13 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000014 create : function (params) {
15 return Object.create(itemClass)
Akrond67d45b2017-05-18 21:47:38 +020016 .upgradeTo(this)._init(params);
Nils Diewald0e6992a2015-04-14 20:13:52 +000017 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000018
19 /**
20 * Get or set the content of the
21 * menu item.
22 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000023 content : function (content) {
24 if (arguments.length === 1) {
Akrond67d45b2017-05-18 21:47:38 +020025 this._content = content;
Nils Diewald0e6992a2015-04-14 20:13:52 +000026 };
27 return this._content;
28 },
29
Akronff1b1f32020-10-18 11:41:29 +020030
Nils Diewald7148c6f2015-05-04 15:07:53 +000031 /**
32 * The foundry attribute of the menu item.
33 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000034 foundry : function () {
35 return this._foundry;
36 },
37
Akronff1b1f32020-10-18 11:41:29 +020038
Nils Diewald7148c6f2015-05-04 15:07:53 +000039 /**
40 * The layer attribute of the menu item.
41 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000042 layer : function () {
43 return this._layer;
44 },
45
Akronff1b1f32020-10-18 11:41:29 +020046
Nils Diewald7148c6f2015-05-04 15:07:53 +000047 /**
Akron0988d882017-11-10 16:13:12 +010048 * The type attribute of the menu item.
49 * Is either "spans" or "rels".
50 */
51 type : function () {
52 return this._type;
53 },
54
Akronff1b1f32020-10-18 11:41:29 +020055
Akron0988d882017-11-10 16:13:12 +010056 /**
Nils Diewald7148c6f2015-05-04 15:07:53 +000057 * Override click action of the menu item.
58 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000059 onclick : function (e) {
Akronff1b1f32020-10-18 11:41:29 +020060 const menu = this.menu();
Nils Diewald0e6992a2015-04-14 20:13:52 +000061 menu.hide();
62 e.halt();
Akronff1b1f32020-10-18 11:41:29 +020063
Akron7f9a6a32018-07-18 15:05:23 +020064 if (menu.panel() !== undefined) {
65 menu.panel().addTree(this._foundry, this._layer, this._type);
Akron0988d882017-11-10 16:13:12 +010066 };
Nils Diewald0e6992a2015-04-14 20:13:52 +000067 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000068
Akronff1b1f32020-10-18 11:41:29 +020069
Nils Diewald7148c6f2015-05-04 15:07:53 +000070 // Initialize tree menu item.
Nils Diewald0e6992a2015-04-14 20:13:52 +000071 _init : function (params) {
72 if (params[0] === undefined)
Akrond67d45b2017-05-18 21:47:38 +020073 throw new Error("Missing parameters");
Nils Diewald0e6992a2015-04-14 20:13:52 +000074
Akronff1b1f32020-10-18 11:41:29 +020075 const t = this;
76
77 t._name = params[0];
78 t._foundry = params[1];
79 t._layer = params[2];
80 t._type = params[3];
81 t._content = document.createTextNode(t._name);
82 t._lcField = ' ' + t.content().textContent.toLowerCase();
83 return t;
Nils Diewald0e6992a2015-04-14 20:13:52 +000084 }
85 };
86});