From 5c0b137c6dc89b61c3d2d9bcea30a1ae914ff087 Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Wed, 21 Nov 2012 14:52:26 +0800 Subject: [PATCH] tmp --- app/assets/javascripts/orbitdesktop.js | 11 +++++++++- .../desktop/co_authors_controller.rb | 10 ++++----- .../desktop/journal_pages_controller.rb | 21 +++++-------------- app/views/desktop/co_authors/new.html.erb | 2 +- app/views/desktop/journal_pages/new.html.erb | 2 +- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js index 3ddb97759..834e1931e 100755 --- a/app/assets/javascripts/orbitdesktop.js +++ b/app/assets/javascripts/orbitdesktop.js @@ -1034,7 +1034,16 @@ var orbitDesktop = function(dom){ } bindHandlers(); } - + this.initializeJournalPapers.coAuthorformCallback = function(ruse){ + this.initializeJournalPapers.formCallback = function(data){ + if(data.success){ + o.notify(data.msg,"success"); + o.sub_menu_item($("div[content-type=menu] a").eq(0)); + }else{ + o.notify(data.msg,"alert"); + } + } + } this.initializeJournalPapers.coauthor = function(){ // to open add pages in journal papers page var bindHandlers = function(){ // to bind handlers for add page o.simple_drop_down(); diff --git a/app/controllers/desktop/co_authors_controller.rb b/app/controllers/desktop/co_authors_controller.rb index 6c4d980a9..9b0d3bd1e 100644 --- a/app/controllers/desktop/co_authors_controller.rb +++ b/app/controllers/desktop/co_authors_controller.rb @@ -36,12 +36,10 @@ class Desktop::CoAuthorsController < ApplicationController @co_author = CoAuthor.new(params[:co_author]) @co_author.name_id= current_user.id - respond_to do |format| - if @co_author.save - format.html { redirect_to desktop_co_authors_path, :layout => false, notice: 'CoAuthor was successfully created.' } - else - format.html { render action: "new", :layout => false} - end + if @writing_journal.save + render :json => {success:true, msg: "Paper successfully saved!"}.to_json + else + render :json => {success:false, msg: "Saving failed!"} end end diff --git a/app/controllers/desktop/journal_pages_controller.rb b/app/controllers/desktop/journal_pages_controller.rb index ee7a71676..72bb54afa 100644 --- a/app/controllers/desktop/journal_pages_controller.rb +++ b/app/controllers/desktop/journal_pages_controller.rb @@ -39,20 +39,14 @@ class Desktop::JournalPagesController < ApplicationController params[:writing_journal][:create_user_id] = current_user.id @writing_journal = WritingJournal.new(params[:writing_journal]) + respond_to do |format| if @writing_journal.save - # respond_to do |format| - # format.html { redirect_to desktop_journal_pages_url, :layout => false, notice: 'User was successfully created.'} - # # format.json { render json: @writing_journal, status: :created, location: @writing_journal} - # # format.js - # end - render :json => {"success"=>true,"msg"=>"Paper successfully saved!"}.to_json + format.json {render json: {success: true, msg: "Paper successfully saved!"}.to_json} else - render :json => {"success"=>false,"msg"=>"Saving failed!"} + format.json {render json: {success: false, msg: "Saving failed!"}.to_json } end - - end - render :json => {"success"=>true,"msg"=>"Paper successfully saved!"}.to_json - + end + end end def update @@ -60,11 +54,6 @@ class Desktop::JournalPagesController < ApplicationController @writing_journal= WritingJournal.find(params[:id]) end - if not params[:writing_journal][:publication_date].nil? - params[:writing_journal][:publication_date] = \ - Date.new *(params[:writing_journal][:publication_date].split("/").map{|s| s.to_i}) - end - respond_to do |format| if @writing_journal.update_attributes(params[:writing_journal]) format.html { redirect_to desktop_journal_pages_url, :layout => false, notice: 'User was successfully updated.'} diff --git a/app/views/desktop/co_authors/new.html.erb b/app/views/desktop/co_authors/new.html.erb index 5c6fab16e..c794f218d 100644 --- a/app/views/desktop/co_authors/new.html.erb +++ b/app/views/desktop/co_authors/new.html.erb @@ -1,3 +1,3 @@ -<%= form_for @co_author, url: desktop_co_authors_path do |f| %> +<%= form_for @co_author, html: { multipart: true ,:type=>"ajax_form", "callback-method"=>"coAuthorformCallback"} , url: desktop_co_authors_path do |f| %> <%= render partial: 'desktop/co_authors/form', locals: {:f => f} %> <% end %> diff --git a/app/views/desktop/journal_pages/new.html.erb b/app/views/desktop/journal_pages/new.html.erb index c402e295b..5b889e6a9 100644 --- a/app/views/desktop/journal_pages/new.html.erb +++ b/app/views/desktop/journal_pages/new.html.erb @@ -1,3 +1,3 @@ -<%= form_for @writing_journal, html: { multipart: true ,:type=>"ajax_form", "callback-method"=>"formCallback"} , url: desktop_journal_pages_path do |f| %> +<%= form_for @writing_journal, html: { multipart: true, :type=>"ajax_form", "callback-method"=>"formCallback"} , url: desktop_journal_pages_path do |f| %> <%= render partial: 'desktop/journal_pages/form', locals: {:f => f} %> <%end%>