Skip to content

Instantly share code, notes, and snippets.

@PlanetExpress.module "Entities", (Entities, App, Backbone, Marionette, $, _) ->
App.commands.setHandler "when:fetched", (entities, callback) ->
xhrs = _.chain([entities]).flatten().pluck("_fetch").value()
# if _.isArray(entities)
# xhrs.push(entity._fetch) for entity in entities
# else
# xhrs.push(entities._fetch)
@brian-mann
brian-mann / problem.js
Last active December 18, 2015 10:29 — forked from anonymous/problem.js
// JSON tree is this kind:
[
{
name: "Ob1",
subobjects: [
{name: "Un1", age: 2},
{name: "Un2", age: 5},
{name: "Un3", age: 4},
{name: "Un4", age: 5},
@brian-mann
brian-mann / gist:6642272
Last active December 23, 2015 13:29
difference between jQuery deferreds and regular javascript callback style
## jQuery Deferred way
App.reqres.setHandler "folder:type:picker", ->
dfd = $.Deferred()
App.load "pickers", ->
dfd.resolve API.list()
dfd.promise()
promise = App.request "folder:type:picker"
promise.done (folderTypePicker) =>
@listenToOnce folderTypePicker, "folder:types:submitted"
@brian-mann
brian-mann / gist:6904285
Created October 9, 2013 16:42
Kendo Template Helpers
myTemplateHelpers = {
foo: "foo",
bar: function(){}
}
$("#something").kendoTreeView({
templateHelpers: myTemplateHelpers,
template: JST["path/to/template"] // this is a function
})
@brian-mann
brian-mann / gist:6922710
Last active December 25, 2015 05:09
spying on ui hash
#= require support/spec_helper
class View extends App.Views.ItemView
template: "tooltips"
describe "Tooltip Concerns", ->
beforeEach ->
@view = new View
@view.onRender = =>
@tooltip = sinon.spy(@view.ui.tooltips, "tooltip")
@brian-mann
brian-mann / gist:6923050
Created October 10, 2013 18:21
Clever trick to automate children tagName based on their parent's element
class Views.CompositeView extends Marionette.CompositeView
itemViewEventPrefix: "childview"
itemViewOptions: (model, index) ->
options = {}
options.tagName = "tr" if @itemViewContainer is "tbody"
options
class Views.CollectionView extends Marionette.CollectionView
itemViewEventPrefix: "childview"
@brian-mann
brian-mann / gist:7085079
Last active July 13, 2023 08:37
Expanded version of loading controller with edge cases covered
showRealView: (realView, loadingView, config) ->
xhrs = App.request "fetched:entities", config.entities
## ...after the entities are successfully fetched, execute this callback
$.when(xhrs...).done =>
## ================================================================ ##
## If the region we are trying to insert is not the loadingView then
## we know the user has navigated to a different page while the loading
## view was still open. In that case, we know to manually close the original
## view so its controller is also closed. We also prevent showing the real
@brian-mann
brian-mann / gist:7085402
Last active September 3, 2017 20:14
The latest and greatest folder and file structure for Backbone / Marionette Apps
##Folder structure
/backbone
app.js
/apps
/entities
/lib
##Inside Apps
/apps
@brian-mann
brian-mann / gist:7343058
Created November 6, 2013 19:55
Kendo mixin to automate closing of kendo elements on ui
## this is the mixin
Concerns.Kendo =
onBeforeClose: ->
@destroyKendos()
destroyKendos: ->
for key, el of @ui
widget = kendo.widgetInstance(el, kendo.ui)
widget?.destroy?()
@brian-mann
brian-mann / gist:7477964
Created November 15, 2013 02:04
automating tagName's and columns for itemViews
class Views.CompositeView extends Marionette.CompositeView
itemViewEventPrefix: "childview"
itemViewOptions: (model, index) ->
options = {}
options.tagName = "tr" if @isTbody()
options.tagName = "li" if @isUl()
options.tableColumns = @$el.find("th").length if @isTbody()
options