Files
edx-platform/lms/static/js/edxnotes/views/tabs/search_results.js
Syed Ali Abbas Zaidi 8480dbc228 chore: apply amnesty on existing not fixable issues (#32215)
* fix: eslint operator-linebreak issue

* fix: eslint quotes issue

* fix: react jsx indent and props issues

* fix: eslint trailing spaces issues

* fix: eslint line around directives issue

* fix: eslint semi rule

* fix: eslint newline per chain rule

* fix: eslint space infix ops rule

* fix: eslint space-in-parens issue

* fix: eslint space before function paren issue

* fix: eslint space before blocks issue

* fix: eslint arrow body style issue

* fix: eslint dot-location issue

* fix: eslint quotes issue

* fix: eslint quote props issue

* fix: eslint operator assignment issue

* fix: eslint new line after import issue

* fix: indent issues

* fix: operator assignment issue

* fix: all autofixable eslint issues

* fix: all react related fixable issues

* fix: autofixable eslint issues

* chore: remove all template literals

* fix: remaining autofixable issues

* chore: apply amnesty on all existing issues

* fix: failing xss-lint issues

* refactor: apply amnesty on remaining issues

* refactor: apply amnesty on new issues

* fix: remove file level suppressions

* refactor: apply amnesty on new issues
2023-08-07 19:13:19 +05:00

157 lines
5.7 KiB
JavaScript

// eslint-disable-next-line no-shadow-restricted-names
(function(define, undefined) {
'use strict';
define([
'jquery', 'underscore', 'gettext', 'js/edxnotes/views/tab_panel', 'js/edxnotes/views/tab_view',
'js/edxnotes/views/search_box', 'edx-ui-toolkit/js/utils/html-utils', 'edx-ui-toolkit/js/utils/string-utils'
], function($, _, gettext, TabPanelView, TabView, SearchBoxView, HtmlUtils, StringUtils) {
var view = 'Search Results';
var SearchResultsView = TabView.extend({
PanelConstructor: TabPanelView.extend({
id: 'search-results-panel',
title: view,
className: function() {
return [
TabPanelView.prototype.className,
'note-group'
].join(' ');
},
renderContent: function() {
this.$el.append(HtmlUtils.HTML(this.getNotes(this.collection.toArray())).toString());
return this;
}
}),
NoResultsViewConstructor: TabPanelView.extend({
id: 'no-results-panel',
title: 'No results found',
className: function() {
return [
TabPanelView.prototype.className,
'note-group'
].join(' ');
},
renderContent: function() {
var message = gettext('No results found for "{query_string}". Please try searching again.');
this.$el.append($('<p />', {
text: StringUtils.interpolate(message, {
query_string: this.options.searchQuery
}, true)
}));
return this;
}
}),
tabInfo: {
identifier: 'view-search-results',
name: gettext('Search Results'),
icon: 'fa fa-search',
is_closable: true,
view: view
},
initialize: function(options) {
this.options = _.extend({}, options);
_.bindAll(this, 'onBeforeSearchStart', 'onSearch', 'onSearchError');
TabView.prototype.initialize.call(this, options);
this.searchResults = null;
this.searchBox = new SearchBoxView({
el: document.getElementById('search-notes-form'),
debug: this.options.debug,
perPage: this.options.perPage,
beforeSearchStart: this.onBeforeSearchStart,
search: this.onSearch,
error: this.onSearchError
});
},
renderContent: function() {
this.getLoadingIndicator().focus();
return this.searchPromise.done(_.bind(function() {
this.contentView = this.getSubView();
if (this.contentView) {
this.$('.wrapper-tabs').append(this.contentView.render().$el);
}
}, this));
},
getSubView: function() {
var collection = this.getCollection();
if (collection) {
if (collection.length) {
return new this.PanelConstructor({
collection: collection,
searchQuery: this.searchResults.searchQuery,
scrollToTag: this.options.scrollToTag,
createHeaderFooter: this.options.createHeaderFooter
});
} else {
return new this.NoResultsViewConstructor({
searchQuery: this.searchResults.searchQuery
});
}
}
return null;
},
getCollection: function() {
if (this.searchResults) {
return this.searchResults.collection;
}
return null;
},
onClose: function() {
this.searchResults = null;
this.searchBox.clearInput();
},
onBeforeSearchStart: function() {
this.searchDeferred = $.Deferred();
this.searchPromise = this.searchDeferred.promise();
this.hideErrorMessage();
this.searchResults = null;
// If tab doesn't exist, creates it.
if (!this.tabModel) {
this.createTab();
}
// If tab is not already active, makes it active
if (!this.tabModel.isActive()) {
this.tabModel.activate();
} else {
this.render();
}
},
onSearch: function(collection, searchQuery) {
this.searchResults = {
collection: collection,
searchQuery: searchQuery
};
if (this.searchDeferred) {
this.searchDeferred.resolve();
}
if (this.contentView) {
this.contentView.$el.focus();
}
},
onSearchError: function(errorMessage) {
this.showErrorMessageHtml(errorMessage);
if (this.searchDeferred) {
this.searchDeferred.reject();
}
}
});
return SearchResultsView;
});
}).call(this, define || RequireJS.define);