Skip to content

Instantly share code, notes, and snippets.

@ktusznio
Created January 10, 2012 21:24
Show Gist options
  • Save ktusznio/1591289 to your computer and use it in GitHub Desktop.
Save ktusznio/1591289 to your computer and use it in GitHub Desktop.
Batman Filtering
class Shopify.OrdersController extends Shopify.ApplicationController
index: (params) ->
@allOrders = Shopify.Order.get('all')
@_filterOrders()
addFilter: (type, value) ->
@set "#{type}Filter", value
@_filterOrders()
_filterOrders: ->
orders = @allOrders
for filterType in ['status', 'payment', 'fulfillment']
if filterValue = @get("#{filterType}Filter")
orders = orders.indexedBy(filterType).get(filterValue)
@set 'orders', orders
<div>Showing status (
<a data-event-click="addFilter | withArguments 'status', ''">any</a>
<a data-event-click="addFilter | withArguments 'status', 'open'">open</a>
<a data-event-click="addFilter | withArguments 'status', 'closed'">closed</a>)
payment status (
<a data-event-click="addFilter | withArguments 'payment', ''">any</a>
<a data-event-click="addFilter | withArguments 'payment', 'paid'">paid</a>
<a data-event-click="addFilter | withArguments 'payment', 'pending'">pending</a>
<a data-event-click="addFilter | withArguments 'payment', 'authorized'">authorized</a>
<a data-event-click="addFilter | withArguments 'payment', 'abandoned'">abandoned</a>
<a data-event-click="addFilter | withArguments 'payment', 'refunded'">refunded</a>
<a data-event-click="addFilter | withArguments 'payment', 'voided'">voided</a>)
</div>
<div data-foreach-order="orders">...</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment