From bb69a059e89f158c365ca7e5b688c7188acc9f24 Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Thu, 22 Nov 2012 02:37:56 +0800 Subject: [PATCH] hidden file field, and fixed updated function --- .../javascripts/desktop/journal_pages.js.erb | 2 +- .../desktop/journal_pages_controller.rb | 33 ++++++++------- .../desktop/journal_pages/_form.html.erb | 41 ++++++++++++------- app/views/desktop/journal_pages/edit.html.erb | 2 +- app/views/desktop/journal_pages/new.html.erb | 2 +- 5 files changed, 45 insertions(+), 35 deletions(-) diff --git a/app/assets/javascripts/desktop/journal_pages.js.erb b/app/assets/javascripts/desktop/journal_pages.js.erb index 0bb9063d0..2c6821da1 100644 --- a/app/assets/javascripts/desktop/journal_pages.js.erb +++ b/app/assets/javascripts/desktop/journal_pages.js.erb @@ -228,4 +228,4 @@ orbitDesktop.prototype.initializeJournalPapers = function(target,url,cache){ // } - }; \ No newline at end of file + }; diff --git a/app/controllers/desktop/journal_pages_controller.rb b/app/controllers/desktop/journal_pages_controller.rb index 143978140..b389dca66 100644 --- a/app/controllers/desktop/journal_pages_controller.rb +++ b/app/controllers/desktop/journal_pages_controller.rb @@ -35,32 +35,24 @@ class Desktop::JournalPagesController < ApplicationController end def create - params[:writing_journal][:create_user_id] = current_user.id - @writing_journal = WritingJournal.new(params[:writing_journal]) - respond_to do |format| - if @writing_journal.save - format.json {render json: {success: true, msg: "Paper successfully saved!"}.to_json} - else - format.json {render json: {success: false, msg: "Saving failed!"}.to_json } - end + + if @writing_journal.save + render json: {success: true, msg: "Paper successfully saved!"}.to_json + else + render json: {success: false, msg: "Saving failed!"}.to_json end - end def update - if params[:commit].eql?"Save" - @writing_journal= WritingJournal.find(params[:id]) - end - + params[:writing_journal][:update_user_id] = current_user.id + @writing_journal= WritingJournal.find(params[:id]) 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.'} - format.json { head :no_content } + render json: {success: true, msg: "Paper successfully saved!"}.to_json else - format.html { render action: "edit" } - format.json { render json: @user.errors, status: :unprocessable_entity } + render json: {success: false, msg: "Saving failed!"}.to_json end end end @@ -117,4 +109,11 @@ class Desktop::JournalPagesController < ApplicationController render json: JSON.pretty_generate(data) end + + private + + def check_for_cancel + if params[:commit] == "Cancel" + end + end end diff --git a/app/views/desktop/journal_pages/_form.html.erb b/app/views/desktop/journal_pages/_form.html.erb index 6acea10d3..3d44ec8ff 100644 --- a/app/views/desktop/journal_pages/_form.html.erb +++ b/app/views/desktop/journal_pages/_form.html.erb @@ -1,8 +1,17 @@ +<% if @writing_journal.errors.any? %> +
+

<%= pluralize(@writing_journal.errors.count, "error") %> prohibited this user from being saved:

+ +
+<% end %>
<%= f.submit "Save", name: "commit", value: "Save", class: "fn_btn hh2 thmc2 thmtxt" %> - <%#= button_tag "Cancel", name: "cancel", value: "Cancel", class: "fn_btn hh2 thmc2 thmtxt" %> - <%= content_tag(:button, "Cancel", :class=>"fn_btn hh2 bt-cancel thmc2 thmtxt") %> +
Entry Year
@@ -49,10 +58,10 @@
  • - <%= f.text_area :paper_title, size: "20x2", value: "Paper Title", class: "s_grid_6 s_grid"%> + <%= f.text_area :paper_title, size: "20x2", value: @writing_journal.paper_title ||= "Paper Title", class: "s_grid_6 s_grid"%>
  • - <%= f.text_field :journal_title, size: "20" ,value: "Journal Title", class: "s_grid_6 s_grid"%> + <%= f.text_field :journal_title, size: "20" ,value: @writing_journal.journal_title ||= "Journal Title", class: "s_grid_6 s_grid"%>
  • @@ -86,34 +95,34 @@
  • - <%= label_tag("", "ISSN(ISBN)", class: "s_grid_2 s_grid") %><%= f.text_field :isbn, size: "20" ,value: "829872987", class: "s_grid_4 s_grid"%> + <%= label_tag("", "ISSN(ISBN)", class: "s_grid_2 s_grid") %><%= f.text_field :isbn, size: "20" ,value: @writing_journal.isbn ||= "829872987", class: "s_grid_4 s_grid"%>
  • - <%= label_tag("", "Volume No.", class: "s_grid_2 s_grid") %><%= f.text_field :vol_no, size: "20" ,value: "829872987", class: "s_grid_4 s_grid"%> + <%= label_tag("", "Volume No.", class: "s_grid_2 s_grid") %><%= f.text_field :vol_no, size: "20" ,value: @writing_journal.vol_no ||= "829872987", class: "s_grid_4 s_grid"%>
  • - <%= label_tag("", "Issue No.", class: "s_grid_2 s_grid") %><%= f.text_field :issue_no, size: "20" ,value: "829872987", class: "s_grid_4 s_grid"%> + <%= label_tag("", "Issue No.", class: "s_grid_2 s_grid") %><%= f.text_field :issue_no, size: "20" ,value: @writing_journal.issue_no ||= "829872987", class: "s_grid_4 s_grid"%>
  • - <%= label_tag("", "Total Pages", class: "s_grid_2 s_grid") %><%= f.text_field :total_pages, size: "20" ,value: "20", class: "s_grid_4 s_grid"%> + <%= label_tag("", "Total Pages", class: "s_grid_2 s_grid") %><%= f.text_field :total_pages, size: "20" ,value: @writing_journal.total_pages ||= "20", class: "s_grid_4 s_grid"%>
  • - <%= label_tag("", "Pages", class: "s_grid_2 s_grid") %><%= label_tag("", "from", class: "s_grid_1 s_grid") %><%= f.text_field :form_to_start, size: "10" ,value: "1", class: "s_grid_1 s_grid"%><%= label_tag("", "to", class: "s_grid_1 s_grid") %><%= f.text_field :form_to_end, size: "10" ,value: "20", class: "s_grid_1 s_grid"%> + <%= label_tag("", "Pages", class: "s_grid_2 s_grid") %><%= label_tag("", "from", class: "s_grid_1 s_grid") %><%= f.text_field :form_to_start, size: "10" ,value: @writing_journal.form_to_start ||= "1", class: "s_grid_1 s_grid"%><%= label_tag("", "to", class: "s_grid_1 s_grid") %><%= f.text_field :form_to_end, size: "10" ,value: @writing_journal.form_to_end ||= "20", class: "s_grid_1 s_grid"%>
  • - <%= label_tag("", "Reference URL", class: "s_grid_2 s_grid") %><%= f.text_field :url, size: "20" ,value: "www.sample.com", class: "s_grid_4 s_grid"%> + <%= label_tag("", "Reference URL", class: "s_grid_2 s_grid") %><%= f.text_field :url, size: "20" ,value: @writing_journal.url ||= "www.sample.com", class: "s_grid_4 s_grid"%>
  • - <%= f.text_area :authors, size: "20x2", value: "Authors", class: "s_grid_6 s_grid"%> + <%= f.text_area :authors, size: "20x2", value: @writing_journal.authors ||= "Authors", class: "s_grid_6 s_grid"%>
  • @@ -148,7 +157,7 @@
  • - <%= f.text_field :keyword, size: "20", value: "Keywords", class: "s_grid_6 s_grid"%> + <%= f.text_field :keywords, size: "20", value: @writing_journal.keywords ||= "Keywords", class: "s_grid_6 s_grid"%>
  • @@ -178,19 +187,21 @@
    • <%= label_tag("", "Full Text", class: "s_grid_2 s_grid") %>
      - <%= f.fields_for :writing_journal_files,@writing_journal do |wjf| %> +
    • - <%= f.text_area :note, size: "20x2", value: "Note", class: "s_grid_6 s_grid"%> + <%= f.text_area :note, size: "20x2", value: @writing_journal.note ||= "Note", class: "s_grid_6 s_grid"%>
  • - <%= f.text_area :abstract, size: "20x26", value: "Abstract", class: "s_grid_6 s_grid"%> + <%= f.text_area :abstract, size: "20x26", value: @writing_journal.abstract ||= "Abstract", class: "s_grid_6 s_grid"%>
diff --git a/app/views/desktop/journal_pages/edit.html.erb b/app/views/desktop/journal_pages/edit.html.erb index 1377af92b..80d8ae2ef 100644 --- a/app/views/desktop/journal_pages/edit.html.erb +++ b/app/views/desktop/journal_pages/edit.html.erb @@ -1,3 +1,3 @@ -<%= form_for @writing_journal, url: desktop_journal_page_path(@writing_journal),html: { multipart: true ,"form-type"=>"ajax_form", "callback-method"=>"formCallback"} do |f| %> +<%= form_for @writing_journal, html: { multipart: true, "form-type"=>"ajax_form", "callback-method"=>"formCallback"}, url: desktop_journal_page_path(@writing_journal) do |f| %> <%= render partial: 'desktop/journal_pages/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 d5f5557bf..c872e7cfe 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, "form-type"=>"ajax_form", "callback-method"=>"formCallback"} , url: desktop_journal_pages_path do |f| %> +<%= form_for @writing_journal, html: { multipart: true, "form-type"=>"ajax_form", "callback-method"=>"formCallback"}, url: desktop_journal_pages_path do |f| %> <%= render partial: 'desktop/journal_pages/form', locals: {:f => f} %> <%end%>