blob: 9a4b952e5b6905927e49d94ed8cb9bf9833da10c [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)
14 .upgradeTo(this)._init(params);
15 },
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) {
23 this._content = content;
24 };
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)
50 menu.info().addTree(this._foundry, this._layer);
51 },
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)
56 throw new Error("Missing parameters");
57
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});