jellyfish-web/src/scripts/searchtab.js

58 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-05-04 12:44:12 +02:00
define(['searchFields', 'searchResults', 'events'], function (SearchFields, SearchResults, events) {
'use strict';
2018-10-23 01:05:09 +03:00
2020-07-24 17:18:28 +02:00
SearchFields = SearchFields.default || SearchFields;
SearchResults = SearchResults.default || SearchResults;
2018-10-23 01:05:09 +03:00
function init(instance, tabContent, options) {
2019-10-08 01:03:29 +03:00
tabContent.innerHTML = '<div class="padded-left padded-right searchFields"></div><div class="searchResults padded-top" style="padding-top:1.5em;"></div>';
instance.searchFields = new SearchFields({
2020-05-04 12:44:12 +02:00
element: tabContent.querySelector('.searchFields')
2019-10-08 01:03:29 +03:00
});
instance.searchResults = new SearchResults({
2020-05-04 12:44:12 +02:00
element: tabContent.querySelector('.searchResults'),
2018-10-23 01:05:09 +03:00
serverId: ApiClient.serverId(),
parentId: options.parentId,
collectionType: options.collectionType
2019-10-08 01:03:29 +03:00
});
2020-05-04 12:44:12 +02:00
events.on(instance.searchFields, 'search', function (e, value) {
2019-10-08 01:03:29 +03:00
instance.searchResults.search(value);
});
2018-10-23 01:05:09 +03:00
}
function SearchTab(view, tabContent, options) {
var self = this;
2019-10-08 01:03:29 +03:00
options = options || {};
init(this, tabContent, options);
self.preRender = function () {};
self.renderTab = function () {
2018-10-23 01:05:09 +03:00
var searchFields = this.searchFields;
2019-10-08 01:03:29 +03:00
if (searchFields) {
searchFields.focus();
}
};
2018-10-23 01:05:09 +03:00
}
2019-10-08 01:03:29 +03:00
SearchTab.prototype.destroy = function () {
2018-10-23 01:05:09 +03:00
var searchFields = this.searchFields;
2019-10-08 01:03:29 +03:00
if (searchFields) {
searchFields.destroy();
}
this.searchFields = null;
2018-10-23 01:05:09 +03:00
var searchResults = this.searchResults;
2019-10-08 01:03:29 +03:00
if (searchResults) {
searchResults.destroy();
}
this.searchResults = null;
};
return SearchTab;
});