diff --git a/app/assets/javascripts/samples/sample_datatable.js.erb b/app/assets/javascripts/samples/sample_datatable.js.erb index ed1a00ec8..5de1b87ff 100644 --- a/app/assets/javascripts/samples/sample_datatable.js.erb +++ b/app/assets/javascripts/samples/sample_datatable.js.erb @@ -749,7 +749,9 @@ function createSampleTypeSelect(data, selected) { var $selectType = $('') .attr('name', 'sample_type_id').addClass('show-tick'); - var $option = $("") + var sampleTypesLink = $('#samples').attr('data-sample-types-link'); + + var $option = $("") .attr('value', -2) .text(I18n.t('samples.table.add_sample_type')); $selectType.append($option); @@ -777,7 +779,9 @@ function createSampleGroupSelect(data, selected) { var $selectGroup = $('') .attr('name', 'sample_group_id').addClass('show-tick'); - var $option = $("") + var sampleGroupsLink = $('#samples').attr('data-sample-groups-link'); + + var $option = $("") .text(I18n.t('samples.table.add_sample_group')); $selectGroup.append($option); $option = $('') diff --git a/app/assets/javascripts/samples/sample_types_groups.js b/app/assets/javascripts/samples/sample_types_groups.js index 9caad1f20..8778f26c0 100644 --- a/app/assets/javascripts/samples/sample_types_groups.js +++ b/app/assets/javascripts/samples/sample_types_groups.js @@ -17,14 +17,6 @@ }); } - function newSampleTypeGroupFormSubmit() { - $('#submit').off(); - $('#submit').on('click', function() { - var form = $(this).closest('form'); - form.submit(); - }); - } - function submitEditSampleTypeGroupForm() { $('.edit-confirm').off(); $('.edit-confirm').on('click', function() { @@ -39,7 +31,7 @@ var li = $(this).closest('li'); var href = $(this).attr('data-element'); var id = $(li).attr('data-id'); - + $().clearFormErrors(); $.ajax({ url: href, data: { id: id }, @@ -47,7 +39,7 @@ $(li).replaceWith($.parseHTML(data.html)); editSampleTypeForm(); destroySampleTypeGroup(); - initSampleGroupColor(); + initSampleColorPicker(li) appendCarretToColorPickerDropdown(); editSampleGroupColor(); editSampleGroupForm(); @@ -95,6 +87,7 @@ $(li).insertAfter('.new-resource-form'); editSampleTypeForm(); destroySampleTypeGroup(); + $('#new_sample_type').clearFormErrors(); }).bind('ajax:error', function(ev, error) { $(this).clearFormErrors(); var msg = $.parseJSON(error.responseText); @@ -128,17 +121,18 @@ } function bindNewSampleGroupAction() { - $('#new_sample_group').off(); + $('#new_sample_group').off(); $('#new_sample_group').bind('ajax:success', function(ev, data) { var li = $.parseHTML(data.html); $('#name-input').val(''); $('.new-resource-form').slideUp(); $(li).insertAfter('.new-resource-form'); - initSampleGroupColor(); + initSampleColorPicker(li); appendCarretToColorPickerDropdown(); editSampleGroupColor(); editSampleGroupForm(); destroySampleTypeGroup(); + $('#new_sample_group').clearFormErrors(); }).bind('ajax:error', function(ev, error) { $(this).clearFormErrors(); var msg = $.parseJSON(error.responseText); @@ -195,7 +189,7 @@ submitEditSampleTypeGroupForm(); abortEditSampleTypeGroupAction(); destroySampleTypeGroup(); - initSampleGroupColor(); + initSampleColorPicker(li); appendCarretToColorPickerDropdown(); editSampleGroupColor(); @@ -209,7 +203,7 @@ $(this).closest('li').replaceWith($.parseHTML(data.html)); editSampleGroupForm(); destroySampleTypeGroup(); - initSampleGroupColor(); + initSampleColorPicker($(this).closest('li')); appendCarretToColorPickerDropdown(); editSampleGroupColor(); }).bind('ajax:error', function(ev, error){ @@ -233,6 +227,12 @@ }); } + function initSampleColorPicker(el) { + var element = $(el).find('.edit-sample-group-color'); + var color = $(element).closest('[data-color]').attr('data-color'); + $(element).colorselector('setColor', color); + } + /** * Opens adding mode when redirected from samples page, when clicking link for * adding sample type or group link @@ -246,7 +246,6 @@ function initSampleTypesGroups() { showNewSampleTypeGroupForm(); newSampleTypeFormCancel(); - newSampleTypeGroupFormSubmit(); bindNewSampleTypeAction(); editSampleTypeForm(); destroySampleTypeGroup(); diff --git a/app/views/sample_types/index.html.erb b/app/views/sample_types/index.html.erb index 591eed490..22875b00a 100644 --- a/app/views/sample_types/index.html.erb +++ b/app/views/sample_types/index.html.erb @@ -40,11 +40,9 @@
- -
<% end %> diff --git a/app/views/shared/_samples.html.erb b/app/views/shared/_samples.html.erb index d5709c0af..9ebb0b329 100644 --- a/app/views/shared/_samples.html.erb +++ b/app/views/shared/_samples.html.erb @@ -129,6 +129,14 @@ data-num-columns="<%= num_of_columns %>" data-new-sample="<%= new_organization_sample_path(organization_id: @organization) %>" data-create-sample="<%= organization_samples_path(organization_id: @organization) %>" + data-sample-types-link="<%= organization_sample_types_path(@organization, + project_id: (@project.id if @project), + my_module_id: (@my_module.id if @my_module), + experiment_id: (@experiment.id if @experiment)) %>" + data-sample-groups-link="<%= organization_sample_groups_path(current_organization, + project_id: (@project.id if @project), + my_module_id: (@my_module.id if @my_module), + experiment_id: (@experiment.id if @experiment)) %>" >