mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 21:24:23 +08:00
Merge pull request #514 from biosistemika/ml_sci_1089
Add error messages to sample group/type edit/delete actions [SCI-1089]
This commit is contained in:
commit
3beb179f87
7 changed files with 142 additions and 43 deletions
|
@ -975,6 +975,7 @@ function changeToEditMode() {
|
|||
'<th class="custom-field" id="' + data.id + '" ' +
|
||||
'data-editable data-deletable ' +
|
||||
'data-edit-url="' + data.edit_url + '" ' +
|
||||
'data-update-url="' + data.update_url + '" ' +
|
||||
'data-destroy-html-url="' + data.destroy_html_url + '"' +
|
||||
'>' + generateColumnNameTooltip(data.name) + '</th>');
|
||||
|
||||
|
@ -1058,6 +1059,7 @@ function changeToEditMode() {
|
|||
'data-position="' + colIndex + '" ' +
|
||||
'data-id="' + $(el).attr('id') + '" ' +
|
||||
'data-edit-url=' + $(el).attr('data-edit-url') + ' ' +
|
||||
'data-update-url=' + $(el).attr('data-update-url') + ' ' +
|
||||
'data-destroy-html-url=' + $(el).attr('data-destroy-html-url') + ' ' +
|
||||
'class="' + visLi + '"' +
|
||||
'>' +
|
||||
|
@ -1159,7 +1161,7 @@ function changeToEditMode() {
|
|||
var text = li.find('.text');
|
||||
var textEdit = li.find('.text-edit');
|
||||
var newName = textEdit.val().trim();
|
||||
var url = li.attr('data-edit-url');
|
||||
var url = li.attr('data-update-url');
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
|
@ -1201,34 +1203,57 @@ function changeToEditMode() {
|
|||
|
||||
cancelEditMode();
|
||||
|
||||
var self = $(this);
|
||||
var li = self.closest('li');
|
||||
var text = li.find('.text');
|
||||
if ($(text).find('.modal-tooltiptext').length > 0) {
|
||||
text = $(text).find('.modal-tooltiptext');
|
||||
var li = $(this).closest('li');
|
||||
var url = li.attr('data-edit-url');
|
||||
ajaxCallEvent();
|
||||
|
||||
function ajaxCallEvent(){
|
||||
$.ajax({
|
||||
url: url,
|
||||
success: function() {
|
||||
var text, textEdit, controls, controlsEdit;
|
||||
text = li.find('.text');
|
||||
if ($(text).find('.modal-tooltiptext').length > 0) {
|
||||
text = $(text).find('.modal-tooltiptext');
|
||||
}
|
||||
textEdit = li.find('.text-edit');
|
||||
controls = li.find('.controls .vis,.edit,.del');
|
||||
controlsEdit = li.find('.controls .ok,.cancel');
|
||||
|
||||
// Toggle edit mode
|
||||
columnEditMode = true;
|
||||
li.addClass('editing');
|
||||
|
||||
// Set the text-edit's value
|
||||
textEdit.val(text.text().trim());
|
||||
|
||||
// Toggle elements
|
||||
text.hide();
|
||||
controls.hide();
|
||||
textEdit.css('display', ''); // show() doesn't work
|
||||
controlsEdit.css('display', ''); // show() doesn't work
|
||||
dropdownList.sortable('disable');
|
||||
dropdownList.on('click', function(ev) {
|
||||
ev.stopPropagation();
|
||||
});
|
||||
// Focus input
|
||||
textEdit.focus();
|
||||
},
|
||||
error: function(e) {
|
||||
$(li).clearFormErrors();
|
||||
var msg = $.parseJSON(e.responseText);
|
||||
|
||||
renderFormError(undefined,
|
||||
$(li).find('.text-edit'),
|
||||
Object.keys(msg)[0] + ' ' + msg.name.toString());
|
||||
var verticalHeight = $(li).offset().top;
|
||||
dropdownList.scrollTo(verticalHeight,0);
|
||||
setTimeout(function() {
|
||||
$(li).clearFormErrors();
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
}
|
||||
var textEdit = li.find('.text-edit');
|
||||
var controls = li.find('.controls .vis,.edit,.del');
|
||||
var controlsEdit = li.find('.controls .ok,.cancel');
|
||||
|
||||
// Toggle edit mode
|
||||
columnEditMode = true;
|
||||
li.addClass('editing');
|
||||
|
||||
// Set the text-edit's value
|
||||
textEdit.val(text.text().trim());
|
||||
|
||||
// Toggle elements
|
||||
text.hide();
|
||||
controls.hide();
|
||||
textEdit.css('display', ''); // show() doesn't work
|
||||
controlsEdit.css('display', ''); // show() doesn't work
|
||||
dropdownList.sortable('disable');
|
||||
dropdownList.on('click', function(ev) {
|
||||
ev.stopPropagation();
|
||||
});
|
||||
// Focus input
|
||||
textEdit.focus();
|
||||
});
|
||||
|
||||
// On hiding dropdown, cancel edit mode throughout dropdown
|
||||
|
|
|
@ -70,6 +70,17 @@
|
|||
});
|
||||
|
||||
clearModal('#modal-delete');
|
||||
},
|
||||
error: function (e) {
|
||||
$(li).clearFormErrors();
|
||||
var msg = $.parseJSON(e.responseText);
|
||||
|
||||
renderFormError(undefined,
|
||||
$(li).find('.text-edit'),
|
||||
Object.keys(msg)[0] + ' ' + msg.name.toString());
|
||||
setTimeout(function() {
|
||||
$(li).clearFormErrors();
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -161,6 +172,17 @@
|
|||
$(this).find('#sample_type_name'),
|
||||
Object.keys(msg)[0] + ' '+ msg.name.toString());
|
||||
});
|
||||
},
|
||||
error: function (e) {
|
||||
$(li).clearFormErrors();
|
||||
var msg = $.parseJSON(e.responseText);
|
||||
|
||||
renderFormError(undefined,
|
||||
$(li).find('.text-edit'),
|
||||
Object.keys(msg)[0] + ' ' + msg.name.toString());
|
||||
setTimeout(function() {
|
||||
$(li).clearFormErrors();
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -202,6 +224,40 @@
|
|||
$(this).find('#sample_group_name'),
|
||||
Object.keys(msg)[0] + ' '+ msg.name.toString());
|
||||
});
|
||||
},
|
||||
error: function (e) {
|
||||
$(li).clearFormErrors();
|
||||
var msg = $.parseJSON(e.responseText);
|
||||
|
||||
renderFormError(undefined,
|
||||
$(li).find('.text-edit'),
|
||||
Object.keys(msg)[0] + ' ' + msg.name.toString());
|
||||
setTimeout(function() {
|
||||
$(li).clearFormErrors();
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function editSampleGroupColor() {
|
||||
$('.color-picker').on('click', function() {
|
||||
var li = $(this).closest('li');
|
||||
$.ajax({
|
||||
url: li.attr('data-edit'),
|
||||
success: function(data) {
|
||||
},
|
||||
error: function (e) {
|
||||
$('.dropdown-colorselector.open').removeClass('open');
|
||||
$(li).clearFormErrors();
|
||||
var msg = $.parseJSON(e.responseText);
|
||||
|
||||
renderFormError(undefined,
|
||||
$(li).find('.text-edit'),
|
||||
Object.keys(msg)[0] + ' ' + msg.name.toString());
|
||||
setTimeout(function() {
|
||||
$(li).clearFormErrors();
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -269,6 +325,7 @@
|
|||
bindNewSampleGroupAction();
|
||||
appendCarretToColorPickerDropdown();
|
||||
sampleTypeGroupEditMode();
|
||||
editSampleGroupColor();
|
||||
}
|
||||
|
||||
// initialize sample types/groups actions
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class CustomFieldsController < ApplicationController
|
||||
include InputSanitizeHelper
|
||||
|
||||
before_action :load_vars, only: [:update, :destroy, :destroy_html]
|
||||
before_action :load_vars, except: :create
|
||||
before_action :load_vars_nested, only: [:create, :destroy_html]
|
||||
before_action :check_create_permissions, only: :create
|
||||
before_action :check_update_permissions, only: :update
|
||||
|
@ -19,6 +19,8 @@ class CustomFieldsController < ApplicationController
|
|||
id: @custom_field.id,
|
||||
name: escape_input(@custom_field.name),
|
||||
edit_url:
|
||||
edit_team_custom_field_path(@team, @custom_field),
|
||||
update_url:
|
||||
team_custom_field_path(@team, @custom_field),
|
||||
destroy_html_url:
|
||||
team_custom_field_destroy_html_path(
|
||||
|
@ -36,6 +38,14 @@ class CustomFieldsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: { status: :ok }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
|
|
|
@ -5,15 +5,18 @@
|
|||
team_sample_group_destroy_confirmation_path(team, sample_group) %>"
|
||||
data-color="<%= sample_group.color %>">
|
||||
<span class="sample-type-group-name"><%= sample_group.name %></span>
|
||||
<span class="pull-right sample-group-controls">
|
||||
<span class="color-picker">
|
||||
<%= bootstrap_form_for [team, sample_group], remote: true do |f| %>
|
||||
<%= f.color_picker_select :color,
|
||||
Constants::TAG_COLORS,
|
||||
class: 'edit-sample-group-color' %>
|
||||
<% end %>
|
||||
<span class="form-group">
|
||||
<input class="text-edit" style="display: none;" />
|
||||
<span class="pull-right sample-group-controls">
|
||||
<span class="color-picker">
|
||||
<%= bootstrap_form_for [team, sample_group], remote: true do |f| %>
|
||||
<%= f.color_picker_select :color,
|
||||
Constants::TAG_COLORS,
|
||||
class: 'edit-sample-group-color' %>
|
||||
<% end %>
|
||||
</span>
|
||||
<span class="edit-sample-group glyphicon glyphicon-pencil"></span>
|
||||
<span class="delete glyphicon glyphicon-trash"></span>
|
||||
</span>
|
||||
<span class="edit-sample-group glyphicon glyphicon-pencil"></span>
|
||||
<span class="delete glyphicon glyphicon-trash"></span>
|
||||
</span>
|
||||
</li>
|
||||
|
|
|
@ -4,8 +4,11 @@
|
|||
team_sample_type_destroy_confirmation_path(team, sample_type)
|
||||
%>">
|
||||
<span class="sample-type-group-name"><%= sample_type.name %></span>
|
||||
<span class="pull-right">
|
||||
<span class="edit-sample-type glyphicon glyphicon-pencil"></span>
|
||||
<span class="delete glyphicon glyphicon-trash"></span>
|
||||
<span class="form-group">
|
||||
<input class="text-edit" style="display: none;" />
|
||||
<span class="pull-right">
|
||||
<span class="edit-sample-type glyphicon glyphicon-pencil"></span>
|
||||
<span class="delete glyphicon glyphicon-trash"></span>
|
||||
</span>
|
||||
</span>
|
||||
</li>
|
||||
|
|
|
@ -145,7 +145,8 @@
|
|||
id="<%= cf.id %>"
|
||||
<%= 'data-editable' if can_edit_custom_field(cf) %>
|
||||
<%= 'data-deletable' if can_delete_custom_field(cf) %>
|
||||
<%= "data-edit-url='#{team_custom_field_path(@team, cf)}'" %>
|
||||
<%= "data-edit-url='#{edit_team_custom_field_path(@team, cf)}'" %>
|
||||
<%= "data-update-url='#{team_custom_field_path(@team, cf)}'" %>
|
||||
<%= "data-destroy-html-url='#{team_custom_field_destroy_html_path(@team, cf)}'" %>
|
||||
>
|
||||
<%= display_tooltip(cf.name) %>
|
||||
|
|
|
@ -123,7 +123,7 @@ Rails.application.routes.draw do
|
|||
get 'sample_group_element', to: 'sample_groups#sample_group_element'
|
||||
get 'destroy_confirmation', to: 'sample_groups#destroy_confirmation'
|
||||
end
|
||||
resources :custom_fields, only: [:create, :update, :destroy] do
|
||||
resources :custom_fields, only: [:create, :edit, :update, :destroy] do
|
||||
get 'destroy_html'
|
||||
end
|
||||
member do
|
||||
|
|
Loading…
Add table
Reference in a new issue