-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the semantic search MultibranchView (#455)
- Loading branch information
1 parent
5375f24
commit 063a9a8
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); |