mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 02:44:18 +00:00
Start redesign of RessourceLists
This commit is contained in:
parent
a2102a48ca
commit
1883a9bc63
68
web/app/static/js/nopaque.lists.new.js
Normal file
68
web/app/static/js/nopaque.lists.new.js
Normal file
@ -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, };
|
Loading…
Reference in New Issue
Block a user