This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Re-enable search, courtesy of BRCM.

  • Loading branch information...
eventualbuddha committed Dec 9, 2010
1 parent 532b2db commit 6041321ec71393660ad7ee8e36673de9400f2a22
@@ -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?
@@ -39,7 +39,6 @@
</div>
</ul>
</li>
- <!--
<li id="nav-search" style="display:none">
<form id="searchform" action="/accounts/search" method="get">
<fieldset>
@@ -49,7 +48,6 @@
</fieldset>
</form>
</li>
- -->
</ul><!-- end of #secondary-nav-->
<div class="clear"></div>
</div>
View
@@ -25,6 +25,7 @@
end
collection do
+ get :search
post :enable
post :trigger_updates
end
@@ -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();
@@ -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();
},
/**
@@ -69,8 +69,6 @@
return false;
});
- this.setUpSearch();
-
wesabe.ready('wesabe.views.widgets.accounts.__instance__', function() {
self.setUpAccountsWidget();
});
@@ -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() {
@@ -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);
},
@@ -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();
}
},
@@ -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'});
@@ -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) {

0 comments on commit 6041321

Please sign in to comment.