2017-03-18 15:33:49 +01:00
|
|
|
define(["helper"], function (helper) {
|
2015-07-08 00:36:57 +02:00
|
|
|
return function (name, key, value, f) {
|
2017-03-17 03:14:57 +01:00
|
|
|
var negate = false;
|
|
|
|
var refresh;
|
2015-07-08 17:20:56 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var label = document.createElement("label");
|
|
|
|
var strong = document.createElement("strong");
|
|
|
|
label.textContent = name + " ";
|
|
|
|
label.appendChild(strong);
|
2015-07-08 20:50:26 +02:00
|
|
|
|
2015-07-08 00:36:57 +02:00
|
|
|
function run(d) {
|
2017-03-18 15:33:49 +01:00
|
|
|
var o = helper.dictGet(d, key.slice(0));
|
2015-07-08 00:36:57 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
if (f) {
|
|
|
|
o = f(o);
|
|
|
|
}
|
2015-07-08 00:36:57 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
return o === value ? !negate : negate;
|
2015-07-08 17:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setRefresh(f) {
|
2017-03-17 03:14:57 +01:00
|
|
|
refresh = f;
|
2015-07-08 00:36:57 +02:00
|
|
|
}
|
|
|
|
|
2015-07-08 17:20:56 +02:00
|
|
|
function draw(el) {
|
2017-03-17 03:14:57 +01:00
|
|
|
if (negate) {
|
|
|
|
el.parentNode.classList.add("not");
|
|
|
|
} else {
|
|
|
|
el.parentNode.classList.remove("not");
|
|
|
|
}
|
2015-07-08 20:50:26 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
strong.textContent = (negate ? "¬" : "" ) + value;
|
2015-07-08 00:36:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function render(el) {
|
2017-03-17 03:14:57 +01:00
|
|
|
el.appendChild(label);
|
|
|
|
draw(el);
|
2015-07-08 17:20:56 +02:00
|
|
|
|
|
|
|
label.onclick = function () {
|
2017-03-17 03:14:57 +01:00
|
|
|
negate = !negate;
|
2015-07-08 17:20:56 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
draw(el);
|
2015-07-08 17:20:56 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
if (refresh) {
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
};
|
2015-07-08 00:36:57 +02:00
|
|
|
}
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
return {
|
|
|
|
run: run,
|
|
|
|
setRefresh: setRefresh,
|
|
|
|
render: render
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|