Created
November 13, 2014 07:49
-
-
Save srsgores/dd0493adb92a3df9a23d to your computer and use it in GitHub Desktop.
Action bubbling
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
`import Ember from "ember"` | |
FormActionsComponent = Ember.Component.extend( | |
save: null | |
classNames: "form-actions", | |
model: null | |
redirectRoute: "admin" | |
icon: "save" | |
iconClassName: (-> | |
"icon-#{@get("icon")}" | |
).property("icon") | |
actions: | |
didSaveObject: -> | |
console.log "Sending save action to controller" | |
@sendAction("save") | |
) | |
`export default FormActionsComponent` |
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
`import Ember from "ember"` | |
NewController = Ember.Controller.extend( | |
slugify: (title) -> | |
return title unless title? | |
slug = title.toLowerCase().dasherize().replace(/\(|\)|\[|\]|:|\./g, "") | |
success: -> | |
console.log "Item saved" | |
@transitionToRoute "manage-categories" | |
failure: -> | |
console.log "Item could not be saved" | |
actions: | |
save: -> | |
console.log "Controller save triggered" | |
model = @get("model") | |
today = new Date() | |
title = @get("title") | |
slug = @slugify(title) | |
model.setProperties( | |
lastModified: today | |
createdDate: today | |
slug: slug | |
) | |
@get("model").save().then(@bind(@success), @bind(@failure)) | |
) | |
`export default NewController` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment