livelist-rails 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -228,7 +228,7 @@ window.Filters = (function(_super) {
228
228
  var _this = this;
229
229
  return _.map(filters, function(filter) {
230
230
  filter.options = _.sortBy(filter.options, function(option) {
231
- return option[_this.sortOptionsProperty];
231
+ return option[_this.optionsSortProperties[filter.filter_slug]];
232
232
  });
233
233
  return filter;
234
234
  });
@@ -1 +1 @@
1
- var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}};window.Utilities=function(){function Utilities(){this.setOptions=__bind(this.setOptions,this)}Utilities.prototype.setOptions=function(options,context){var _this=this;if(context==null){context=this}return _.each(options,function(value,option){return context[option]=value})};return Utilities}();var __hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.LiveList=function(_super){__extends(LiveList,_super);function LiveList(options){this.listSelector=options.list.renderTo;this.resourceName=options.global.resourceName;this.resourceNameSingular=options.global.resourceNameSingular;this.urlPrefix=options.global.urlPrefix||"/"+this.resourceName;this.httpMethod=options.global.httpMethod||"get";this.eventName="livelist:"+this.resourceName;this.search=new Search(options.search,this);this.filters=new Filters(options.filters,this);this.pagination=new Pagination(options.pagination,this);this.list=new List(options.list,this)}return LiveList}(Utilities);var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.List=function(_super){__extends(List,_super);function List(options,livelist){this.renderIndex=__bind(this.renderIndex,this);this.removeFetchingIndication=__bind(this.removeFetchingIndication,this);this.displayFetchingIndication=__bind(this.displayFetchingIndication,this);var _this=this;this.fetchRequest=null;this.livelist=livelist;this.listTemplate="{{#"+this.livelist.resourceName+"}}{{>"+this.livelist.resourceNameSingular+"}}{{/"+this.livelist.resourceName+"}}";this.listItemTemplate="<li>{{id}}</li>";this.fetchingIndicationClass="updating";this.renderTo="ul#"+this.livelist.resourceName;this.setOptions(options);$(this.renderTo).bind(this.livelist.eventName,function(event,params){return _this.fetch({presets:null,page:params!=null?params.page:void 0})});this.fetch({presets:this.livelist.filters.getPresets()})}List.prototype.displayFetchingIndication=function(){return $(this.renderTo).addClass(this.fetchingIndicationClass)};List.prototype.removeFetchingIndication=function(){return $(this.renderTo).removeClass(this.fetchingIndicationClass)};List.prototype.renderIndex=function(data,textStatus,jqXHR){this.livelist.data=data;this.render();this.livelist.pagination.render(this.livelist.data);return this.livelist.filters.render(this.livelist.data)};List.prototype.fetch=function(options){var params,searchTerm;if(this.fetchRequest){this.fetchRequest.abort()}searchTerm=this.livelist.search.searchTerm();params={};params.filters=this.livelist.filters.setPresets(options.presets);if(searchTerm){params.q=searchTerm}if(options.page){params.page=options.page}return this.fetchRequest=$.ajax({url:this.livelist.urlPrefix,type:this.livelist.httpMethod,dataType:"json",data:params,beforeSend:this.displayFetchingIndication,success:this.renderIndex})};List.prototype.render=function(){var listHTML,partials;partials={};partials[this.livelist.resourceNameSingular]=this.listItemTemplate;listHTML=Mustache.to_html(this.listTemplate,this.livelist.data,partials);$(this.renderTo).html(listHTML);return this.removeFetchingIndication()};return List}(Utilities);window.LiveList.version="0.0.10";var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.Filters=function(_super){__extends(Filters,_super);function Filters(options,livelist){this.handleAdvancedOptionsClick=__bind(this.handleAdvancedOptionsClick,this);var _this=this;this.livelist=livelist;this.filters=options.presets?_.keys(options.presets):[];this.initializeCookies();this.setOptions(options);$("input.filter_option",this.renderTo).live("change",function(){return $(_this.livelist.listSelector).trigger(_this.livelist.eventName)});$(this.advancedOptionsToggleSelector).click(this.handleAdvancedOptionsClick)}Filters.prototype.initializeCookies=function(){if(jQuery.cookie&&this.useCookies&&this.cookieName){return this.cookieName="livelist_filter_presets"}};Filters.prototype.getPresets=function(){var cookie;if(jQuery.cookie&&this.useCookies){cookie=jQuery.cookie(this.cookieName)}if(this.useCookies&&cookie){return JSON.parse(cookie)}else{return this.presets}};Filters.prototype.setPresets=function(presets){var filters;filters={};if(jQuery.isEmptyObject(presets)){filters=this.selections();if(jQuery.cookie){this.setCookie(filters)}}else{filters=presets}return filters};Filters.prototype.setCookie=function(params_filters){if(!jQuery.isEmptyObject(params_filters)){return jQuery.cookie(this.cookieName,JSON.stringify(params_filters))}};Filters.prototype.template="{{#filters}}\n<div class='filter'>\n <h3>\n {{name}}\n </h3>\n <ul id='{{filter_slug}}_filter_options'>\n {{#options}}\n <label>\n <li>\n <input {{#selected}}checked='checked'{{/selected}}\n class='left filter_option'\n id='filter_{{slug}}'\n name='filters[]'\n type='checkbox'\n value='{{value}}' />\n <div class='left filter_name'>{{name}}</div>\n <div class='right filter_count'>{{count}}</div>\n <div class='clear'></div>\n </li>\n </label>\n {{/options}}\n </ul>\n</div>\n{{/filters}}";Filters.prototype.selections=function(){var filters,_this=this;filters={};_.each(this.filters,function(filter){return filters[filter]=_.pluck($("#"+filter+"_filter_options input.filter_option:checked"),"value")});return filters};Filters.prototype.noFiltersSelected=function(data){return _.all(data.filters,function(filter){return _.all(filter.options,function(option){return!option.selected})})};Filters.prototype.sortOptions=function(filters){var _this=this;return _.map(filters,function(filter){filter.options=_.sortBy(filter.options,function(option){return option[_this.sortOptionsProperty]});return filter})};Filters.prototype.sort=function(filters){return _.sortBy(filters,function(filter){return filter.name})};Filters.prototype.render=function(data){var filtersHTML;this.filters=_.pluck(data.filters,"filter_slug");this.sort(data.filters);this.sortOptions(data.filters);filtersHTML=Mustache.to_html(this.template,data);$(this.renderTo).html(filtersHTML);if(this.noFiltersSelected(data)&&data[this.livelist.resourceName].length>0){return $('input[type="checkbox"]',this.renderTo).attr("checked","checked")}};Filters.prototype.handleAdvancedOptionsClick=function(event){event.preventDefault();return $(this.renderTo).slideToggle()};return Filters}(Utilities);var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.Pagination=function(_super){__extends(Pagination,_super);function Pagination(options,livelist){this.handlePaginationLinkClick=__bind(this.handlePaginationLinkClick,this);this.livelist=livelist;this.pagination=null;this.maxPages=30;this.emptyListMessage="<p>No "+this.livelist.resourceName+" matched your filter criteria</p>";this.setOptions(options);$(""+this.renderTo+" a").live("click",function(event){return event.preventDefault()});$(""+this.renderTo+" li:not(.disabled) a").live("click",this.handlePaginationLinkClick)}Pagination.prototype.template="{{#isEmpty}}\n {{{emptyListMessage}}}\n{{/isEmpty}}\n{{^isEmpty}}\n<div class=\"pagination\">\n <ul>\n <li class=\"{{^previousPage}}disabled{{/previousPage}}\">\n <a href='{{urlPrefix}}?page={{previousPage}}' data-page='{{previousPage}}'>← Previous</a>\n </li>\n\n {{#pages}}\n <li class=\"{{#currentPage}}active disabled{{/currentPage}}\">\n <a href='{{urlPrefix}}?page={{page}}' data-page='{{page}}'>{{page}}</a>\n </li>\n {{/pages}}\n\n <li class=\"{{^nextPage}}disabled{{/nextPage}}\">\n <a href='{{urlPrefix}}?page={{nextPage}}' data-page='{{nextPage}}'>Next →</a>\n </li>\n </ul>\n</div>\n{{/isEmpty}}";Pagination.prototype.pagesJSON=function(currentPage,totalPages){var firstPage,groupSize,lastPage,previousPage,_i,_results;groupSize=Math.floor(this.maxPages/2);firstPage=currentPage<=groupSize?1:currentPage-groupSize;previousPage=firstPage+groupSize*2-1;lastPage=previousPage>=totalPages?totalPages:previousPage;return _.map(function(){_results=[];for(var _i=firstPage;firstPage<=lastPage?_i<=lastPage:_i>=lastPage;firstPage<=lastPage?_i++:_i--){_results.push(_i)}return _results}.apply(this),function(page){return{page:page,currentPage:currentPage===page}})};Pagination.prototype.paginationJSON=function(pagination){return{isEmpty:pagination.total_pages===0,emptyListMessage:this.emptyListMessage,currentPage:pagination.current_page,nextPage:pagination.next_page,previousPage:pagination.previous_page,urlPrefix:this.livelist.urlPrefix,pages:this.pagesJSON(pagination.current_page,pagination.total_pages)}};Pagination.prototype.render=function(data){var paginationHTML;this.pagination=this.paginationJSON(data.pagination);paginationHTML=Mustache.to_html(this.template,this.pagination);return $(this.renderTo).html(paginationHTML)};Pagination.prototype.handlePaginationLinkClick=function(event){event.preventDefault();return $(this.livelist.listSelector).trigger(this.livelist.eventName,{page:$(event.target).data("page")})};return Pagination}(Utilities);var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.Search=function(_super){__extends(Search,_super);function Search(options,livelist){this.handleSearchFormSubmit=__bind(this.handleSearchFormSubmit,this);var _this=this;this.livelist=livelist;this.setOptions(options);$(this.formSelector).submit(function(event){return _this.handleSearchFormSubmit(event)})}Search.prototype.searchTerm=function(){var q;q=$(this.searchTextInputSelector).val();if(!q||q===""){return null}else{return q}};Search.prototype.handleSearchFormSubmit=function(event){event.preventDefault();return $(this.livelist.listSelector).trigger(this.livelist.eventName)};return Search}(Utilities);
1
+ var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}};window.Utilities=function(){function Utilities(){this.setOptions=__bind(this.setOptions,this)}Utilities.prototype.setOptions=function(options,context){var _this=this;if(context==null){context=this}return _.each(options,function(value,option){return context[option]=value})};return Utilities}();var __hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.LiveList=function(_super){__extends(LiveList,_super);function LiveList(options){this.listSelector=options.list.renderTo;this.resourceName=options.global.resourceName;this.resourceNameSingular=options.global.resourceNameSingular;this.urlPrefix=options.global.urlPrefix||"/"+this.resourceName;this.httpMethod=options.global.httpMethod||"get";this.eventName="livelist:"+this.resourceName;this.search=new Search(options.search,this);this.filters=new Filters(options.filters,this);this.pagination=new Pagination(options.pagination,this);this.list=new List(options.list,this)}return LiveList}(Utilities);var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.List=function(_super){__extends(List,_super);function List(options,livelist){this.renderIndex=__bind(this.renderIndex,this);this.removeFetchingIndication=__bind(this.removeFetchingIndication,this);this.displayFetchingIndication=__bind(this.displayFetchingIndication,this);var _this=this;this.fetchRequest=null;this.livelist=livelist;this.listTemplate="{{#"+this.livelist.resourceName+"}}{{>"+this.livelist.resourceNameSingular+"}}{{/"+this.livelist.resourceName+"}}";this.listItemTemplate="<li>{{id}}</li>";this.fetchingIndicationClass="updating";this.renderTo="ul#"+this.livelist.resourceName;this.setOptions(options);$(this.renderTo).bind(this.livelist.eventName,function(event,params){return _this.fetch({presets:null,page:params!=null?params.page:void 0})});this.fetch({presets:this.livelist.filters.getPresets()})}List.prototype.displayFetchingIndication=function(){return $(this.renderTo).addClass(this.fetchingIndicationClass)};List.prototype.removeFetchingIndication=function(){return $(this.renderTo).removeClass(this.fetchingIndicationClass)};List.prototype.renderIndex=function(data,textStatus,jqXHR){this.livelist.data=data;this.render();this.livelist.pagination.render(this.livelist.data);return this.livelist.filters.render(this.livelist.data)};List.prototype.fetch=function(options){var params,searchTerm;if(this.fetchRequest){this.fetchRequest.abort()}searchTerm=this.livelist.search.searchTerm();params={};params.filters=this.livelist.filters.setPresets(options.presets);if(searchTerm){params.q=searchTerm}if(options.page){params.page=options.page}return this.fetchRequest=$.ajax({url:this.livelist.urlPrefix,type:this.livelist.httpMethod,dataType:"json",data:params,beforeSend:this.displayFetchingIndication,success:this.renderIndex})};List.prototype.render=function(){var listHTML,partials;partials={};partials[this.livelist.resourceNameSingular]=this.listItemTemplate;listHTML=Mustache.to_html(this.listTemplate,this.livelist.data,partials);$(this.renderTo).html(listHTML);return this.removeFetchingIndication()};return List}(Utilities);window.LiveList.version="0.0.10";var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.Filters=function(_super){__extends(Filters,_super);function Filters(options,livelist){this.handleAdvancedOptionsClick=__bind(this.handleAdvancedOptionsClick,this);var _this=this;this.livelist=livelist;this.filters=options.presets?_.keys(options.presets):[];this.initializeCookies();this.setOptions(options);$("input.filter_option",this.renderTo).live("change",function(){return $(_this.livelist.listSelector).trigger(_this.livelist.eventName)});$(this.advancedOptionsToggleSelector).click(this.handleAdvancedOptionsClick)}Filters.prototype.initializeCookies=function(){if(jQuery.cookie&&this.useCookies&&this.cookieName){return this.cookieName="livelist_filter_presets"}};Filters.prototype.getPresets=function(){var cookie;if(jQuery.cookie&&this.useCookies){cookie=jQuery.cookie(this.cookieName)}if(this.useCookies&&cookie){return JSON.parse(cookie)}else{return this.presets}};Filters.prototype.setPresets=function(presets){var filters;filters={};if(jQuery.isEmptyObject(presets)){filters=this.selections();if(jQuery.cookie){this.setCookie(filters)}}else{filters=presets}return filters};Filters.prototype.setCookie=function(params_filters){if(!jQuery.isEmptyObject(params_filters)){return jQuery.cookie(this.cookieName,JSON.stringify(params_filters))}};Filters.prototype.template="{{#filters}}\n<div class='filter'>\n <h3>\n {{name}}\n </h3>\n <ul id='{{filter_slug}}_filter_options'>\n {{#options}}\n <label>\n <li>\n <input {{#selected}}checked='checked'{{/selected}}\n class='left filter_option'\n id='filter_{{slug}}'\n name='filters[]'\n type='checkbox'\n value='{{value}}' />\n <div class='left filter_name'>{{name}}</div>\n <div class='right filter_count'>{{count}}</div>\n <div class='clear'></div>\n </li>\n </label>\n {{/options}}\n </ul>\n</div>\n{{/filters}}";Filters.prototype.selections=function(){var filters,_this=this;filters={};_.each(this.filters,function(filter){return filters[filter]=_.pluck($("#"+filter+"_filter_options input.filter_option:checked"),"value")});return filters};Filters.prototype.noFiltersSelected=function(data){return _.all(data.filters,function(filter){return _.all(filter.options,function(option){return!option.selected})})};Filters.prototype.sortOptions=function(filters){var _this=this;return _.map(filters,function(filter){filter.options=_.sortBy(filter.options,function(option){return option[_this.optionsSortProperties[filter.filter_slug]]});return filter})};Filters.prototype.sort=function(filters){return _.sortBy(filters,function(filter){return filter.name})};Filters.prototype.render=function(data){var filtersHTML;this.filters=_.pluck(data.filters,"filter_slug");this.sort(data.filters);this.sortOptions(data.filters);filtersHTML=Mustache.to_html(this.template,data);$(this.renderTo).html(filtersHTML);if(this.noFiltersSelected(data)&&data[this.livelist.resourceName].length>0){return $('input[type="checkbox"]',this.renderTo).attr("checked","checked")}};Filters.prototype.handleAdvancedOptionsClick=function(event){event.preventDefault();return $(this.renderTo).slideToggle()};return Filters}(Utilities);var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.Pagination=function(_super){__extends(Pagination,_super);function Pagination(options,livelist){this.handlePaginationLinkClick=__bind(this.handlePaginationLinkClick,this);this.livelist=livelist;this.pagination=null;this.maxPages=30;this.emptyListMessage="<p>No "+this.livelist.resourceName+" matched your filter criteria</p>";this.setOptions(options);$(""+this.renderTo+" a").live("click",function(event){return event.preventDefault()});$(""+this.renderTo+" li:not(.disabled) a").live("click",this.handlePaginationLinkClick)}Pagination.prototype.template="{{#isEmpty}}\n {{{emptyListMessage}}}\n{{/isEmpty}}\n{{^isEmpty}}\n<div class=\"pagination\">\n <ul>\n <li class=\"{{^previousPage}}disabled{{/previousPage}}\">\n <a href='{{urlPrefix}}?page={{previousPage}}' data-page='{{previousPage}}'>← Previous</a>\n </li>\n\n {{#pages}}\n <li class=\"{{#currentPage}}active disabled{{/currentPage}}\">\n <a href='{{urlPrefix}}?page={{page}}' data-page='{{page}}'>{{page}}</a>\n </li>\n {{/pages}}\n\n <li class=\"{{^nextPage}}disabled{{/nextPage}}\">\n <a href='{{urlPrefix}}?page={{nextPage}}' data-page='{{nextPage}}'>Next →</a>\n </li>\n </ul>\n</div>\n{{/isEmpty}}";Pagination.prototype.pagesJSON=function(currentPage,totalPages){var firstPage,groupSize,lastPage,previousPage,_i,_results;groupSize=Math.floor(this.maxPages/2);firstPage=currentPage<=groupSize?1:currentPage-groupSize;previousPage=firstPage+groupSize*2-1;lastPage=previousPage>=totalPages?totalPages:previousPage;return _.map(function(){_results=[];for(var _i=firstPage;firstPage<=lastPage?_i<=lastPage:_i>=lastPage;firstPage<=lastPage?_i++:_i--){_results.push(_i)}return _results}.apply(this),function(page){return{page:page,currentPage:currentPage===page}})};Pagination.prototype.paginationJSON=function(pagination){return{isEmpty:pagination.total_pages===0,emptyListMessage:this.emptyListMessage,currentPage:pagination.current_page,nextPage:pagination.next_page,previousPage:pagination.previous_page,urlPrefix:this.livelist.urlPrefix,pages:this.pagesJSON(pagination.current_page,pagination.total_pages)}};Pagination.prototype.render=function(data){var paginationHTML;this.pagination=this.paginationJSON(data.pagination);paginationHTML=Mustache.to_html(this.template,this.pagination);return $(this.renderTo).html(paginationHTML)};Pagination.prototype.handlePaginationLinkClick=function(event){event.preventDefault();return $(this.livelist.listSelector).trigger(this.livelist.eventName,{page:$(event.target).data("page")})};return Pagination}(Utilities);var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.Search=function(_super){__extends(Search,_super);function Search(options,livelist){this.handleSearchFormSubmit=__bind(this.handleSearchFormSubmit,this);var _this=this;this.livelist=livelist;this.setOptions(options);$(this.formSelector).submit(function(event){return _this.handleSearchFormSubmit(event)})}Search.prototype.searchTerm=function(){var q;q=$(this.searchTextInputSelector).val();if(!q||q===""){return null}else{return q}};Search.prototype.handleSearchFormSubmit=function(event){event.preventDefault();return $(this.livelist.listSelector).trigger(this.livelist.eventName)};return Search}(Utilities);
@@ -11,12 +11,10 @@ module Livelist
11
11
 
12
12
  def filter_for(slug, options = {})
13
13
  filters.create_filter(
14
- :reference_criteria => options[:reference_criteria],
15
- :name => options[:name],
16
- :model_name => model_name,
17
- :attribute => options[:attribute],
18
- :key_name => options[:key_name],
19
- :slug => slug
14
+ options.merge(
15
+ :model_name => model_name,
16
+ :slug => slug
17
+ )
20
18
  )
21
19
  end
22
20
 
@@ -35,6 +35,7 @@ module Livelist
35
35
  @criteria = FilterCriteria.new(
36
36
  :filter => self,
37
37
  :reference_criteria => options[:reference_criteria],
38
+ :metadata_properties => options[:option_metadata_properties],
38
39
  :slug => @key_name
39
40
  )
40
41
  end
@@ -7,11 +7,12 @@ module Livelist
7
7
  class FilterCriteria < HashWithIndifferentAccess
8
8
  alias :criteria :values
9
9
  alias :find_criteria :[]
10
- attr_reader :slug
10
+ attr_reader :slug, :metadata_properties
11
11
 
12
12
  def initialize(options)
13
- @filter = options[:filter]
14
- @slug = options[:slug]
13
+ @filter = options[:filter]
14
+ @slug = options[:slug]
15
+ @metadata_properties = options[:metadata_properties] || {}
15
16
 
16
17
  initialize_criteria(options[:reference_criteria])
17
18
  end
@@ -26,13 +26,13 @@ module Livelist
26
26
  end
27
27
 
28
28
  def as_json(params)
29
- {
29
+ metadata.merge(
30
30
  :slug => @filter.slug,
31
31
  :name => @name,
32
32
  :value => @slug.to_s,
33
33
  :count => @count,
34
34
  :selected => selected?(params)
35
- }
35
+ )
36
36
  end
37
37
 
38
38
  private
@@ -75,6 +75,21 @@ module Livelist
75
75
  when :model then @reference.send(@label)
76
76
  end
77
77
  end
78
+
79
+ def property_value(property)
80
+ case @type
81
+ when :scalar then nil
82
+ when :hash then @reference[property]
83
+ when :model then @reference.send(property)
84
+ end
85
+ end
86
+
87
+ def metadata
88
+ @criteria.metadata_properties.reduce({}) do |result, property|
89
+ result[property] = property_value(property)
90
+ result
91
+ end
92
+ end
78
93
  end
79
94
 
80
95
  end
@@ -1,6 +1,6 @@
1
1
  module Livelist
2
2
  module Rails
3
- VERSION = '0.0.16'
3
+ VERSION = '0.0.17'
4
4
  LIVELIST_VERSION = '0.0.10'
5
5
  MUSTACHE_VERSION = '0.4.2'
6
6
  UNDERSCORE_VERSION = '1.4.2'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livelist-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: