/*! * teeble - v0.3.15 - 2015-03-03 * https://github.com/HubSpot/teeble * Copyright (c) 2015 HubSpot, Marc Neuwirth, Jonathan Kim; * Licensed MIT */ (function(){this.Teeble={}}).call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}};this.Teeble.TableRenderer=function(){function t(t){this.options=t,this.update_template=e(this.update_template,this),this.generate_columns=e(this.generate_columns,this),this.render_empty=e(this.render_empty,this),this.render_footer=e(this.render_footer,this),this.render_header=e(this.render_header,this),this.render_row=e(this.render_row,this),this._render=e(this._render,this),this._getExtraData=e(this._getExtraData,this),this._initialize=e(this._initialize,this),this._initialize(),this}return t.prototype.key="rows",t.prototype.hasFooter=!1,t.prototype.data=null,t.prototype.header_template=null,t.prototype.row_template=null,t.prototype.rows_template=null,t.prototype.table_class=null,t.prototype.table_template=null,t.prototype.table_template_compiled=null,t.prototype.empty_message="No data to display",t.prototype.classes={sorting:{sortable_class:"sorting"}},t.prototype.compile=_.template,t.prototype._initialize=function(){var e,t,n,r;t=["table_class","partials","hasFooter","empty_message","cid","classes","compile"];for(n=0,r=t.length;n"+a+""}l+=a}}n&&(l="<"+n+">"+l+"")}return l},t.prototype.generate_columns=function(e,t){var n,r,i,s;e==null&&(e=this.partials),t==null&&(t=!1);if(this.columns&&!t)return this.columns;r=0,this.columns=[];for(s in e)i=e[s],n={},i.header&&(n.header=this._get_template_attributes("header",i,r)),i.footer&&(n.footer=this._get_template_attributes("footer",i,r)),i.cell&&(n.cell=this._get_template_attributes("cell",i,r)),this.columns.push(n),r++;return this.columns},t.prototype.update_template=function(e){var t;return e==null&&(e=this.partials),t=this.generate_columns(),this.header_template=this._generate_template("header",t,"tr","th"),this.footer_template=this._generate_template("footer",t,"tr"),this.row_template=this._generate_template("cell",t),this.table_empty_template='{{{message}}}'},t}()}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};this.Teeble.EmptyView=function(t){function r(){return this.render=e(this.render,this),this.initialize=e(this.initialize,this),r.__super__.constructor.apply(this,arguments)}return n(r,t),r.prototype.initialize=function(e){return this.options=e,this.renderer=this.options.renderer},r.prototype.render=function(){return this.renderer&&(this.el=this.renderer.render_empty(this.options)),this},r}(Backbone.View)}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};this.Teeble.FooterView=function(t){function r(){return this.stopListening=e(this.stopListening,this),this.render=e(this.render,this),this.initialize=e(this.initialize,this),r.__super__.constructor.apply(this,arguments)}return n(r,t),r.prototype.tagName="tfoot",r.prototype.initialize=function(e){var t=this;return this.options=e,this.renderer=this.options.renderer,this.collection.footer?(this.collection.footer instanceof Backbone.Model&&this.collection.footer.on("change",function(){return t.render()}),this.data=this.collection.footer):this.data=this.options,this.collection.footer},r.prototype.render=function(){var e;return this.renderer&&(this.data.toJSON?e=this.data.toJSON():e=this.data,this.$el.html(this.renderer.render_footer(e))),this},r.prototype.stopListening=function(){var e;return(e=this.collection.footer)!=null&&e.off("change"),r.__super__.stopListening.apply(this,arguments)},r}(Backbone.View)}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};this.Teeble.HeaderView=function(t){function r(){return this.setSort=e(this.setSort,this),this.sort=e(this.sort,this),this._sort=e(this._sort,this),this.render=e(this.render,this),this.initialize=e(this.initialize,this),r.__super__.constructor.apply(this,arguments)}return n(r,t),r.prototype.events={"click .sorting":"sort"},r.prototype.tagName="thead",r.prototype.initialize=function(e){return this.options=e,this.renderer=this.options.renderer,this.classes=this.options.classes},r.prototype.delegateEvents=function(){return r.__super__.delegateEvents.apply(this,arguments),this.collection.on("reset",this.setSort,this)},r.prototype.undelegateEvents=function(){return r.__super__.undelegateEvents.apply(this,arguments),this.collection.off("reset",this.setSort)},r.prototype.render=function(){return this.renderer&&(this.$el.html(this.renderer.render_header(this.options)),this.setSort()),this},r.prototype._sort=function(e,t){var n,r,i;return e.preventDefault(),n=this.$(e.target),n.hasClass(this.classes.sorting.sortable_class)||(n=n.parents("."+this.classes.sorting.sortable_class)),r=n.attr("data-sort"),!n.hasClass(this.classes.sorting.sorted_desc_class)&&!n.hasClass(this.classes.sorting.sorted_asc_class)&&(t=(i=this.collection.sortDirections[r])!=null?i:t),this.collection.setSort(r,t)},r.prototype.sort=function(e){var t;return t=this.$(e.currentTarget),t.hasClass(this.classes.sorting.sorted_desc_class)?this._sort(e,"asc"):this._sort(e,"desc")},r.prototype.setSort=function(){var e,t;if(this.collection.sortColumn)return t="desc",this.collection.sortDirection&&(t=this.collection.sortDirection),e="sorted_"+t+"_class",this.$el.find("."+this.classes.sorting.sortable_class).removeClass(""+this.classes.sorting.sorted_desc_class+" "+this.classes.sorting.sorted_asc_class).filter('.sorting[data-sort="'+this.collection.sortColumn+'"]').addClass(""+this.classes.sorting[e])},r}(Backbone.View)}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};this.Teeble.PaginationView=function(t){function r(){return this.gotoPage=e(this.gotoPage,this),this.gotoLast=e(this.gotoLast,this),this.gotoNext=e(this.gotoNext,this),this.gotoPrev=e(this.gotoPrev,this),this.gotoFirst=e(this.gotoFirst,this),this.render=e(this.render,this),r.__super__.constructor.apply(this,arguments)}return n(r,t),r.prototype.initialize=function(e){this.options=e},r.prototype.tagName="div",r.prototype.events={"click a.first":"gotoFirst","click a.previous":"gotoPrev","click a.next":"gotoNext","click a.last":"gotoLast","click a.pagination-page":"gotoPage"},r.prototype.template='
\n \n
',r.prototype.render=function(){var e,t,n,r;return this.collection.information||this.collection.pager(),t=this.collection.information,t.totalPages>1&&(r=function(){var e,r,i,s;i=t.pageSet,s=[];for(e=0,r=i.length;e"),this.table=this.$("table").addClass(this.options.table_class),this.body=this.$("tbody"),this.rendered=!0,this.renderHeader(),this.renderBody(),this.renderFooter(),this.renderPagination(),this.trigger("teeble.render",this),this},r.prototype.renderPagination=function(){var e;if(this.options.pagination&&this.rendered)return(e=this.pagination)!=null&&e.remove(),this.pagination=new this.subviews.pagination({collection:this.collection,pagination:this.classes.pagination}),this.$el.append(this.pagination.render().el),this.trigger("pagination.render",this)},r.prototype.renderHeader=function(){var e;if(this.rendered)return(e=this.header)!=null&&e.remove(),this.header=new this.subviews.header({renderer:this.renderer,collection:this.collection,classes:this.classes}),this.table.prepend(this.header.render().el),this.trigger("header.render",this)},r.prototype.renderFooter=function(){var e;if(this.options.footer&&this.rendered){(e=this.footer)!=null&&e.remove();if(this.collection.length>0)return this.footer=new this.subviews.footer({renderer:this.renderer,collection:this.collection}),this.table.append(this.footer.render().el),this.trigger("footer.render",this)}},r.prototype.renderBody=function(){if(this.rendered)return this.body.empty(),this.collection.length>0?(this.collection.each(this.addOne),this.trigger("body.render",this)):this.renderEmpty()},r.prototype.renderEmpty=function(){var e;if(this.rendered)return e=_.extend({},this.options,{renderer:this.renderer,collection:this.collection}),this.empty=new this.subviews.empty(e),this.body.append(this.empty.render().el),this.trigger("empty.render",this)},r.prototype.addOne=function(e){var t,n;return this.collection.sortColumn&&(t=this.sortIndex[this.collection.sortColumn]),n=new this.subviews.row({model:e,renderer:this.renderer,sortColumnIndex:t,sortableClass:this.classes.sorting.sortable_cell}),this.rows.push(n),this.body.append(n.render().el),this.trigger("row.render",n)},r.prototype.remove=function(){var e,t,n,i,s,o;r.__super__.remove.apply(this,arguments),i=this.rows;for(t=0,n=i.length;t1)return this.promise=this.requestPreviousPage(e)},r.prototype.setSort=function(e,t){if(e!==void 0&&t!==void 0)return this.lastSortColumn=this.sortColumn,this.sortColumn=e,this.sortDirection=t,this.pager(),this.info()},r.prototype.pager=function(e){var t;return e==null&&(e={}),this.lastSortColumn!==this.sortColumn&&this.sortColumn!=null&&(this.currentPage=1,this.lastSortColumn=this.sortColumn),(t=e.reset)==null&&(e.reset=!0),r.__super__.pager.call(this,e),this.info()},r}(Backbone.Paginator.requestPager)}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};this.Teeble.SortbarHeaderView=function(t){function r(){return this.sort=e(this.sort,this),this.sortFieldChange=e(this.sortFieldChange,this),this.sortBarChange=e(this.sortBarChange,this),r.__super__.constructor.apply(this,arguments)}return n(r,t),r.prototype.events={"change .sortbar-column":"sortBarChange","change .sortbar-field-select":"sortFieldChange","click .sort-reverser":"sort"},r.prototype.sortBarChange=function(e){var t,n,r,i,s;return t=this.$(e.currentTarget),n=~~t.attr("data-column"),s=t.val(),i=this.collection.sortbarColumns[n],r=_.indexOf(this.collection.sortbarColumns,s),r>=0&&(this.collection.sortbarColumns[r]=i),this.collection.sortbarColumns[n]=s,this.renderer.update_template(),this.render(),this.collection.trigger("reset")},r.prototype.sortFieldChange=function(e){return this.sort(e,"asc")},r.prototype.sort=function(e,t){var n,r;return e!=null&&e.preventDefault(),n=this.$(".sort-reverser"),n.hasClass("reverse")||t?(n.removeClass("reverse"),t="asc"):(n.addClass("reverse"),t="desc"),r=this.$(".sortbar-field-select").val(),this.collection.setSort(r,t)},r}(this.Teeble.HeaderView)}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};this.Teeble.SortbarRenderer=function(t){function r(){return this.update_template=e(this.update_template,this),this._generate_template=e(this._generate_template,this),this._getExtraData=e(this._getExtraData,this),r.__super__.constructor.apply(this,arguments)}return n(r,t),r.prototype._getExtraData=function(){return{sortbarColumns:this.options.collection.sortbarColumns,sortbarSortOptions:this.options.collection.sortbarSortOptions,sortbarColumnOptions:this.options.collection.sortbarColumnOptions,sortColumn:this.options.collection.sortColumn,sortDirection:this.options.collection.sortDirection,partials:this.partials}},r.prototype._generate_template=function(e,t,n){var i,s,o,u,a;s=r.__super__._generate_template.call(this,e,t),a=this.options.collection.sortbarColumns;for(o=0,u=a.length;o<%= "+i+" %>";return n&&(s="<"+n+">"+s+""),s},r.prototype.update_template=function(e){var t;return e==null&&(e=this.partials),t=this.generate_columns(),this.header_template='\n \n
Sorted by:
\n
\n \n
\n
\n
\n
\n
\n
Showing:
\n \n <% for(var i = 0; i < sortbarColumns.length; i++) { %>\n \n