Skip to content

Instantly share code, notes, and snippets.

@ialexi
Created December 4, 2009 19:07
Show Gist options
  • Select an option

  • Save ialexi/249260 to your computer and use it in GitHub Desktop.

Select an option

Save ialexi/249260 to your computer and use it in GitHub Desktop.
// ==========================================================================
// Project: RsvpClient.contactsFilterController
// Copyright: ©2009 My Company, Inc.
// ==========================================================================
/*globals RsvpClient */
/** @class
@extends SC.Object
*/
sc_require("data_sources/rsvp");
RsvpClient.contactsFilterController = SC.ArrayController.create(
/** @scope RsvpClient.contactsFilterController.prototype */ {
sortMethod: RsvpClient.SORT_PRIORITY,
showAll: YES,
showVisited: YES,
showUnvisited: YES,
showResponded: YES,
showUnresponded: YES,
showNo: YES,
showYes: YES,
filteredContent: null,
// query: RsvpClient.DATA_QUERY,
sortingOrderChanged: function()
{
this._refilter();
}.observes("sortMethod"),
showAllDidChange: function()
{
if (this.get("showAll"))
{
this.set("showVisited", YES);
this.set("showUnvisited", YES);
this.set("showResponded", YES);
this.set("showUnresponded", YES);
this.set("showNo", YES);
this.set("showYes", YES);
}
}.observes("showAll"),
otherDidChange: function()
{
var each = this.getEach("showVisited", "showUnvisited", "showResponded", "showUnresponded", "showNo", "showYes");
var isAll = YES;
for (var i = 0; i < each.length; i++)
{
if (!each[i])
{
isAll = NO;
break;
}
}
this.set("showAll", isAll);
this._refilter();
}.observes("showVisited", "showUnvisited", "showResponded", "showUnresponded", "showNo", "showYes"),
_refilter: function()
{
if (!this.get("content"))
{
this.set("filteredContent", null);
return;
}
var result = [];
var c = this.get("content"), l = c.get("length");
var visited = this.get("showVisited"), unvisited = this.get("showUnvisited"),
yes = this.get("showYes"), no = this.get("showNo"),
responded = this.get("showResponded"), unresponded = this.get("showUnresponded");
for (var i = 0; i < l; i++)
{
var o = c.objectAt(i);
if (!visited && o.get("hasVisited")) continue;
if (!unvisited && !o.get("hasVisited")) continue;
if (!no && (!o.get("isAttending") && o.get("hasResponded"))) continue;
if (!yes && (o.get("isAttending") && o.get("hasResponded"))) continue;
if (!responded && o.get("hasResponded")) continue;
if (!unresponded && !o.get("hasResponded")) continue;
result.push(o);
}
this.set("filteredContent", result);
},
contentDidChange: function()
{
this._refilter();
}.observes('[]')
}) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment