refactoring

This commit is contained in:
Mojca Lorber 2017-03-17 17:52:15 +01:00
parent 4792bd87b9
commit 83fa8570d7
4 changed files with 22 additions and 8 deletions

View file

@ -967,6 +967,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>');
@ -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;

View file

@ -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

View file

@ -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) %>

View file

@ -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