Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dragula(this.$refs.list, {})
  2.                 .on("drag", (card) => {
  3.                     card.classList.add(movingClass);
  4.                 })
  5.                 .on("drop", (card, list) => {
  6.  
  7.                     //TODO: Слишком забористо вышло, нужно сделать проще как-то... как-то не сломав реактивность
  8.                     let cardId = card.getAttribute("card-id");
  9.  
  10.                     let newStepIndex = 0;
  11.                     for (let i = 0; i < list.children.length; i++) {
  12.                         let card = list.children[i];
  13.                         if (card.classList.contains(movingClass)) {
  14.                             card.classList.remove(movingClass);
  15.                             newStepIndex = i;
  16.                             break;
  17.                         }
  18.                     }
  19.  
  20.                     let newStageIndex = 0;
  21.                     for (let i = 0; i < this.$refs.wrap.children.length; i++) {
  22.                         if (this.$refs.wrap.children[i].querySelector(".dash-list") === list) {
  23.                             newStageIndex = i;
  24.                             break;
  25.                         }
  26.                     }
  27.  
  28.                     let [oldStageIndex, oldStepIndex] = (() => {
  29.                         for (let istage = 0; istage < this.stages.length; istage++) {
  30.                             for (let istep = 0; istep < this.stages[istage].steps.length; istep++) {
  31.                                 let step = this.stages[istage].steps[istep];
  32.                                 if (step.id == cardId)
  33.                                     return [istage, istep];
  34.                             }
  35.                         }
  36.                     })();
  37.  
  38.                     // Отмена переноса элемента для возвращения в поток реактивности
  39.                     if (oldStepIndex > 0)
  40.                         if (newStepIndex < this.$refs.list[oldStageIndex].children.length - 1)
  41.                             this.$refs.list[oldStageIndex].insertBefore(card, this.$refs.list[oldStageIndex].children[oldStepIndex + 1]);
  42.                         else
  43.                             this.$refs.list[oldStageIndex].insertBefore(card, this.$refs.list[oldStageIndex].children[oldStepIndex]);
  44.                     else
  45.                         this.$refs.list[oldStageIndex].insertAdjacentElement("afterbegin", card);
  46.  
  47.                     // Переносим элемент по средствам реактивности
  48.                     let step = this.stages[oldStageIndex].steps[oldStepIndex];
  49.                     this.stages[oldStageIndex].steps.splice(oldStepIndex, 1);
  50.                     this.stages[newStageIndex].steps.splice(newStepIndex, 0, step);
  51.                 });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement