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 + '" ' + '<th class="custom-field" id="' + data.id + '" ' +
'data-editable data-deletable ' + 'data-editable data-deletable ' +
'data-edit-url="' + data.edit_url + '" ' + 'data-edit-url="' + data.edit_url + '" ' +
'data-update-url="' + data.update_url + '" ' +
'data-destroy-html-url="' + data.destroy_html_url + '"' + 'data-destroy-html-url="' + data.destroy_html_url + '"' +
'>' + generateColumnNameTooltip(data.name) + '</th>'); '>' + generateColumnNameTooltip(data.name) + '</th>');
@ -1050,6 +1051,7 @@ function changeToEditMode() {
'data-position="' + colIndex + '" ' + 'data-position="' + colIndex + '" ' +
'data-id="' + $(el).attr('id') + '" ' + 'data-id="' + $(el).attr('id') + '" ' +
'data-edit-url=' + $(el).attr('data-edit-url') + ' ' + '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') + ' ' + 'data-destroy-html-url=' + $(el).attr('data-destroy-html-url') + ' ' +
'class="' + visLi + '"' + 'class="' + visLi + '"' +
'>' + '>' +
@ -1151,7 +1153,7 @@ function changeToEditMode() {
var text = li.find('.text'); var text = li.find('.text');
var textEdit = li.find('.text-edit'); var textEdit = li.find('.text-edit');
var newName = textEdit.val().trim(); var newName = textEdit.val().trim();
var url = li.attr('data-edit-url'); var url = li.attr('data-update-url');
$.ajax({ $.ajax({
url: url, url: url,
@ -1194,20 +1196,21 @@ function changeToEditMode() {
cancelEditMode(); cancelEditMode();
var li = $(this).closest('li'); var li = $(this).closest('li');
var url = li.attr('data-edit-url') + "/electronic_sign_edit"; var url = li.attr('data-edit-url');
ajaxCallEvent(); ajaxCallEvent();
function ajaxCallEvent(){ function ajaxCallEvent(){
$.ajax({ $.ajax({
url: url, url: url,
success: function() { success: function() {
var text = li.find('.text'); var text, textEdit, controls, controlsEdit;
text = li.find('.text');
if ($(text).find('.modal-tooltiptext').length > 0) { if ($(text).find('.modal-tooltiptext').length > 0) {
text = $(text).find('.modal-tooltiptext'); text = $(text).find('.modal-tooltiptext');
} }
var textEdit = li.find('.text-edit'); textEdit = li.find('.text-edit');
var controls = li.find('.controls .vis,.edit,.del'); controls = li.find('.controls .vis,.edit,.del');
var controlsEdit = li.find('.controls .ok,.cancel'); controlsEdit = li.find('.controls .ok,.cancel');
// Toggle edit mode // Toggle edit mode
columnEditMode = true; columnEditMode = true;

View file

@ -19,6 +19,8 @@ class CustomFieldsController < ApplicationController
id: @custom_field.id, id: @custom_field.id,
name: escape_input(@custom_field.name), name: escape_input(@custom_field.name),
edit_url: edit_url:
edit_team_custom_field_path(@team, @custom_field),
update_url:
team_custom_field_path(@team, @custom_field), team_custom_field_path(@team, @custom_field),
destroy_html_url: destroy_html_url:
team_custom_field_destroy_html_path( team_custom_field_destroy_html_path(
@ -36,6 +38,14 @@ class CustomFieldsController < ApplicationController
end end
end end
def edit
respond_to do |format|
format.json do
render json: { status: :ok }
end
end
end
def update def update
respond_to do |format| respond_to do |format|
format.json do format.json do

View file

@ -145,7 +145,8 @@
id="<%= cf.id %>" id="<%= cf.id %>"
<%= 'data-editable' if can_edit_custom_field(cf) %> <%= 'data-editable' if can_edit_custom_field(cf) %>
<%= 'data-deletable' if can_delete_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)}'" %> <%= "data-destroy-html-url='#{team_custom_field_destroy_html_path(@team, cf)}'" %>
> >
<%= display_tooltip(cf.name) %> <%= 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 'sample_group_element', to: 'sample_groups#sample_group_element'
get 'destroy_confirmation', to: 'sample_groups#destroy_confirmation' get 'destroy_confirmation', to: 'sample_groups#destroy_confirmation'
end end
resources :custom_fields, only: [:create, :update, :destroy] do resources :custom_fields, only: [:create, :edit, :update, :destroy] do
get 'destroy_html' get 'destroy_html'
end end
member do member do