blob: 7922bbd452bae9f3a8cb53459fa778078e04a4ce [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001// Field menu item
2define(['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 Diewald1fcb2ad2015-04-20 19:19:18 +000023 onclick : function (e) {
24 this.menu().release(
25 this._name,
26 this._value,
27 this._type
28 );
29 e.halt();
30 },
31
Nils Diewald0e6992a2015-04-14 20:13:52 +000032 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 Diewald1fcb2ad2015-04-20 19:19:18 +000049
50 // Connect action
51 li["onclick"] = this.onclick.bind(this);
52
Nils Diewald0e6992a2015-04-14 20:13:52 +000053 li.appendChild(document.createTextNode(this._name));
54 return this._element = li;
55 }
56 };
57});