159 lines
6.1 KiB
ERB
159 lines
6.1 KiB
ERB
<h2>New Deliverable</h2>
|
|
|
|
<% remote_form_for :deliverable, @deliverable, :url => {:controller => 'deliverables', :action => 'create', :id => @project },
|
|
:method => :post, :builder => TabularFormBuilder, :lang => current_language,
|
|
:html => {:multipart => true, :id => 'deliverable-form', :class => 'tabular'} do |f| %>
|
|
<%= error_messages_for 'deliverable' %>
|
|
<div class="box">
|
|
<div class="splitcontentleft">
|
|
<p><%= f.text_field :subject, :size => 65, :required => true %></p>
|
|
<p><%= f.text_area :description, :required => true,
|
|
:cols => 60,
|
|
:rows => (@deliverable.description.blank? ? 10 : [[10, @deliverable.description.length / 50].max, 100].min),
|
|
:accesskey => accesskey(:edit),
|
|
:class => 'wiki-edit' %></p>
|
|
<p><%= f.text_field :due_date, :size => 10 %><%= calendar_for('deliverable_due_date') %></p>
|
|
<%# TODO: Sign off PM and Client %>
|
|
</div>
|
|
|
|
<div class="splitcontentright">
|
|
<%# TODO: Need to update subtotals with observers %>
|
|
<p>TODO: Fixed cost</p>
|
|
|
|
<p><%= f.text_field :cost_per_hour, :size => 7 %></p>
|
|
<%= observe_field('deliverable_cost_per_hour', :function => "new Budget.updateAmounts();") %>
|
|
|
|
<p>
|
|
<%= f.text_field :total_hours, :size => 7 %>
|
|
<%= content_tag(:span, 0, :class => "budget-calculation", :id => 'variableCost') %>
|
|
</p>
|
|
<%= observe_field('deliverable_total_hours', :function => "new Budget.updateAmounts();") %>
|
|
|
|
<%= field_with_budget_observer_and_totals(f, :overhead) %>
|
|
<%= field_with_budget_observer_and_totals(f, :materials) %>
|
|
<%= field_with_budget_observer_and_totals(f, :profit) %>
|
|
|
|
<%= content_tag(:p,"Total Budget:" + content_tag(:span, 0, :id => 'total-budget-calculation', :class => "budget-calculation"),
|
|
:class => "total-budget") %>
|
|
|
|
<p><%= f.hidden_field :budget %></p>
|
|
</div>
|
|
|
|
<div style="clear:both;"> </div>
|
|
|
|
|
|
|
|
</div>
|
|
<%= submit_tag l(:button_create) %>
|
|
<%= link_to_remote l(:label_preview),
|
|
{ :url => { :controller => 'deliverables', :action => 'preview', :id => @project },
|
|
:method => 'post',
|
|
:update => 'preview',
|
|
:with => "Form.serialize('deliverable-form')",
|
|
:complete => "Element.scrollTo('preview')"
|
|
}, :accesskey => accesskey(:preview) %>
|
|
<% end %>
|
|
|
|
<%# Same as `wikitoolbar_for 'deliverable_description'` but without the help link %>
|
|
<%= javascript_include_tag('jstoolbar/jstoolbar') %>
|
|
<%= javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") %>
|
|
<%= javascript_tag("var toolbar = new jsToolBar($('deliverable_description'));toolbar.draw();") %>
|
|
|
|
|
|
<div id="preview" class="wiki"></div>
|
|
|
|
<% content_for :header_tags do %>
|
|
<script type="text/javascript">
|
|
|
|
var BudgetModule = Class.create();
|
|
|
|
Object.extend(BudgetModule.prototype, {
|
|
initialize: function () {},
|
|
|
|
toAmount: function(value) {
|
|
var amount = value.replace(/[^1234567890.]/ig,'');
|
|
if (amount) {
|
|
return parseFloat(amount);
|
|
} else {
|
|
return 0;
|
|
}
|
|
},
|
|
|
|
updateAmounts: function() {
|
|
var perHour = Budget.toAmount($('deliverable_cost_per_hour').value);
|
|
var hours = Budget.toAmount($('deliverable_total_hours').value);
|
|
|
|
var variableCost = perHour * hours;
|
|
|
|
if ($('deliverable_overhead').value.match('%')) {
|
|
var overhead_subtotal = (Budget.toAmount($('deliverable_overhead').value) / 100) * variableCost;
|
|
} else {
|
|
var overhead_subtotal = Budget.toAmount($('deliverable_overhead').value);
|
|
}
|
|
|
|
if ($('deliverable_materials').value.match('%')) {
|
|
var materials_subtotal = (Budget.toAmount($('deliverable_materials').value) / 100) * variableCost;
|
|
} else {
|
|
var materials_subtotal = Budget.toAmount($('deliverable_materials').value);
|
|
}
|
|
|
|
if ($('deliverable_profit').value.match('%')) {
|
|
var profit_subtotal = (Budget.toAmount($('deliverable_profit').value) / 100) * variableCost;
|
|
} else {
|
|
var profit_subtotal = Budget.toAmount($('deliverable_profit').value);
|
|
}
|
|
|
|
// Amounts
|
|
Budget.updateAmount($('variableCost'), variableCost);
|
|
Budget.updateAmount($('overhead_subtotal'), overhead_subtotal);
|
|
Budget.updateAmount($('materials_subtotal'), materials_subtotal);
|
|
Budget.updateAmount($('profit_subtotal'), profit_subtotal);
|
|
|
|
var total = variableCost + overhead_subtotal + materials_subtotal + profit_subtotal;
|
|
$('deliverable_budget').value = total;
|
|
$('total-budget-calculation').innerHTML = Budget.number_to_currency(total);
|
|
},
|
|
|
|
updateAmount: function(element, value) {
|
|
if (element) {
|
|
element.innerHTML = Budget.number_to_currency(value);
|
|
}
|
|
},
|
|
|
|
// Rails-like number_to_currency currency formatting
|
|
// http://snippets.dzone.com/posts/show/4646
|
|
number_to_currency: function (number, options) {
|
|
try {
|
|
var options = options || {};
|
|
var precision = options["precision"] || 2;
|
|
var unit = options["unit"] || "$";
|
|
var separator = precision > 0 ? options["separator"] || "." : "";
|
|
var delimiter = options["delimiter"] || ",";
|
|
|
|
var parts = parseFloat(number).toFixed(precision).split('.');
|
|
return unit + Budget.number_with_delimiter(parts[0], delimiter) + separator + parts[1].toString();
|
|
} catch(e) {
|
|
return number
|
|
}
|
|
},
|
|
|
|
number_with_delimiter: function (number, delimiter, separator) {
|
|
try {
|
|
var delimiter = delimiter || ",";
|
|
var separator = separator || ".";
|
|
|
|
var parts = number.toString().split('.');
|
|
parts[0] = parts[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + delimiter);
|
|
return parts.join(separator);
|
|
} catch(e) {
|
|
return number
|
|
}
|
|
}
|
|
});
|
|
|
|
Budget = new BudgetModule();
|
|
|
|
|
|
</script>
|
|
<% end %>
|