hidden file field, and fixed updated function

This commit is contained in:
Rueshyna 2012-11-22 02:37:56 +08:00
parent 262df57298
commit bb69a059e8
5 changed files with 45 additions and 35 deletions

View File

@ -35,32 +35,24 @@ class Desktop::JournalPagesController < ApplicationController
end end
def create def create
params[:writing_journal][:create_user_id] = current_user.id params[:writing_journal][:create_user_id] = current_user.id
@writing_journal = WritingJournal.new(params[:writing_journal]) @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
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 end
def update def update
if params[:commit].eql?"Save" params[:writing_journal][:update_user_id] = current_user.id
@writing_journal= WritingJournal.find(params[:id]) @writing_journal= WritingJournal.find(params[:id])
end
respond_to do |format| respond_to do |format|
if @writing_journal.update_attributes(params[:writing_journal]) if @writing_journal.update_attributes(params[:writing_journal])
format.html { redirect_to desktop_journal_pages_url, :layout => false, notice: 'User was successfully updated.'} render json: {success: true, msg: "Paper successfully saved!"}.to_json
format.json { head :no_content }
else else
format.html { render action: "edit" } render json: {success: false, msg: "Saving failed!"}.to_json
format.json { render json: @user.errors, status: :unprocessable_entity }
end end
end end
end end
@ -117,4 +109,11 @@ class Desktop::JournalPagesController < ApplicationController
render json: JSON.pretty_generate(data) render json: JSON.pretty_generate(data)
end end
private
def check_for_cancel
if params[:commit] == "Cancel"
end
end
end end

View File

@ -1,8 +1,17 @@
<% if @writing_journal.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@writing_journal.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @writing_journal.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="toolbar hh2"> <div class="toolbar hh2">
<div class="fn_g hp"> <div class="fn_g hp">
<%= f.submit "Save", name: "commit", value: "Save", class: "fn_btn hh2 thmc2 thmtxt" %> <%= 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" %> <!-- <%= submit_tag "Cancel", :class=>"fn_btn hh2 bt-cancel thmc2 thmtxt" %>-->
<%= content_tag(:button, "Cancel", :class=>"fn_btn hh2 bt-cancel thmc2 thmtxt") %>
</div> </div>
<div class="hh2 hp sdm"> <div class="hh2 hp sdm">
<div class="sdm_t hh2">Entry Year</div> <div class="sdm_t hh2">Entry Year</div>
@ -49,10 +58,10 @@
<div class="s_grid_con s_form"> <div class="s_grid_con s_form">
<ul> <ul>
<li class="s_grid_row"> <li class="s_grid_row">
<%= 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"%>
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">
<%= 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"%>
<span class="icon-plus input_append"></span> <span class="icon-plus input_append"></span>
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">
@ -86,34 +95,34 @@
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">
<%= 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"%>
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">
<%= 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"%>
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">
<%= 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"%>
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">
<%= 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"%>
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">
<%= 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"%>
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">
<%= 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"%>
</li> </li>
</ul> </ul>
</div> </div>
<div class="s_grid_con s_form"> <div class="s_grid_con s_form">
<ul> <ul>
<li class="s_grid_row"> <li class="s_grid_row">
<%= 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"%>
<span class="icon-plus input_append"></span> <span class="icon-plus input_append"></span>
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">
@ -148,7 +157,7 @@
<li class="s_grid_row"> <li class="s_grid_row">
<%= 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"%>
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">
@ -178,19 +187,21 @@
<ul> <ul>
<li class="s_grid_row"> <li class="s_grid_row">
<div> <%= label_tag("", "Full Text", class: "s_grid_2 s_grid") %></div> <div> <%= label_tag("", "Full Text", class: "s_grid_2 s_grid") %></div>
<%= f.fields_for :writing_journal_files,@writing_journal do |wjf| %> <!--
<%= f.fields_for :writing_journal_files, @writing_journal do |wjf| %>
<%= wjf.file_field :file %> <%= wjf.file_field :file %>
<% end %> <% end %>
-->
</li> </li>
<li class="s_grid_row"> <li class="s_grid_row">
<%= 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"%>
</li> </li>
</ul> </ul>
</div> </div>
<div class="s_grid_con s_form"> <div class="s_grid_con s_form">
<ul> <ul>
<li class="s_grid_row"> <li class="s_grid_row">
<%= 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"%>
</li> </li>
</ul> </ul>
</div> </div>

View File

@ -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} %> <%= render partial: 'desktop/journal_pages/form', locals: {:f => f} %>
<%end%> <%end%>

View File

@ -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} %> <%= render partial: 'desktop/journal_pages/form', locals: {:f => f} %>
<%end%> <%end%>