-
Notifications
You must be signed in to change notification settings - Fork 6
/
ribs.min.js
1 lines (1 loc) · 25.4 KB
/
ribs.min.js
1
(function(){var t,e,i=function(t,e){return function(){return t.apply(e,arguments)}},s={}.hasOwnProperty,n=function(t,e){function i(){this.constructor=t}for(var n in e)s.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e="undefined"==typeof exports?window:exports,t=e.Ribs={},t.VERSION="0.1.3",function(s){var n;return n=null,t.getKeyboardManager=function(){return null!=n?n:n=new t.KeyboardManager},t.KeyboardManager=function(){function n(t){this.handleKeypress=i(this.handleKeypress,this),this.options=_.extend(this.options,t),"undefined"!=typeof window&&(this.registeredViews.global={bindings:[],tree:{},label:"Global",context:window},s(window).on("keypress",this.handleKeypress)),this.registerHotKey({hotkey:"?",callback:this.showKeyboardBindings,context:this,label:"Show hotkeys"})}return n.prototype.boundCharCodes={},n.prototype.registeredViews={},n.prototype.options={jumpPrefixKey:"g",jumpTime:1e3,enableKeyboardShortcuts:!0},n.prototype.registerView=function(t,e){var i;return i=_.uniqueId("view"),this.registeredViews[i]={label:e,context:t,tree:{},bindings:[]},i},n.prototype.deregisterView=function(t){return delete this.registeredViews[t]},n.prototype.registerHotKey=function(t){var i,s,n,o,r,l,c;for(null==t.charCodes&&(t.charCodes=function(){var e,i,s,o;for(s=t.hotkey.split(""),o=[],e=0,i=s.length;i>e;e++)n=s[e],o.push(n.charCodeAt(0));return o}()),o=null!=t.namespace?t.namespace:t.namespace="global",e=this.registeredViews[o].tree,c=t.charCodes,s=r=0,l=c.length;l>r;s=++r)i=c[s],null==e[i]&&(e[i]={bindings:[],upcoming:0}),s===t.charCodes.length-1?e[i].bindings.push(t):e[i].upcoming+=1,e=e[i];return this.registeredViews[o].bindings.push(t),o},n.prototype.deregisterHotKey=function(t){var i,s,n,o,r,l,c,u,a;for(null==t.charCodes&&(t.charCodes=function(){var e,i,s,n;for(s=t.hotkey.split(""),n=[],e=0,i=s.length;i>e;e++)o=s[e],n.push(o.charCodeAt(0));return n}()),r=null!=t.namespace?t.namespace:t.namespace="global",e=s=this.registeredViews[r].tree,u=t.charCodes,a=[],n=l=0,c=u.length;c>l;n=++l)i=u[n],s=s[i],a.push(n===t.charCodes.length-1?s.bindings=_.reject(s.bindings,function(e){return!(t.context&&t.context!==e.context||t.callback&&t.callback!==e.callback)}):s.upcoming-=1);return a},n.prototype.registerJumpKey=function(t){return t.label="Go to "+t.label,t.hotkey=this.options.jumpPrefixKey+t.jumpkey,this.registerHotKey(t)},n.prototype.deregisterJumpKey=function(t){return t.hotkey=this.options.jumpPrefixKey+t.jumpkey,this.deregisterHotKey(t)},n.prototype.handleKeypress=function(t,e){var i,n;return null==e&&(e="global"),this.options.enableKeyboardShortcuts&&!s(document.activeElement).not(":radio").not(":checkbox").not(":button").is(":input,[contenteditable]")?(i=null!=(n=this.currentContext)?n:this.registeredViews[e].tree,null!=i?this.walkContext(i,t.which):void 0):void 0},n.prototype.walkContext=function(t,e){return this.jumpTimeout&&clearTimeout(this.jumpTimeout),delete this.currentContext,e in t?(t=t[e],0===t.upcoming?this.execute(t):(this.currentContext=t,this.jumpTimeout=setTimeout(function(e){return function(){return delete e.currentContext,e.execute(t)}}(this),this.options.jumpTime)),!1):void 0},n.prototype.execute=function(t){var e,i,s,n,o,r,l;if(t.bindings.length){for(o=t.bindings,l=[],s=0,n=o.length;n>s;s++)e=o[s],i=null!=(r=e.context)?r:this.registeredViews[e.namespace].context,l.push(!e.precondition||e.precondition.call(i)?e.callback.call(i):void 0);return l}},n.prototype.showKeyboardBindings=function(){var e,i;return null!=(i=this.constructor.view)&&i.$el.remove(),e=this.constructor.view=new t.KeyboardHelpView({views:this.registeredViews,hotkeys:this.boundCharCodes}),e.render(),s("body").append(e.el)},n}()}(jQuery),t.Action=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return n(i,e),i.prototype.defaults={min:1,max:-1,arity:null,check:null,batch:!0,inline:!1},i.prototype.initialize=function(e,i){var s,n,o;return this.ribs=null!=(n=i.ribs)?n:this.collection.ribs,this.has("actions")&&(s=_.reject(this.get("actions"),function(t){return function(e){return null!=e.available&&!e.available.call(t.ribs)}}(this)),this.actions=new t.Actions(s,{ribs:this.ribs}),this.min=0),this.has("hotkey")&&!this.ribs.suppressHotKeys&&null!=(o=this.ribs.keyboardManager)?o.registerHotKey({hotkey:this.get("hotkey"),label:this.get("label"),namespace:this.ribs.keyboardNamespace,context:this,precondition:this.allowed,callback:function(t){return function(){return t.activate()}}(this)}):void 0},i.prototype.allowed=function(t){var e,i,s,n,o;return null==t&&(t=this.getSelected()),s=t.length,i=!1,null!=this.get("arity")?(e=this.get("arity"),n=e===s,o=-1===e,i=n||o):(n=-1===this.get("min")||s>=this.get("min"),o=-1===this.get("max")||s<=this.get("max"),i=n&&o),i&&null!=this.get("check")&&(i=this.get("check").call(this.ribs,t)),i},i.prototype.activate=function(t,e){var i;return null==t&&(t=this.getSelected()),i=this.get("activate"),_.isFunction(i)?i.call(this.ribs,t,e):void 0},i.prototype.getSelected=function(){return this.ribs.getSelected()},i}(Backbone.Model),t.Actions=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return n(i,e),i.prototype.model=t.Action,i}(Backbone.Collection),t.BatchAction=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return n(i,e),i.prototype.tagName="li",i.prototype.className="action",i.prototype.events={click:"activateIfAllowed",keypress:"keypressed"},i.prototype.attributes={tabindex:0},i.prototype.render=function(){var e,i;return e=$("<div/>",{"class":"button",title:this.tooltip(),html:this.label()}),this.$el.html(e),this.model.actions?(i=$("<ul/>",{"class":"dropdown",title:this.label(!1)}),this.model.actions.each(function(e){var s;return s=new t.BatchAction({model:e}),$(i).append(s.el),s.render()}),$(e).append(i)):this.checkRequirements(),this},i.prototype.tooltip=function(){var t;return null!=(t=this.model.get("tooltip"))?t:this.label(!1)},i.prototype.label=function(t){var e,i;return null==t&&(t=!0),e=null!=(i=this.model.get("batchLabel"))?i:this.model.get("label"),t&&this.model.has("hotkey")&&(e=this.constructor.highlightHotkey(e,this.model.get("hotkey"))),e},i.prototype.getSelected=function(){return this.model.getSelected()},i.prototype.getListItem=function(){},i.prototype.checkRequirements=function(){return this.setEnabled(this.model.allowed(this.getSelected()))},i.prototype.setEnabled=function(t){var e;return this.$el.toggleClass("disabled",!t),e=t?0:-1,this.$el.prop("tabindex",e)},i.prototype.activate=function(){return this.model.activate(this.getSelected(),this.getListItem()),!1},i.prototype.activateIfAllowed=function(){return this.$el.is(".disabled")||this.activate(),!1},i.prototype.keypressed=function(t){return 13===t.which?(this.activate(),!1):void 0},i.highlightHotkey=function(t,e){var i,s;return s=_.template("<span class='hotkey'><strong><%= hotkey %></strong></span>"),i=t.replace(e,s({hotkey:e})),i===t&&(i=""+t+" "+s({hotkey:"["+e+"]"})),i},i}(Backbone.View),t.InlineAction=function(t){function e(t){e.__super__.constructor.apply(this,arguments),this.listItem=t.listItem}return n(e,t),e.prototype.label=function(){var t,e;return t=null!=(e=this.model.get("inlineLabel"))?e:this.model.get("label"),_.isFunction(t)&&(t=t.call(this.model,this.listItem.model)),t},e.prototype.getSelected=function(){return[this.listItem.model]},e.prototype.getListItem=function(){return this.listItem},e}(t.BatchAction),t.KeyboardHelpView=function(t){function e(){return this.handleKeyup=i(this.handleKeyup,this),e.__super__.constructor.apply(this,arguments)}return n(e,t),e.prototype.className="ribs-keyboard-shortcuts-overlay",e.prototype.events={click:"remove"},e.prototype.initialize=function(t){return this.views=t.views,$(window).on("keyup",this.handleKeyup)},e.prototype.remove=function(){return $(window).off("keyup",this.handleKeyup),e.__super__.remove.apply(this,arguments)},e.prototype.handleKeyup=function(t){return 27===t.which&&this.remove(),!1},e.prototype.render=function(){var t,e,i,s,n,o,r,l,c,u,a,h,p,d;this.$el.empty(),h=this.views,d=[];for(r in h)if(c=h[r],e=c.bindings,n=$(null!=(p=c.context)?p.el:void 0).is(":hidden"),s=0===Object.keys(e).length,n||s)d.push(void 0);else{for(i=$("<h1/>",{text:c.label}),l=$("<ul/>"),u=0,a=e.length;a>u;u++)t=e[u],o=$("<li/>",{"class":"hotkey"}),o.append($("<span/>",{"class":"key",text:t.hotkey})),o.append($("<span/>",{"class":"action",text:t.label})),l.append(o);d.push(this.$el.append(i,l))}return d},e}(Backbone.View),function(e){return t.List=function(i){function s(e){var i,n,o,r;for(this.sortArrows={},this.sortArrows[-1]="↓",this.sortArrows[1]="↑",null==this.itemView&&(this.itemView=t.ListItem),null==this.actionView&&(this.actionView=t.BatchAction),this.events=_.extend({},this.events,this._ribsEvents),this.sortingDirection={},this.sortingBy="id",r=this._ribsOptions,n=0,o=r.length;o>n;n++)i=r[n],null!=e[i]&&(this[i]=e[i]);this.keyboardManager="function"==typeof t.getKeyboardManager?t.getKeyboardManager():void 0,null!=this.keyboardManager&&this.initializeHotKeys(),s.__super__.constructor.apply(this,arguments),this.$el.addClass("ribs")}return n(s,i),s.prototype.tagName="div",s.prototype.itemName="item",s.prototype._ribsEvents={keypress:"keypressed",focusin:"focusin",focusout:"focusout","click .header .toggle input":"toggleSelected","click .maximize .minimize":"toggleVisibility","click [data-sort-by]":"sortByField"},s.prototype._ribsOptions=["displayAttributes","actions","itemView","itemName","title","jumpkey"],s.prototype.jumpSelector=".list li:first",s.prototype.focussed=!1,s.prototype.selectedByDefault=!1,s.prototype.renderOrder=["Title","Actions","Header","List","Footer"],s.prototype.setElement=function(){return s.__super__.setElement.apply(this,arguments),this.build()},s.prototype.remove=function(){var t;return this.removeAllSubviews(),null!=(t=this.keyboardManager)&&t.deregisterView(this.keyboardNamespace),s.__super__.remove.apply(this,arguments)},s.prototype.removeAllSubviews=function(){return this.removeSubviews("list"),this.removeSubviews("action")},s.prototype.removeSubviews=function(t){var e,i,s,n;if(e=this.subviews(t))for(s=0,n=e.length;n>s;s++)i=e[s],i.remove();return this["_"+t+"Subviews"]=[]},s.prototype.subviews=function(t){return this["_"+t+"Subviews"]},s.prototype.build=function(){var t,e,i,s,n;for(this.removeAllSubviews(),this.$el.empty(),n=this.renderOrder,i=0,s=n.length;s>i;i++)e=n[i],t=e.replace(/^./,"$"+e[0].toLowerCase()),this["suppress"+e]||null!=this[t]||(this[t]=this["initialize"+e]()),this.$el.append(this[t]);return null!=this.collection?this.setCollection(this.collection):void 0},s.prototype.delegateEvents=function(){var t,e,i,n,o,r;for(s.__super__.delegateEvents.apply(this,arguments),o=["list","actions"],r=[],i=0,n=o.length;n>i;i++)t=o[i],null!=this.subviews(t)&&r.push(function(){var i,s,n,o;for(n=this.subviews(t),o=[],i=0,s=n.length;s>i;i++)e=n[i],o.push(e.delegateEvents());return o}.call(this));return r},s.prototype.render=function(){return this._render(this.renderOrder),this},s.prototype._render=function(t){var e,i,s,n;for(n=[],i=0,s=t.length;s>i;i++)e=t[i],n.push(this["suppress"+e]?void 0:this["render"+e]());return n},s.prototype.setCollection=function(t){var e,i,s,n,o;for(this.collection=t,this.stopListening(this.collection),this.listenTo(this.collection,"add",this.addItem),this.listenTo(this.collection,"sort reset",this.addAllItems),o=["Actions","Footer","Header"],s=0,n=o.length;n>s;s++)i=o[s],e=this["render"+i],!this["suppress"+i]&&_.isFunction(e)&&this.listenTo(this.collection,"selected deselected add remove reset",e);return this.addAllItems(),this.suppressHeader?void 0:this.updateHeaderArrows(this.sortingBy)},s.prototype.getSelected=function(){return null==this.$list?[]:this.$list.find(".item.selected").map(function(t){return function(i,s){return t.collection.get(e(s).data("cid"))}}(this))},s.prototype.getDeselected=function(){return null==this.$list?[]:this.$list.find(".item:not(.selected)").map(function(t){return function(i,s){return t.collection.get(e(s).data("cid"))}}(this))},s.prototype.getNumSelected=function(){return null==this.$list?0:this.$list.find(".item.selected").size()},s.prototype.getNumDeselected=function(){return null==this.$list?0:this.$list.find(".item:not(.selected)").size()},s.prototype.getNumTotal=function(){return null==this.collection?0:this.collection.length},s.prototype.toggleFocussedSelected=function(){return this.suppressToggle?void 0:this.$(".item:focus").trigger("toggle")},s.prototype.toggleSelected=function(){var t,e;return this.selectedByDefault===!0?(this.$list.find(".item.selected").trigger("deselectitem",{silent:!0}),this.selectedByDefault=!1,null!=(t=this.collection)&&t.trigger("deselected")):(this.$list.find(".item:not(.selected)").trigger("selectitem",{silent:!0}),this.selectedByDefault=!0,null!=(e=this.collection)&&e.trigger("selected")),delete this.lastSelected},s.prototype.invertSelected=function(){var t,e;return e=this.$list.find(":not(.item.selected)"),t=this.$list.find(".item.selected"),e.trigger("select"),t.trigger("deselectitem")},s.prototype.select=function(t){var e,i,s,n;for(_.isArray(t)||(t=[t]),i=0,s=t.length;s>i;i++)e=t[i],null!=(n=this.get(e))&&n.$el.trigger("selectitem",{silent:!0});return this._render(["Header","Footer","Actions"])},s.prototype.toggleVisibility=function(){return this.$header.find(".maximize, .minimize").toggle(),this.$el.toggleClass("minimized",100)},s.prototype.sortByField=function(t){var i,s,n;return s=e(t.target).attr("data-sort-by"),null!=s&&null!=this.collection?(n=this.sortingBy,this.sortingBy=s,s===n&&s in this.sortingDirection?this.sortingDirection[s]*=-1:this.sortingDirection[s]=1,i=this.sortingDirection[s],this.sortCollection(s,i),this.updateHeaderArrows(s,n)):void 0},s.prototype.sortCollection=function(t,e){return this.collection.remoteSort?this.collection.trigger("remoteSort",t,e):(this.collection.comparator=function(i){return function(s,n){var o,r,l,c;return o=s.get(t),l=i.displayAttributeMap[t],_.isFunction(l.map)&&(o=l.map.call(i,o,s)),r=n.get(t),c=i.displayAttributeMap[t],_.isFunction(c.map)&&(r=c.map.call(i,r,n)),null!=(null!=o?o.toLowerCase:void 0)&&(o=o.toLowerCase()),null!=(null!=r?r.toLowerCase:void 0)&&(r=r.toLowerCase()),o===r?0:o>r||null==r?1*e:r>o||null==o?-1*e:void 0}}(this),this.collection.sort())},s.prototype.updateHeaderArrows=function(t,i){var s,n,o,r;return o=new RegExp(" ("+_.values(this.sortArrows).join("|")+")$|$"),s=null!=(r=this.sortingDirection[t])?r:1,null!=i&&this.$header.find("[data-sort-by='"+i+"'] .arrow").remove(),n=e("<span />",{"class":"arrow",text:this.sortArrows[s]}),this.$header.find("[data-sort-by='"+t+"']").append(n)},s.prototype.initializeHotKeys=function(){var t,i,s,n,o;if(this.keyboardNamespace=this.keyboardManager.registerView(this,this.plural()),null!=this.jumpkey&&this.keyboardManager.registerJumpKey({label:this.plural(),jumpkey:this.jumpkey,context:this,callback:function(t){return function(){return t.$(t.jumpSelector).focus()}}(this),precondition:function(t){return function(){return t.$el.is(":visible")}}(this)}),!this.suppressHotKeys){for(i=[{hotkey:"j",label:"Focus next item",callback:function(){return function(){return e(document.activeElement).nextAll(".item:visible:not(.disabled):first").focus()}}(this)},{hotkey:"J",label:"Focus last item",callback:function(t){return function(){return t.$list.find(".item:last").focus()}}(this)},{hotkey:"k",label:"Focus previous item",callback:function(){return function(){return e(document.activeElement).prevAll(".item:visible:not(.disabled):first").focus()}}(this)},{hotkey:"K",label:"Focus first item",callback:function(t){return function(){return t.$list.find(".item:first").focus()}}(this)},{hotkey:"x",label:"Select/deselect item",callback:function(t){return function(){return t.toggleFocussedSelected()}}(this)},{hotkey:"X",label:"Select/deselect all",callback:function(t){return function(){return t.toggleSelected()}}(this)},{hotkey:"_",label:"Expand/collapse list",callback:function(t){return function(){return t.toggleVisibility()}}(this)},{hotkey:"R",label:"Refresh items",callback:function(t){return function(){return t.refresh()}}(this)}],o=[],s=0,n=i.length;n>s;s++)t=i[s],t.namespace=this.keyboardNamespace,o.push(this.keyboardManager.registerHotKey(t));return o}},s.prototype.keypressed=function(t){var e;return this.trigger("keypressed",t),null!=(e=this.keyboardManager)?e.handleKeypress(t,this.keyboardNamespace):void 0},s.prototype.refresh=function(){return null!=this.collection.url?(this.trigger("refresh"),this.collection.fetch({success:function(t){return function(){var e;return null!=(e=t.$list.find(".item:first"))?e.focus():void 0}}(this)})):void 0},s.prototype.focusin=function(){var t;return this.focussed||(this.focussed=!0),this.$el.addClass("focussed"),null!=(t=this.collection)?t.trigger("focusin"):void 0},s.prototype.focusout=function(){return this.focussed?setTimeout(function(t){return function(){var e;return 0===t.$(document.activeElement).length&&t.$el.removeClass("focussed"),t.focussed=!1,null!=(e=t.collection)?e.trigger("focusout"):void 0}}(this),10):void 0},s.prototype.plural=function(){var t;return null!=(t=this.itemNamePlural)?t:this.itemName+"s"},s.prototype.addItem=function(t){var e,i,s,n;return i=Backbone.View.prototype.isPrototypeOf(this.itemView.prototype)?this.itemView:this.itemView(t),s=new i({model:t,view:this}),e=this.collection.indexOf(t),0===(n=this.$list.children().size())||n===e?this.$list.append(s.el):this.$list.children(":nth-child("+(e+1)+")").before(s.el),s.render(),this.subviews("list").push(s),this.selectedByDefault?s.select():void 0},s.prototype.addAllItems=function(){var t;return this.removeSubviews("list"),this.$list.empty(),null!=(t=this.collection)?t.each(this.addItem,this):void 0},s.prototype.get=function(t){return _.find(this.subviews("list"),function(e){return e.model.id===t})},s.prototype.initializeTitle=function(){var t,i,s;return i=null!=(s=this.title)?s:this.plural(),_.isFunction(i)&&(i=i.call(this)),t=e("<h1 />",{"class":"title",text:i})},s.prototype.renderTitle=function(){},s.prototype.initializeActions=function(){var i,s,n,o,r,l,c;for(this.removeSubviews("action"),i=e("<ul/>",{"class":"actions"}),o=_.reject(this.actions,function(t){return function(e){return null!=e.available&&!e.available.call(t)}}(this)),this.allActions=new t.Actions(o,{ribs:this}),this.inlineActions=this.allActions.where({inline:!0}),this.batchActions=this.allActions.where({batch:!0}),c=this.batchActions,r=0,l=c.length;l>r;r++)s=c[r],n=new this.actionView({model:s}),this.subviews("action").push(n),i.append(n.el),n.render();return i},s.prototype.renderActions=function(){var t,e,i,s,n;for(s=this.subviews("action"),n=[],e=0,i=s.length;i>e;e++)t=s[e],t.render(),n.push(t.delegateEvents());return n},s.prototype.initializeList=function(){var t;return t=e("<ul/>",{"class":"list"})},s.prototype.renderList=function(){var t,e,i,s,n;for(s=this.subviews("list"),n=[],e=0,i=s.length;i>e;e++)t=s[e],t.render(),n.push(t.delegateEvents());return n},s.prototype.initializeHeader=function(){var t,i,s;return t=e("<div />",{"class":"header"}),this.suppressToggle||(s=e("<input />",{type:"checkbox",checked:this.selectedByDefault}),t.append(e("<div />",{"class":"toggle",html:s}))),null==this.displayAttributes&&(i=_.map(this.collection.first().toJSON(),function(t,e){return{field:e}})),this.displayAttributeMap={},_.each(this.displayAttributes,function(i){return function(s){var n,o,r,l,c;return i.displayAttributeMap[s.field]=s,r=null!=(l=s.label)?l:s.field,o=null!=(c=s["class"])?c:s.field,n=e("<div/>",{"class":o,"data-sort-by":s.sortField||s.field}),n.append(r),t.append(n)}}(this)),t},s.prototype.renderHeader=function(){var t,e,i,s,n;return s=this.getNumSelected(),i=this.getNumTotal(),s>=i&&(this.selectedByDefault=!0),0===s&&(this.selectedByDefault=!1),t=0!==s,e=t&&i>s,n=e?.5:1,this.$header.find(".toggle input").prop("checked",t).css("opacity",n)},s.prototype.initializeFooter=function(){var t;return t=e("<div/>",{"class":"footer"})},s.prototype.renderFooter=function(){var t,e;return t=1!==this.getNumTotal(),e=t?this.plural():this.itemName,this.$footer.text(""+this.getNumSelected()+" / "+this.getNumTotal()+" "+e+" selected")},s}(Backbone.View)}(jQuery),function(e){return t.ListItem=function(i){function s(e){var i,n,o,r,l,c,u,a,h;for(this.events||(this.events={}),_.extend(this.events,this._ribsEvents),null==this.itemCellView&&(this.itemCellView=t.ListItemCell),null==this.actionView&&(this.actionView=t.InlineAction),this.view=null!=e?e.view:void 0,this.listItemCells=[],a=this.view.displayAttributes,c=0,u=a.length;u>c;c++)n=a[c],n=_.clone(n),n.view=this,n.model=e.model,l=new this.itemCellView(n),this.listItemCells.push(l);this.inlineActions=[],h=this.view.inlineActions;for(r in h)i=h[r],(null==i.filter||i.filter(this.model)!==!1)&&(o=new this.actionView({model:i,listItem:this}),this.inlineActions.push(o));s.__super__.constructor.apply(this,arguments),null!=this.model&&(this.listenTo(this.model,"change",this.render),this.listenTo(this.model,"remove",this.remove))}return n(s,i),s.prototype.tagName="li",s.prototype.className="item",s.prototype.attributes={tabindex:0},s.prototype._ribsEvents={click:"toggle",toggle:"toggle",selectitem:"select",deselectitem:"deselect","click a":"stopPropogation"},s.prototype.render=function(){var t,i,s,n,o,r,l,c,u,a,h;if(this.$el.empty(),this.model){for(this.$el.data("cid",this.model.cid),o=e("<ul/>",{"class":"actions"}),a=this.inlineActions,r=0,c=a.length;c>r;r++)s=a[r],e(o).append(s.el),s.render(),s.delegateEvents();for(this.$el.append(o),this.view.suppressToggle||(n=e("<input/>",{type:"checkbox",tabindex:-1}),this.$el.is(".selected")&&e(n).prop("checked",!0),i=e("<div/>",{"class":"toggle"}),i.append(n),this.$el.append(i)),h=this.listItemCells,l=0,u=h.length;u>l;l++)t=h[l],this.$el.append(t.el),t.render(),t.delegateEvents();return this}},s.prototype.toggle=function(t){return this.$el.is(".disabled")?void 0:this.$el.is(".selected")?(this.deselect(),delete this.view.lastSelected):(this.select(),this.multiSelect(t),this.view.lastSelected=this.$el)},s.prototype.multiSelect=function(t){var e;if(t.shiftKey&&this.view.lastSelected)return e=this.$el.prevAll().filter(this.view.lastSelected).length?this.$el.prevUntil(this.view.lastSelected):this.$el.nextUntil(this.view.lastSelected),e.find("input:checkbox:not(:checked)").click()},s.prototype.stopPropogation=function(t){return t.stopImmediatePropagation()},s.prototype.select=function(t,e){return null==e&&(e={}),this.view.suppressToggle?void 0:(this.$el.addClass("selected"),this.$("input:checkbox").prop("checked",!0),e.silent?void 0:this.model.trigger("selected"))},s.prototype.deselect=function(t,e){return null==e&&(e={}),this.view.suppressToggle?void 0:(this.$el.removeClass("selected"),this.$("input:checkbox").prop("checked",!1),e.silent?void 0:this.model.trigger("deselected"))},s.prototype.enable=function(){return this.$el.removeClass("disabled"),this.$("input:checkbox").prop("disabled",!1),this.$el.prop("tabindex",0),this.model.trigger("enabled")},s.prototype.disable=function(){return this.$el.addClass("disabled"),this.$("input:checkbox").prop("disabled",!0),this.$el.prop("tabindex",-1),this.model.trigger("disabled")},s.prototype.remove=function(){var t,e,i,n,o,r,l,c;for(this.deselect(),l=this.inlineActions,i=0,o=l.length;o>i;i++)t=l[i],t.remove();for(c=this.listItemCells,n=0,r=c.length;r>n;n++)e=c[n],e.remove();return s.__super__.remove.apply(this,arguments)},s}(Backbone.View)}(jQuery),t.ListItemCell=function(t){function e(t){var i;this.events||(this.events={}),_.extend(this.events,this._ribsEvents),e.__super__.constructor.apply(this,arguments),this.field=t.field,this.view=t.view,this.map=t.map,this.escape=t.escape,this.editable=t.editable,this.label=t.label,this.edit=t.edit,this.save=t.save,this.$el.addClass(null!=(i=t["class"])?i:t.field)}return n(e,t),e.prototype.tagName="div",e.prototype.className="cell",e.prototype._ribsEvents={"click .edit":"handleEdit","click .editableField":"stopPropagation","keypress .editableField":"handleKeypress","blur .editableField":"saveEditedField"},e.prototype.renderableValue=function(t){var e;return e=this.model.get(this.field),!t&&_.isFunction(this.map)&&(e=this.map.call(this.view.view,e,this.model)),null!=e?e:""},e.prototype.render=function(){var t,e,i,s;return this.$el.empty(),this.escape===!1?this.$el.html(this.renderableValue()):this.$el.text(this.renderableValue()),this.editable===!0&&(e=null!=(i=this.label)?i:this.field,t=$("<span/>",{"class":"edit button inline",title:"Edit "+e,text:"✎"}),(void 0===(s=this.model.get(this.field))||null===s||""===s)&&$(t).addClass("show"),this.$el.append(t)),this},e.prototype.handleEdit=function(t){var e,i,s,n,o,r,l,c,u;if(this.editable===!0){if(o=this.model.get(this.field),_.isFunction(this.edit))e=this.edit.call(this,o,this.model);else if(_.isArray(this.edit))for(e=$("<select/>"),c=this.edit,r=0,l=c.length;l>r;r++)s=c[r],n=$("<option/>",{value:s,text:s}),e.append(n),$(n).prop("selected",s===o);else if(_.isObject(this.edit)){e=$("<select/>"),u=this.edit;for(i in u)s=u[i],n=$("<option/>",{value:i,text:s}),$(n).prop("selected",i===o),e.append(n)}else e=$("<input/>",{type:"text",value:o});(_.isElement(e)||e instanceof jQuery)&&($(e).addClass("editableField"),this.$el.html(e),$(e).focus())}return t.preventDefault(),!1},e.prototype.stopPropagation=function(t){return t.preventDefault(),!1},e.prototype.saveEditedField=function(){var t,e,i,s;if(i=this.$(".editableField"),_.isFunction(this.save))return this.save.call(this,i,this.model);if(s=i.val(),t=$.extend(!0,{},this.model.attributes),t[this.field]=s,this.model._validate(t,this.model))try{return this.model.save(t,{success:function(t){return function(){return t.render()}}(this),error:function(t){return function(){return t.render()}}(this)})}catch(n){return e=n,this.render()}},e.prototype.handleKeypress=function(t){return 13===t.which?(this.saveEditedField(),!1):void 0},e}(Backbone.View)}).call(this);