Skip to content

Instantly share code, notes, and snippets.

@brian-mann
brian-mann / gist:3139398
Created July 18, 2012 22:31
setting itemView with a switch
class Show.PointRowView extends Marionette.CompositeView
template: "folders/templates/dialogRegion/_point"
itemViewContainer: ".PointTypesContainer"
itemViewOptions: ->
PointTypeID: @model.get("PointTypeID")
eventpoint: @model.get("eventpoint")
tagName: "li"
className: "control-group"
constructor: (options) ->
@brian-mann
brian-mann / gist:3194911
Created July 28, 2012 21:41
Dynamically call model methods to chain includes
## Customer.rb
def self.references
includes(:account)
end
def self.forms
includes(:forms)
end
@brian-mann
brian-mann / gist:3849999
Created October 7, 2012 23:47
Accepts nested attributes for not working
# models/delivery.rb
class Delivery < ActiveRecord::Base
has_one :order
has_one :customer, :through => :order
accepts_nested_attributes_for :order
attr_accessible :note, :position, :crew_ids, :order_attributes
end
# models/order.rb
@brian-mann
brian-mann / FadeTransitionRegion.js
Created October 24, 2012 16:28
Allows jQuery animation transitions between marionette regions
var FadeTransitionRegion = Backbone.Marionette.Region.extend({
show: function(view){
this.ensureEl();
view.render();
this.close(function() {
if (this.currentView && this.currentView !== view) { return; }
this.currentView = view;
@brian-mann
brian-mann / gist:4198530
Created December 3, 2012 22:04
Component Structure
## /backbone/apps
## /backbone/entities
## /backbone/mixins
## /backbone/components
## Example Component as a class instantiated from an app's controller
## /backbone/components/pattern_selector/pattern_selector.js
@YOURAPP.module "Components", (Components, App, Backbone, Marionette, $, _) ->
class Components.PatternSelector
CanSing =
sing: ->
console.log "I am #{@name} la la la"
include = (ctr, mixin) ->
console.log "including", ctr
for key of mixin
ctr.prototype[key] = mixin[key]
class Man
do (Backbone) ->
_.extend Backbone.Marionette.Application::,
register: (instance, id) ->
@_registry ?= {}
@_registry[id] = instance
unregister: (instance, id) ->
delete @_registry[id]
@brian-mann
brian-mann / gist:5430655
Last active March 30, 2017 05:50
keyboard shortcuts in marionette views with mousetrap lib
_delegate = Backbone.Marionette.View::delegateEvents
_close = Backbone.Marionette.View::close
_.extend Backbone.Marionette.View::,
delegateEvents: (events) ->
_delegate.call(@, events)
@bindShortCuts()
bindShortCuts: ->
for key, method of _.result(@, "shortCuts")
@brian-mann
brian-mann / gist:5460185
Created April 25, 2013 14:36
simple mixin pattern
#mixin =
#bar: -> alert "bar"
class Bar
#bar: -> alert "bar"
#baz: (b) -> console.log "baz", b, @
Bar.baz = (b) -> console.log "baz", b, @
class Foo extends Bar
class List.Event extends Marionette.ItemView
template: "events/list/templates/_event"
tagName: "tr"
triggers:
"click button" : "edit:event:clicked"