diff --git a/app/assets/javascripts/repositories/repository_datatable.js b/app/assets/javascripts/repositories/repository_datatable.js index 4a7607edf..25ffa9b50 100644 --- a/app/assets/javascripts/repositories/repository_datatable.js +++ b/app/assets/javascripts/repositories/repository_datatable.js @@ -24,8 +24,6 @@ var RepositoryDatatable = (function(global) { // Tells whether we're currently viewing or editing table var currentMode = 'viewMode'; - // var selectedRecord; - // Extend datatables API with searchable options // (http://stackoverflow.com/questions/39912395/datatables-dynamically-set-columns-searchable) $.fn.dataTable.Api.register('isColumnSearchable()', function(colSelector) { @@ -419,13 +417,7 @@ var RepositoryDatatable = (function(global) { return JSON.stringify(d); }, global: false, - type: 'POST', - error: function(e) { - $('#filtersDropdownButton').removeClass('active-filters'); - $('#saveRepositoryFilters').addClass('hidden'); - $('.repository-table-error').addClass('active').html(e.responseJSON.error); - animateSpinner(null, false); - } + type: 'POST' }, columnDefs: [{ // Checkbox column needs special handling @@ -613,6 +605,20 @@ var RepositoryDatatable = (function(global) { $(this).parent().find('.repository-row-selector').trigger('click'); }); + // Handling of special errors + $(TABLE_ID).on('xhr.dt', function(e, settings, json) { + if (json.custom_error) { + json.data = []; + json.recordsFiltered = 0; + json.recordsTotal = 0; + TABLE.one('draw', function() { + $('#filtersDropdownButton').removeClass('active-filters'); + $('#saveRepositoryFilters').addClass('hidden'); + $('.repository-table-error').addClass('active').text(json.custom_error); + }); + } + }) + initRowSelection(); bindExportActions(); $(window).resize(() => { diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index 70c6e0415..41fa67041 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -32,9 +32,9 @@ class RepositoryRowsController < ApplicationController @repository_rows = @repository_rows.where(archived: params[:archived]) unless @repository.archived? rescue RepositoryFilters::ColumnNotFoundException - render json: { error: I18n.t('repositories.show.repository_filter.errors.column_not_found') }, status: :not_found + render json: { custom_error: I18n.t('repositories.show.repository_filter.errors.column_not_found') } rescue RepositoryFilters::ValueNotFoundException - render json: { error: I18n.t('repositories.show.repository_filter.errors.value_not_found') }, status: :not_found + render json: { custom_error: I18n.t('repositories.show.repository_filter.errors.value_not_found') } end def create diff --git a/config/locales/en.yml b/config/locales/en.yml index 986884446..a7ca2e4ff 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1398,7 +1398,7 @@ en: filter_inventory_items: "Filter items" no_items: "No items here" - no_items_matched: "No items matched your search request" + no_items_matched: "No items here" no_archived_items: "No archived items here" no_archived_items_matched: "No archived items matched your search request" error_searching: "Error searching, please try again"