From 3d1fb484896f59908d3df5d826bab58277a9a367 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 5 Dec 2012 18:58:43 +0800 Subject: [PATCH] edit coauthor relation done --- .../javascripts/desktop/journal_pages.js.erb | 23 +++++++++++++++++++ .../desktop/co_author_relations_controller.rb | 7 +++--- .../co_author_relations/_form.html.erb | 6 ++--- .../co_author_relations/_show_form.html.erb | 4 ++-- .../desktop/co_author_relations/edit.html.erb | 2 +- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/desktop/journal_pages.js.erb b/app/assets/javascripts/desktop/journal_pages.js.erb index 02406c73..dceffd3f 100644 --- a/app/assets/javascripts/desktop/journal_pages.js.erb +++ b/app/assets/javascripts/desktop/journal_pages.js.erb @@ -280,6 +280,21 @@ orbitDesktop.prototype.initializeJournalPapers = function(target,url,cache){ // }) return false; }) + $("div[container=true]").unbind(".editype").on("click.edittype", "a.bt-edit-type", function(){ + var parent = $(this).parent().parent(); + $.ajax({ + url : $(this).attr("href"), + type : "get", + success : function(data){ + var prev_data = parent.find("td.form_space").html(); + parent.find("td.form_space").html(data); + $(".bt-cancel-type").click(function(){ + parent.find("td.form_space").html(prev_data); + }) + } + }) + return false; + }) $("div[container=true]").unbind(".delete").on("click.delete","a.bt-delete",function(){ var delurl = $(this).attr("href"); @@ -351,4 +366,12 @@ orbitDesktop.prototype.initializeJournalPapers = function(target,url,cache){ // o.notify(data.msg,"alert"); } } + this.initializeJournalPapers.coauthorRelationEditForm = function(data){ + if(data.success){ + o.notify(data.msg,"success"); + $("#co_author_relation_table tbody").html(data.newvalue); + }else{ + o.notify(data.msg,"alert"); + } + } }; diff --git a/app/controllers/desktop/co_author_relations_controller.rb b/app/controllers/desktop/co_author_relations_controller.rb index 6ee8bce1..bc3eb451 100644 --- a/app/controllers/desktop/co_author_relations_controller.rb +++ b/app/controllers/desktop/co_author_relations_controller.rb @@ -25,7 +25,7 @@ class Desktop::CoAuthorRelationsController < ApplicationController if @co_author_relation.save newv = render_to_string partial: "show_form", object: @co_author_relations - render json: {success: true, msg: "New Relation successfully saved!", newvalue: newv}.to_json + render json: {success: true, msg: "New Relation successfully saved!", newvalue: newvm}.to_json else error_msg = @co_author_relation.errors.full_messages.join("
") render json: {success: false, msg: error_msg}.to_json @@ -34,9 +34,10 @@ class Desktop::CoAuthorRelationsController < ApplicationController def update @co_author_relation = CoAuthorRelation.find(params[:id]) - if @co_author_relation.update_attributes(params[:co_author_relation]) - render json: {success:true, msg: t('update.sucess.co_author')}.to_json + @co_author_relations = CoAuthorRelation.all + newv = render_to_string partial: "show_form", object: @co_author_relations + render json: {success: true, msg: "New Relation successfully updated!", newvalue: newv}.to_json else error_msg = @co_author.errors.full_messages.join("
") render json: {success: false, msg: error_msg}.to_json diff --git a/app/views/desktop/co_author_relations/_form.html.erb b/app/views/desktop/co_author_relations/_form.html.erb index 37d49006..11a2944f 100644 --- a/app/views/desktop/co_author_relations/_form.html.erb +++ b/app/views/desktop/co_author_relations/_form.html.erb @@ -1,5 +1,5 @@ -<% if not @co_author_relation.new_record? %> - <%= submit_tag "Cancel", :type => "button", class: "bt-cancel ini_input hp hh2 thmadm thmtxt" %> -<% end %> <%= f.text_field :relation %> <%= f.submit "Save" %> +<% if not @co_author_relation.new_record? %> + <%= submit_tag "Cancel", :type => "button", class: "bt-cancel-type" %> +<% end %> \ No newline at end of file diff --git a/app/views/desktop/co_author_relations/_show_form.html.erb b/app/views/desktop/co_author_relations/_show_form.html.erb index 36c9728a..9b478f90 100644 --- a/app/views/desktop/co_author_relations/_show_form.html.erb +++ b/app/views/desktop/co_author_relations/_show_form.html.erb @@ -1,7 +1,7 @@ <% @co_author_relations.each do |co_author_relation| %> - <%= co_author_relation.relation %> - <%= link_to 'Edit', edit_desktop_co_author_relation_path(co_author_relation), :class => "bt-edit" %> + <%= co_author_relation.relation %> + <%= link_to 'Edit', edit_desktop_co_author_relation_path(co_author_relation), :class => "bt-edit-type" %> <%= link_to 'Destroy', desktop_co_author_relation_path(co_author_relation), confirm: 'Are you sure?', method: :delete, :class=>"bt-delete" %> <% end %> diff --git a/app/views/desktop/co_author_relations/edit.html.erb b/app/views/desktop/co_author_relations/edit.html.erb index 585b57c3..0132d45b 100644 --- a/app/views/desktop/co_author_relations/edit.html.erb +++ b/app/views/desktop/co_author_relations/edit.html.erb @@ -1,3 +1,3 @@ -<%= form_for(@co_author_relation, url: desktop_co_author_relation_path(@co_author_relation), html:{"form-type"=>"ajax_form", "callback-method"=>"coauthorRelationForm"} ) do |f| %> +<%= form_for(@co_author_relation, url: desktop_co_author_relation_path(@co_author_relation), html:{"form-type"=>"ajax_form", "callback-method"=>"coauthorRelationEditForm"} ) do |f| %> <%= render partial: 'desktop/co_author_relations/form' , locals: {:f => f}%> <% end %>