blob: 68ffe8c78d1432a1b39a0cdaa906277e0119bd62 [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
Nils Diewald7148c6f2015-05-04 15:07:53 +000030 /**
31 * The foundry attribute of the menu item.
32 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000033 foundry : function () {
34 return this._foundry;
35 },
36
Nils Diewald7148c6f2015-05-04 15:07:53 +000037 /**
38 * The layer attribute of the menu item.
39 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000040 layer : function () {
41 return this._layer;
42 },
43
Nils Diewald7148c6f2015-05-04 15:07:53 +000044 /**
Akron0988d882017-11-10 16:13:12 +010045 * The type attribute of the menu item.
46 * Is either "spans" or "rels".
47 */
48 type : function () {
49 return this._type;
50 },
51
52 /**
Nils Diewald7148c6f2015-05-04 15:07:53 +000053 * Override click action of the menu item.
54 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000055 onclick : function (e) {
56 var menu = this.menu();
57 menu.hide();
58 e.halt();
Akron0988d882017-11-10 16:13:12 +010059 if (menu.info() !== undefined) {
Akron151bc872018-02-02 14:04:15 +010060 menu.info().showTree(this._foundry, this._layer, this._type);
Akron0988d882017-11-10 16:13:12 +010061 };
Nils Diewald0e6992a2015-04-14 20:13:52 +000062 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000063
64 // Initialize tree menu item.
Nils Diewald0e6992a2015-04-14 20:13:52 +000065 _init : function (params) {
66 if (params[0] === undefined)
Akrond67d45b2017-05-18 21:47:38 +020067 throw new Error("Missing parameters");
Nils Diewald0e6992a2015-04-14 20:13:52 +000068
69 this._name = params[0];
70 this._foundry = params[1];
71 this._layer = params[2];
Akron0988d882017-11-10 16:13:12 +010072 this._type = params[3];
Nils Diewald0e6992a2015-04-14 20:13:52 +000073 this._content = document.createTextNode(this._name);
74 this._lcField = ' ' + this.content().textContent.toLowerCase();
75 return this;
76 }
77 };
78});