diff --git a/app/assets/javascripts/application.js.erb b/app/assets/javascripts/application.js.erb index 32ca184d0..5838a2ba6 100644 --- a/app/assets/javascripts/application.js.erb +++ b/app/assets/javascripts/application.js.erb @@ -28,6 +28,7 @@ //= require typeahead.bundle.min //= require nested_form_fields //= require_directory ./sitewide +//= require datatables //= require dataTables.noSearchHidden //= require bootstrap-select //= require underscore diff --git a/app/assets/javascripts/my_modules/protocols.js.erb b/app/assets/javascripts/my_modules/protocols.js.erb index 1d74cfcb5..50a9a7b89 100644 --- a/app/assets/javascripts/my_modules/protocols.js.erb +++ b/app/assets/javascripts/my_modules/protocols.js.erb @@ -1,7 +1,6 @@ //= require protocols/import_export/import //= require protocols/import_export/export //= require comments -//= require datatables // Currently selected row in "load from protocol" modal var selectedRow = null; diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index 844f9bb75..9070e1034 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -1,6 +1,5 @@ //= require protocols/import_export/import //= require protocols/import_export/export -//= require datatables // Global variables var rowsSelected = []; diff --git a/app/assets/javascripts/samples/sample_datatable.js.erb b/app/assets/javascripts/samples/sample_datatable.js.erb index bda336b8f..fcd25e9ff 100644 --- a/app/assets/javascripts/samples/sample_datatable.js.erb +++ b/app/assets/javascripts/samples/sample_datatable.js.erb @@ -56,9 +56,8 @@ function dataTableInit() { }, { targets: 2, render: function(data, type, row) { - return "" + data + ''; + return "" + data + ''; } }], rowCallback: function(row, data) { @@ -89,12 +88,11 @@ function dataTableInit() { fnDrawCallback: function() { animateSpinner(this, false); changeToViewMode(); - sampleInfoListener(); updateButtons(); }, preDrawCallback: function() { animateSpinner(this); - $('.sample_info').off('click'); + $('.sample-info-link').off('click'); }, stateLoadCallback: function(settings) { // Send an Ajax request to the server to get the data. Note that @@ -145,7 +143,6 @@ function dataTableInit() { table.on('mousedown', function() { $('#samples-columns-dropdown').removeClass('open'); }); - sampleInfoListener(); } }); @@ -162,8 +159,11 @@ function dataTableInit() { }); // Handle click on table cells with checkboxes - $('#samples').on('click', 'tbody td, thead th:first-child', function() { - $(this).parent().find('input[type="checkbox"]').trigger('click'); + $('#samples').on('click', 'tbody td, thead th:first-child', function(e) { + if (!$(e.target).is('.sample-info-link')) { + // Skip if clicking on samples info link + $(this).parent().find('input[type="checkbox"]').trigger('click'); + } }); // Handle clicks on checkbox @@ -322,54 +322,6 @@ function appendSamplesIdToForm(form) { }); } -//Show sample info -function sampleInfoListener() { - $(".sample_info").on("click", function(e){ - var that = $(this); - $.ajax({ - method: "GET", - url: that.attr("data-href") + '.json', - dataType: "json" - }).done(function(xhr, settings, data) { - $("body").append($.parseHTML(data.responseJSON.html)); - $("#modal-info-sample").modal('show',{ - backdrop: true, - keyboard: false, - }).on('hidden.bs.modal', function () { - $(this).find(".modal-body #sample-info-table").DataTable().destroy(); - $(this).remove(); - }); - - $('#sample-info-table').DataTable({ - dom: "RBltpi", - stateSave: false, - buttons: [], - processing: true, - colReorder: { - fixedColumnsLeft: 1000000 // Disable reordering - }, - columnDefs: [{ - targets: 0, - searchable: false, - orderable: false - }], - fnDrawCallback: function(settings, json) { - animateSpinner(this, false); - }, - preDrawCallback: function(settings) { - animateSpinner(this); - } - }); - }).fail(function(error){ - // TODO - }).always(function(data){ - // TODO - }); - e.preventDefault(); - return false; - }); -} - // Edit sample function onClickEdit() { if (rowsSelected.length != 1) return; diff --git a/app/assets/javascripts/samples/samples.js b/app/assets/javascripts/samples/samples.js index e648e1872..9e945a64d 100644 --- a/app/assets/javascripts/samples/samples.js +++ b/app/assets/javascripts/samples/samples.js @@ -1,5 +1,3 @@ -//= require datatables - // Create import samples ajax $("#modal-import-samples").on("show.bs.modal", function(event) { formGroup = $(this).find(".form-group"); diff --git a/app/assets/javascripts/sitewide/sample_info_modal.js b/app/assets/javascripts/sitewide/sample_info_modal.js new file mode 100644 index 000000000..f98aa6bfa --- /dev/null +++ b/app/assets/javascripts/sitewide/sample_info_modal.js @@ -0,0 +1,44 @@ +(function() { + 'use strict'; + + $(document).on('click', '.sample-info-link', function(e) { + var that = $(this); + $.ajax({ + method: 'GET', + url: that.attr('href'), + dataType: 'json' + }).done(function(xhr, settings, data) { + $('body').append($.parseHTML(data.responseJSON.html)); + $('#modal-info-sample').modal('show', { + backdrop: true, + keyboard: false + }).on('hidden.bs.modal', function() { + $(this).find('.modal-body #sample-info-table').DataTable().destroy(); + $(this).remove(); + }); + + $('#sample-info-table').DataTable({ + dom: 'RBltpi', + stateSave: false, + buttons: [], + processing: true, + colReorder: { + fixedColumnsLeft: 1000000 // Disable reordering + }, + columnDefs: [{ + targets: 0, + searchable: false, + orderable: false + }], + fnDrawCallback: function(settings, json) { + animateSpinner(this, false); + }, + preDrawCallback: function(settings) { + animateSpinner(this); + } + }); + }); + e.preventDefault(); + return false; + }); +})(); diff --git a/app/assets/javascripts/users/settings/organization.js b/app/assets/javascripts/users/settings/organization.js index 969bf8e5d..cc60e706f 100644 --- a/app/assets/javascripts/users/settings/organization.js +++ b/app/assets/javascripts/users/settings/organization.js @@ -1,5 +1,3 @@ -//= require datatables - var usersDatatable = null; // Initialize edit name modal window diff --git a/app/datatables/sample_datatable.rb b/app/datatables/sample_datatable.rb index da3832738..cbf933a14 100644 --- a/app/datatables/sample_datatable.rb +++ b/app/datatables/sample_datatable.rb @@ -110,13 +110,13 @@ class SampleDatatable < AjaxDatatablesRails::Base '1': assigned_cell(record), '2': record.name, '3': record.sample_type.nil? ? I18n.t('samples.table.no_type') : record.sample_type.name, - '4': record.sample_group.nil? ? - " " + I18n.t("samples.table.no_group") : - " " + record.sample_group.name, - "5": I18n.l(record.created_at, format: :full), - "6": record.user.full_name, - "sampleInfoUrl": Rails.application.routes.url_helpers.edit_sample_path(record.id), - "sampleUpdateUrl": Rails.application.routes.url_helpers.sample_path(record.id) + '4': sample_group_cell(record), + '5': I18n.l(record.created_at, format: :full), + '6': record.user.full_name, + 'sampleInfoUrl': + Rails.application.routes.url_helpers.sample_path(record.id), + 'sampleUpdateUrl': + Rails.application.routes.url_helpers.sample_path(record.id) } # Add custom attributes @@ -137,6 +137,17 @@ class SampleDatatable < AjaxDatatablesRails::Base " " end + def sample_group_cell(record) + if record.sample_group.nil? + " " \ + "#{I18n.t('samples.table.no_group')}" + else + " " \ + "#{record.sample_group.name}" + end + end + # Query database for records (this will be later paginated and filtered) # after that "data" function will return json def get_raw_records diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3084ebc05..e8d4d7cfb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -100,11 +100,9 @@ module ApplicationHelper sample = Sample.find_by_id(match[3].base62_decode) if sample " " \ - "#{link_to sample.name, - samples_project_path(sample - .organization - .projects - .first)}" + "#{link_to(sample.name, + sample_path(sample.id), + class: 'sample-info-link')}" else " " \ "#{match[1]} #{t'atwho.res.deleted'}" diff --git a/app/views/samples/_info_sample_modal.html.erb b/app/views/samples/_info_sample_modal.html.erb index c546956d4..042df8a29 100644 --- a/app/views/samples/_info_sample_modal.html.erb +++ b/app/views/samples/_info_sample_modal.html.erb @@ -1,4 +1,3 @@ -