var $ = require('jquery');
var Event = require('./Event');
var City = require('./City');

function EventsStore(eventsData, citiesData) {
  var store = this;
  this.events = [];
  this.cities = [];

  citiesData.forEach(function (data) {
    store.cities.push(new City(data));
  });

  eventsData.forEach(function (data) {
    var event = new Event(data);
    if (event.city)
      store.events.push(event);
  });

  store.events.forEach(function (event) {
    var eventCity = store.cities.filter(function (city) {
      return city.name == event.city;
    })[0];

    event.city = eventCity;
  });
}

/**
 * @static
 * @param {string} eventsUrl
 * @param {string} citiesUrl
 * @returns {Deferred}
 */
EventsStore.create = function (eventsUrl, citiesUrl) {
  var events;
  var cities;

  return $.getJSON(eventsUrl)
    .then(function (result) { events = result })
    .then(function () { return $.getJSON(citiesUrl) })
    .then(function (result) { cities = result })
    .then(function () { return new EventsStore(events, cities) })
};

module.exports = EventsStore;
@@ -1031,16 +1031,1579 @@
  %7D)%0A%7D;%0A%0A
+/**%0A * @static%0A */%0AEventsStore.filters = %7B%0A  time: function (time, event) %7B%0A    var isMatch = false;%0A    if (time == 'upcoming')%0A      isMatch = event.isUpcoming();%0A    else if (time == 'past')%0A      isMatch = !event.isUpcoming();%0A    else%0A      isMatch = true;%0A%0A    return isMatch;%0A  %7D,%0A%0A  lang: function (lang, event) %7B%0A    return event.lang == lang;%0A  %7D,%0A%0A  materials: function (materialType, event) %7B%0A    return event.content && event.content.hasOwnProperty(materialType);%0A  %7D,%0A%0A  fitBounds: function (bounds, event) %7B%0A    return bounds.contains(event.getBounds());%0A  %7D%0A%7D;%0A%0A/**%0A * @returns %7BArray%3CEvent%3E%7D%0A */%0AEventsStore.prototype.getUpcoming = function () %7B%0A  return this.events.filter(function (event) %7B%0A    return event.isUpcoming();%0A  %7D);%0A%7D;%0A%0A/**%0A * @returns %7BArray%3CEvent%3E%7D%0A */%0AEventsStore.prototype.getPast = function () %7B%0A  return this.events.filter(function (event) %7B%0A    return !event.isUpcoming();%0A  %7D);%0A%7D;%0A%0A/**%0A * @returns %7BArray%3CEvent%3E%7D%0A */%0AEventsStore.prototype.filter = function (constraints) %7B%0A  var events = this.events;%0A  var filtered = %5B%5D;%0A  var constraintNames = Object.keys(constraints);%0A%0A  events.forEach(function (event) %7B%0A    //var isMatched = false;%0A    var performedConstraintsCount = 0;%0A%0A    constraintNames.forEach(function (name) %7B%0A      var constraint = constraints%5Bname%5D;%0A      var filter = EventsStore.filters%5Bname%5D;%0A      if (filter(constraint, event)) %7B%0A        performedConstraintsCount++;%0A      %7D%0A    %7D);%0A%0A    if (performedConstraintsCount == constraintNames.length)%0A      filtered.push(event);%0A  %7D);%0A%0A  return filtered;%0A%7D;%0A%0A
 module.e

Add filters to EventStore