Skip to content

Commit

Permalink
final draft of the search
Browse files Browse the repository at this point in the history
  • Loading branch information
ishmael committed Jul 29, 2010
1 parent 11931ab commit c0d753f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
16 changes: 10 additions & 6 deletions app/models/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def end_date
end

def max_amount
options[:max_amount].to_i != 0 ? options[:max_amount].to_i : nil
Money.new(options[:max_amount].to_money.cents,currency)
end

def min_amount
options[:min_amount].to_i != 0 ? options[:min_amount].to_i : nil
Money.new(options[:min_amount].to_money.cents,currency)
end

def description
Expand All @@ -32,6 +32,10 @@ def type_mov_hidden
options[:type_mov_hidden]
end

def currency
options[:currency]
end

# method_missing will autogenerate an accessor for any attribute other
# than the methods already written. I love this magic. :)
def method_missing(method_id, *arguments)
Expand Down Expand Up @@ -61,14 +65,14 @@ def conditions
parameters << end_date
end

if min_amount
if min_amount.cents != 0
conditions << "#{@model.table_name}.amount_in_cents >= ?"
parameters << min_amount * 100
parameters << min_amount.cents
end

if max_amount
if max_amount.cents != 0
conditions << "#{@model.table_name}.amount_in_cents <= ?"
parameters << max_amount * 100
parameters << max_amount.cents
end

if not type_mov_hidden.empty?
Expand Down
5 changes: 3 additions & 2 deletions app/views/movements/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="boxin">
<div class="header">
<h3><%= I18n.t('layout.movements.name') %></h3>
<h4><%= I18n.t('layout.movements.dates_interval') % [@startdate,@enddate] %> </h4>
<h4><%= I18n.t('layout.movements.dates_interval') % [@startdate.strftime("%d-%m-%Y"),@enddate.strftime("%d-%m-%Y")] %> </h4>
<% if not @movements.empty? %>
<% if @account.allow_insert == '1' %>
<%= link_to I18n.t('layout.movements.new'), new_polymorphic_path([@account,:movement]) ,:class => 'button'%>
Expand Down Expand Up @@ -98,7 +98,7 @@
</dd>
<dt><%= I18n.t('layout.movements.amount') %></dt>
<dd class="search-input">
<%= f.text_field :min_amount,:class=>'txt' %> a <%= f.text_field :max_amount,:class=>'txt' %>
<%= f.text_field :min_amount,:value=> Money.new(0,@account.currency).to_s,:class=>'txt' %> a <%= f.text_field :max_amount,:value=> Money.new(0,@account.currency).to_s,:class=>'txt' %>
</dd>
<dt><%= I18n.t('layout.movements.typetag') %></dt>
<dd>
Expand All @@ -114,6 +114,7 @@
<dd ><div id="calSearchContainer" >
<%= f.hidden_field :start_date %>
<%= f.hidden_field :end_date %>
<%= f.hidden_field :currency, :value => @account.currency %>

</div></dd>
<dd class="submit">
Expand Down
4 changes: 2 additions & 2 deletions app/views/movements/search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</dd>
<dt><%= I18n.t('layout.movements.amount') %></dt>
<dd class="search-input">
<%= f.text_field :min_amount,:class=>'txt' %> a <%= f.text_field :max_amount,:class=>'txt' %>
<%= f.text_field :min_amount,:value => @search.min_amount,:class=>'txt' %> a <%= f.text_field :max_amount,:class=>'txt' %>
</dd>
<dt><%= I18n.t('layout.movements.typetag') %></dt>
<dd>
Expand All @@ -108,7 +108,7 @@
<dd ><div id="calSearchContainer" >
<%= f.hidden_field :start_date %>
<%= f.hidden_field :end_date %>

<%= f.hidden_field :currency, :value => @account.currency %>
</div></dd>
<dd class="submit">
<div>
Expand Down
14 changes: 7 additions & 7 deletions public/javascripts/bankaccount_dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@
var d = a[0][0];
/*alert(d[0]);
alert(d[1]);
alert(d[2]); */
var date = YAHOO.widget.DateMath.getDate(d[2], d[1] - 1, d[0]);
alert(d[2]);*/
var date = YAHOO.widget.DateMath.getDate(d[0], d[1] - 1, d[2]);
var page = this.getCalendarPage(date);
if(page) {
// Now (re)select the individual date
Expand Down Expand Up @@ -298,7 +298,7 @@
/*inTxt.value = "";
outTxt.value = "";*/

var cal = new YAHOO.example.calendar.IntervalCalendar("calSearchContainer", {pages:1,navigator:true,DATE_RANGE_DELIMITER:"/",DATE_FIELD_DELIMITER:"-",MDY_MONTH_POSITION:2,MDY_DAY_POSITION:3,MDY_YEAR_POSITION:1});
var cal = new YAHOO.example.calendar.IntervalCalendar("calSearchContainer", {pages:1,navigator:true,MDY_MONTH_POSITION:2,MDY_DAY_POSITION:1,MDY_YEAR_POSITION:3});
// cal.cfg.setProperty("DATE_FIELD_DELIMITER", ".");
var oButtonGroup1 = new YAHOO.widget.ButtonGroup("buttongroup1");

Expand All @@ -320,11 +320,11 @@

if (interval.length == 2) {
inDate = interval[0];
inTxt.value = inDate.getFullYear() + "-" + (inDate.getMonth() + 1) + "-" + inDate.getDate() ;
inTxt.value = inDate.getDate() + "/" + (inDate.getMonth() + 1) + "/" + inDate.getFullYear() ;
//inTxt.value= inDate;
if (interval[0].getTime() != interval[1].getTime()) {
outDate = interval[1];
outTxt.value = outDate.getFullYear() + "-" + (outDate.getMonth() + 1) + "-" +outDate.getDate();
outTxt.value = outDate.getDate() + "/" + (outDate.getMonth() + 1) + "/" +outDate.getFullYear();
} else {
outTxt.value = "";
}
Expand All @@ -340,8 +340,8 @@
outTxt.value = "";
}
}, cal, true);
//alert(new Date(inTxt.value));
//cal.setInterval(new Date(inTxt.value),new Date(outTxt.value));
//alert( new Date(Date.parse(outTxt.value)));
//cal.setInterval(inTxt.value,outTxt.value);
cal.render();

});
Expand Down

0 comments on commit c0d753f

Please sign in to comment.