Skip to content

Instantly share code, notes, and snippets.

# Using a Promise
loadCompanies: ->
@companyService.loadCompanies().then(
success: ( records ) ->
# Do something with results
failure: ( error ) ->
# Do something with the error
).always( ->
# Do something whether the call succeeded or failed
)
# Common way of making async call via underlying Ext.Ajax call
loadCompanies: ->
@companyService.loadCompanies(
success: ( response ) ->
results = Ext.decode( response.responseText )
# Do something with results
# Do something whether the call succeeded or failed
failure: ( response ) ->
# Do something with the error
# Common way of making async call via underlying Store
loadCompanies: ->
@companyService.loadCompanies(
callback: ( records, operation, success ) ->
if( success )
# Do something with results
else
# Do something with the error
# Do something whether the call succeeded or failed
@brian428
brian428 / MainTabPanelTest.coffee
Created September 26, 2012 05:14
SpyOn_intercept.coffee
it "should allow setting the current company to be intercepted and altered", ->
store = Deft.ioc.Injector.resolve( "companyStore" )
waitsFor( ( -> store.getCount() > 0 ), "Store data never loaded.", 2000 )
runs( ->
grid = viewController.getCompanyGridPanel()
changedPrice = 12345.67
spyOn( viewController, 'setCurrentCompany').andCallFake( ( company ) ->
originalFunction = @setCurrentCompany.originalValue
@brian428
brian428 / MainTabPanelTest.coffee
Created September 26, 2012 05:14
SpyOn_andCallFake.coffee
it "should allow getting the current company to be faked", ->
grid = viewController.getCompanyGridPanel()
spyOn( viewController, 'getCurrentCompany').andCallFake( ->
return "Fake Company"
)
expect( viewController.getCurrentCompany() ).toBe( "Fake Company" )
@brian428
brian428 / MainTabPanelTest.coffee
Created September 26, 2012 05:14
SpyOn_andCallThrough.coffee
it "should store the selected company as the current company", ->
store = Deft.ioc.Injector.resolve( "companyStore" )
waitsFor( ( -> store.getCount() > 0 ), "Store data never loaded.", 2000 )
runs( ->
grid = viewController.getCompanyGridPanel()
spyOn( viewController, 'setCurrentCompany').andCallThrough()
firstCompany = grid.store.getAt( 0 )
grid.fireEvent( "selectionchange", {}, [ firstCompany ], 0 )
@brian428
brian428 / MainTabPanelTest.coffee
Created September 26, 2012 05:13
SpyOn_toHaveBeenCalledWith.coffee
it "should pass the selected company when setting the current company", ->
store = Deft.ioc.Injector.resolve( "companyStore" )
waitsFor( ( -> store.getCount() > 0 ), "Store data never loaded.", 2000 )
runs( ->
grid = viewController.getCompanyGridPanel()
spyOn( viewController, 'setCurrentCompany')
firstCompany = grid.store.getAt( 0 )
grid.fireEvent( "selectionchange", {}, [ firstCompany ], 0 )
@brian428
brian428 / MainTabPanelTest.coffee
Created September 26, 2012 05:06
SpyOn_toHaveBeenCalled.coffee
it "should update the current company upon selection", ->
store = Deft.ioc.Injector.resolve( "companyStore" )
waitsFor( ( -> store.getCount() > 0 ), "Store data never loaded.", 2000 )
runs( ->
grid = viewController.getCompanyGridPanel()
spyOn( viewController, 'setCurrentCompany' )
firstCompany = grid.store.getAt( 0 )
grid.fireEvent( "selectionchange", {}, [ firstCompany ] )
@brian428
brian428 / MainController.coffee
Created September 26, 2012 05:05
MainController.coffee
Ext.define( "JasmineExample.controller.MainController",
extend: "Deft.mvc.ViewController"
control:
companyGridPanel:
selectionchange: "onCompanySelected"
panel2: {}
config:
@brian428
brian428 / Ext.ux.MultiCellSelectionModel.js
Created September 11, 2012 00:28 — forked from anonymous/Ext.ux.MultiCellSelectionModel.js
Multiple cell selection model for the Ext JS grid component.
/**
* Original version by harley.333
* Updated 5/6/2011 by taylorbarstow
*
* FOUND HERE: http://www.sencha.com/forum/showthread.php?53118-Multiple-Cells-Selection-Model
*
* @class Ext.ux.MultiCellSelectionModel
* @extends Ext.grid.AbstractSelectionModel
* Supports multiple selections and keyboard selection/navigation.
* @constructor