blob: 7922bbd452bae9f3a8cb53459fa778078e04a4ce [file] [log] [blame]
// Field menu item
define(['menu/item'], function (itemClass) {
return {
create : function (params) {
return Object.create(itemClass)
.upgradeTo(this)
._init(params);
},
_init : function (params) {
if (params[0] === undefined)
throw new Error("Missing parameters");
this._name = params[0];
this._value = params[1];
this._type = params[2];
this._lcField = ' ' + this._name.toLowerCase();
return this;
},
onclick : function (e) {
this.menu().release(
this._name,
this._value,
this._type
);
e.halt();
},
name : function () {
return this._name;
},
type : function () {
return this._type;
},
element : function () {
// already defined
if (this._element !== undefined)
return this._element;
// Create list item
var li = document.createElement("li");
li.setAttribute("data-type", this._type);
li.setAttribute("data-value", this._value);
// Connect action
li["onclick"] = this.onclick.bind(this);
li.appendChild(document.createTextNode(this._name));
return this._element = li;
}
};
});