Skip to content

Commit

Permalink
fix #97
Browse files Browse the repository at this point in the history
  • Loading branch information
luniki committed Feb 6, 2017
1 parent 5e3b8a5 commit 0387c12
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions assets/hbs/task-groups-create.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

<fieldset>
<label>
Name
Titel
<input type="text" name="title" required>
</label>
</fieldset>

<footer>
{{button "create" "Speichern" once=true}}
{{button "create" "Speichern" type="submit"}}
{{button "cancel" "Abbrechen"}}
</footer>
</form>
33 changes: 15 additions & 18 deletions assets/js/views/task_groups_create.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
import Backbone from 'backbone'
import _ from 'underscore'
import Viewmaster from './viewmaster'

const TaskGroupsCreateView = Backbone.View.extend({
const TaskGroupsCreateView = Viewmaster.extend({

tagName: 'article',

className: 'cliqr--task-groups-create',

events: {
'click .js-create': 'onClickCreate',
'submit form': 'onClickCreate',
'click .js-cancel': 'onClickCancel'
},

render() {
const template = require('../../hbs/task-groups-create.hbs')
this.$el.html(template(this.collection.toJSON()))
return this
initialize() {
Viewmaster.prototype.initialize.call(this)
},

template: require('../../hbs/task-groups-create.hbs'),

onClickCreate(event) {
event.preventDefault()
const $formData = Backbone.$(event.target.closest('form')).serializeArray(),
formData = _.reduce(
$formData,
(memo, item) => _.tap(memo, (memo) => memo[item.name] = item.value),
{})
this.collection.create(formData, {
success: (args) => {
this.trigger('cancel', event, this)
}
})

const title = this.$('form')[0].title.value.trim()

if (!title.length) {
return
}

this.collection.create({ title }, { success: () => { this.trigger('cancel', event, this) } })
},

onClickCancel(event) {
Expand Down

0 comments on commit 0387c12

Please sign in to comment.