From 1883a9bc632f3ab22ce75ef630e61783646c6f2a Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Fri, 4 Dec 2020 14:16:11 +0100 Subject: [PATCH] Start redesign of RessourceLists --- web/app/static/js/nopaque.lists.new.js | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 web/app/static/js/nopaque.lists.new.js diff --git a/web/app/static/js/nopaque.lists.new.js b/web/app/static/js/nopaque.lists.new.js new file mode 100644 index 00000000..564bae45 --- /dev/null +++ b/web/app/static/js/nopaque.lists.new.js @@ -0,0 +1,68 @@ +class RessourceList extends List { + constructor(idOrElement, options) { + super(idOrElement, {...RessourceList.options['default'], ...(options ? options : {})}); + } + + _init(ressources) { + this.clear(); + this._add(Object.values(ressources)); + this.sort("id", {order: "desc"}); + } + + + _update(patch) { + let item, pathArray; + + for (let operation of patch) { + /* + * '/{ressourceName}/{ressourceId}/...' -> ['{ressourceId}', ...] + * Example: '/jobs/1/status' -> ['1', 'status'] + */ + pathArray = operation.path.split("/").slice(2); + switch(operation.op) { + case "add": + this.add_handler([operation.value]); + break; + case "remove": + this.remove_handler(pathArray[0]); + break; + case "replace": + this.replace_handler(pathArray[0], pathArray[1], operation.value); + break; + default: + break; + } + } + } + + add_handler(values, callback) { + if (this.hasOwnProperty('add_')) { + this.add_(values, callback); + } else { + this.add(values, callback); + } + } + + remove_handler(id) { + if (this.hasOwnProperty('remove_')) { + this.remove_(id); + } else { + this.remove(id); + } + } + + replace_handler(id, valueName, newValue) { + let item = this.get('id', id); + if (this.hasOwnProperty('add_')) + item.values({valueName: operation.value}); + } +} + + +RessourceList.options = { + // default RessourceList options + default: {page: 5, pagination: [{innerWindow: 4, outerWindow: 1}]}, +}; + + +export { RessourceList, };