blob: 9ddb1feb6513c523e9fbcf32732141936dfddb4d [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001define(['menu/item'], function (itemClass) {
2 /**
3 * Menu item for tree view choice.
4 */
5
6 return {
Nils Diewald7148c6f2015-05-04 15:07:53 +00007
8 /**
9 * Create new menu item
10 * for tree views.
11 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000012 create : function (params) {
13 return Object.create(itemClass)
Akrond67d45b2017-05-18 21:47:38 +020014 .upgradeTo(this)._init(params);
Nils Diewald0e6992a2015-04-14 20:13:52 +000015 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000016
17 /**
18 * Get or set the content of the
19 * menu item.
20 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000021 content : function (content) {
22 if (arguments.length === 1) {
Akrond67d45b2017-05-18 21:47:38 +020023 this._content = content;
Nils Diewald0e6992a2015-04-14 20:13:52 +000024 };
25 return this._content;
26 },
27
Nils Diewald7148c6f2015-05-04 15:07:53 +000028 /**
29 * The foundry attribute of the menu item.
30 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000031 foundry : function () {
32 return this._foundry;
33 },
34
Nils Diewald7148c6f2015-05-04 15:07:53 +000035 /**
36 * The layer attribute of the menu item.
37 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000038 layer : function () {
39 return this._layer;
40 },
41
Nils Diewald7148c6f2015-05-04 15:07:53 +000042 /**
43 * Override click action of the menu item.
44 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000045 onclick : function (e) {
46 var menu = this.menu();
47 menu.hide();
48 e.halt();
49 if (menu.info() !== undefined)
Akrond67d45b2017-05-18 21:47:38 +020050 menu.info().addTree(this._foundry, this._layer);
Nils Diewald0e6992a2015-04-14 20:13:52 +000051 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000052
53 // Initialize tree menu item.
Nils Diewald0e6992a2015-04-14 20:13:52 +000054 _init : function (params) {
55 if (params[0] === undefined)
Akrond67d45b2017-05-18 21:47:38 +020056 throw new Error("Missing parameters");
Nils Diewald0e6992a2015-04-14 20:13:52 +000057
58 this._name = params[0];
59 this._foundry = params[1];
60 this._layer = params[2];
61 this._content = document.createTextNode(this._name);
62 this._lcField = ' ' + this.content().textContent.toLowerCase();
63 return this;
64 }
65 };
66});