Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | define(['menu/item'], function (itemClass) { |
| 2 | /** |
| 3 | * Menu item for tree view choice. |
| 4 | */ |
| 5 | |
| 6 | return { |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame^] | 7 | |
| 8 | /** |
| 9 | * Create new menu item |
| 10 | * for tree views. |
| 11 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 12 | create : function (params) { |
| 13 | return Object.create(itemClass) |
| 14 | .upgradeTo(this)._init(params); |
| 15 | }, |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame^] | 16 | |
| 17 | /** |
| 18 | * Get or set the content of the |
| 19 | * menu item. |
| 20 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 21 | content : function (content) { |
| 22 | if (arguments.length === 1) { |
| 23 | this._content = content; |
| 24 | }; |
| 25 | return this._content; |
| 26 | }, |
| 27 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame^] | 28 | /** |
| 29 | * The foundry attribute of the menu item. |
| 30 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 31 | foundry : function () { |
| 32 | return this._foundry; |
| 33 | }, |
| 34 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame^] | 35 | /** |
| 36 | * The layer attribute of the menu item. |
| 37 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 38 | layer : function () { |
| 39 | return this._layer; |
| 40 | }, |
| 41 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame^] | 42 | /** |
| 43 | * Override click action of the menu item. |
| 44 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 45 | 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 Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame^] | 52 | |
| 53 | // Initialize tree menu item. |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 54 | _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 | }); |