Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | // Field menu item |
| 2 | define(['menu/item'], function (itemClass) { |
| 3 | return { |
| 4 | create : function (params) { |
| 5 | return Object.create(itemClass) |
| 6 | .upgradeTo(this) |
| 7 | ._init(params); |
| 8 | }, |
| 9 | |
| 10 | _init : function (params) { |
| 11 | if (params[0] === undefined) |
| 12 | throw new Error("Missing parameters"); |
| 13 | |
| 14 | this._name = params[0]; |
| 15 | this._value = params[1]; |
| 16 | this._type = params[2]; |
| 17 | |
| 18 | this._lcField = ' ' + this._name.toLowerCase(); |
| 19 | |
| 20 | return this; |
| 21 | }, |
| 22 | |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame^] | 23 | onclick : function (e) { |
| 24 | this.menu().release( |
| 25 | this._name, |
| 26 | this._value, |
| 27 | this._type |
| 28 | ); |
| 29 | e.halt(); |
| 30 | }, |
| 31 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 32 | name : function () { |
| 33 | return this._name; |
| 34 | }, |
| 35 | |
| 36 | type : function () { |
| 37 | return this._type; |
| 38 | }, |
| 39 | |
| 40 | element : function () { |
| 41 | // already defined |
| 42 | if (this._element !== undefined) |
| 43 | return this._element; |
| 44 | |
| 45 | // Create list item |
| 46 | var li = document.createElement("li"); |
| 47 | li.setAttribute("data-type", this._type); |
| 48 | li.setAttribute("data-value", this._value); |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame^] | 49 | |
| 50 | // Connect action |
| 51 | li["onclick"] = this.onclick.bind(this); |
| 52 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 53 | li.appendChild(document.createTextNode(this._name)); |
| 54 | return this._element = li; |
| 55 | } |
| 56 | }; |
| 57 | }); |