From 0b9f89547d3512060282d7696e3987232605bfb6 Mon Sep 17 00:00:00 2001 From: Tower He Date: Sat, 18 Oct 2014 22:22:27 +0800 Subject: [PATCH] Create a component for creating or updating models --- app/components/model-form.coffee | 35 ++++++++++++++++++++++ app/templates/components/model-form.emblem | 26 ++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 app/components/model-form.coffee create mode 100644 app/templates/components/model-form.emblem diff --git a/app/components/model-form.coffee b/app/components/model-form.coffee new file mode 100644 index 0000000..bdc1b87 --- /dev/null +++ b/app/components/model-form.coffee @@ -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` diff --git a/app/templates/components/model-form.emblem b/app/templates/components/model-form.emblem new file mode 100644 index 0000000..511b4e7 --- /dev/null +++ b/app/templates/components/model-form.emblem @@ -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