Skip to content

Instantly share code, notes, and snippets.

@srsgores
Created November 13, 2014 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srsgores/dd0493adb92a3df9a23d to your computer and use it in GitHub Desktop.
Save srsgores/dd0493adb92a3df9a23d to your computer and use it in GitHub Desktop.
Action bubbling
`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`
`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`
<header>
<h1>New post {{title}}</h1>
</header>
{{#form-for model}}
{{input title hint="Specify a title for the post" placeholder="Title"}}
{{#input author}}
<fieldset>
<legend>Author Info</legend>
{{#if controllers.admin.allAuthors.length}}
{{input author as "select"
collection="controllers.admin.allAuthors"
selection="author"
optionValuePath="content.id"
optionLabelPath="content.name"
prompt="Select an author"
}}
{{else}}
{{#alert-message dismissible=false}}
<p>No Authors found. Create one below:</p>
{{/alert-message}}
{{input author placeholder="Author"}}
{{/if}}
</fieldset>
{{/input}}
{{#input tags}}
<fieldset>
<legend>Tags <i class="icon-tags"></i></legend>
{{#if controllers.admin.allTags.length}}
{{input tags as "select"
collection="controllers.admin.allTags"
selection="tag"
optionValuePath="content.id"
optionLabelPath="content.name"
prompt="Select a tag"
}}
{{else}}
{{#alert-message dismissible=false}}
<p>No tags found. Create one below:</p>
{{/alert-message}}
{{/if}}
</fieldset>
{{/input}}
{{input body hint="Input the content you want to appear under the body of the post" as="text" placeholder="Describe your post"}}
{{/form-for}}
{{#form-actions model=model save=save}}{{/form-actions}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment