This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent extends Batman.Model | |
# Encode 'children' from JSON like {children: [1,2,3]} | |
@encode 'children', | |
# to put the child ids in JSON, just pull out the ides and set them on the JSON object | |
encode: (value, key, builtJSON, record) -> | |
ids = value.mapToProperty('id') | |
builtJSON.key = ids | |
# to load records from JSON, make a new Set and fill it with child records |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#helpdesk_search_results{"data-event-scroll" => "checkScroll"} | |
.doc_search_container | |
%ul.lesson_container | |
%li{"data-foreach-lesson" => "Lesson.loaded"} | |
%div{"data-partial" => "lessons/_lesson"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from https://github.com/batmanjs/batman/pull/992/ | |
# example: | |
# | |
# class App.ThingsController extends Batman.Controller | |
# edit: (params) -> | |
# App.Thing.find params.id, (err, record) => | |
# @set('thing', record.transaction()) | |
# | |
# save: -> | |
# @get('thing').save() # The `transaction` implements ::save which applies changes and fires save on the original. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App.Wizard extends Batman.Model | |
loadedSet = App.Wizard.get('loaded') | |
loadedSet.on 'itemsWereAdded', (items, indexes) -> | |
# items is an array of the new records | |
console.log("#{items.length} new wizards!") | |
loadedSet.on 'itemsWereRemoved', (items, indexes) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App.Model extends Batman.Model | |
toJSON: -> | |
builtJSON = super | |
builtJSON.nested_items_attributes = builtJSON.nested_items | |
delete builtJSON.nested_items | |
builtJSON |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyApp.Thing extends Batman.Model | |
constructor: -> | |
super | |
# Whenever someProperty changes, capitalized property will be updated | |
@observe 'someProperty', (newValue, oldValue) -> | |
@set('capitalizedProperty', newValue?.toUpperCase()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var coffee = require('gulp-coffee'); | |
var concat = require('gulp-concat'); | |
var jade = require('gulp-jade'); | |
var batmanTemplates = require("gulp-batman-templates") | |
gulp.task('default', function(){ | |
gulp.watch('./**/*', ["build", "html", "finalize"]) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loader = | |
show: -> | |
hide: -> | |
window.activeXhrCount = 0 | |
window.globalLoaderEnabled = true | |
$(document).ajaxSend -> | |
window.activeXhrCount++ | |
Loader.show() | |
.ajaxComplete -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Props to @theberg for making this | |
# | |
# usage: | |
# | |
# select data-view='Select2View' data-view-bind='item.option_id' | |
# option value='' None | |
# option data-foreach-opt='Option.all' data-bind='opt.name' data-bind-value='opt.id' | |
# | |
class App.Select2View extends Batman.View | |
@option 'bind', 'placeholder' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Taken from Batman.RailsStorage https://github.com/batmanjs/batman/blob/master/src/extras/batman.rails.coffee#L62 | |
# | |
# Usage: | |
# #= require ./json_storage | |
# class MyApp.Model extends Batman.Model | |
# @persist Batman.JSONStorage | |
# | |
class Batman.JSONStorage extends Batman.RestStorage | |
# override the default URL functions to add .json: | |
urlForRecord: -> @_addJsonExtension(super) |
OlderNewer