-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial work on componentizing search, re #4771
- Loading branch information
Showing
12 changed files
with
571 additions
and
355 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
arches/app/media/js/views/components/search/term-filter.js
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,80 @@ | ||
define([ | ||
'knockout', | ||
'underscore', | ||
'views/search/base-filter', | ||
'bindings/term-search' | ||
], function(ko, _, BaseFilter, termSearchComponent) { | ||
return ko.components.register('term-filter', { | ||
viewModel: BaseFilter.extend({ | ||
initialize: function(options) { | ||
BaseFilter.prototype.initialize.call(this, options); | ||
|
||
this.name = 'Term Filter'; | ||
|
||
this.filter.terms = ko.observableArray(); | ||
this.filter.tags = ko.observableArray(); | ||
}, | ||
|
||
restoreState: function(query) { | ||
var doQuery = false; | ||
if ('termFilter' in query) { | ||
query.termFilter = JSON.parse(query.termFilter); | ||
if (query.termFilter.length > 0) { | ||
query.termFilter.forEach(function(term){ | ||
term.inverted = ko.observable(term.inverted); | ||
}); | ||
this.filter.terms(query.termFilter); | ||
} | ||
|
||
doQuery = true; | ||
} | ||
return doQuery; | ||
}, | ||
|
||
clear: function() { | ||
this.filter.terms.removeAll(); | ||
}, | ||
|
||
appendFilters: function(filterParams) { | ||
var terms = _.filter(this.filter.terms(), function(term){ | ||
return term.type === 'string' || term.type === 'concept' || term.type === 'term'; | ||
}, this); | ||
|
||
if(terms.length > 0){ | ||
filterParams.termFilter = ko.toJSON(terms); | ||
} | ||
|
||
return terms.length > 0; | ||
}, | ||
|
||
addTag: function(term, type, inverted){ | ||
this.filter.tags.unshift({ | ||
inverted: inverted, | ||
type: type, | ||
context: '', | ||
context_label: '', | ||
id: term, | ||
text: term, | ||
value: term | ||
}); | ||
}, | ||
|
||
removeTag: function(term){ | ||
this.filter.tags.remove(function(term_item){ | ||
return term_item.id == term && term_item.text == term && term_item.value == term; | ||
}); | ||
}, | ||
|
||
hasTag: function(tag_text){ | ||
var has_tag = false; | ||
this.filter.terms().forEach(function(term_item){ | ||
if (term_item.text == tag_text) { | ||
has_tag = true; | ||
} | ||
}); | ||
return has_tag; | ||
} | ||
}), | ||
template: { require: 'text!templates/views/search/term-filter.htm' } | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.