Skip to content

Commit

Permalink
Create a component for creating or updating models
Browse files Browse the repository at this point in the history
  • Loading branch information
towerhe committed Oct 18, 2014
1 parent 65141a0 commit 0b9f895
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/components/model-form.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
`import Ember from 'ember'`

ModelFormComponent = Ember.Component.extend
typeKey: undefined
typeHumanName: undefined
model: undefined

removeConfirmationName: (->
"remove#{@typeKey.capitalize()}Confirmation"
).property('typeKey')
removeConfirmationTitle: '确认删除'
removeConfirmationMessage: (->
"您确认需要删除该#{@typeHumanName}吗?"
).property('typeHumanName')
removeConfirmationButtons: [
Ember.Object.create title: '确认', clicked: "confirmRemove"
Ember.Object.create title: '取消', dismiss: 'modal'
]

save: 'save'
cancel: 'cancel'
remove: 'remove'
confirmRemove: 'confirmRemove'
revertChanges: 'revertChanges'
return: 'return'

actions:
save: -> @sendAction('save')
cancel: -> @sendAction('cancel')
remove: -> @sendAction('remove')
confirmRemove: -> @sendAction('confirmRemove')
revertChanges: -> @sendAction('revertChanges')
return: -> @sendAction('return')

`export default ModelFormComponent`
26 changes: 26 additions & 0 deletions app/templates/components/model-form.emblem
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
em-form model=model form_layout="horizontal" submit_button=false
h2
= formLegend

yield

.form-group.buttons
.col-sm-2
.col-sm-10
button.btn.btn-primary{action 'save'}
i.fa.fa-save
| 保存
if model.isNew
button.btn.btn-link{action 'cancel'}
| 取消
else
button.btn.btn-danger{action 'remove'}
i.fa.fa-times 删除
button.btn.btn-link{action 'revertChanges'}
| 重置
button.btn.btn-default{action 'return'}
i.fa.fa-mail-reply
| 返回

bs-modal name=removeConfirmationName fade=true footerButtons=removeConfirmationButtons title=removeConfirmationTitle
p= removeConfirmationMessage

0 comments on commit 0b9f895

Please sign in to comment.