Skip to content

Commit

Permalink
Tela de cadastro unificada com o dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
pbalduino committed Dec 22, 2009
1 parent b30871d commit 41a7d0e
Show file tree
Hide file tree
Showing 10 changed files with 1,663 additions and 1,165 deletions.
3 changes: 2 additions & 1 deletion app/controllers/users_controller.rb
Expand Up @@ -24,8 +24,9 @@ def create

def edit
@user = User.find(session[:user_id])
@weight = Weight.new
@weights = Weight.find(:all, :order => 'date DESC', :limit => 5, :conditions => {:user_id => session[:user_id]})
@first_weight = Weight.first(:order => :date, :conditions => {:user_id => session[:user_id]})
@first_weight = Weight.first(:order => :date, :conditions => {:user_id => session[:user_id]})
end

def ajax_update
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/weights_controller.rb
Expand Up @@ -23,13 +23,12 @@ def create
@weight = Weight.new(params[:weight])
@weight.user_id = session[:user_id]
date = params[:weight][:date]
@weight.date = DateTime.new(date[6..9].to_i, date[3..4].to_i, date[0..1].to_i)
@weight.date = DateTime.new(date[6..9].to_i, date[3..4].to_i, date[0..1].to_i)

puts @weight.to_json

if @weight.save
flash[:notice] = 'Weight was successfully created.'
redirect_to(@weight)
redirect_to profile_path
else
render :action => "new"
end
Expand Down
17 changes: 13 additions & 4 deletions app/views/layouts/default.html.erb
Expand Up @@ -14,23 +14,32 @@
'jquery.datepicker',
'jquery.flot.min',
'jquery.flot.crosshair',
'jquery.labelify'] %>
'jquery.labelify',
'jquery.blockUI'] %>
<%= stylesheet_link_tag 'default' %>
<%= stylesheet_link_tag 'datepicker' %>
</head>
<script type="text/javascript">
$(document).ready(function() {
$('.date-pick').datePicker({startDate:'01/11/2009'}); // .val($(this).attr('value')).trigger('change');
$('#addWeight').click(function() {
$.blockUI({
message: $('#weightForm')
});
});

$('#closeForm').click(function() {
$.unblockUI();
});
labelify();
$('.date-pick').datePicker({startDate:'01/11/2009'});
});
</script>

<body>
<%= yield %>
<div id="footer">
PercaPeso<br/>
Versão 0.4.35 - 22/Dez/2009
Versão 0.5.0 - 22/Dez/2009
</div>
</body>
</html>
33 changes: 17 additions & 16 deletions app/views/users/edit.html.erb
Expand Up @@ -16,7 +16,6 @@
<%= text_field_tag :date, @user.date, :class => 'labelified', :value => @user.date ? @user.date.strftime('%d/%m/%Y') : '' %>
<br/>
<%= link_to 'Sair', logout_path %>

</div>
<div id="user_weight">
meu peso
Expand All @@ -34,18 +33,16 @@
</tr>
<% end %>
</table>
<%= link_to 'Adicionar peso', weights_path %>
<a href='#' id='addWeight'>Adicionar peso</a>
<br/>
</div>
<div id="graphic">
evolução x meta <br/>

<div id="placeholder" style="width:600px;height:300px;">
</div>
<script type="text/javascript">
<% if @first_weight && @user.date %>
uw = [
<% fw = @first_weight.date
uw = [<% fw = @first_weight.date
ud = @user.date
d = -1;
(Date.new(fw.year, fw.month, fw.day) .. Date.new(ud.year, ud.month, ud.day)).each do |day| %>
Expand All @@ -56,9 +53,9 @@
meta = [];
<%= "daily_meta = #{(@first_weight.weight.to_f - @user.meta.to_f) / 33}" %>;
for (i = 0; i < 34; i++) {
meta.push([i, <%= @first_weight.weight %> - (daily_meta * i)]);
meta.push([i,<%= @first_weight.weight %>-(daily_meta * i)]);
}
plot = $.plot($("#placeholder"), [
$.plot($("#placeholder"), [
{
label: "meta (kg)",
data: meta
Expand All @@ -67,17 +64,21 @@
label: "peso (kg)",
data: uw
},
],
{
grid: {
backgroundColor: {
colors: ["#fff", "#eee"]
}
}
});

], {grid:{backgroundColor:{colors:["#fff","#eee"]}}});
<% else %>
$.plot($("#placeholder"), [], {grid: {backgroundColor: { colors: ["#fff", "#eee"] }}});
<% end %>
</script>
</div>
<div id="weightForm">
<a href="#" id="closeForm">[X] fechar</a>
<% form_for(@weight) do |f| %>
<%= f.error_messages %>
<%= f.label :date, 'data' %>
<%= f.text_field :date, :readonly => true, :class => 'date-pick', :value => Date.today.strftime('%d/%m/%Y') %><br />
<%= f.label :weight, 'peso (kg)' %>
<%= f.text_field :weight, :maxlength => 6 %>
<br/>
<%= f.submit 'Adicionar' %>
<% end %>
</div>
15 changes: 5 additions & 10 deletions app/views/weights/new.html.erb
@@ -1,19 +1,14 @@
<h1>New weight</h1>

<% form_for(@weight) do |f| %>
<%= f.error_messages %>
<%= f.error_messages %>
<p>
<%= f.label :date %><br />
<%= f.text_field :date, :readonly => true, :class => 'date-pick', :value => Date.today.strftime('%d/%m/%Y') %>
</p>
<p>
<%= f.label :weight %><br />
<%= f.label :date %>
<%= f.text_field :date, :readonly => true, :class => 'date-pick', :value => Date.today.strftime('%d/%m/%Y') %><br />
<%= f.label :weight %>
<%= f.text_field :weight, :maxlength => 6 %>
</p>
<p>
<br/>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', weights_path %>

0 comments on commit 41a7d0e

Please sign in to comment.