mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-04 04:12:45 +00:00 
			
		
		
		
	Enable auto initialization for ressource lists
This commit is contained in:
		@@ -5,7 +5,6 @@ class CorpusFileList extends RessourceList {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  init(user) {
 | 
			
		||||
    console.log(user);
 | 
			
		||||
    this._init(user.corpora[this.corpusId].files);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ class QueryResultList extends RessourceList {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  init(user) {
 | 
			
		||||
    super.init(user.query_results);
 | 
			
		||||
    super._init(user.query_results);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  onclick(event) {
 | 
			
		||||
 
 | 
			
		||||
@@ -4,8 +4,17 @@ class RessourceList {
 | 
			
		||||
   * a base class for concrete ressource list implementations.
 | 
			
		||||
   */
 | 
			
		||||
  constructor(listElement, options = {}) {
 | 
			
		||||
    this.list = new List(listElement, {...RessourceList.options, ...options});
 | 
			
		||||
    this.list.list.innerHTML = `
 | 
			
		||||
    let i;
 | 
			
		||||
 | 
			
		||||
    if (!(listElement.hasAttribute('id'))) {
 | 
			
		||||
      for (i = 0; true; i++) {
 | 
			
		||||
        if (document.querySelector(`ressource-list-${i}`)) {continue;}
 | 
			
		||||
        listElement.id = `ressource-list-${i}`;
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    this.listjs = new List(listElement, {...RessourceList.options, ...options});
 | 
			
		||||
    this.listjs.list.innerHTML = `
 | 
			
		||||
      <tr>
 | 
			
		||||
        <td class="row" colspan="100%">
 | 
			
		||||
          <div class="col s12"> </div>
 | 
			
		||||
@@ -31,9 +40,9 @@ class RessourceList {
 | 
			
		||||
        </td>
 | 
			
		||||
      </tr>
 | 
			
		||||
    `.trim();
 | 
			
		||||
    this.list.list.style.cursor = 'pointer';
 | 
			
		||||
    this.listjs.list.style.cursor = 'pointer';
 | 
			
		||||
    this.userId = listElement.dataset.userId;
 | 
			
		||||
    if (typeof this.onclick === 'function') {this.list.list.addEventListener('click', event => this.onclick(event));}
 | 
			
		||||
    if (typeof this.onclick === 'function') {this.listjs.list.addEventListener('click', event => this.onclick(event));}
 | 
			
		||||
    if (this.userId) {
 | 
			
		||||
      app.addEventListener('users.patch', patch => this.usersPatchHandler(patch));
 | 
			
		||||
      app.getUserById(this.userId).then(
 | 
			
		||||
@@ -44,7 +53,7 @@ class RessourceList {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  _init(ressources) {
 | 
			
		||||
    this.list.clear();
 | 
			
		||||
    this.listjs.clear();
 | 
			
		||||
    this.add(Object.values(ressources));
 | 
			
		||||
    let emptyListElementHTML = `
 | 
			
		||||
      <tr class="show-if-only-child">
 | 
			
		||||
@@ -54,7 +63,7 @@ class RessourceList {
 | 
			
		||||
        </td>
 | 
			
		||||
      </tr>
 | 
			
		||||
    `.trim();
 | 
			
		||||
    this.list.list.insertAdjacentHTML('afterbegin', emptyListElementHTML);
 | 
			
		||||
    this.listjs.list.insertAdjacentHTML('afterbegin', emptyListElementHTML);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  init(user) {throw 'Not implemented';}
 | 
			
		||||
@@ -66,17 +75,17 @@ class RessourceList {
 | 
			
		||||
  add(values) {
 | 
			
		||||
    let ressources = Array.isArray(values) ? values : [values];
 | 
			
		||||
    ressources = ressources.map(ressource => this.preprocessRessource(ressource));
 | 
			
		||||
    this.list.add(ressources, () => {
 | 
			
		||||
      this.list.sort('id', {order: 'desc'});
 | 
			
		||||
    this.listjs.add(ressources, () => {
 | 
			
		||||
      this.listjs.sort('id', {order: 'desc'});
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  remove(id) {
 | 
			
		||||
    this.list.remove('id', id);
 | 
			
		||||
    this.listjs.remove('id', id);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  replace(id, valueName, newValue) {
 | 
			
		||||
      this.list.get('id', id)[0].values({[valueName]: newValue});
 | 
			
		||||
      this.listjs.get('id', id)[0].values({[valueName]: newValue});
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
RessourceList.options = {page: 5, pagination: [{innerWindow: 4, outerWindow: 1}]};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user