diff options
author | Lauri Ojansivu <x@xet7.org> | 2017-02-10 09:54:23 +0200 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2017-02-10 09:54:23 +0200 |
commit | 0065ca3ad6a3a627cde557b6c80f87c8c6267492 (patch) | |
tree | f832fde75ee9fba0310a51196c2e7ce90dedcfec /client/components/cards/checklists.js | |
parent | 89959753cd10321fc21cf290bdd06f26b19874b9 (diff) | |
parent | 1f7d1f023ff4a6ec2e8923e54fe26c68fa7d9380 (diff) | |
download | wekan-0065ca3ad6a3a627cde557b6c80f87c8c6267492.tar.gz wekan-0065ca3ad6a3a627cde557b6c80f87c8c6267492.tar.bz2 wekan-0065ca3ad6a3a627cde557b6c80f87c8c6267492.zip |
Merge branch 'devel' into greenkeeper-xss-0.3.3
Diffstat (limited to 'client/components/cards/checklists.js')
-rw-r--r-- | client/components/cards/checklists.js | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/client/components/cards/checklists.js b/client/components/cards/checklists.js new file mode 100644 index 00000000..5dac7bd3 --- /dev/null +++ b/client/components/cards/checklists.js @@ -0,0 +1,89 @@ +BlazeComponent.extendComponent({ + addChecklist(event) { + event.preventDefault(); + const textarea = this.find('textarea.js-add-checklist-item'); + const title = textarea.value.trim(); + const cardId = this.currentData().cardId; + Checklists.insert({ + cardId, + title, + }); + }, + + addChecklistItem(event) { + event.preventDefault(); + const textarea = this.find('textarea.js-add-checklist-item'); + const title = textarea.value.trim(); + const checklist = this.currentData().checklist; + checklist.addItem(title); + }, + + editChecklist(event) { + event.preventDefault(); + const textarea = this.find('textarea.js-edit-checklist-item'); + const title = textarea.value.trim(); + const checklist = this.currentData().checklist; + checklist.setTitle(title); + }, + + editChecklistItem(event) { + event.preventDefault(); + + const textarea = this.find('textarea.js-edit-checklist-item'); + const title = textarea.value.trim(); + const itemId = this.currentData().item._id; + const checklist = this.currentData().checklist; + checklist.editItem(itemId, title); + }, + + deleteItem() { + const checklist = this.currentData().checklist; + const item = this.currentData().item; + if (checklist && item && item._id) { + checklist.removeItem(item._id); + } + }, + + deleteChecklist() { + const checklist = this.currentData().checklist; + if (checklist && checklist._id) { + Checklists.remove(checklist._id); + } + }, + + pressKey(event) { + //If user press enter key inside a form, submit it, so user doesn't have to leave keyboard to submit a form. + if (event.keyCode === 13) { + event.preventDefault(); + const $form = $(event.currentTarget).closest('form'); + $form.find('button[type=submit]').click(); + } + }, + + events() { + return [{ + 'submit .js-add-checklist': this.addChecklist, + 'submit .js-edit-checklist-title': this.editChecklist, + 'submit .js-add-checklist-item': this.addChecklistItem, + 'submit .js-edit-checklist-item': this.editChecklistItem, + 'click .js-delete-checklist-item': this.deleteItem, + 'click .js-delete-checklist': this.deleteChecklist, + keydown: this.pressKey, + }]; + }, +}).register('checklists'); + +BlazeComponent.extendComponent({ + toggleItem() { + const checklist = this.currentData().checklist; + const item = this.currentData().item; + if (checklist && item && item._id) { + checklist.toggleItem(item._id); + } + }, + events() { + return [{ + 'click .item .check-box': this.toggleItem, + }]; + }, +}).register('itemDetail'); |