From 83fa8570d7ae10edfd6ea31a75f5c9ef6e9a3796 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Fri, 17 Mar 2017 17:52:15 +0100 Subject: [PATCH] refactoring --- .../javascripts/samples/sample_datatable.js.erb | 15 +++++++++------ app/controllers/custom_fields_controller.rb | 10 ++++++++++ app/views/shared/_samples.html.erb | 3 ++- config/routes.rb | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/samples/sample_datatable.js.erb b/app/assets/javascripts/samples/sample_datatable.js.erb index 7fb9cbc25..9ad53f960 100644 --- a/app/assets/javascripts/samples/sample_datatable.js.erb +++ b/app/assets/javascripts/samples/sample_datatable.js.erb @@ -967,6 +967,7 @@ function changeToEditMode() { '' + generateColumnNameTooltip(data.name) + ''); @@ -1050,6 +1051,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 + '"' + '>' + @@ -1151,7 +1153,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, @@ -1194,20 +1196,21 @@ function changeToEditMode() { cancelEditMode(); var li = $(this).closest('li'); - var url = li.attr('data-edit-url') + "/electronic_sign_edit"; + var url = li.attr('data-edit-url'); ajaxCallEvent(); function ajaxCallEvent(){ $.ajax({ url: url, success: function() { - var text = li.find('.text'); + var text, textEdit, controls, controlsEdit; + text = li.find('.text'); if ($(text).find('.modal-tooltiptext').length > 0) { text = $(text).find('.modal-tooltiptext'); } - var textEdit = li.find('.text-edit'); - var controls = li.find('.controls .vis,.edit,.del'); - var controlsEdit = li.find('.controls .ok,.cancel'); + textEdit = li.find('.text-edit'); + controls = li.find('.controls .vis,.edit,.del'); + controlsEdit = li.find('.controls .ok,.cancel'); // Toggle edit mode columnEditMode = true; diff --git a/app/controllers/custom_fields_controller.rb b/app/controllers/custom_fields_controller.rb index 059512e75..388d8dc96 100644 --- a/app/controllers/custom_fields_controller.rb +++ b/app/controllers/custom_fields_controller.rb @@ -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 diff --git a/app/views/shared/_samples.html.erb b/app/views/shared/_samples.html.erb index 79c52a545..2652d0366 100644 --- a/app/views/shared/_samples.html.erb +++ b/app/views/shared/_samples.html.erb @@ -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) %> diff --git a/config/routes.rb b/config/routes.rb index 83da5977b..a8a8a663e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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