Skip to content
This repository has been archived by the owner on May 8, 2018. It is now read-only.

Commit

Permalink
Re-enable search, courtesy of BRCM.
Browse files Browse the repository at this point in the history
  • Loading branch information
eventualbuddha committed Dec 9, 2010
1 parent 532b2db commit 6041321
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 60 deletions.
5 changes: 5 additions & 0 deletions app/controllers/accounts_controller.rb
Expand Up @@ -17,6 +17,11 @@ def show
end
end

# GET /accounts/search
def search
render :action => 'index'
end

# DELETE /accounts/1
def destroy
if account.nil?
Expand Down
2 changes: 0 additions & 2 deletions app/views/layouts/_masthead.html.erb
Expand Up @@ -39,7 +39,6 @@
</div>
</ul>
</li>
<!--
<li id="nav-search" style="display:none">
<form id="searchform" action="/accounts/search" method="get">
<fieldset>
Expand All @@ -49,7 +48,6 @@
</fieldset>
</form>
</li>
-->
</ul><!-- end of #secondary-nav-->
<div class="clear"></div>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -25,6 +25,7 @@
end

collection do
get :search
post :enable
post :trigger_updates
end
Expand Down
23 changes: 2 additions & 21 deletions public/javascripts/wesabe/data/TransactionDataSource.js
Expand Up @@ -23,9 +23,7 @@ wesabe.$class('wesabe.data.TransactionDataSource', wesabe.data.BaseDataSource, f
getSourceURI: function() {
// REVIEW: I'm sure this is not the right way to do this, but it works
var accountSelections = page.selection.getByClass(wesabe.views.widgets.accounts.Account);
if (this.isSearch())
return '/accounts/search'
else if (accountSelections[0] && accountSelections[0].isInvestment()) // main selection needs to be investment account
if (accountSelections[0] && accountSelections[0].isInvestment()) // main selection needs to be investment account
return '/data/investment-transactions/'+this._getCurrency();
else
return '/data/transactions/'+this._getCurrency();
Expand Down Expand Up @@ -76,24 +74,7 @@ wesabe.$class('wesabe.data.TransactionDataSource', wesabe.data.BaseDataSource, f
* @return {jQuery.ajax.data}
*/
getRequestQueryParams: function() {
var params = this.getParams();

if (!this.isSearch())
return params;

// ask for the right data type
lang.params.set(params, 'format', this.getDataType());

// pfc expects q=, not query=
lang.params.set(params, 'q', lang.params.get(params, 'query'));
lang.params.remove(params, 'query');

// pfc expects a page number, not offset/limit
lang.params.set(params, 'page', this._getPageNumber());
lang.params.remove(params, 'offset');
lang.params.remove(params, 'limit');

return params;
return this.getParams();
},

/**
Expand Down
59 changes: 23 additions & 36 deletions public/javascripts/wesabe/views/pages/accounts.js
Expand Up @@ -69,8 +69,6 @@
return false;
});

this.setUpSearch();

wesabe.ready('wesabe.views.widgets.accounts.__instance__', function() {
self.setUpAccountsWidget();
});
Expand All @@ -83,19 +81,16 @@
self.setUpTagsWidget();
});

shared.addSearchListener(function(query) {
self.onSearch(query);
});

$(function(){ self.attemptToReloadState() });
},

setUpSearch: function() {
var self = this;

// enable search
$('#nav-search').show();
$("#searchform").submit(function(event) {
event.preventDefault();
$('#query').blur();
shared.pushState('/accounts/search', {q: $('#query').val()});
});
onSearch: function(query) {
this.search = query;
this.storeState();
},

setUpAccountsWidget: function() {
Expand Down Expand Up @@ -340,7 +335,7 @@
}
}

$('#query').val(this.search || '');
shared.setSearch(this.search || '');
this.setTitleForState(accounts, groups, tags, merchants, this.search);
this.setAddTransactionAvailabilityForState(accounts, groups, tags, merchants, this.search);
},
Expand Down Expand Up @@ -477,18 +472,14 @@
var chart = wesabe.charts.txn;
chart.params = this.paramsForCurrentSelection();

if (this.search) chart.hide();
else {
var account = page.selection.getByClass(wesabe.views.widgets.accounts.Account)[0];
if (account && account.isInvestment()) {
chart.hide();
this.displayInvestmentHeader(account);
}
else {
$("#investment-header").hide();
chart.redraw();
chart.show();
}
var account = page.selection.getByClass(wesabe.views.widgets.accounts.Account)[0];
if (account && account.isInvestment()) {
chart.hide();
this.displayInvestmentHeader(account);
} else {
$("#investment-header").hide();
chart.redraw();
chart.show();
}
},

Expand Down Expand Up @@ -546,18 +537,14 @@
params.push({name: 'end', value: date.toParam(this.end)});
}

if (this.search) {
if (this.search != null)
params.push({name: 'query', value: this.search});
// searching requires an offset and a limit, so always give it something
params.push({name: 'offset', value: this.offset || 0});
params.push({name: 'limit', value: this.limit || TRANSACTIONS_PER_PAGE});
} else {
// when not searching we don't necessarily need offset and limit
if (this.offset !== null)
params.push({name: 'offset', value: this.offset});
if (this.limit !== null)
params.push({name: 'limit', value: this.limit});
}

// when not searching we don't necessarily need offset and limit
if (this.offset !== null)
params.push({name: 'offset', value: this.offset});
if (this.limit !== null)
params.push({name: 'limit', value: this.limit});

params.push({name: 'unedited', value: this.unedited ? 'true' : 'false'});

Expand Down
9 changes: 8 additions & 1 deletion public/javascripts/wesabe/views/shared.js
Expand Up @@ -129,14 +129,21 @@ wesabe.provide('views.shared', {
},

addSearchListener: function(fn) {
var input = $('#query');

$('#nav-search').show();
$("#searchform").submit(function(event) {
event.preventDefault();
fn();
fn(input.val());
input.blur();
});
return this;
},

setSearch: function(search) {
$('#query').val(search);
},

enableDefaultAccountsSearch: function() {
var self = this;
self.addSearchListener(function(event) {
Expand Down

0 comments on commit 6041321

Please sign in to comment.