Skip to content
Snippets Groups Projects
Commit 1883a9bc authored by Patrick Jentsch's avatar Patrick Jentsch
Browse files

Start redesign of RessourceLists

parent a2102a48
No related branches found
No related tags found
No related merge requests found
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, };
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