Skip to content

Commit

Permalink
Add the semantic search MultibranchView (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgonggrijp committed May 19, 2021
1 parent 5375f24 commit 063a9a8
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
34 changes: 34 additions & 0 deletions frontend/src/semantic-search/multibranch-row-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import RemoveButton from '../forms/remove-button-view';

import Chain from './chain-view';

/**
* Every row in a Multibranch is a Chain with a RemoveButton in front.
*/
export default class MultibranchRow extends Chain {
removeButton: RemoveButton;

initialize(): void {
this.removeButton = new RemoveButton().on('click', this.close, this);
super.initialize();
}

beforeRender(): this {
this.removeButton.$el.detach();
return this;
}

afterRender(): this {
this.removeButton.$el.prependTo(this.$el);
return this;
}

remove(): this {
this.removeButton.remove();
return super.remove();
}

close(): void {
this.trigger('close', this, this.model);
}
}
40 changes: 40 additions & 0 deletions frontend/src/semantic-search/multibranch-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { extend } from 'lodash';

import Model from '../core/model';
import Collection from '../core/collection';
import { CollectionView } from '../core/view';

import MultibranchRow from './multibranch-row-view';

/**
* .rowManager of Chains in a Multifield.
*/
export default class Multibranch extends CollectionView {
initialize(): void {
if (!this.collection) {
this.collection = new Collection();
this.addRow();
}
this.initItems().render().initCollectionEvents();
}

makeItem(model: Model): MultibranchRow {
return new MultibranchRow({ model }).on('close', this.removeRow, this);
}

addRow(): this {
this.collection.push(
{ precedent: this.model.get('precedent') } as unknown as Model
);
return this;
}

removeRow(row: MultibranchRow, model: Model): this {
this.collection.remove(model);
return this;
}
}

extend(Multibranch.prototype, {
className: 'field',
});

0 comments on commit 063a9a8

Please sign in to comment.