Made the new deliverable form to submit via Ajax
* Added DeliverablesController#create * Refactored each deliverable row to a partial * Added RJS to update the page after a submission #1135
This commit is contained in:
1 parent
d1418c25d3
commit
b2ecaca21e
6 files changed
+51
-12
No files matched your search
@@ -30,6 +30,22 @@ class DeliverablesController < ApplicationController
|
|||||||
render :partial => 'common/preview'
|
render :partial => 'common/preview'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@deliverable = Deliverable.new(params[:deliverable])
|
||||||
|
@deliverable.project = @project
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @deliverable.save
|
||||||
|
@flash = l(:notice_successful_create)
|
||||||
|
format.html { redirect_to :action => 'index' }
|
||||||
|
format.js { render :action => 'create.js.rjs'}
|
||||||
|
else
|
||||||
|
# TODO: Failed save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
def find_project
|
||||||
@project = Project.find(params[:id])
|
@project = Project.find(params[:id])
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
class Deliverable < ActiveRecord::Base
|
class Deliverable < ActiveRecord::Base
|
||||||
|
unloadable
|
||||||
|
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
|
||||||
attr_accessor :overhead
|
attr_accessor :overhead
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<tr id="deliverable-<%= deliverable.id %>" class="deliverable <%= cycle('odd', 'even') %>">
|
||||||
|
<%= content_tag(:td, deliverable.id) %>
|
||||||
|
<%= content_tag(:td, deliverable.score) %>
|
||||||
|
<%= content_tag(:td, deliverable.subject) %>
|
||||||
|
<%= content_tag(:td, number_to_currency(deliverable.cost)) %>
|
||||||
|
<%= content_tag(:td, number_to_currency(deliverable.spent)) %>
|
||||||
|
<%= content_tag(:td, format_date(deliverable.due_date)) %>
|
||||||
|
<%= content_tag(:td, progress_bar(deliverable.progress, :width => '80px')) %>
|
||||||
|
</tr>
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
<h2>New Deliverable</h2>
|
<h2>New Deliverable</h2>
|
||||||
|
|
||||||
<% labelled_tabular_form_for :deliverable, @deliverable,
|
<% remote_form_for :deliverable, @deliverable, :url => {:controller => 'deliverables', :action => 'create', :id => @project },
|
||||||
:html => {:multipart => true, :id => 'deliverable-form'} do |f| %>
|
:method => :post, :builder => TabularFormBuilder, :lang => current_language,
|
||||||
|
:html => {:multipart => true, :id => 'deliverable-form', :class => 'tabular'} do |f| %>
|
||||||
<%= error_messages_for 'deliverable' %>
|
<%= error_messages_for 'deliverable' %>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="splitcontentleft">
|
<div class="splitcontentleft">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<% form_tag({}) do -%>
|
<% form_tag({}) do -%>
|
||||||
<table class="list deliverables">
|
<table id="deliverable-list" class="list deliverables">
|
||||||
<thead><tr>
|
<thead><tr>
|
||||||
<%# TODO: Other sorts %>
|
<%# TODO: Other sorts %>
|
||||||
<%= sort_header_tag("#{Deliverable.table_name}.id", :caption => '#', :default_order => 'desc') %>
|
<%= sort_header_tag("#{Deliverable.table_name}.id", :caption => '#', :default_order => 'desc') %>
|
||||||
@@ -12,15 +12,7 @@
|
|||||||
</tr></thead>
|
</tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% deliverables.each do |deliverable| -%>
|
<% deliverables.each do |deliverable| -%>
|
||||||
<tr id="deliverable-<%= deliverable.id %>" class="deliverable <%= cycle('odd', 'even') %>">
|
<%= render :partial => 'deliverable', :locals => { :deliverable => deliverable} %>
|
||||||
<%= content_tag(:td, deliverable.id) %>
|
|
||||||
<%= content_tag(:td, deliverable.score) %>
|
|
||||||
<%= content_tag(:td, deliverable.subject) %>
|
|
||||||
<%= content_tag(:td, number_to_currency(deliverable.cost)) %>
|
|
||||||
<%= content_tag(:td, number_to_currency(deliverable.spent)) %>
|
|
||||||
<%= content_tag(:td, format_date(deliverable.due_date)) %>
|
|
||||||
<%= content_tag(:td, progress_bar(deliverable.progress, :width => '80px')) %>
|
|
||||||
</tr>
|
|
||||||
<% end -%>
|
<% end -%>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# If there is no deliverable list, refresh the page
|
||||||
|
page << "if ($('deliverable-list') == null) {document.location.reload()}"
|
||||||
|
|
||||||
|
# Add deliverable to list
|
||||||
|
page.insert_html :top, 'deliverable-list', :partial => 'deliverable', :locals => {:deliverable => @deliverable}
|
||||||
|
|
||||||
|
# Remove errors if found
|
||||||
|
page.select('#errorExplanation').each do |value|
|
||||||
|
page.remove value
|
||||||
|
end
|
||||||
|
|
||||||
|
page << "Form.reset($('deliverable-form'))"
|
||||||
|
|
||||||
|
# Add a fading out flash
|
||||||
|
page.insert_html :before, 'new-deliverable', content_tag(:div, @flash, :class => "flash notice", :id => 'rjs-flash')
|
||||||
|
page.delay(3) do
|
||||||
|
page.visual_effect :fade, 'rjs-flash'
|
||||||
|
end
|
||||||
|
|
||||||
Reference in new issue
Block a user