|
@@ -119,6 +119,7 @@ BlazeComponent.extendComponent({
|
|
|
event.preventDefault();
|
|
|
const textarea = this.find('textarea.js-add-checklist-item');
|
|
|
const newlineBecomesNewChecklistItem = this.find('input#toggleNewlineBecomesNewChecklistItem');
|
|
|
+ const newlineBecomesNewChecklistItemOriginOrder = this.find('input#toggleNewlineBecomesNewChecklistItemOriginOrder');
|
|
|
const title = textarea.value.trim();
|
|
|
const checklist = this.currentData().checklist;
|
|
|
|
|
@@ -127,22 +128,28 @@ BlazeComponent.extendComponent({
|
|
|
if (newlineBecomesNewChecklistItem.checked) {
|
|
|
checklistItems = title.split('\n').map(_value => _value.trim());
|
|
|
if (this.currentData().position === 'top') {
|
|
|
- checklistItems = checklistItems.reverse();
|
|
|
+ if (newlineBecomesNewChecklistItemOriginOrder.checked === false) {
|
|
|
+ checklistItems = checklistItems.reverse();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ let addIndex;
|
|
|
+ let sortIndex;
|
|
|
+ if (this.currentData().position === 'top') {
|
|
|
+ sortIndex = Utils.calculateIndexData(null, checklist.firstItem()).base;
|
|
|
+ addIndex = -1;
|
|
|
+ } else {
|
|
|
+ sortIndex = Utils.calculateIndexData(checklist.lastItem(), null).base;
|
|
|
+ addIndex = 1;
|
|
|
+ }
|
|
|
for (let checklistItem of checklistItems) {
|
|
|
- let sortIndex;
|
|
|
- if (this.currentData().position === 'top') {
|
|
|
- sortIndex = Utils.calculateIndexData(null, checklist.firstItem()).base;
|
|
|
- } else {
|
|
|
- sortIndex = Utils.calculateIndexData(checklist.lastItem(), null).base;
|
|
|
- }
|
|
|
ChecklistItems.insert({
|
|
|
title: checklistItem,
|
|
|
checklistId: checklist._id,
|
|
|
cardId: checklist.cardId,
|
|
|
sort: sortIndex,
|
|
|
});
|
|
|
+ sortIndex += addIndex;
|
|
|
}
|
|
|
}
|
|
|
// We keep the form opened, empty it.
|