Skip to content
Snippets Groups Projects
Commit 74fcfba3 authored by Maximilian Giller's avatar Maximilian Giller
Browse files

Expaneded menu interface for value exchange

parent 717b613a
No related branches found
No related tags found
No related merge requests found
...@@ -4,13 +4,66 @@ export default class ToolMenu { ...@@ -4,13 +4,66 @@ export default class ToolMenu {
constructor(tool) { constructor(tool) {
this.tool = tool; this.tool = tool;
this.menuId = this.tool.getKey() + "-menu"; this.menuId = this.tool.getKey() + "-menu";
this.warnings = false;
this.values = {};
} }
show() { show() {
jQuery("#" + this.menuId).removeClass("hidden"); this.getMenu().removeClass("hidden");
} }
hide() { hide() {
jQuery("#" + this.menuId).addClass("hidden"); this.getMenu().addClass("hidden");
}
beforeGet(key) {
if (this.warnings) {
console.warn('Method "beforeGet" not implemented.');
}
}
afterSet(key, value) {
if (this.warnings) {
console.warn('Method "afterSet" not implemented.');
}
}
value(key, newValue) {
// If key not defined
// (be it by giving no arguments, or giving it an undefined value)
// Return all values as dict.
if (key === undefined) {
return this.values;
}
// Is key valid?
// If not, create undefined entry
if (key in this.values == false) {
this.values[key] = undefined;
}
// If value not defined, returned specified value.
if (newValue === undefined) {
newValue = this.beforeGet(key);
if (newValue !== undefined) {
this.values[key] = newValue;
}
return this.values[key];
}
// If bot defined, store specified value.
else {
this.values[key] = newValue;
newValue = this.afterSet(key, newValue);
}
}
getChildren(selector) {
return this.getMenu().children(selector);
}
getMenu() {
return jQuery("#tool-menu #" + this.menuId);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment