summaryrefslogtreecommitdiffstats
path: root/client/lib/utils.js
diff options
context:
space:
mode:
authorLauri Ojansivu <x@xet7.org>2018-03-20 22:58:22 +0200
committerLauri Ojansivu <x@xet7.org>2018-03-20 22:58:22 +0200
commita7855f3f582d193b0a6dbd70b5da6f59384f9520 (patch)
tree8bb0c9d19a23dfb374a251241ba83f8e7b448bae /client/lib/utils.js
parent90f3f7ba163ef5d015bc473946b02c23e263a011 (diff)
parentac19904ee86541165b0017dcaaee33629904806b (diff)
downloadwekan-a7855f3f582d193b0a6dbd70b5da6f59384f9520.tar.gz
wekan-a7855f3f582d193b0a6dbd70b5da6f59384f9520.tar.bz2
wekan-a7855f3f582d193b0a6dbd70b5da6f59384f9520.zip
Merge branch 'andresmanelli-checklistItems' into devel
Diffstat (limited to 'client/lib/utils.js')
-rw-r--r--client/lib/utils.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/client/lib/utils.js b/client/lib/utils.js
index 9a9ff654..1f44c60d 100644
--- a/client/lib/utils.js
+++ b/client/lib/utils.js
@@ -33,6 +33,37 @@ Utils = {
return $(window).width() <= 800;
},
+ calculateIndexData(prevData, nextData, nItems = 1) {
+ let base, increment;
+ // If we drop the card to an empty column
+ if (!prevData && !nextData) {
+ base = 0;
+ increment = 1;
+ // If we drop the card in the first position
+ } else if (!prevData) {
+ base = nextData.sort - 1;
+ increment = -1;
+ // If we drop the card in the last position
+ } else if (!nextData) {
+ base = prevData.sort + 1;
+ increment = 1;
+ }
+ // In the general case take the average of the previous and next element
+ // sort indexes.
+ else {
+ const prevSortIndex = prevData.sort;
+ const nextSortIndex = nextData.sort;
+ increment = (nextSortIndex - prevSortIndex) / (nItems + 1);
+ base = prevSortIndex + increment;
+ }
+ // XXX Return a generator that yield values instead of a base with a
+ // increment number.
+ return {
+ base,
+ increment,
+ };
+ },
+
// Determine the new sort index
calculateIndex(prevCardDomElement, nextCardDomElement, nCards = 1) {
let base, increment;