mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-13 00:24:42 +08:00
Edit functionality now works
This commit is contained in:
parent
54ebdbb06c
commit
754c90b612
3 changed files with 73 additions and 15 deletions
|
@ -808,6 +808,7 @@ function changeToEditMode() {
|
|||
(function(table) {
|
||||
'use strict';
|
||||
|
||||
var dropdown = $('#samples-columns-dropdown');
|
||||
var dropdownList = $('#samples-columns-list');
|
||||
var editMode = false;
|
||||
|
||||
|
@ -912,7 +913,11 @@ function changeToEditMode() {
|
|||
var editClass = (editable) ? '' : 'disabled';
|
||||
var delClass = (deletable) ? '' : 'disabled';
|
||||
var html =
|
||||
'<li data-position="' + colIndex + '" class="' + visLi + '">' +
|
||||
'<li ' +
|
||||
'data-position="' + colIndex + '" ' +
|
||||
'data-id="' + $(el).attr('id') + '" ' +
|
||||
'class="' + visLi + '"' +
|
||||
'>' +
|
||||
'<i class="grippy"></i> ' +
|
||||
'<span class="text">' + el.innerText + '</span> ' +
|
||||
'<input type="text" class="text-edit form-control" style="display: none;" />' +
|
||||
|
@ -1004,7 +1009,6 @@ function changeToEditMode() {
|
|||
|
||||
cancelEditMode();
|
||||
|
||||
|
||||
var self = $(this);
|
||||
var li = self.closest('li');
|
||||
var text = li.find('.text');
|
||||
|
@ -1029,6 +1033,39 @@ function changeToEditMode() {
|
|||
textEdit.focus();
|
||||
});
|
||||
|
||||
// On hiding dropdown, cancel edit mode throughout dropdown
|
||||
dropdown.on('hidden.bs.dropdown', function() {
|
||||
cancelEditMode();
|
||||
});
|
||||
|
||||
// On ok buttons click
|
||||
var okBtns = dropdownList.find('.ok');
|
||||
okBtns.on('click', function(event) {
|
||||
event.stopPropagation();
|
||||
|
||||
var self = $(this);
|
||||
var li = self.closest('li');
|
||||
var id = li.attr('data-id');
|
||||
var text = li.find('.text');
|
||||
var textEdit = li.find('.text-edit');
|
||||
var newName = textEdit.val().trim();
|
||||
|
||||
$.ajax({
|
||||
url: '/organizations/1/custom_fields/' + id,
|
||||
type: 'PUT',
|
||||
data: {custom_field: {name: newName}},
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
text.text(newName);
|
||||
$(table.columns().header()).filter('#' + id).text(newName);
|
||||
cancelEditMode();
|
||||
},
|
||||
error: function(xhr) {
|
||||
// TODO
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// On cancel buttons click
|
||||
var cancelBtns = dropdownList.find('.cancel');
|
||||
cancelBtns.on('click', function(event) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
class CustomFieldsController < ApplicationController
|
||||
before_action :load_vars, only: :update
|
||||
before_action :load_vars_nested, only: [:create]
|
||||
before_action :check_create_permissions, only: [:create]
|
||||
before_action :check_update_permissions, only: :update
|
||||
|
||||
def create
|
||||
@custom_field = CustomField.new(custom_field_params)
|
||||
|
@ -9,12 +11,13 @@ class CustomFieldsController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
if @custom_field.save
|
||||
format.json {
|
||||
format.json do
|
||||
render json: {
|
||||
id: @custom_field.id,
|
||||
name: @custom_field.name
|
||||
},
|
||||
status: :ok }
|
||||
status: :ok
|
||||
end
|
||||
else
|
||||
format.json do
|
||||
render json: @custom_field.errors.to_json,
|
||||
|
@ -24,20 +27,38 @@ class CustomFieldsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_vars_nested
|
||||
@organization = Organization.find_by_id(params[:organization_id])
|
||||
|
||||
unless @organization
|
||||
render_404
|
||||
def update
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
@custom_field.update_attributes(custom_field_params)
|
||||
if @custom_field.save
|
||||
render json: { status: :ok }
|
||||
else
|
||||
render json: @custom_field.errors.to_json,
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_vars
|
||||
@custom_field = CustomField.find_by_id(params[:id])
|
||||
render_404 unless @custom_field
|
||||
end
|
||||
|
||||
def load_vars_nested
|
||||
@organization = Organization.find_by_id(params[:organization_id])
|
||||
render_404 unless @organization
|
||||
end
|
||||
|
||||
def check_create_permissions
|
||||
unless can_create_custom_field_in_organization(@organization)
|
||||
render_403
|
||||
end
|
||||
render_403 unless can_create_custom_field_in_organization(@organization)
|
||||
end
|
||||
|
||||
def check_update_permissions
|
||||
render_403 unless can_edit_custom_field(@custom_field)
|
||||
end
|
||||
|
||||
def custom_field_params
|
||||
|
|
|
@ -79,7 +79,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]
|
||||
resources :custom_fields, only: [:create, :update]
|
||||
member do
|
||||
post 'parse_sheet'
|
||||
post 'import_samples'
|
||||
|
|
Loading…
Add table
Reference in a new issue