From b9ae36048d0313ffbce0506fbfb8e2a312f8af69 Mon Sep 17 00:00:00 2001 From: Alan Palazzolo Date: Wed, 16 Apr 2014 12:22:56 -0500 Subject: [PATCH] Making custom events simpler and more focused. --- README.md | 8 +++----- dist/legislature-tracker.js | 11 ++++++----- dist/legislature-tracker.min.css | 2 +- dist/legislature-tracker.min.js | 6 +++--- js/app.js | 4 ++-- js/parsers.js | 5 +++-- js/templates/template-ebill.html | 28 ++++++++++++++++++++-------- 7 files changed, 38 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index d53beaf..5b6e00b 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ First make sure you have 3 sheets with the following columns: * `category_id`: the identifier that will be used in URL linking. Should be something like `social_issues`. * `title`: The text title. * `short_title`: Used for the top menu list. If none is given, the first word from the category title will be used. - * `description`: The full description. + * `description`: The full description. Feel free to use HTML here, but do note that the content will be wrapped in a paragragh tag. * `links`: Links field, see below. * `image`: Name of image for the category. By default, these pull from the images directory, which is configurable in the `imagePath` option. Or if you use a full URL, starting with `http` it will use that directly. * `Bills` @@ -133,13 +133,11 @@ First make sure you have 3 sheets with the following columns: * `title` * `description`: Descriptions get split up when in the category list view and have a "more details" link. By default, this is based on the number of words. To handle longer texts with HTML, you can use `` to define that break point. Also note that is no description is given, then the application will use the primary bill summary which may or may not be useful and significant. * `links`: Links field, see below. -* `Events`: Events are custom events like the stalling of a bill or committee that would otherwise not show up in the data from Open States. This shows up as part of the overall bill information below the description. +* `Events`: Events are custom events like the stalling of a bill or committee that would otherwise not show up in the data from Open States. This shows up as part of the overall editorial bill information below the description. * `bill`: The primary bill ID. * `date`: A date in a format like `'YYYY-MM-DD'` * `chamber`: This should be `upper` or `lower`. - * `title`: A title for the event. - * `description`: A short description for the event. - * `links`: Any links associated with the event. + * `description`: A short description for the event. Feel free to use HTML here for things like links. #### Link field formatting diff --git a/dist/legislature-tracker.js b/dist/legislature-tracker.js index 437c264..38fcb03 100644 --- a/dist/legislature-tracker.js +++ b/dist/legislature-tracker.js @@ -34,7 +34,7 @@ this.LTTemplates = { 'template-application' : '
\n\n {{#(!!categories)}}\n
\n
\n\n \n \n All Categories\n \n\n \n   |  \n\n {{#categories}}\n \n {{ (short_title) ? short_title : title.split(\' \')[0] }}\n \n   \n {{/categories}}\n \n
\n
\n {{/()}}\n\n {{#options.title}}\n

{{ options.title }}

\n {{/options.title}}\n\n
\n {{>loading}}\n
\n
\n', 'template-categories' : '\n{{^categories}}\n {{>loading}}\n{{/categories}}\n\n
\n \n
\n', 'template-category' : '\n{{^category}}\n {{>loading}}\n{{/category}}\n\n
\n

\n {{#category.image}}\n \n {{/category.image}}\n\n {{ category.title }}\n

\n\n

{{{ category.description }}}

\n\n {{#(category.links && category.links.length && category.links.length > 0)}}\n \n {{/()}}\n\n
\n {{#category.bills:bill}}\n \n {{/category.bills}}\n
\n\n
\n Watching\n {{ category.bills.length }}\n {{#(typeof category.total_bill_count != \'undefined\')}}\n of {{ category.total_bill_count }}\n {{/()}}\n bills in the {{ category.title }} category.\n
\n
\n', - 'template-ebill' : '\n
\n
\n \n\n \n\n \n\n {{#options.conferenceBill}}\n \n {{/options.conferenceBill}}\n\n \n
\n\n {{#compact}}\n

\n {{ bill.title }}\n

\n {{/compact}}\n {{^compact}}\n

{{ bill.title }}

\n {{/compact}}\n\n {{^bill.hasBill}}\n
\n This bill has not been tracked by the legislature yet.\n
\n {{/bill.hasBill}}\n\n {{#bill.newest_action}}\n
Last action about {{ date.fromNow() }}: {{ action }}.
\n {{/bill.newest_action}}\n\n
\n {{{ bill.description }}}\n
\n\n
\n Categories:\n {{#bill.categories:i}}\n \n {{#image}}\n \n {{/image}}\n {{ title }}\n {{#(i < bill.categories.length - 1)}},{{/()}}\n {{/bill.categories}}\n
\n\n {{#(bill.links && bill.links.length && bill.links.length > 0)}}\n \n {{/()}}\n\n\n {{#(compact == true)}}\n
\n {{#bill.bill_conference}}\n
\n

Conference bill\n {{#sources.0.url}}\n {{ bill_id }}\n {{/sources.0.url}}\n {{^sources.0.url}} {{ bill_id }} {{/sources.0.url}}\n

\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n {{#sponsors}}\n \n {{/sponsors}}\n
\n {{/bill.bill_conference}}\n\n {{#bill.bill_primary}}\n
\n

\n {{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Primary bill\' }}\n {{#sources.0.url}}\n {{ bill_id }}\n {{/sources.0.url}}\n {{^sources.0.url}} {{ bill_id }} {{/sources.0.url}}\n

\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n {{#sponsors}}\n \n {{/sponsors}}\n
\n {{/bill.bill_primary}}\n\n {{#bill.bill_companion}}\n
\n

\n {{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Companion bill\' }}\n {{#sources.0.url}}\n {{ bill_id }}\n {{/sources.0.url}}\n {{^sources.0.url}} {{ bill_id }} {{/sources.0.url}}\n

\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n {{#sponsors}}\n \n {{/sponsors}}\n
\n {{/bill.bill_companion}}\n
\n\n \n {{/()}}\n\n\n {{#(compact != true)}}\n {{#(bill.custom_events && bill.custom_events.length && bill.custom_events.length > 0)}}\n
\n Events\n {{#bill.custom_events}}\n
{{ bill_id }} {{ action }} on {{ date.format(\'MMM DD, YYYY\') }}: {{ e.description }}
\n {{/bill.custom_events}}\n
\n {{/()}}\n\n
\n\n {{#bill.bill_conference}}\n
\n

Conference bill {{ bill_id }}

\n \n
\n {{/bill.bill_conference}}\n\n {{#bill.bill_primary}}\n
\n

{{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Primary bill\' }} {{ bill_id }}

\n \n
\n {{/bill.bill_primary}}\n\n {{#bill.bill_companion}}\n
\n

{{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Companion bill\' }} {{ bill_id }}

\n \n
\n {{/bill.bill_companion}}\n {{/()}}\n\n
\n', + 'template-ebill' : '\n
\n
\n \n\n \n\n \n\n {{#options.conferenceBill}}\n \n {{/options.conferenceBill}}\n\n \n
\n\n {{#compact}}\n

\n {{ bill.title }}\n

\n {{/compact}}\n {{^compact}}\n

{{ bill.title }}

\n {{/compact}}\n\n {{^bill.hasBill}}\n
\n This bill has not been tracked by the legislature yet.\n
\n {{/bill.hasBill}}\n\n {{#bill.newest_action}}\n
Last action about {{ date.fromNow() }}: {{ action }}.
\n {{/bill.newest_action}}\n\n
\n {{{ bill.description }}}\n
\n\n
\n Categories:\n {{#bill.categories:i}}\n \n {{#image}}\n \n {{/image}}\n {{ title }}\n {{#(i < bill.categories.length - 1)}},{{/()}}\n {{/bill.categories}}\n
\n\n {{#(compact == true && bill.custom_events && bill.custom_events.length && bill.custom_events.length > 0)}}\n
\n Latest updates:\n {{#bill.custom_events.0}}\n {{ date.format(\'MMM DD, YYYY\') }}, {{ bill_id }}, {{{ description }}} ({{ translate(\'chamber\', chamber) }})\n {{/bill.custom_events.0}}\n
\n {{/()}}\n\n {{#(compact != true && bill.custom_events && bill.custom_events.length && bill.custom_events.length > 0)}}\n
\n Latest updates:\n {{#bill.custom_events}}\n
\n {{ date.format(\'MMM DD, YYYY\') }}: {{ bill_id }}, {{{ description }}} ({{ translate(\'chamber\', chamber) }})\n
\n {{/bill.custom_events}}\n
\n {{/()}}\n\n {{#(bill.links && bill.links.length && bill.links.length > 0)}}\n \n {{/()}}\n\n\n {{#(compact == true)}}\n
\n {{#bill.bill_conference}}\n
\n

Conference bill\n {{#sources.0.url}}\n {{ bill_id }}\n {{/sources.0.url}}\n {{^sources.0.url}} {{ bill_id }} {{/sources.0.url}}\n

\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n {{#sponsors}}\n \n {{/sponsors}}\n
\n {{/bill.bill_conference}}\n\n {{#bill.bill_primary}}\n
\n

\n {{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Primary bill\' }}\n {{#sources.0.url}}\n {{ bill_id }}\n {{/sources.0.url}}\n {{^sources.0.url}} {{ bill_id }} {{/sources.0.url}}\n

\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n {{#sponsors}}\n \n {{/sponsors}}\n
\n {{/bill.bill_primary}}\n\n {{#bill.bill_companion}}\n
\n

\n {{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Companion bill\' }}\n {{#sources.0.url}}\n {{ bill_id }}\n {{/sources.0.url}}\n {{^sources.0.url}} {{ bill_id }} {{/sources.0.url}}\n

\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n {{#sponsors}}\n \n {{/sponsors}}\n
\n {{/bill.bill_companion}}\n
\n\n \n {{/()}}\n\n\n {{#(compact != true)}}\n\n
\n\n {{#bill.bill_conference}}\n
\n

Conference bill {{ bill_id }}

\n \n
\n {{/bill.bill_conference}}\n\n {{#bill.bill_primary}}\n
\n

{{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Primary bill\' }} {{ bill_id }}

\n \n
\n {{/bill.bill_primary}}\n\n {{#bill.bill_companion}}\n
\n

{{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Companion bill\' }} {{ bill_id }}

\n \n
\n {{/bill.bill_companion}}\n {{/()}}\n\n
\n', 'template-error' : '
\n
There was an error.
\n
', 'template-legislator' : '\n
\n <% if (LT.options.legImageProxy) { %>\n \n <% } else { %>\n \n <% } %>\n \n
\n <%= full_name %>
\n <% if (typeof district != \'undefined\') { %>\n District <%= district %>\n <% } %>\n <% if (typeof party != \'undefined\') { %>\n (<%= LT.utils.translate(\'partyAbbr\', party) %>) \n <% } %>
\n <% if (typeof chamber != \'undefined\') { %>\n <%= LT.utils.translate(\'chamber\', chamber) %>\n <% } %>\n
\n
', 'template-loading' : '
\n
Loading...
\n
', @@ -437,14 +437,15 @@ LT.parsers.eCategories = function(categories, options) { }; LT.parsers.eEvents = function(events, options) { - return _.map(events, function(row) { + return _.sortBy(_.map(events, function(row) { LT.parsers.translateFields(options.fieldTranslations.eEvents, row); - row.links = LT.parsers.eLinks(row.links); row.date = moment(row.date); // Add some things to fit format of Open States actions row.type = ['custom']; return row; + }), function(e, ei) { + return e.date.unix * -1; }); }; @@ -1717,8 +1718,8 @@ _.extend(App.prototype, { }, eEvents: { 'bill_id': 'bill', - 'actor': 'chamber', - 'action': 'title' + 'chamber': 'chamber', + 'description': 'description' } }, wordTranslations: { diff --git a/dist/legislature-tracker.min.css b/dist/legislature-tracker.min.css index 8eb72ce..0d3e5c9 100644 --- a/dist/legislature-tracker.min.css +++ b/dist/legislature-tracker.min.css @@ -1,4 +1,4 @@ -/*! legislature-tracker - v0.2.0 - 2014-04-15 +/*! legislature-tracker - v0.2.0 - 2014-04-16 * https://github.com/MinnPost/legislature-tracker * Copyright (c) 2014 ; Licensed MIT */ diff --git a/dist/legislature-tracker.min.js b/dist/legislature-tracker.min.js index 2373295..4b44419 100644 --- a/dist/legislature-tracker.min.js +++ b/dist/legislature-tracker.min.js @@ -1,6 +1,6 @@ -/*! legislature-tracker - v0.2.0 - 2014-04-15 +/*! legislature-tracker - v0.2.0 - 2014-04-16 * https://github.com/MinnPost/legislature-tracker * Copyright (c) 2014 ; Licensed MIT */ -(function(t,e){if("undefined"!=typeof module&&module.exports&&"function"==typeof require)module.exports=e(require("underscore"),require("jquery"),require("Backbone"),require("moment"),require("tabletop"),require("Ractive"));else if("function"==typeof define&&define.amd)define("LT",["underscore","jquery","Backbone","moment","tabletop","Ractive"],e);else{if(!(t._&&t.jQuery&&t.Backbone&&t.moment&&t.Tabletop))throw Error("Could not find dependencies for Legislature Tracker.");t.LT=e(t._,t.jQuery,t.Backbone,t.moment,t.Tabletop,t.Ractive)}})("undefined"!=typeof window?window:this,function(t,e,i,n,s,l){function o(t,i){this.element=t,this.$element=e(t),this._defaults=r.nav.stickDefaults,this.options=e.extend({},this._defaults,i),this._name="ltStick",this._scrollEvent="scroll.lt.ltStick",this._on=!1,this.init()}var a,r={};return this.LTTemplates={"template-application":'
\n\n {{#(!!categories)}}\n
\n
\n\n \n \n All Categories\n \n\n \n   |  \n\n {{#categories}}\n \n {{ (short_title) ? short_title : title.split(\' \')[0] }}\n \n   \n {{/categories}}\n \n
\n
\n {{/()}}\n\n {{#options.title}}\n

{{ options.title }}

\n {{/options.title}}\n\n
\n {{>loading}}\n
\n
\n',"template-categories":'\n{{^categories}}\n {{>loading}}\n{{/categories}}\n\n
\n \n
\n',"template-category":'\n{{^category}}\n {{>loading}}\n{{/category}}\n\n
\n

\n {{#category.image}}\n \n {{/category.image}}\n\n {{ category.title }}\n

\n\n

{{{ category.description }}}

\n\n {{#(category.links && category.links.length && category.links.length > 0)}}\n \n {{/()}}\n\n
\n {{#category.bills:bill}}\n \n {{/category.bills}}\n
\n\n
\n Watching\n {{ category.bills.length }}\n {{#(typeof category.total_bill_count != \'undefined\')}}\n of {{ category.total_bill_count }}\n {{/()}}\n bills in the {{ category.title }} category.\n
\n
\n',"template-ebill":'\n
\n
\n \n\n \n\n \n\n {{#options.conferenceBill}}\n \n {{/options.conferenceBill}}\n\n \n
\n\n {{#compact}}\n

\n {{ bill.title }}\n

\n {{/compact}}\n {{^compact}}\n

{{ bill.title }}

\n {{/compact}}\n\n {{^bill.hasBill}}\n
\n This bill has not been tracked by the legislature yet.\n
\n {{/bill.hasBill}}\n\n {{#bill.newest_action}}\n
Last action about {{ date.fromNow() }}: {{ action }}.
\n {{/bill.newest_action}}\n\n
\n {{{ bill.description }}}\n
\n\n
\n Categories:\n {{#bill.categories:i}}\n \n {{#image}}\n \n {{/image}}\n {{ title }}\n {{#(i < bill.categories.length - 1)}},{{/()}}\n {{/bill.categories}}\n
\n\n {{#(bill.links && bill.links.length && bill.links.length > 0)}}\n \n {{/()}}\n\n\n {{#(compact == true)}}\n
\n {{#bill.bill_conference}}\n
\n

Conference bill\n {{#sources.0.url}}\n {{ bill_id }}\n {{/sources.0.url}}\n {{^sources.0.url}} {{ bill_id }} {{/sources.0.url}}\n

\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n {{#sponsors}}\n \n {{/sponsors}}\n
\n {{/bill.bill_conference}}\n\n {{#bill.bill_primary}}\n
\n

\n {{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Primary bill\' }}\n {{#sources.0.url}}\n {{ bill_id }}\n {{/sources.0.url}}\n {{^sources.0.url}} {{ bill_id }} {{/sources.0.url}}\n

\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n {{#sponsors}}\n \n {{/sponsors}}\n
\n {{/bill.bill_primary}}\n\n {{#bill.bill_companion}}\n
\n

\n {{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Companion bill\' }}\n {{#sources.0.url}}\n {{ bill_id }}\n {{/sources.0.url}}\n {{^sources.0.url}} {{ bill_id }} {{/sources.0.url}}\n

\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n {{#sponsors}}\n \n {{/sponsors}}\n
\n {{/bill.bill_companion}}\n
\n\n \n {{/()}}\n\n\n {{#(compact != true)}}\n {{#(bill.custom_events && bill.custom_events.length && bill.custom_events.length > 0)}}\n
\n Events\n {{#bill.custom_events}}\n
{{ bill_id }} {{ action }} on {{ date.format(\'MMM DD, YYYY\') }}: {{ e.description }}
\n {{/bill.custom_events}}\n
\n {{/()}}\n\n
\n\n {{#bill.bill_conference}}\n
\n

Conference bill {{ bill_id }}

\n \n
\n {{/bill.bill_conference}}\n\n {{#bill.bill_primary}}\n
\n

{{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Primary bill\' }} {{ bill_id }}

\n \n
\n {{/bill.bill_primary}}\n\n {{#bill.bill_companion}}\n
\n

{{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Companion bill\' }} {{ bill_id }}

\n \n
\n {{/bill.bill_companion}}\n {{/()}}\n\n
\n',"template-error":'
\n
There was an error.
\n
',"template-legislator":"\n
\n <% if (LT.options.legImageProxy) { %>\n <%= encodeURI(photo_url) %>\" />\n <% } else { %>\n \" />\n <% } %>\n \n
\n <%= full_name %>
\n <% if (typeof district != 'undefined') { %>\n District <%= district %>\n <% } %>\n <% if (typeof party != 'undefined') { %>\n (<%= LT.utils.translate('partyAbbr', party) %>) \n <% } %>
\n <% if (typeof chamber != 'undefined') { %>\n <%= LT.utils.translate('chamber', chamber) %>\n <% } %>\n
\n
","template-loading":'
\n
Loading...
\n
',"template-osbill":'\n
\n

\n {{#(!!bill.title)}}\n {{ bill.title }}\n {{/()}}\n\n {{^(!!bill.title)}}\n {{ bill.bill_id }}\n {{/()}}\n

\n\n
\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n
\n {{#bill.sponsors}}\n \n {{/bill.sponsors}}\n
\n
\n\n
\n Actions\n
\n {{#bill.actions}}\n {{#(!!date)}}\n
\n {{ date.format(\'MMM DD, YYYY\') }}:\n {{ action }}\n ({{ translate(\'chamber\', actor) }})\n
\n {{/())}}\n {{/bill.actions}}\n
\n
\n\n {{#(bill.sponsors && bill.sponsors.length && bill.sponsors.length > 0)}}\n
\n {{ translate(\'sponsors\', \'Co-sponsors\') }}\n
\n {{#bill.sponsors}}\n \n {{/bill.sponsors}}\n
\n
\n {{/()}}\n\n {{#(bill.votes && bill.votes.length && bill.votes.length > 0)}}\n
\n Votes\n
\n {{#bill.votes}}\n {{ date.format(\'MMM DD, YYYY\') }}\n {{ motion }} {{ (passed) ? \'passed\' : \'failed\' }}\n {{ yes_count }} Y -\n {{ no_count }} N
\n {{/bill.votes}}\n
\n
\n {{/()}}\n\n
\n Sources\n \n
\n
\n',"template-sponsor":'\n{{#(((!!type && sponsor.type === type) || !type) && !compact)}}\n\n \n{{/()}}\n\n\n{{#(((!!type && sponsor.type === type) || !type) && !!compact)}}\n \n{{/()}}\n'},t.mixin({filterEmpty:function(e){return t.filter(e,function(t){return t})},filterObject:function(e,i,n){return t.reduce(e,function(t,s,l){return i.call(n,s,l,e)&&(t[l]=s),t},{},n)},mapObject:function(e,i,n){return t.reduce(e,function(t,s,l){return t[l]=i.call(n,s,l,e),t},{},n)},trim:function(e){return t.isString(e)&&(e=String.prototype.trim?e.trim():e.replace(/^\s+|\s+$/g,"")),e},cssClass:function(t){return t.toLowerCase().replace(/[^a-z0-9]/g,"-")},numberFormatCommas:function(t){return(""+t).replace(/\B(?=(\d{3})+(?!\d))/g,",")},parseURL:function(t){var e=document.createElement("a");return e.href=t,e}}),i.ajax=function(){var t=arguments;return t[0].dataTypeForce!==!0&&(t[0].dataType="jsonp"),i.$.ajax.apply(i.$,t)},e.fn.hasScrollBar=function(){return this.get(0)&&this.get(0).scrollHeight?this.get(0).scrollHeight>this.height():!1},r.nav=r.nav||{},r.nav.stickDefaults={activeClass:"stuck top",wrapperClass:"menu-stick-container",topPadding:0,throttle:90},o.prototype={init:function(){this.$container=void 0===this.options.container?this.$element.parent():e(this.options.container),this.elementHeight=this.$element.outerHeight(!0),this.$spacer=e("
").height(this.elementHeight).hide(),this.$element.after(this.$spacer),this.options.wrapperClass&&this.$element.wrapInner('
'),this._throttledListen=t.bind(t.throttle(this.listen,this.options.throttle),this),this._throttledListen(),e(window).on(this._scrollEvent,this._throttledListen)},listen:function(){var t=this.$container.offset().top,i=t+this.$container.height(),n=e(window).scrollTop(),s=t-this.options.topPadding,l=i-this.elementHeight-this.options.topPadding-2;!this._on&&n>s&&l>n?this.on():this._on&&(s>n||n>l)&&this.off()},on:function(){this.$element.addClass(this.options.activeClass),this.options.topPadding&&this.$element.css("top",this.options.topPadding),this.$spacer.show(),this._on=!0},off:function(){this.$element.removeClass(this.options.activeClass),this.options.topPadding&&this.$element.css("top","inherit"),this.$spacer.hide(),this._on=!1},remove:function(){this.$container.off(this._scrollEvent)}},e.fn.ltStick=function(t){return this.each(function(){e.data(this,"ltStick")||e.data(this,"ltStick",new o(this,t))})},function(){var t,e;if(!l||!i)throw Error("Could not find Ractive or Backbone! Check your paths config");l.adaptors.Backbone={filter:function(t){return t instanceof i.Model||t instanceof i.Collection,t instanceof i.Model||t instanceof i.Collection},wrap:function(n,s,l,o){return s instanceof i.Model?new t(n,s,l,o):new e(n,s,l,o)}},t=function(t,e,i,n){var s=this;this.value=e,e.on("change",this.modelChangeHandler=function(){s.setting=!0,t.set(n(e.changed)),s.setting=!1}),e.on("sync",this.modelSyncHandler=function(){t.update(i)})},t.prototype={teardown:function(){this.value.off("change",this.changeHandler),this.value.off("sync",this.modelSyncHandler)},get:function(){return this.value.attributes},set:function(t,e){this.setting||-1!==t.indexOf(".")||this.value.set(t,e)},reset:function(t){return t instanceof i.Model||"object"!=typeof t?!1:(this.value.reset(t),void 0)}},e=function(t,e,i){var n=this;this.value=e,e.on("add remove reset sort",this.changeHandler=function(){n.setting=!0,t.set(i,e.models),n.setting=!1})},e.prototype={teardown:function(){this.value.off("add remove reset sort",this.changeHandler)},get:function(){return this.value.models},reset:function(t){return this.setting?void 0:t instanceof i.Collection||"[object Array]"!==Object.prototype.toString.call(t)?!1:(this.value.reset(t),void 0)}}}(),r.parsers=r.parsers||{},r.log=function(e){t.isObject(console)&&t.isFunction(console.log)&&console.log(e)},r.parsers.eData=function(e,i){var n={},s=e.sheets("Bills").all();return s.length>i.maxBills&&r.log("The number of bills in your spreadsheet exceeds maxBills. Set the maxBills option to display them, but be aware that this may significantly slow down the Legislature Tracker."),n.categories=r.parsers.eCategories(e.sheets("Categories").all(),i),n.bills=r.parsers.eBills(s.slice(0,i.maxBills),i),n.events=r.parsers.eEvents(e.sheets("Events").all(),i),t.each(t.groupBy(n.events,"bill_id"),function(e,i){t.each(n.bills,function(t,s){t.bill===i&&(n.bills[s].custom_events=e)})}),n},r.parsers.validateBillNumber=function(t,e){return e.billNumberFormat.test(t)},r.parsers.eBills=function(e,i){return t.map(e,function(e){return r.parsers.translateFields(i.fieldTranslations.eBills,e),e.links=r.parsers.eLinks(e.links),e.id=e.id||t.cssClass(e.bill)+t.cssClass(e.title),e.categories=e.categories?e.categories.split(","):[],e.categories=t.map(e.categories,t.trim),e.bill_primary=t.trim(e.bill),e.bill&&!r.parsers.validateBillNumber(e.bill,i)&&r.log('Invalid primary bill number "'+e.bill+'" for row '+e.rowNumber+", see documentation."),e.bill_companion=t.trim(e.bill_companion),e.bill_companion&&!r.parsers.validateBillNumber(e.bill_companion,i)&&r.log('Invalid companion bill number "'+e.bill_companion+'" for row '+e.rowNumber+", see documentation."),e.bill_conference=t.trim(e.bill_conference),e.bill_conference&&!r.parsers.validateBillNumber(e.bill_conference,i)&&r.log('Invalid conference bill number "'+e.bill_conference+'" for row '+e.rowNumber+", see documentation."),e.hasBill=!0,e.bill&&e.bill_primary||(e.hasBill=!1,e.bill=t.cssClass(e.title.toLowerCase())),e})},r.parsers.eCategories=function(e,i){return t.map(e,function(t){return r.parsers.translateFields(i.fieldTranslations.eCategories,t),t.links=r.parsers.eLinks(t.links),t})},r.parsers.eEvents=function(e,i){return t.map(e,function(t){return r.parsers.translateFields(i.fieldTranslations.eEvents,t),t.links=r.parsers.eLinks(t.links),t.date=n(t.date),t.type=["custom"],t})},r.parsers.eLinks=function(e){var i=[];return e=t.trim(e),0===e.length?i:(e='"'===e.substring(0,1)?e.substring(1):e,e='"'===e.substring(e.length-1,e.length)?e.slice(0,-1):e,i=e.split('", "'),i=t.map(i,function(t){return{title:t.split("|")[0],url:t.split("|")[1]}}))},r.parsers.csvCategories=function(e){return e=t.trim(e),0===e.length?[]:(e='"'===e.substring(0,1)?e.substring(1):e,e='"'===e.substring(e.length-1,e.length)?e.slice(0,-1):e,e.split('", "'))},r.parsers.detectCompanionBill=function(e,i){var n,s;return t.isFunction(i.detectCompanionBill)?(n=i.detectCompanionBill(e),s=r.parsers.validateBillNumber(n,i)?n:void 0):t.isRegExp(i.detectCompanionBill)&&(n=i.detectCompanionBill.exec(e),s=n&&r.parsers.validateBillNumber(n[1],i)?n[1]:void 0),t.trim(s)},r.parsers.translateFields=function(e,i){return t.each(e,function(t,e){i[e]=i[t],e!==t&&delete i[t]}),i},r.BaseModel=i.Model.extend({initialize:function(t,e){this.options=e,this.app=this.options.app,this.on("sync",function(t){t.set("fetched",!0)})}}),r.OSModel=r.BaseModel.extend({urlBase:function(){return"http://openstates.org/api/v1/"},urlEnd:function(){return"/?apikey="+encodeURI(this.app.options.OSKey)+"&callback=?"},url:function(){return this.urlBase()+encodeURI(this.osType)+"/"+encodeURI(this.id)+this.urlEnd()},initialize:function(){r.OSModel.__super__.initialize.apply(this,arguments)}}),r.OSStateModel=r.OSModel.extend({url:function(){return this.urlBase()+"metadata/"+encodeURI(this.options.state)+this.urlEnd()}}),r.OSLegislatorModel=r.OSModel.extend({osType:"legislators",initialize:function(){r.OSBillModel.__super__.initialize.apply(this,arguments),this.get("leg_id")&&this.app.fetchModel(this)}}),r.OSCommitteeModel=r.OSModel.extend({osType:"committees"}),r.OSBillModel=r.OSModel.extend({url:function(){return t.isUndefined(this.id)?t.isUndefined(this.get("bill_id"))||""===this.get("bill_id")?void 0:this.urlBase()+"bills/"+encodeURI(this.app.options.state)+"/"+encodeURI(this.app.options.session)+"/"+encodeURI(this.get("bill_id"))+this.urlEnd():this.urlBase()+"bills/"+this.id+this.urlEnd()},initialize:function(){r.OSBillModel.__super__.initialize.apply(this,arguments)},parse:function(e){var i=this;return e.created_at=e.created_at?n(e.created_at):void 0,e.updated_at=e.updated_at?n(e.updated_at):void 0,e.action_dates=t.filterObject(e.action_dates,function(t){return t}),e.action_dates=t.mapObject(e.action_dates,function(t){return n(t)}),e.actions=t.mapObject(e.actions,function(t){return t.date=n(t.date),t}),e.votes=t.mapObject(e.votes,function(t){return t.date=n(t.date),t}),this.get("custom_events")&&(e.actions=t.union(e.actions,this.get("custom_events"))),e.actions=t.sortBy(e.actions,function(t,e){return-1*(t.date.unix()+e)}),e.newest_action=e.actions[0],this.app.options.osBillParse&&t.isFunction(this.app.options.osBillParse)&&(e=this.app.options.osBillParse.apply(this,[e,this.app])),e.sponsors&&(e.sponsors=t.map(e.sponsors,function(t){return t.id=t.leg_id,t.leg=i.app.getModel("OSLegislatorModel","leg_id",t),t})),e},getActionDate:function(t){return this.get("action_dates")[t]?this.get("action_dates")[t]:!1},isSubstituted:function(){var e=!1,i=this;return t.isBoolean(this.get("substitued"))?e=this.get("substitued"):this.app.options.substituteMatch===!1?e=!1:(e=t.find(this.get("actions"),function(t){return t.action.match(i.app.options.substituteMatch)}),e=e?!0:!1,this.set("substitued",e)),e}}),r.BillModel=r.BaseModel.extend({subbills:["bill_primary","bill_companion","bill_conference"],initialize:function(){r.BillModel.__super__.initialize.apply(this,arguments),this.loadOSBills()},loadOSBills:function(){var e=this;t.each(this.subbills,function(t){var i;e.get(t)&&(i=e.app.getModel("OSBillModel","bill_id",{bill_id:e.get(t)}),e.set(t,i))})},getOSBills:function(){var e=this;return t.filterEmpty(t.map(this.subbills,function(t){return e.get(t)}))},getOSBillIDs:function(){var e=this.getOSBills();return t.filterEmpty(t.map(e,function(e){return t.isObject(e)?e.get("bill_id"):e}))},fetchOSBills:function(){var i=this,n=[];return this.getCategories(),t.each(this.subbills,function(t){i.get("hasBill")&&i.get(t)&&n.push(i.app.fetchModel(i.get(t)))}),e.when.apply(e,n).done(function(){i.loadOSCompanion().done(function(){i.parseMeta(),i.lastUpdatedAt(),i.newestAction(),i.trigger("fetched:osbills")})})},fetch:function(){return this.fetchOSBills()},loadOSCompanion:function(){var i,n=[];return this.get("hasBill")===!0&&!this.get("bill_companion")&&t.isObject(this.get("bill_primary"))&&t.isArray(this.get("bill_primary").get("companions"))&&t.isObject(this.get("bill_primary").get("companions")[0])&&(i=r.parsers.detectCompanionBill(this.get("bill_primary").get("companions")[0],this.app.options),i&&(this.set("bill_companion",this.app.getModel("OSBillModel","bill_id",{bill_id:i})),n.push(this.app.fetchModel(this.get("bill_companion"))))),e.when.apply(e,n)},getCategories:function(){var e=this;this.get("categories")&&this.set("categories",t.map(this.get("categories"),function(i){return t.isObject(i)||(i=e.app.getModel("CategoryModel","id",{id:i})),i}))},lastUpdatedAt:function(){var t,e=this.get("bill_primary"),i=this.get("bill_companion"),n=this.get("bill_conference");return e&&e.get("updated_at")&&(t=e.get("updated_at"),i&&i.get("updated_at")&&(t=i.get("updated_at").unix()>t.unix()?i.get("updated_at"):t),n&&n.get("updated_at")&&(t=n.get("updated_at").unix()>t.unix()?n.get("updated_at"):t),this.set("last_updated_at",t)),this.get("last_updated_at")},newestAction:function(){var t,e=this.get("bill_primary"),i=this.get("bill_companion"),n=this.get("bill_conference");return this.get("hasBill")&&e.get("newest_action")&&(t=e.get("newest_action"),i&&i.get("newest_action")&&(t=i.get("newest_action").date.unix()>t.date.unix()?i.get("newest_action"):t),n&&n.get("newest_action")&&(t=n.get("newest_action").date.unix()>t.date.unix()?n.get("newest_action"):t),this.set("newest_action",t)),this.get("newest_action")},isRecent:function(){var e=this.newestAction(),i=this.get("bill_primary")?this.get("bill_primary").get("action_dates"):null;return t.isObject(e)&&e.date&&n().diff(e.date,"days")<=this.app.options.recentChangeThreshold?!0:t.isObject(i)&&i.last&&n().diff(i.last,"days")<=this.app.options.recentChangeThreshold?!0:!1},parseMeta:function(){var e,i,n=this,s={upper:!1,lower:!1,conference:!1,signed:!1,last:!1},l={companion:this.get("bill_companion")?!0:!1,conference:this.get("bill_conference")?!0:!1};if(this.get("custom_events")&&this.set("custom_events",t.sortBy(this.get("custom_events"),function(t,e){return-1*(t.date.unix()+e)})),this.get("hasBill")){if(l.companion&&(this.get("bill_companion").isSubstituted()&&(l.substituted=!0),this.get("bill_primary").isSubstituted()&&(l.substituted=!0,e=this.get("bill_primary").get("bill_id"),i=this.get("bill_companion").get("bill_id"),this.unset("bill_primary"),this.set("bill_primary",function(){return n.app.getModel("OSBillModel","bill_id",{bill_id:i})}()),this.unset("bill_companion"),this.set("bill_companion",function(){return n.app.getModel("OSBillModel","bill_id",{bill_id:e})}()))),(!l.companion||l.substituted)&&(s.lower=this.get("bill_primary").getActionDate("passed_lower"),s.upper=this.get("bill_primary").getActionDate("passed_upper")),l.companion&&!l.substituted&&("upper"===this.get("bill_primary").get("chamber")?(s.upper=this.get("bill_primary").getActionDate("passed_upper"),s.lower=this.get("bill_companion").getActionDate("passed_lower")):(s.lower=this.get("bill_primary").getActionDate("passed_lower"),s.upper=this.get("bill_companion").getActionDate("passed_upper"))),l.conference){var o=this.get("bill_conference").getActionDate("passed_lower"),a=this.get("bill_conference").getActionDate("passed_upper");o&&a&&(s.conference=o.unix()>=a.unix()?o:a)}s.signed=l.conference?this.get("bill_conference").getActionDate("signed"):this.get("bill_primary").getActionDate("signed"),s.last=l.conference?this.get("bill_conference").getActionDate("last"):l.companion?this.get("bill_companion").getActionDate("last").unix()>=this.get("bill_primary").getActionDate("last").unix()?this.get("bill_companion").getActionDate("last"):this.get("bill_primary").getActionDate("last"):this.get("bill_primary").getActionDate("last"),this.get("description")||this.set("description",this.get("bill_primary").get("summary"))}return l.recent=this.isRecent(),this.set("actions",s),this.set("bill_type",l),this.trigger("change"),this}}),r.CategoryModel=r.BaseModel.extend({initialize:function(){r.CategoryModel.__super__.initialize.apply(this,arguments),this.set("bills",new r.BillsCollection(null))},getBills:function(e){var i=this,n=this.get("id");return this.get("loadedBills")&&this.get("bills").length>0?this:(e.each(function(e){-1!==t.indexOf(e.get("categories"),n)&&i.get("bills").add(i.app.getModel("BillModel","bill",e.toJSON()))}),this.set("loadedBills",!0,{silent:!0}),this)}}),r.CategoriesCollection=i.Collection.extend({model:r.CategoryModel,comparator:function(t){return-1!==t.get("title").toLowerCase().indexOf("recent")?"zzzzz":t.get("title")}}),r.BillsCollection=i.Collection.extend({model:r.BillModel,initialize:function(){this.on("change:newest_action",function(){})},comparator:function(t){var e=t.newestAction()?n().diff(t.newestAction().date,"days"):null;return e}}),r.OSBillsCollection=i.Collection.extend({model:r.OSBillModel,comparator:function(t){var e=t.get("newest_action");return e?-1*e.date.unix():9999}}),r.OSLegislatorsCollection=i.Collection.extend({model:r.OSLegislatorModel,comparator:function(t){return("primary"===t.get("type")?"aaa":"bbb")+t.get("name")}}),r.BaseView=l.extend({baseInit:function(t){this.options=t.options,this.app=t.app,this.router=t.router},adaptors:["Backbone"]}),r.ApplicationView=r.BaseView.extend({init:function(){this.baseInit.apply(this,arguments),this.stuck=!1,this.observe("categories",function(i){this.stuck||this.get("options").stickMenu===!0||(this.stuck=!0),!this.stuck&&i&&t.isObject(i)&&i.length>0&&(this.stuck=!0,e(this.el).find(".ls-header").ltStick({container:e(this.el)}))})}}),r.CategoriesView=r.BaseView.extend({init:function(){this.baseInit.apply(this,arguments)}}),r.CategoryView=r.BaseView.extend({init:function(){this.baseInit.apply(this,arguments)}}),r.EBillView=r.BaseView.extend({init:function(){this.baseInit.apply(this,arguments)}}),r.OSBillView=r.BaseView.extend({init:function(){this.baseInit.apply(this,arguments)}}),r.OSSponsorView=r.BaseView.extend({init:function(){this.baseInit.apply(this,arguments)}}),r.MainRouter=i.Router.extend({routes:{categories:"routeCategories","category/recent":"routeRecentCategory","category/:category":"routeCategory","bill/:bill":"routeEBill","*defaultR":"routeDefault"},initialize:function(e){e.router=this,this.options=e,this.app=e.app,this.imagePath=t.bind(this.app.imagePath,this.app),this.translate=t.bind(this.app.translate,this.app),this.app.views.application=new r.ApplicationView({el:this.app.$el,template:this.app.templates.application,data:{options:this.options,categories:this.app.categories,imagePath:this.imagePath},options:this.options,partials:{loading:this.app.templates.loading}}),this.$content=this.app.$el.find(".ls-content-container")},start:function(){i.history.start() -},routeDefault:function(){this.navigate("/categories",{trigger:!0,replace:!0})},routeCategories:function(){this.app.fetchBasicBillData(),this.app.views.application.set("menuOff",!0),t.isObject(this.app.views.categories)&&this.app.views.categories.teardown(),this.app.views.categories=new r.CategoriesView({el:this.$content,template:this.app.templates.categories,data:{options:this.options,categories:this.app.categories,imagePath:this.imagePath},options:this.options,partials:{loading:this.app.templates.loading}}),this.scrollFocus(),this.pageTitle("Categories")},routeCategory:function(e,i){i=t.isUndefined(i)||null===i?!0:i;var n=decodeURI(e),s={options:this.options,imagePath:this.imagePath,translate:this.translate};e=this.app.categories.get(n),this.app.views.application.set("menuOff",!1),e||this.navigate("/",{trigger:!0,replace:!0}),t.isObject(this.app.views.category)&&this.app.views.category.teardown(),i&&this.app.fetchOSBillsFromCategory(e),this.app.views.category=new r.CategoryView({el:this.$content,template:this.app.templates.category,data:t.extend({},s,{category:e,categoryID:n}),options:this.options,partials:{loading:this.app.templates.loading},components:{ebill:r.EBillView.extend({template:this.app.templates.ebill,data:s,components:{osbill:r.OSBillView.extend({template:this.app.templates.osbill,data:s}),sponsor:r.OSSponsorView.extend({template:this.app.templates.sponsor,data:s})}})}}),this.scrollFocus(),this.pageTitle("Category | "+e.get("title"))},routeRecentCategory:function(){var t=this;this.app.fetchBasicBillData().done(function(){t.app.fetchOSBillsFromCategory(t.app.categories.get("recent"))}),this.routeCategory("recent",!1)},routeEBill:function(e){var i=decodeURI(e),n={options:this.options,imagePath:this.imagePath,translate:this.translate};e=this.app.bills.where({bill:i})[0],this.app.views.application.set("menuOff",!1),e||this.navigate("/",{trigger:!0,replace:!0}),t.isObject(this.app.views.bill)&&this.app.views.bill.teardown(),e.fetchOSBills(),this.app.views.bill=new r.EBillView({el:this.$content,template:this.app.templates.ebill,data:t.extend({},n,{bill:e,billID:i}),options:this.options,partials:{loading:this.app.templates.loading},components:{osbill:r.OSBillView.extend({template:this.app.templates.osbill,data:n,components:{sponsor:r.OSSponsorView.extend({template:this.app.templates.sponsor,data:n})}})}}),this.scrollFocus(),this.pageTitle("Bill | "+e.get("title"))},hasInitalFocus:!1,scrollFocus:function(){this.hasInitalFocus&&this.app.options.scollFocus&&e("html, body").animate({scrollTop:this.app.$el.offset().top+this.app.options.scollFocusOffset},this.app.options.scollFocusTime),this.hasInitalFocus=!0},pageTitle:function(t){document.title=this.app.options.documentTitle+" | "+t},error:function(){}}),a=function(t){this.options=e.extend(!0,{},this.defaultOptions,t),this.options.app=this,this.options.$el=this.$el=e(this.options.el),this.options.documentTitle=this.options.documentTitle||document.title,this.on("fetched:base-data",this.loadBaseData),this.on("loaded:basic-bill-data",this.loadRecentCategory),this.categories=new r.CategoriesCollection(null),this.bills=new r.BillsCollection(null),this.getTemplates(),this.fetchBaseData(),this.router=new r.MainRouter(this.options),this.on("loaded:base-data",this.startRouting)},t.extend(a.prototype,i.Events),t.extend(a.prototype,{views:{},cache:{},fetched:{},startRouting:function(){this.router.start()},fetchBaseData:function(){var e=this;this.fetched.baseData!==!0&&(this.tabletop=s.init(t.extend(this.options.tabletopOptions,{key:this.options.eKey,callback:function(t,i){e.fetched.baseData=!0,e.trigger("fetched:base-data",t,i)},callbackContext:e,wanted:this.options.sheetsWanted})))},loadBaseData:function(e,i){var n,s,l=this;s=r.parsers.eData(i,this.options),t.each(s.categories,function(t){this.categories.add(this.getModel("CategoryModel","id",t))},this),t.each(s.bills,function(t){this.bills.add(this.getModel("BillModel","bill",t))},this),n={id:"recent",title:"Recent Actions",description:"The following bills have been updated in the past "+this.options.recentChangeThreshold+" days.",image:this.options.recentImage},this.categories.add(this.getModel("CategoryModel","id",n)),this.categories.each(function(t){t.getBills(l.bills)}),this.trigger("loaded:base-data")},fetchBasicBillData:function(){var i,s=this,l=[];return this.fetched.basicBillData===!0?e.when.apply(e,[]):(this.bills.each(function(e){t.each(e.getOSBillIDs(),function(t){l.push(t)})}),i="http://openstates.org/api/v1/bills/?state="+this.options.state+"&fields=action_dates,chamber,title,id,created_at,updated_at,bill_id"+"&search_window=session:"+this.options.session+"&bill_id__in="+encodeURI(l.join("|"))+"&apikey="+this.options.OSKey+"&callback=?",e.getJSON(i).done(function(e){s.fetched.basicBillData=!0,s.trigger("fetched:basic-bill-data",e),t.each(e,function(e){e.action_dates=t.filterObject(e.action_dates,function(t){return t}),e.action_dates=t.mapObject(e.action_dates,function(t){return n(t)}),e.created_at=n(e.created_at),e.updated_at=n(e.updated_at),s.getModel("OSBillModel","bill_id",e).set(e)}),s.trigger("loaded:basic-bill-data")}))},loadRecentCategory:function(){var t=this.getModel("CategoryModel","id",{id:"recent"});this.bills.each(function(e){var i=e.get("categories");e.isRecent()&&(i.push(t.get("id")),e.set("categories",i))}),t.getBills(this.bills)},fetchOSBillsFromCategory:function(t,i){var n=this,s=[];return t.get("fetchedBills")&&!i?e.when.apply(e,s):(t.getBills(this.bills),t.get("bills").each(function(t){s.push(n.fetchModel(t))}),t.set("fetchedBills",!0,{silent:!0}),e.when.apply(e,s).done(function(){n.trigger("fetched:osbills"),n.trigger("fetched:osbills:category:"+t.id)}))},getModel:function(e,i,n,s){var l="models:"+e+":"+i+":"+n[i];return s=t.extend(s||{},{app:this}),t.isUndefined(this.cache[l])&&(this.cache[l]=new r[e](n,s)),this.cache[l]},fetchModel:function(t){var i;return t.get("fetched")!==!0?t.fetch({success:function(t){t.set("fetched",!0,{silent:!0})}}):(i=e.Deferred(),i.resolveWith(t),i)},translate:function(e,i){var n=i;return t.isObject(this.options.wordTranslations[e])&&t.isString(this.options.wordTranslations[e][i])&&(n=this.options.wordTranslations[e][i]),n},imagePath:function(t){return 0===t.indexOf("http")?t:this.options.imagePath+t},getTemplate:function(t){return r.templates[t]},templates:{},getTemplates:function(){this.templates.application=this.getTemplate("template-application"),this.templates.loading=this.getTemplate("template-loading"),this.templates.error=this.getTemplate("template-error"),this.templates.ebill=this.getTemplate("template-ebill"),this.templates.osbill=this.getTemplate("template-osbill"),this.templates.category=this.getTemplate("template-category"),this.templates.categories=this.getTemplate("template-categories"),this.templates.sponsor=this.getTemplate("template-sponsor")},defaultOptions:{sheetsWanted:["Categories","Bills","Events"],fieldTranslations:{eCategories:{id:"categoryid",short_title:"shorttitle"},eBills:{bill:"bill",bill_companion:"companionbill",bill_conference:"conferencebill",categories:"categories",title:"title",description:"description"},eEvents:{bill_id:"bill",actor:"chamber",action:"title"}},wordTranslations:{chamber:{upper:"Senate",lower:"House"},partyAbbr:{"Democratic-Farmer-Labor":"DFL",Democratic:"D",Republican:"R"},sponsors:{"Primary sponsors":"Primary sponsors","primary sponsors":"primary sponsors","Primary sponsor":"Primary sponsor","primary sponsor":"primary sponsor","Co-sponsors":"Co-sponsors","co-sponsors":"co-sponsors","Co-sponsor":"Co-sponsor","co-sponsor":"co-sponsor"}},maxBills:30,substituteMatch:/substituted/i,billNumberFormat:/[A-Z]+ [1-9][0-9]*/,detectCompanionBill:/([A-Z]+ [1-9][0-9]*)$/,imagePath:"./styles/images/",recentChangeThreshold:7,tabletopOptions:{},conferenceBill:!0,recentImage:"RecentUpdatedBill.png",chamberLabel:!1,osBillParse:void 0,stickMenu:!0,scollFocus:!0,scollFocusOffset:-15,scollFocusTime:500}}),r.templates=this.LTTemplates,a.LT=r,a}); \ No newline at end of file +(function(t,e){if("undefined"!=typeof module&&module.exports&&"function"==typeof require)module.exports=e(require("underscore"),require("jquery"),require("Backbone"),require("moment"),require("tabletop"),require("Ractive"));else if("function"==typeof define&&define.amd)define("LT",["underscore","jquery","Backbone","moment","tabletop","Ractive"],e);else{if(!(t._&&t.jQuery&&t.Backbone&&t.moment&&t.Tabletop))throw Error("Could not find dependencies for Legislature Tracker.");t.LT=e(t._,t.jQuery,t.Backbone,t.moment,t.Tabletop,t.Ractive)}})("undefined"!=typeof window?window:this,function(t,e,i,n,s,l){function o(t,i){this.element=t,this.$element=e(t),this._defaults=r.nav.stickDefaults,this.options=e.extend({},this._defaults,i),this._name="ltStick",this._scrollEvent="scroll.lt.ltStick",this._on=!1,this.init()}var a,r={};return this.LTTemplates={"template-application":'
\n\n {{#(!!categories)}}\n
\n
\n\n \n \n All Categories\n \n\n \n   |  \n\n {{#categories}}\n \n {{ (short_title) ? short_title : title.split(\' \')[0] }}\n \n   \n {{/categories}}\n \n
\n
\n {{/()}}\n\n {{#options.title}}\n

{{ options.title }}

\n {{/options.title}}\n\n
\n {{>loading}}\n
\n
\n',"template-categories":'\n{{^categories}}\n {{>loading}}\n{{/categories}}\n\n
\n \n
\n',"template-category":'\n{{^category}}\n {{>loading}}\n{{/category}}\n\n
\n

\n {{#category.image}}\n \n {{/category.image}}\n\n {{ category.title }}\n

\n\n

{{{ category.description }}}

\n\n {{#(category.links && category.links.length && category.links.length > 0)}}\n \n {{/()}}\n\n
\n {{#category.bills:bill}}\n \n {{/category.bills}}\n
\n\n
\n Watching\n {{ category.bills.length }}\n {{#(typeof category.total_bill_count != \'undefined\')}}\n of {{ category.total_bill_count }}\n {{/()}}\n bills in the {{ category.title }} category.\n
\n
\n',"template-ebill":'\n
\n
\n \n\n \n\n \n\n {{#options.conferenceBill}}\n \n {{/options.conferenceBill}}\n\n \n
\n\n {{#compact}}\n

\n {{ bill.title }}\n

\n {{/compact}}\n {{^compact}}\n

{{ bill.title }}

\n {{/compact}}\n\n {{^bill.hasBill}}\n
\n This bill has not been tracked by the legislature yet.\n
\n {{/bill.hasBill}}\n\n {{#bill.newest_action}}\n
Last action about {{ date.fromNow() }}: {{ action }}.
\n {{/bill.newest_action}}\n\n
\n {{{ bill.description }}}\n
\n\n
\n Categories:\n {{#bill.categories:i}}\n \n {{#image}}\n \n {{/image}}\n {{ title }}\n {{#(i < bill.categories.length - 1)}},{{/()}}\n {{/bill.categories}}\n
\n\n {{#(compact == true && bill.custom_events && bill.custom_events.length && bill.custom_events.length > 0)}}\n
\n Latest updates:\n {{#bill.custom_events.0}}\n {{ date.format(\'MMM DD, YYYY\') }}, {{ bill_id }}, {{{ description }}} ({{ translate(\'chamber\', chamber) }})\n {{/bill.custom_events.0}}\n
\n {{/()}}\n\n {{#(compact != true && bill.custom_events && bill.custom_events.length && bill.custom_events.length > 0)}}\n
\n Latest updates:\n {{#bill.custom_events}}\n
\n {{ date.format(\'MMM DD, YYYY\') }}: {{ bill_id }}, {{{ description }}} ({{ translate(\'chamber\', chamber) }})\n
\n {{/bill.custom_events}}\n
\n {{/()}}\n\n {{#(bill.links && bill.links.length && bill.links.length > 0)}}\n \n {{/()}}\n\n\n {{#(compact == true)}}\n
\n {{#bill.bill_conference}}\n
\n

Conference bill\n {{#sources.0.url}}\n {{ bill_id }}\n {{/sources.0.url}}\n {{^sources.0.url}} {{ bill_id }} {{/sources.0.url}}\n

\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n {{#sponsors}}\n \n {{/sponsors}}\n
\n {{/bill.bill_conference}}\n\n {{#bill.bill_primary}}\n
\n

\n {{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Primary bill\' }}\n {{#sources.0.url}}\n {{ bill_id }}\n {{/sources.0.url}}\n {{^sources.0.url}} {{ bill_id }} {{/sources.0.url}}\n

\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n {{#sponsors}}\n \n {{/sponsors}}\n
\n {{/bill.bill_primary}}\n\n {{#bill.bill_companion}}\n
\n

\n {{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Companion bill\' }}\n {{#sources.0.url}}\n {{ bill_id }}\n {{/sources.0.url}}\n {{^sources.0.url}} {{ bill_id }} {{/sources.0.url}}\n

\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n {{#sponsors}}\n \n {{/sponsors}}\n
\n {{/bill.bill_companion}}\n
\n\n \n {{/()}}\n\n\n {{#(compact != true)}}\n\n
\n\n {{#bill.bill_conference}}\n
\n

Conference bill {{ bill_id }}

\n \n
\n {{/bill.bill_conference}}\n\n {{#bill.bill_primary}}\n
\n

{{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Primary bill\' }} {{ bill_id }}

\n \n
\n {{/bill.bill_primary}}\n\n {{#bill.bill_companion}}\n
\n

{{ (options.chamberLabel) ? translate(\'chamber\', chamber) + \' bill\' : \'Companion bill\' }} {{ bill_id }}

\n \n
\n {{/bill.bill_companion}}\n {{/()}}\n\n
\n',"template-error":'
\n
There was an error.
\n
',"template-legislator":"\n
\n <% if (LT.options.legImageProxy) { %>\n <%= encodeURI(photo_url) %>\" />\n <% } else { %>\n \" />\n <% } %>\n \n
\n <%= full_name %>
\n <% if (typeof district != 'undefined') { %>\n District <%= district %>\n <% } %>\n <% if (typeof party != 'undefined') { %>\n (<%= LT.utils.translate('partyAbbr', party) %>) \n <% } %>
\n <% if (typeof chamber != 'undefined') { %>\n <%= LT.utils.translate('chamber', chamber) %>\n <% } %>\n
\n
","template-loading":'
\n
Loading...
\n
',"template-osbill":'\n
\n

\n {{#(!!bill.title)}}\n {{ bill.title }}\n {{/()}}\n\n {{^(!!bill.title)}}\n {{ bill.bill_id }}\n {{/()}}\n

\n\n
\n {{ translate(\'sponsors\', \'Primary sponsors\') }}\n
\n {{#bill.sponsors}}\n \n {{/bill.sponsors}}\n
\n
\n\n
\n Actions\n
\n {{#bill.actions}}\n {{#(!!date)}}\n
\n {{ date.format(\'MMM DD, YYYY\') }}:\n {{ action }}\n ({{ translate(\'chamber\', actor) }})\n
\n {{/())}}\n {{/bill.actions}}\n
\n
\n\n {{#(bill.sponsors && bill.sponsors.length && bill.sponsors.length > 0)}}\n
\n {{ translate(\'sponsors\', \'Co-sponsors\') }}\n
\n {{#bill.sponsors}}\n \n {{/bill.sponsors}}\n
\n
\n {{/()}}\n\n {{#(bill.votes && bill.votes.length && bill.votes.length > 0)}}\n
\n Votes\n
\n {{#bill.votes}}\n {{ date.format(\'MMM DD, YYYY\') }}\n {{ motion }} {{ (passed) ? \'passed\' : \'failed\' }}\n {{ yes_count }} Y -\n {{ no_count }} N
\n {{/bill.votes}}\n
\n
\n {{/()}}\n\n
\n Sources\n \n
\n
\n',"template-sponsor":'\n{{#(((!!type && sponsor.type === type) || !type) && !compact)}}\n\n \n{{/()}}\n\n\n{{#(((!!type && sponsor.type === type) || !type) && !!compact)}}\n \n{{/()}}\n'},t.mixin({filterEmpty:function(e){return t.filter(e,function(t){return t})},filterObject:function(e,i,n){return t.reduce(e,function(t,s,l){return i.call(n,s,l,e)&&(t[l]=s),t},{},n)},mapObject:function(e,i,n){return t.reduce(e,function(t,s,l){return t[l]=i.call(n,s,l,e),t},{},n)},trim:function(e){return t.isString(e)&&(e=String.prototype.trim?e.trim():e.replace(/^\s+|\s+$/g,"")),e},cssClass:function(t){return t.toLowerCase().replace(/[^a-z0-9]/g,"-")},numberFormatCommas:function(t){return(""+t).replace(/\B(?=(\d{3})+(?!\d))/g,",")},parseURL:function(t){var e=document.createElement("a");return e.href=t,e}}),i.ajax=function(){var t=arguments;return t[0].dataTypeForce!==!0&&(t[0].dataType="jsonp"),i.$.ajax.apply(i.$,t)},e.fn.hasScrollBar=function(){return this.get(0)&&this.get(0).scrollHeight?this.get(0).scrollHeight>this.height():!1},r.nav=r.nav||{},r.nav.stickDefaults={activeClass:"stuck top",wrapperClass:"menu-stick-container",topPadding:0,throttle:90},o.prototype={init:function(){this.$container=void 0===this.options.container?this.$element.parent():e(this.options.container),this.elementHeight=this.$element.outerHeight(!0),this.$spacer=e("
").height(this.elementHeight).hide(),this.$element.after(this.$spacer),this.options.wrapperClass&&this.$element.wrapInner('
'),this._throttledListen=t.bind(t.throttle(this.listen,this.options.throttle),this),this._throttledListen(),e(window).on(this._scrollEvent,this._throttledListen)},listen:function(){var t=this.$container.offset().top,i=t+this.$container.height(),n=e(window).scrollTop(),s=t-this.options.topPadding,l=i-this.elementHeight-this.options.topPadding-2;!this._on&&n>s&&l>n?this.on():this._on&&(s>n||n>l)&&this.off()},on:function(){this.$element.addClass(this.options.activeClass),this.options.topPadding&&this.$element.css("top",this.options.topPadding),this.$spacer.show(),this._on=!0},off:function(){this.$element.removeClass(this.options.activeClass),this.options.topPadding&&this.$element.css("top","inherit"),this.$spacer.hide(),this._on=!1},remove:function(){this.$container.off(this._scrollEvent)}},e.fn.ltStick=function(t){return this.each(function(){e.data(this,"ltStick")||e.data(this,"ltStick",new o(this,t))})},function(){var t,e;if(!l||!i)throw Error("Could not find Ractive or Backbone! Check your paths config");l.adaptors.Backbone={filter:function(t){return t instanceof i.Model||t instanceof i.Collection,t instanceof i.Model||t instanceof i.Collection},wrap:function(n,s,l,o){return s instanceof i.Model?new t(n,s,l,o):new e(n,s,l,o)}},t=function(t,e,i,n){var s=this;this.value=e,e.on("change",this.modelChangeHandler=function(){s.setting=!0,t.set(n(e.changed)),s.setting=!1}),e.on("sync",this.modelSyncHandler=function(){t.update(i)})},t.prototype={teardown:function(){this.value.off("change",this.changeHandler),this.value.off("sync",this.modelSyncHandler)},get:function(){return this.value.attributes},set:function(t,e){this.setting||-1!==t.indexOf(".")||this.value.set(t,e)},reset:function(t){return t instanceof i.Model||"object"!=typeof t?!1:(this.value.reset(t),void 0)}},e=function(t,e,i){var n=this;this.value=e,e.on("add remove reset sort",this.changeHandler=function(){n.setting=!0,t.set(i,e.models),n.setting=!1})},e.prototype={teardown:function(){this.value.off("add remove reset sort",this.changeHandler)},get:function(){return this.value.models},reset:function(t){return this.setting?void 0:t instanceof i.Collection||"[object Array]"!==Object.prototype.toString.call(t)?!1:(this.value.reset(t),void 0)}}}(),r.parsers=r.parsers||{},r.log=function(e){t.isObject(console)&&t.isFunction(console.log)&&console.log(e)},r.parsers.eData=function(e,i){var n={},s=e.sheets("Bills").all();return s.length>i.maxBills&&r.log("The number of bills in your spreadsheet exceeds maxBills. Set the maxBills option to display them, but be aware that this may significantly slow down the Legislature Tracker."),n.categories=r.parsers.eCategories(e.sheets("Categories").all(),i),n.bills=r.parsers.eBills(s.slice(0,i.maxBills),i),n.events=r.parsers.eEvents(e.sheets("Events").all(),i),t.each(t.groupBy(n.events,"bill_id"),function(e,i){t.each(n.bills,function(t,s){t.bill===i&&(n.bills[s].custom_events=e)})}),n},r.parsers.validateBillNumber=function(t,e){return e.billNumberFormat.test(t)},r.parsers.eBills=function(e,i){return t.map(e,function(e){return r.parsers.translateFields(i.fieldTranslations.eBills,e),e.links=r.parsers.eLinks(e.links),e.id=e.id||t.cssClass(e.bill)+t.cssClass(e.title),e.categories=e.categories?e.categories.split(","):[],e.categories=t.map(e.categories,t.trim),e.bill_primary=t.trim(e.bill),e.bill&&!r.parsers.validateBillNumber(e.bill,i)&&r.log('Invalid primary bill number "'+e.bill+'" for row '+e.rowNumber+", see documentation."),e.bill_companion=t.trim(e.bill_companion),e.bill_companion&&!r.parsers.validateBillNumber(e.bill_companion,i)&&r.log('Invalid companion bill number "'+e.bill_companion+'" for row '+e.rowNumber+", see documentation."),e.bill_conference=t.trim(e.bill_conference),e.bill_conference&&!r.parsers.validateBillNumber(e.bill_conference,i)&&r.log('Invalid conference bill number "'+e.bill_conference+'" for row '+e.rowNumber+", see documentation."),e.hasBill=!0,e.bill&&e.bill_primary||(e.hasBill=!1,e.bill=t.cssClass(e.title.toLowerCase())),e})},r.parsers.eCategories=function(e,i){return t.map(e,function(t){return r.parsers.translateFields(i.fieldTranslations.eCategories,t),t.links=r.parsers.eLinks(t.links),t})},r.parsers.eEvents=function(e,i){return t.sortBy(t.map(e,function(t){return r.parsers.translateFields(i.fieldTranslations.eEvents,t),t.date=n(t.date),t.type=["custom"],t}),function(t){return-1*t.date.unix})},r.parsers.eLinks=function(e){var i=[];return e=t.trim(e),0===e.length?i:(e='"'===e.substring(0,1)?e.substring(1):e,e='"'===e.substring(e.length-1,e.length)?e.slice(0,-1):e,i=e.split('", "'),i=t.map(i,function(t){return{title:t.split("|")[0],url:t.split("|")[1]}}))},r.parsers.csvCategories=function(e){return e=t.trim(e),0===e.length?[]:(e='"'===e.substring(0,1)?e.substring(1):e,e='"'===e.substring(e.length-1,e.length)?e.slice(0,-1):e,e.split('", "'))},r.parsers.detectCompanionBill=function(e,i){var n,s;return t.isFunction(i.detectCompanionBill)?(n=i.detectCompanionBill(e),s=r.parsers.validateBillNumber(n,i)?n:void 0):t.isRegExp(i.detectCompanionBill)&&(n=i.detectCompanionBill.exec(e),s=n&&r.parsers.validateBillNumber(n[1],i)?n[1]:void 0),t.trim(s)},r.parsers.translateFields=function(e,i){return t.each(e,function(t,e){i[e]=i[t],e!==t&&delete i[t]}),i},r.BaseModel=i.Model.extend({initialize:function(t,e){this.options=e,this.app=this.options.app,this.on("sync",function(t){t.set("fetched",!0)})}}),r.OSModel=r.BaseModel.extend({urlBase:function(){return"http://openstates.org/api/v1/"},urlEnd:function(){return"/?apikey="+encodeURI(this.app.options.OSKey)+"&callback=?"},url:function(){return this.urlBase()+encodeURI(this.osType)+"/"+encodeURI(this.id)+this.urlEnd()},initialize:function(){r.OSModel.__super__.initialize.apply(this,arguments)}}),r.OSStateModel=r.OSModel.extend({url:function(){return this.urlBase()+"metadata/"+encodeURI(this.options.state)+this.urlEnd()}}),r.OSLegislatorModel=r.OSModel.extend({osType:"legislators",initialize:function(){r.OSBillModel.__super__.initialize.apply(this,arguments),this.get("leg_id")&&this.app.fetchModel(this)}}),r.OSCommitteeModel=r.OSModel.extend({osType:"committees"}),r.OSBillModel=r.OSModel.extend({url:function(){return t.isUndefined(this.id)?t.isUndefined(this.get("bill_id"))||""===this.get("bill_id")?void 0:this.urlBase()+"bills/"+encodeURI(this.app.options.state)+"/"+encodeURI(this.app.options.session)+"/"+encodeURI(this.get("bill_id"))+this.urlEnd():this.urlBase()+"bills/"+this.id+this.urlEnd()},initialize:function(){r.OSBillModel.__super__.initialize.apply(this,arguments)},parse:function(e){var i=this;return e.created_at=e.created_at?n(e.created_at):void 0,e.updated_at=e.updated_at?n(e.updated_at):void 0,e.action_dates=t.filterObject(e.action_dates,function(t){return t}),e.action_dates=t.mapObject(e.action_dates,function(t){return n(t)}),e.actions=t.mapObject(e.actions,function(t){return t.date=n(t.date),t}),e.votes=t.mapObject(e.votes,function(t){return t.date=n(t.date),t}),this.get("custom_events")&&(e.actions=t.union(e.actions,this.get("custom_events"))),e.actions=t.sortBy(e.actions,function(t,e){return-1*(t.date.unix()+e)}),e.newest_action=e.actions[0],this.app.options.osBillParse&&t.isFunction(this.app.options.osBillParse)&&(e=this.app.options.osBillParse.apply(this,[e,this.app])),e.sponsors&&(e.sponsors=t.map(e.sponsors,function(t){return t.id=t.leg_id,t.leg=i.app.getModel("OSLegislatorModel","leg_id",t),t})),e},getActionDate:function(t){return this.get("action_dates")[t]?this.get("action_dates")[t]:!1},isSubstituted:function(){var e=!1,i=this;return t.isBoolean(this.get("substitued"))?e=this.get("substitued"):this.app.options.substituteMatch===!1?e=!1:(e=t.find(this.get("actions"),function(t){return t.action.match(i.app.options.substituteMatch)}),e=e?!0:!1,this.set("substitued",e)),e}}),r.BillModel=r.BaseModel.extend({subbills:["bill_primary","bill_companion","bill_conference"],initialize:function(){r.BillModel.__super__.initialize.apply(this,arguments),this.loadOSBills()},loadOSBills:function(){var e=this;t.each(this.subbills,function(t){var i;e.get(t)&&(i=e.app.getModel("OSBillModel","bill_id",{bill_id:e.get(t)}),e.set(t,i))})},getOSBills:function(){var e=this;return t.filterEmpty(t.map(this.subbills,function(t){return e.get(t)}))},getOSBillIDs:function(){var e=this.getOSBills();return t.filterEmpty(t.map(e,function(e){return t.isObject(e)?e.get("bill_id"):e}))},fetchOSBills:function(){var i=this,n=[];return this.getCategories(),t.each(this.subbills,function(t){i.get("hasBill")&&i.get(t)&&n.push(i.app.fetchModel(i.get(t)))}),e.when.apply(e,n).done(function(){i.loadOSCompanion().done(function(){i.parseMeta(),i.lastUpdatedAt(),i.newestAction(),i.trigger("fetched:osbills")})})},fetch:function(){return this.fetchOSBills()},loadOSCompanion:function(){var i,n=[];return this.get("hasBill")===!0&&!this.get("bill_companion")&&t.isObject(this.get("bill_primary"))&&t.isArray(this.get("bill_primary").get("companions"))&&t.isObject(this.get("bill_primary").get("companions")[0])&&(i=r.parsers.detectCompanionBill(this.get("bill_primary").get("companions")[0],this.app.options),i&&(this.set("bill_companion",this.app.getModel("OSBillModel","bill_id",{bill_id:i})),n.push(this.app.fetchModel(this.get("bill_companion"))))),e.when.apply(e,n)},getCategories:function(){var e=this;this.get("categories")&&this.set("categories",t.map(this.get("categories"),function(i){return t.isObject(i)||(i=e.app.getModel("CategoryModel","id",{id:i})),i}))},lastUpdatedAt:function(){var t,e=this.get("bill_primary"),i=this.get("bill_companion"),n=this.get("bill_conference");return e&&e.get("updated_at")&&(t=e.get("updated_at"),i&&i.get("updated_at")&&(t=i.get("updated_at").unix()>t.unix()?i.get("updated_at"):t),n&&n.get("updated_at")&&(t=n.get("updated_at").unix()>t.unix()?n.get("updated_at"):t),this.set("last_updated_at",t)),this.get("last_updated_at")},newestAction:function(){var t,e=this.get("bill_primary"),i=this.get("bill_companion"),n=this.get("bill_conference");return this.get("hasBill")&&e.get("newest_action")&&(t=e.get("newest_action"),i&&i.get("newest_action")&&(t=i.get("newest_action").date.unix()>t.date.unix()?i.get("newest_action"):t),n&&n.get("newest_action")&&(t=n.get("newest_action").date.unix()>t.date.unix()?n.get("newest_action"):t),this.set("newest_action",t)),this.get("newest_action")},isRecent:function(){var e=this.newestAction(),i=this.get("bill_primary")?this.get("bill_primary").get("action_dates"):null;return t.isObject(e)&&e.date&&n().diff(e.date,"days")<=this.app.options.recentChangeThreshold?!0:t.isObject(i)&&i.last&&n().diff(i.last,"days")<=this.app.options.recentChangeThreshold?!0:!1},parseMeta:function(){var e,i,n=this,s={upper:!1,lower:!1,conference:!1,signed:!1,last:!1},l={companion:this.get("bill_companion")?!0:!1,conference:this.get("bill_conference")?!0:!1};if(this.get("custom_events")&&this.set("custom_events",t.sortBy(this.get("custom_events"),function(t,e){return-1*(t.date.unix()+e)})),this.get("hasBill")){if(l.companion&&(this.get("bill_companion").isSubstituted()&&(l.substituted=!0),this.get("bill_primary").isSubstituted()&&(l.substituted=!0,e=this.get("bill_primary").get("bill_id"),i=this.get("bill_companion").get("bill_id"),this.unset("bill_primary"),this.set("bill_primary",function(){return n.app.getModel("OSBillModel","bill_id",{bill_id:i})}()),this.unset("bill_companion"),this.set("bill_companion",function(){return n.app.getModel("OSBillModel","bill_id",{bill_id:e})}()))),(!l.companion||l.substituted)&&(s.lower=this.get("bill_primary").getActionDate("passed_lower"),s.upper=this.get("bill_primary").getActionDate("passed_upper")),l.companion&&!l.substituted&&("upper"===this.get("bill_primary").get("chamber")?(s.upper=this.get("bill_primary").getActionDate("passed_upper"),s.lower=this.get("bill_companion").getActionDate("passed_lower")):(s.lower=this.get("bill_primary").getActionDate("passed_lower"),s.upper=this.get("bill_companion").getActionDate("passed_upper"))),l.conference){var o=this.get("bill_conference").getActionDate("passed_lower"),a=this.get("bill_conference").getActionDate("passed_upper");o&&a&&(s.conference=o.unix()>=a.unix()?o:a)}s.signed=l.conference?this.get("bill_conference").getActionDate("signed"):this.get("bill_primary").getActionDate("signed"),s.last=l.conference?this.get("bill_conference").getActionDate("last"):l.companion?this.get("bill_companion").getActionDate("last").unix()>=this.get("bill_primary").getActionDate("last").unix()?this.get("bill_companion").getActionDate("last"):this.get("bill_primary").getActionDate("last"):this.get("bill_primary").getActionDate("last"),this.get("description")||this.set("description",this.get("bill_primary").get("summary"))}return l.recent=this.isRecent(),this.set("actions",s),this.set("bill_type",l),this.trigger("change"),this}}),r.CategoryModel=r.BaseModel.extend({initialize:function(){r.CategoryModel.__super__.initialize.apply(this,arguments),this.set("bills",new r.BillsCollection(null))},getBills:function(e){var i=this,n=this.get("id");return this.get("loadedBills")&&this.get("bills").length>0?this:(e.each(function(e){-1!==t.indexOf(e.get("categories"),n)&&i.get("bills").add(i.app.getModel("BillModel","bill",e.toJSON()))}),this.set("loadedBills",!0,{silent:!0}),this)}}),r.CategoriesCollection=i.Collection.extend({model:r.CategoryModel,comparator:function(t){return-1!==t.get("title").toLowerCase().indexOf("recent")?"zzzzz":t.get("title")}}),r.BillsCollection=i.Collection.extend({model:r.BillModel,initialize:function(){this.on("change:newest_action",function(){})},comparator:function(t){var e=t.newestAction()?n().diff(t.newestAction().date,"days"):null;return e}}),r.OSBillsCollection=i.Collection.extend({model:r.OSBillModel,comparator:function(t){var e=t.get("newest_action");return e?-1*e.date.unix():9999}}),r.OSLegislatorsCollection=i.Collection.extend({model:r.OSLegislatorModel,comparator:function(t){return("primary"===t.get("type")?"aaa":"bbb")+t.get("name")}}),r.BaseView=l.extend({baseInit:function(t){this.options=t.options,this.app=t.app,this.router=t.router},adaptors:["Backbone"]}),r.ApplicationView=r.BaseView.extend({init:function(){this.baseInit.apply(this,arguments),this.stuck=!1,this.observe("categories",function(i){this.stuck||this.get("options").stickMenu===!0||(this.stuck=!0),!this.stuck&&i&&t.isObject(i)&&i.length>0&&(this.stuck=!0,e(this.el).find(".ls-header").ltStick({container:e(this.el)}))})}}),r.CategoriesView=r.BaseView.extend({init:function(){this.baseInit.apply(this,arguments)}}),r.CategoryView=r.BaseView.extend({init:function(){this.baseInit.apply(this,arguments)}}),r.EBillView=r.BaseView.extend({init:function(){this.baseInit.apply(this,arguments)}}),r.OSBillView=r.BaseView.extend({init:function(){this.baseInit.apply(this,arguments)}}),r.OSSponsorView=r.BaseView.extend({init:function(){this.baseInit.apply(this,arguments)}}),r.MainRouter=i.Router.extend({routes:{categories:"routeCategories","category/recent":"routeRecentCategory","category/:category":"routeCategory","bill/:bill":"routeEBill","*defaultR":"routeDefault"},initialize:function(e){e.router=this,this.options=e,this.app=e.app,this.imagePath=t.bind(this.app.imagePath,this.app),this.translate=t.bind(this.app.translate,this.app),this.app.views.application=new r.ApplicationView({el:this.app.$el,template:this.app.templates.application,data:{options:this.options,categories:this.app.categories,imagePath:this.imagePath},options:this.options,partials:{loading:this.app.templates.loading}}),this.$content=this.app.$el.find(".ls-content-container") +},start:function(){i.history.start()},routeDefault:function(){this.navigate("/categories",{trigger:!0,replace:!0})},routeCategories:function(){this.app.fetchBasicBillData(),this.app.views.application.set("menuOff",!0),t.isObject(this.app.views.categories)&&this.app.views.categories.teardown(),this.app.views.categories=new r.CategoriesView({el:this.$content,template:this.app.templates.categories,data:{options:this.options,categories:this.app.categories,imagePath:this.imagePath},options:this.options,partials:{loading:this.app.templates.loading}}),this.scrollFocus(),this.pageTitle("Categories")},routeCategory:function(e,i){i=t.isUndefined(i)||null===i?!0:i;var n=decodeURI(e),s={options:this.options,imagePath:this.imagePath,translate:this.translate};e=this.app.categories.get(n),this.app.views.application.set("menuOff",!1),e||this.navigate("/",{trigger:!0,replace:!0}),t.isObject(this.app.views.category)&&this.app.views.category.teardown(),i&&this.app.fetchOSBillsFromCategory(e),this.app.views.category=new r.CategoryView({el:this.$content,template:this.app.templates.category,data:t.extend({},s,{category:e,categoryID:n}),options:this.options,partials:{loading:this.app.templates.loading},components:{ebill:r.EBillView.extend({template:this.app.templates.ebill,data:s,components:{osbill:r.OSBillView.extend({template:this.app.templates.osbill,data:s}),sponsor:r.OSSponsorView.extend({template:this.app.templates.sponsor,data:s})}})}}),this.scrollFocus(),this.pageTitle("Category | "+e.get("title"))},routeRecentCategory:function(){var t=this;this.app.fetchBasicBillData().done(function(){t.app.fetchOSBillsFromCategory(t.app.categories.get("recent"))}),this.routeCategory("recent",!1)},routeEBill:function(e){var i=decodeURI(e),n={options:this.options,imagePath:this.imagePath,translate:this.translate};e=this.app.bills.where({bill:i})[0],this.app.views.application.set("menuOff",!1),e||this.navigate("/",{trigger:!0,replace:!0}),t.isObject(this.app.views.bill)&&this.app.views.bill.teardown(),e.fetchOSBills(),this.app.views.bill=new r.EBillView({el:this.$content,template:this.app.templates.ebill,data:t.extend({},n,{bill:e,billID:i}),options:this.options,partials:{loading:this.app.templates.loading},components:{osbill:r.OSBillView.extend({template:this.app.templates.osbill,data:n,components:{sponsor:r.OSSponsorView.extend({template:this.app.templates.sponsor,data:n})}})}}),this.scrollFocus(),this.pageTitle("Bill | "+e.get("title"))},hasInitalFocus:!1,scrollFocus:function(){this.hasInitalFocus&&this.app.options.scollFocus&&e("html, body").animate({scrollTop:this.app.$el.offset().top+this.app.options.scollFocusOffset},this.app.options.scollFocusTime),this.hasInitalFocus=!0},pageTitle:function(t){document.title=this.app.options.documentTitle+" | "+t},error:function(){}}),a=function(t){this.options=e.extend(!0,{},this.defaultOptions,t),this.options.app=this,this.options.$el=this.$el=e(this.options.el),this.options.documentTitle=this.options.documentTitle||document.title,this.on("fetched:base-data",this.loadBaseData),this.on("loaded:basic-bill-data",this.loadRecentCategory),this.categories=new r.CategoriesCollection(null),this.bills=new r.BillsCollection(null),this.getTemplates(),this.fetchBaseData(),this.router=new r.MainRouter(this.options),this.on("loaded:base-data",this.startRouting)},t.extend(a.prototype,i.Events),t.extend(a.prototype,{views:{},cache:{},fetched:{},startRouting:function(){this.router.start()},fetchBaseData:function(){var e=this;this.fetched.baseData!==!0&&(this.tabletop=s.init(t.extend(this.options.tabletopOptions,{key:this.options.eKey,callback:function(t,i){e.fetched.baseData=!0,e.trigger("fetched:base-data",t,i)},callbackContext:e,wanted:this.options.sheetsWanted})))},loadBaseData:function(e,i){var n,s,l=this;s=r.parsers.eData(i,this.options),t.each(s.categories,function(t){this.categories.add(this.getModel("CategoryModel","id",t))},this),t.each(s.bills,function(t){this.bills.add(this.getModel("BillModel","bill",t))},this),n={id:"recent",title:"Recent Actions",description:"The following bills have been updated in the past "+this.options.recentChangeThreshold+" days.",image:this.options.recentImage},this.categories.add(this.getModel("CategoryModel","id",n)),this.categories.each(function(t){t.getBills(l.bills)}),this.trigger("loaded:base-data")},fetchBasicBillData:function(){var i,s=this,l=[];return this.fetched.basicBillData===!0?e.when.apply(e,[]):(this.bills.each(function(e){t.each(e.getOSBillIDs(),function(t){l.push(t)})}),i="http://openstates.org/api/v1/bills/?state="+this.options.state+"&fields=action_dates,chamber,title,id,created_at,updated_at,bill_id"+"&search_window=session:"+this.options.session+"&bill_id__in="+encodeURI(l.join("|"))+"&apikey="+this.options.OSKey+"&callback=?",e.getJSON(i).done(function(e){s.fetched.basicBillData=!0,s.trigger("fetched:basic-bill-data",e),t.each(e,function(e){e.action_dates=t.filterObject(e.action_dates,function(t){return t}),e.action_dates=t.mapObject(e.action_dates,function(t){return n(t)}),e.created_at=n(e.created_at),e.updated_at=n(e.updated_at),s.getModel("OSBillModel","bill_id",e).set(e)}),s.trigger("loaded:basic-bill-data")}))},loadRecentCategory:function(){var t=this.getModel("CategoryModel","id",{id:"recent"});this.bills.each(function(e){var i=e.get("categories");e.isRecent()&&(i.push(t.get("id")),e.set("categories",i))}),t.getBills(this.bills)},fetchOSBillsFromCategory:function(t,i){var n=this,s=[];return t.get("fetchedBills")&&!i?e.when.apply(e,s):(t.getBills(this.bills),t.get("bills").each(function(t){s.push(n.fetchModel(t))}),t.set("fetchedBills",!0,{silent:!0}),e.when.apply(e,s).done(function(){n.trigger("fetched:osbills"),n.trigger("fetched:osbills:category:"+t.id)}))},getModel:function(e,i,n,s){var l="models:"+e+":"+i+":"+n[i];return s=t.extend(s||{},{app:this}),t.isUndefined(this.cache[l])&&(this.cache[l]=new r[e](n,s)),this.cache[l]},fetchModel:function(t){var i;return t.get("fetched")!==!0?t.fetch({success:function(t){t.set("fetched",!0,{silent:!0})}}):(i=e.Deferred(),i.resolveWith(t),i)},translate:function(e,i){var n=i;return t.isObject(this.options.wordTranslations[e])&&t.isString(this.options.wordTranslations[e][i])&&(n=this.options.wordTranslations[e][i]),n},imagePath:function(t){return 0===t.indexOf("http")?t:this.options.imagePath+t},getTemplate:function(t){return r.templates[t]},templates:{},getTemplates:function(){this.templates.application=this.getTemplate("template-application"),this.templates.loading=this.getTemplate("template-loading"),this.templates.error=this.getTemplate("template-error"),this.templates.ebill=this.getTemplate("template-ebill"),this.templates.osbill=this.getTemplate("template-osbill"),this.templates.category=this.getTemplate("template-category"),this.templates.categories=this.getTemplate("template-categories"),this.templates.sponsor=this.getTemplate("template-sponsor")},defaultOptions:{sheetsWanted:["Categories","Bills","Events"],fieldTranslations:{eCategories:{id:"categoryid",short_title:"shorttitle"},eBills:{bill:"bill",bill_companion:"companionbill",bill_conference:"conferencebill",categories:"categories",title:"title",description:"description"},eEvents:{bill_id:"bill",chamber:"chamber",description:"description"}},wordTranslations:{chamber:{upper:"Senate",lower:"House"},partyAbbr:{"Democratic-Farmer-Labor":"DFL",Democratic:"D",Republican:"R"},sponsors:{"Primary sponsors":"Primary sponsors","primary sponsors":"primary sponsors","Primary sponsor":"Primary sponsor","primary sponsor":"primary sponsor","Co-sponsors":"Co-sponsors","co-sponsors":"co-sponsors","Co-sponsor":"Co-sponsor","co-sponsor":"co-sponsor"}},maxBills:30,substituteMatch:/substituted/i,billNumberFormat:/[A-Z]+ [1-9][0-9]*/,detectCompanionBill:/([A-Z]+ [1-9][0-9]*)$/,imagePath:"./styles/images/",recentChangeThreshold:7,tabletopOptions:{},conferenceBill:!0,recentImage:"RecentUpdatedBill.png",chamberLabel:!1,osBillParse:void 0,stickMenu:!0,scollFocus:!0,scollFocusOffset:-15,scollFocusTime:500}}),r.templates=this.LTTemplates,a.LT=r,a}); \ No newline at end of file diff --git a/js/app.js b/js/app.js index 41f7aca..65efa41 100644 --- a/js/app.js +++ b/js/app.js @@ -282,8 +282,8 @@ _.extend(App.prototype, { }, eEvents: { 'bill_id': 'bill', - 'actor': 'chamber', - 'action': 'title' + 'chamber': 'chamber', + 'description': 'description' } }, wordTranslations: { diff --git a/js/parsers.js b/js/parsers.js index 7eb92c4..2743b96 100644 --- a/js/parsers.js +++ b/js/parsers.js @@ -97,14 +97,15 @@ LT.parsers.eCategories = function(categories, options) { }; LT.parsers.eEvents = function(events, options) { - return _.map(events, function(row) { + return _.sortBy(_.map(events, function(row) { LT.parsers.translateFields(options.fieldTranslations.eEvents, row); - row.links = LT.parsers.eLinks(row.links); row.date = moment(row.date); // Add some things to fit format of Open States actions row.type = ['custom']; return row; + }), function(e, ei) { + return e.date.unix * -1; }); }; diff --git a/js/templates/template-ebill.html b/js/templates/template-ebill.html index 1239a59..c547e81 100644 --- a/js/templates/template-ebill.html +++ b/js/templates/template-ebill.html @@ -74,6 +74,26 @@

{{ bill.title }}

{{/bill.categories}}
+ {{#(compact == true && bill.custom_events && bill.custom_events.length && bill.custom_events.length > 0)}} +
+ Latest updates: + {{#bill.custom_events.0}} + {{ date.format('MMM DD, YYYY') }}, {{ bill_id }}, {{{ description }}} ({{ translate('chamber', chamber) }}) + {{/bill.custom_events.0}} +
+ {{/()}} + + {{#(compact != true && bill.custom_events && bill.custom_events.length && bill.custom_events.length > 0)}} +
+ Latest updates: + {{#bill.custom_events}} +
+ {{ date.format('MMM DD, YYYY') }}: {{ bill_id }}, {{{ description }}} ({{ translate('chamber', chamber) }}) +
+ {{/bill.custom_events}} +
+ {{/()}} + {{#(bill.links && bill.links.length && bill.links.length > 0)}}