blob: c284de3fe60b264a279c476193c768700fde8074 [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 /**
45 * Override click action of the menu item.
46 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000047 onclick : function (e) {
48 var menu = this.menu();
49 menu.hide();
50 e.halt();
51 if (menu.info() !== undefined)
Akrond67d45b2017-05-18 21:47:38 +020052 menu.info().addTree(this._foundry, this._layer);
Nils Diewald0e6992a2015-04-14 20:13:52 +000053 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000054
55 // Initialize tree menu item.
Nils Diewald0e6992a2015-04-14 20:13:52 +000056 _init : function (params) {
57 if (params[0] === undefined)
Akrond67d45b2017-05-18 21:47:38 +020058 throw new Error("Missing parameters");
Nils Diewald0e6992a2015-04-14 20:13:52 +000059
60 this._name = params[0];
61 this._foundry = params[1];
62 this._layer = params[2];
63 this._content = document.createTextNode(this._name);
64 this._lcField = ' ' + this.content().textContent.toLowerCase();
65 return this;
66 }
67 };
68});