diff --git a/Gemfile b/Gemfile index aa0f704..6b050e3 100644 --- a/Gemfile +++ b/Gemfile @@ -110,7 +110,7 @@ group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' - # Better Errors replaces the standard Rails error page with a much better and more useful error page. + # Better Errors replaces the standard Rails error page with a much better and more useful error page. gem "better_errors" gem "binding_of_caller" diff --git a/app/assets/stylesheets/application.sass b/app/assets/stylesheets/application.sass index 424b669..b408dd9 100644 --- a/app/assets/stylesheets/application.sass +++ b/app/assets/stylesheets/application.sass @@ -22,7 +22,7 @@ @import "donations" @import "nav" -*:focus +*:focus outline: 0 -webkit-box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.075), 0 0 8px red box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.075), 0 0 8px red @@ -38,6 +38,10 @@ .alert-notice @extend .alert-info +.form-inline > * + margin: 5px + + body.admin background: repeating-linear-gradient(45deg, yellow, yellow 50px, black 50px, black 100px) @@ -51,7 +55,7 @@ body padding: 20px margin-top: 10px background: #FFF - + .anouncement margin-top: 10px @@ -64,38 +68,38 @@ body h1 font-size: 20px margin-top: 35px - + .navbar .container padding-left: 0px - + header > .row margin-bottom: 12px - + main > h1 margin-top: 0px ul#topnav font-size: 1.2em - + li text-transform: uppercase - + ul - li + li text-transform: none - + li.active border-bottom: 1px solid #66903F - + .lead font-weight: normal - + #new_supporter label.required abbr display: none - + #counter background-color: $brand-success margin-top: 24px @@ -103,7 +107,7 @@ body border: 1px solid $brand-success border-radius: 5px color: white - + .counter_char background-color: white width: 20px @@ -114,7 +118,7 @@ body display: inline-block text-align: center color: $brand-success - + .text-success color: $brand-success @@ -122,18 +126,18 @@ body display: block float: left margin: 12px - + .table-inherit width: inherit - - footer + + footer h2 margin: 0px font-size: $font-size-base - ol + ol padding-left: 1em - + .donation_button height: 50px background: $brand-success @@ -149,10 +153,10 @@ body left: -47px box-shadow: inset 0px 0px 0px 4px rgba(255, 255, 255, 0.34) - a + a color: #FFF -.row.fix +.row.fix display: flex flex-wrap: wrap width: 100% diff --git a/app/controllers/network/signature_collections_controller.rb b/app/controllers/network/signature_collections_controller.rb index bc9bc22..d8fb45c 100644 --- a/app/controllers/network/signature_collections_controller.rb +++ b/app/controllers/network/signature_collections_controller.rb @@ -5,7 +5,22 @@ class Network::SignatureCollectionsController < ApplicationController # GET /network/signature_collections # GET /network/signature_collections.json def index + @query, @location, @distance = params[:query], params[:location], params[:distance] + @network_signature_collections = Network::SignatureCollection.where(:event_date_start.gte => DateTime.now) + + @network_signature_collections = @network_signature_collections.or(location_zip_s: /#{@query}/) if @query + @network_signature_collections = @network_signature_collections.or(location_name: /#{@query}/) if @query + @network_signature_collections = @network_signature_collections.or(location_address: /#{@query}/) if @query + + distance_from_location + end + + def distance_from_location + return unless @location && @distance + location_coordinates = Geocoder.coordinates(@location) + return unless location_coordinates # only filter when coordinates found + @network_signature_collections = @network_signature_collections.geo_near(location_coordinates.reverse).max_distance(@distance.to_f/111) end # GET /network/signature_collections/1 diff --git a/app/models/network/signature_collection.rb b/app/models/network/signature_collection.rb index 62c7df8..006b7ab 100644 --- a/app/models/network/signature_collection.rb +++ b/app/models/network/signature_collection.rb @@ -1,8 +1,30 @@ class Network::SignatureCollection include Mongoid::Document + include Geocoder::Model::Mongoid + field :location_name, type: String field :location_zip, type: Integer + field :location_zip_s, type: String field :location_address, type: String field :event_date_start, type: Time field :event_date_end, type: Time + field :coordinates, type: Array + + geocoded_by :address + before_save :update_location # auto-fetch coordinates + before_save :stringify_zip # auto-fetch coordinates + + def address + "#{location_zip} #{location_name}, Switzerland" + end + + def update_location + geocode + end + + def stringify_zip + self.location_zip_s = self.location_zip.to_s + end + + index({coordinates: "2d"}) end diff --git a/app/views/network/signature_collections/index.html.slim b/app/views/network/signature_collections/index.html.slim index f2b7263..8bfaef7 100644 --- a/app/views/network/signature_collections/index.html.slim +++ b/app/views/network/signature_collections/index.html.slim @@ -1,6 +1,21 @@ h1 = title t('.title') -#signature_collections_table - input.search.form-control.string placeholder="#{t('.search')}" +css: + .form-inline > * { + margin: 5px; + } +form + .form-inline + input.form-control placeholder="#{t('.search')}" name="query" value="#{@query}" + input.form-control placeholder="#{t('.location')}" name="location" value="#{@location}" + select.form-control name="distance" + - [5, 10, 20, 50, 100, 150, 200].each do | d | + - if d == @distance.to_i + option value="#{d}" selected="selected" #{d} Km + - else + option value="#{d}" #{d} Km + + input.btn.btn-primary type="submit" value="#{t('.search')}" + table.table thead tr @@ -30,10 +45,3 @@ h1 = title t('.title') br = link_to t('.new'), new_network_signature_collection_path - -javascript: - var options = { - valueNames: [ 'location_name', 'location_zip', 'location_address', 'event_date_start', 'event_date_end' ] - }; - - var signature_collections = new List('signature_collections_table', options); diff --git a/config/locales/de.yml b/config/locales/de.yml index 05f36f8..d41f39c 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -119,6 +119,7 @@ de: new: Neue Sammlung erfasssen title: Unterschriftensammlungen search: Suche + location: Ort routes: initiative_text: initiativtext arguments: argumentarium diff --git a/db/seeds.rb b/db/seeds.rb index b10f45d..9dc17d1 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,8 +7,9 @@ # Mayor.create(name: 'Emanuel', city: cities.first) @cities = CSV.read Rails.root.join('db', 'plz_ch.csv') - @cities.sample(122).each do |city| tmp_date = DateTime.now + rand(50) Network::SignatureCollection.create(location_zip: city.first, location_name: city.last, location_address: Faker::Address.street_address, event_date_start: tmp_date, event_date_end: tmp_date+rand(10).to_f/10) end + +# Network::SignatureCollection.where(location: {"$near" => x.location, '$maxDistance' => 1.fdiv(111.12)}).map &:location_name diff --git a/vendor/assets/javascripts/list.js b/vendor/assets/javascripts/list.js deleted file mode 100644 index d40457f..0000000 --- a/vendor/assets/javascripts/list.js +++ /dev/null @@ -1,1758 +0,0 @@ -/*! List.js v1.5.0 (http://listjs.com) by Jonny Strömberg (http://javve.com) */ -var List = -/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; - -/******/ // The require function -/******/ function __webpack_require__(moduleId) { - -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; - -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; - -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - -/******/ // Flag the module as loaded -/******/ module.l = true; - -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } - - -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; - -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; - -/******/ // identity function for calling harmony imports with the correct context -/******/ __webpack_require__.i = function(value) { return value; }; - -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { -/******/ configurable: false, -/******/ enumerable: true, -/******/ get: getter -/******/ }); -/******/ } -/******/ }; - -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; - -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; - -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; - -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 11); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, exports, __webpack_require__) { - -/** - * Module dependencies. - */ - -var index = __webpack_require__(4); - -/** - * Whitespace regexp. - */ - -var re = /\s+/; - -/** - * toString reference. - */ - -var toString = Object.prototype.toString; - -/** - * Wrap `el` in a `ClassList`. - * - * @param {Element} el - * @return {ClassList} - * @api public - */ - -module.exports = function(el){ - return new ClassList(el); -}; - -/** - * Initialize a new ClassList for `el`. - * - * @param {Element} el - * @api private - */ - -function ClassList(el) { - if (!el || !el.nodeType) { - throw new Error('A DOM element reference is required'); - } - this.el = el; - this.list = el.classList; -} - -/** - * Add class `name` if not already present. - * - * @param {String} name - * @return {ClassList} - * @api public - */ - -ClassList.prototype.add = function(name){ - // classList - if (this.list) { - this.list.add(name); - return this; - } - - // fallback - var arr = this.array(); - var i = index(arr, name); - if (!~i) arr.push(name); - this.el.className = arr.join(' '); - return this; -}; - -/** - * Remove class `name` when present, or - * pass a regular expression to remove - * any which match. - * - * @param {String|RegExp} name - * @return {ClassList} - * @api public - */ - -ClassList.prototype.remove = function(name){ - // classList - if (this.list) { - this.list.remove(name); - return this; - } - - // fallback - var arr = this.array(); - var i = index(arr, name); - if (~i) arr.splice(i, 1); - this.el.className = arr.join(' '); - return this; -}; - - -/** - * Toggle class `name`, can force state via `force`. - * - * For browsers that support classList, but do not support `force` yet, - * the mistake will be detected and corrected. - * - * @param {String} name - * @param {Boolean} force - * @return {ClassList} - * @api public - */ - -ClassList.prototype.toggle = function(name, force){ - // classList - if (this.list) { - if ("undefined" !== typeof force) { - if (force !== this.list.toggle(name, force)) { - this.list.toggle(name); // toggle again to correct - } - } else { - this.list.toggle(name); - } - return this; - } - - // fallback - if ("undefined" !== typeof force) { - if (!force) { - this.remove(name); - } else { - this.add(name); - } - } else { - if (this.has(name)) { - this.remove(name); - } else { - this.add(name); - } - } - - return this; -}; - -/** - * Return an array of classes. - * - * @return {Array} - * @api public - */ - -ClassList.prototype.array = function(){ - var className = this.el.getAttribute('class') || ''; - var str = className.replace(/^\s+|\s+$/g, ''); - var arr = str.split(re); - if ('' === arr[0]) arr.shift(); - return arr; -}; - -/** - * Check if class `name` is present. - * - * @param {String} name - * @return {ClassList} - * @api public - */ - -ClassList.prototype.has = -ClassList.prototype.contains = function(name){ - return this.list ? this.list.contains(name) : !! ~index(this.array(), name); -}; - - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -var bind = window.addEventListener ? 'addEventListener' : 'attachEvent', - unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent', - prefix = bind !== 'addEventListener' ? 'on' : '', - toArray = __webpack_require__(5); - -/** - * Bind `el` event `type` to `fn`. - * - * @param {Element} el, NodeList, HTMLCollection or Array - * @param {String} type - * @param {Function} fn - * @param {Boolean} capture - * @api public - */ - -exports.bind = function(el, type, fn, capture){ - el = toArray(el); - for ( var i = 0; i < el.length; i++ ) { - el[i][bind](prefix + type, fn, capture || false); - } -}; - -/** - * Unbind `el` event `type`'s callback `fn`. - * - * @param {Element} el, NodeList, HTMLCollection or Array - * @param {String} type - * @param {Function} fn - * @param {Boolean} capture - * @api public - */ - -exports.unbind = function(el, type, fn, capture){ - el = toArray(el); - for ( var i = 0; i < el.length; i++ ) { - el[i][unbind](prefix + type, fn, capture || false); - } -}; - - -/***/ }), -/* 2 */ -/***/ (function(module, exports) { - -module.exports = function(list) { - return function(initValues, element, notCreate) { - var item = this; - - this._values = {}; - - this.found = false; // Show if list.searched == true and this.found == true - this.filtered = false;// Show if list.filtered == true and this.filtered == true - - var init = function(initValues, element, notCreate) { - if (element === undefined) { - if (notCreate) { - item.values(initValues, notCreate); - } else { - item.values(initValues); - } - } else { - item.elm = element; - var values = list.templater.get(item, initValues); - item.values(values); - } - }; - - this.values = function(newValues, notCreate) { - if (newValues !== undefined) { - for(var name in newValues) { - item._values[name] = newValues[name]; - } - if (notCreate !== true) { - list.templater.set(item, item.values()); - } - } else { - return item._values; - } - }; - - this.show = function() { - list.templater.show(item); - }; - - this.hide = function() { - list.templater.hide(item); - }; - - this.matching = function() { - return ( - (list.filtered && list.searched && item.found && item.filtered) || - (list.filtered && !list.searched && item.filtered) || - (!list.filtered && list.searched && item.found) || - (!list.filtered && !list.searched) - ); - }; - - this.visible = function() { - return (item.elm && (item.elm.parentNode == list.list)) ? true : false; - }; - - init(initValues, element, notCreate); - }; -}; - - -/***/ }), -/* 3 */ -/***/ (function(module, exports) { - -/** - * A cross-browser implementation of getElementsByClass. - * Heavily based on Dustin Diaz's function: http://dustindiaz.com/getelementsbyclass. - * - * Find all elements with class `className` inside `container`. - * Use `single = true` to increase performance in older browsers - * when only one element is needed. - * - * @param {String} className - * @param {Element} container - * @param {Boolean} single - * @api public - */ - -var getElementsByClassName = function(container, className, single) { - if (single) { - return container.getElementsByClassName(className)[0]; - } else { - return container.getElementsByClassName(className); - } -}; - -var querySelector = function(container, className, single) { - className = '.' + className; - if (single) { - return container.querySelector(className); - } else { - return container.querySelectorAll(className); - } -}; - -var polyfill = function(container, className, single) { - var classElements = [], - tag = '*'; - - var els = container.getElementsByTagName(tag); - var elsLen = els.length; - var pattern = new RegExp("(^|\\s)"+className+"(\\s|$)"); - for (var i = 0, j = 0; i < elsLen; i++) { - if ( pattern.test(els[i].className) ) { - if (single) { - return els[i]; - } else { - classElements[j] = els[i]; - j++; - } - } - } - return classElements; -}; - -module.exports = (function() { - return function(container, className, single, options) { - options = options || {}; - if ((options.test && options.getElementsByClassName) || (!options.test && document.getElementsByClassName)) { - return getElementsByClassName(container, className, single); - } else if ((options.test && options.querySelector) || (!options.test && document.querySelector)) { - return querySelector(container, className, single); - } else { - return polyfill(container, className, single); - } - }; -})(); - - -/***/ }), -/* 4 */ -/***/ (function(module, exports) { - -var indexOf = [].indexOf; - -module.exports = function(arr, obj){ - if (indexOf) return arr.indexOf(obj); - for (var i = 0; i < arr.length; ++i) { - if (arr[i] === obj) return i; - } - return -1; -}; - - -/***/ }), -/* 5 */ -/***/ (function(module, exports) { - -/** - * Source: https://github.com/timoxley/to-array - * - * Convert an array-like object into an `Array`. - * If `collection` is already an `Array`, then will return a clone of `collection`. - * - * @param {Array | Mixed} collection An `Array` or array-like object to convert e.g. `arguments` or `NodeList` - * @return {Array} Naive conversion of `collection` to a new `Array`. - * @api public - */ - -module.exports = function toArray(collection) { - if (typeof collection === 'undefined') return []; - if (collection === null) return [null]; - if (collection === window) return [window]; - if (typeof collection === 'string') return [collection]; - if (isArray(collection)) return collection; - if (typeof collection.length != 'number') return [collection]; - if (typeof collection === 'function' && collection instanceof Function) return [collection]; - - var arr = []; - for (var i = 0; i < collection.length; i++) { - if (Object.prototype.hasOwnProperty.call(collection, i) || i in collection) { - arr.push(collection[i]); - } - } - if (!arr.length) return []; - return arr; -}; - -function isArray(arr) { - return Object.prototype.toString.call(arr) === "[object Array]"; -} - - -/***/ }), -/* 6 */ -/***/ (function(module, exports) { - -module.exports = function(s) { - s = (s === undefined) ? "" : s; - s = (s === null) ? "" : s; - s = s.toString(); - return s; -}; - - -/***/ }), -/* 7 */ -/***/ (function(module, exports) { - -/* - * Source: https://github.com/segmentio/extend - */ - -module.exports = function extend (object) { - // Takes an unlimited number of extenders. - var args = Array.prototype.slice.call(arguments, 1); - - // For each extender, copy their properties on our object. - for (var i = 0, source; source = args[i]; i++) { - if (!source) continue; - for (var property in source) { - object[property] = source[property]; - } - } - - return object; -}; - - -/***/ }), -/* 8 */ -/***/ (function(module, exports) { - -module.exports = function(list) { - var addAsync = function(values, callback, items) { - var valuesToAdd = values.splice(0, 50); - items = items || []; - items = items.concat(list.add(valuesToAdd)); - if (values.length > 0) { - setTimeout(function() { - addAsync(values, callback, items); - }, 1); - } else { - list.update(); - callback(items); - } - }; - return addAsync; -}; - - -/***/ }), -/* 9 */ -/***/ (function(module, exports) { - -module.exports = function(list) { - - // Add handlers - list.handlers.filterStart = list.handlers.filterStart || []; - list.handlers.filterComplete = list.handlers.filterComplete || []; - - return function(filterFunction) { - list.trigger('filterStart'); - list.i = 1; // Reset paging - list.reset.filter(); - if (filterFunction === undefined) { - list.filtered = false; - } else { - list.filtered = true; - var is = list.items; - for (var i = 0, il = is.length; i < il; i++) { - var item = is[i]; - if (filterFunction(item)) { - item.filtered = true; - } else { - item.filtered = false; - } - } - } - list.update(); - list.trigger('filterComplete'); - return list.visibleItems; - }; -}; - - -/***/ }), -/* 10 */ -/***/ (function(module, exports, __webpack_require__) { - - -var classes = __webpack_require__(0), - events = __webpack_require__(1), - extend = __webpack_require__(7), - toString = __webpack_require__(6), - getByClass = __webpack_require__(3), - fuzzy = __webpack_require__(19); - -module.exports = function(list, options) { - options = options || {}; - - options = extend({ - location: 0, - distance: 100, - threshold: 0.4, - multiSearch: true, - searchClass: 'fuzzy-search' - }, options); - - - - var fuzzySearch = { - search: function(searchString, columns) { - // Substract arguments from the searchString or put searchString as only argument - var searchArguments = options.multiSearch ? searchString.replace(/ +$/, '').split(/ +/) : [searchString]; - - for (var k = 0, kl = list.items.length; k < kl; k++) { - fuzzySearch.item(list.items[k], columns, searchArguments); - } - }, - item: function(item, columns, searchArguments) { - var found = true; - for(var i = 0; i < searchArguments.length; i++) { - var foundArgument = false; - for (var j = 0, jl = columns.length; j < jl; j++) { - if (fuzzySearch.values(item.values(), columns[j], searchArguments[i])) { - foundArgument = true; - } - } - if(!foundArgument) { - found = false; - } - } - item.found = found; - }, - values: function(values, value, searchArgument) { - if (values.hasOwnProperty(value)) { - var text = toString(values[value]).toLowerCase(); - - if (fuzzy(text, searchArgument, options)) { - return true; - } - } - return false; - } - }; - - - events.bind(getByClass(list.listContainer, options.searchClass), 'keyup', function(e) { - var target = e.target || e.srcElement; // IE have srcElement - list.search(target.value, fuzzySearch.search); - }); - - return function(str, columns) { - list.search(str, columns, fuzzySearch.search); - }; -}; - - -/***/ }), -/* 11 */ -/***/ (function(module, exports, __webpack_require__) { - -var naturalSort = __webpack_require__(18), - getByClass = __webpack_require__(3), - extend = __webpack_require__(7), - indexOf = __webpack_require__(4), - events = __webpack_require__(1), - toString = __webpack_require__(6), - classes = __webpack_require__(0), - getAttribute = __webpack_require__(17), - toArray = __webpack_require__(5); - -module.exports = function(id, options, values) { - - var self = this, - init, - Item = __webpack_require__(2)(self), - addAsync = __webpack_require__(8)(self), - initPagination = __webpack_require__(12)(self); - - init = { - start: function() { - self.listClass = "list"; - self.searchClass = "search"; - self.sortClass = "sort"; - self.page = 10000; - self.i = 1; - self.items = []; - self.visibleItems = []; - self.matchingItems = []; - self.searched = false; - self.filtered = false; - self.searchColumns = undefined; - self.handlers = { 'updated': [] }; - self.valueNames = []; - self.utils = { - getByClass: getByClass, - extend: extend, - indexOf: indexOf, - events: events, - toString: toString, - naturalSort: naturalSort, - classes: classes, - getAttribute: getAttribute, - toArray: toArray - }; - - self.utils.extend(self, options); - - self.listContainer = (typeof(id) === 'string') ? document.getElementById(id) : id; - if (!self.listContainer) { return; } - self.list = getByClass(self.listContainer, self.listClass, true); - - self.parse = __webpack_require__(13)(self); - self.templater = __webpack_require__(16)(self); - self.search = __webpack_require__(14)(self); - self.filter = __webpack_require__(9)(self); - self.sort = __webpack_require__(15)(self); - self.fuzzySearch = __webpack_require__(10)(self, options.fuzzySearch); - - this.handlers(); - this.items(); - this.pagination(); - - self.update(); - }, - handlers: function() { - for (var handler in self.handlers) { - if (self[handler]) { - self.on(handler, self[handler]); - } - } - }, - items: function() { - self.parse(self.list); - if (values !== undefined) { - self.add(values); - } - }, - pagination: function() { - if (options.pagination !== undefined) { - if (options.pagination === true) { - options.pagination = [{}]; - } - if (options.pagination[0] === undefined){ - options.pagination = [options.pagination]; - } - for (var i = 0, il = options.pagination.length; i < il; i++) { - initPagination(options.pagination[i]); - } - } - } - }; - - /* - * Re-parse the List, use if html have changed - */ - this.reIndex = function() { - self.items = []; - self.visibleItems = []; - self.matchingItems = []; - self.searched = false; - self.filtered = false; - self.parse(self.list); - }; - - this.toJSON = function() { - var json = []; - for (var i = 0, il = self.items.length; i < il; i++) { - json.push(self.items[i].values()); - } - return json; - }; - - - /* - * Add object to list - */ - this.add = function(values, callback) { - if (values.length === 0) { - return; - } - if (callback) { - addAsync(values, callback); - return; - } - var added = [], - notCreate = false; - if (values[0] === undefined){ - values = [values]; - } - for (var i = 0, il = values.length; i < il; i++) { - var item = null; - notCreate = (self.items.length > self.page) ? true : false; - item = new Item(values[i], undefined, notCreate); - self.items.push(item); - added.push(item); - } - self.update(); - return added; - }; - - this.show = function(i, page) { - this.i = i; - this.page = page; - self.update(); - return self; - }; - - /* Removes object from list. - * Loops through the list and removes objects where - * property "valuename" === value - */ - this.remove = function(valueName, value, options) { - var found = 0; - for (var i = 0, il = self.items.length; i < il; i++) { - if (self.items[i].values()[valueName] == value) { - self.templater.remove(self.items[i], options); - self.items.splice(i,1); - il--; - i--; - found++; - } - } - self.update(); - return found; - }; - - /* Gets the objects in the list which - * property "valueName" === value - */ - this.get = function(valueName, value) { - var matchedItems = []; - for (var i = 0, il = self.items.length; i < il; i++) { - var item = self.items[i]; - if (item.values()[valueName] == value) { - matchedItems.push(item); - } - } - return matchedItems; - }; - - /* - * Get size of the list - */ - this.size = function() { - return self.items.length; - }; - - /* - * Removes all items from the list - */ - this.clear = function() { - self.templater.clear(); - self.items = []; - return self; - }; - - this.on = function(event, callback) { - self.handlers[event].push(callback); - return self; - }; - - this.off = function(event, callback) { - var e = self.handlers[event]; - var index = indexOf(e, callback); - if (index > -1) { - e.splice(index, 1); - } - return self; - }; - - this.trigger = function(event) { - var i = self.handlers[event].length; - while(i--) { - self.handlers[event][i](self); - } - return self; - }; - - this.reset = { - filter: function() { - var is = self.items, - il = is.length; - while (il--) { - is[il].filtered = false; - } - return self; - }, - search: function() { - var is = self.items, - il = is.length; - while (il--) { - is[il].found = false; - } - return self; - } - }; - - this.update = function() { - var is = self.items, - il = is.length; - - self.visibleItems = []; - self.matchingItems = []; - self.templater.clear(); - for (var i = 0; i < il; i++) { - if (is[i].matching() && ((self.matchingItems.length+1) >= self.i && self.visibleItems.length < self.page)) { - is[i].show(); - self.visibleItems.push(is[i]); - self.matchingItems.push(is[i]); - } else if (is[i].matching()) { - self.matchingItems.push(is[i]); - is[i].hide(); - } else { - is[i].hide(); - } - } - self.trigger('updated'); - return self; - }; - - init.start(); -}; - - -/***/ }), -/* 12 */ -/***/ (function(module, exports, __webpack_require__) { - -var classes = __webpack_require__(0), - events = __webpack_require__(1), - List = __webpack_require__(11); - -module.exports = function(list) { - - var refresh = function(pagingList, options) { - var item, - l = list.matchingItems.length, - index = list.i, - page = list.page, - pages = Math.ceil(l / page), - currentPage = Math.ceil((index / page)), - innerWindow = options.innerWindow || 2, - left = options.left || options.outerWindow || 0, - right = options.right || options.outerWindow || 0; - - right = pages - right; - - pagingList.clear(); - for (var i = 1; i <= pages; i++) { - var className = (currentPage === i) ? "active" : ""; - - //console.log(i, left, right, currentPage, (currentPage - innerWindow), (currentPage + innerWindow), className); - - if (is.number(i, left, right, currentPage, innerWindow)) { - item = pagingList.add({ - page: i, - dotted: false - })[0]; - if (className) { - classes(item.elm).add(className); - } - addEvent(item.elm, i, page); - } else if (is.dotted(pagingList, i, left, right, currentPage, innerWindow, pagingList.size())) { - item = pagingList.add({ - page: "...", - dotted: true - })[0]; - classes(item.elm).add("disabled"); - } - } - }; - - var is = { - number: function(i, left, right, currentPage, innerWindow) { - return this.left(i, left) || this.right(i, right) || this.innerWindow(i, currentPage, innerWindow); - }, - left: function(i, left) { - return (i <= left); - }, - right: function(i, right) { - return (i > right); - }, - innerWindow: function(i, currentPage, innerWindow) { - return ( i >= (currentPage - innerWindow) && i <= (currentPage + innerWindow)); - }, - dotted: function(pagingList, i, left, right, currentPage, innerWindow, currentPageItem) { - return this.dottedLeft(pagingList, i, left, right, currentPage, innerWindow) || (this.dottedRight(pagingList, i, left, right, currentPage, innerWindow, currentPageItem)); - }, - dottedLeft: function(pagingList, i, left, right, currentPage, innerWindow) { - return ((i == (left + 1)) && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right)); - }, - dottedRight: function(pagingList, i, left, right, currentPage, innerWindow, currentPageItem) { - if (pagingList.items[currentPageItem-1].values().dotted) { - return false; - } else { - return ((i == (right)) && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right)); - } - } - }; - - var addEvent = function(elm, i, page) { - events.bind(elm, 'click', function() { - list.show((i-1)*page + 1, page); - }); - }; - - return function(options) { - var pagingList = new List(list.listContainer.id, { - listClass: options.paginationClass || 'pagination', - item: "