From 4217e9bc2c1cad4cbedbf3a59a7535dd551c117d Mon Sep 17 00:00:00 2001 From: randallrupper Date: Fri, 1 Sep 2023 08:30:36 -0600 Subject: [PATCH] ERM-103 Fix arrows not reordering. Listeners attached after html creation. --- resources/js/forms/currentWorkflowForm.js | 143 +++++++++++----------- 1 file changed, 72 insertions(+), 71 deletions(-) diff --git a/resources/js/forms/currentWorkflowForm.js b/resources/js/forms/currentWorkflowForm.js index 5eed0c9cd..b386daad1 100644 --- a/resources/js/forms/currentWorkflowForm.js +++ b/resources/js/forms/currentWorkflowForm.js @@ -1,6 +1,6 @@ $(document).ready(function(){ - lastKey = $('#finalKey').val(); + lastKey = $('#finalKey').val() || 0; $(".addStep").on('click', function() { var originalTR = $('.newStepTR').clone(); @@ -39,7 +39,7 @@ $(document).ready(function(){ lastKey = newKey; setArrows(); - updatePriorSteps(sName); + updatePriorSteps('addStep'); }); @@ -88,75 +88,6 @@ $(document).ready(function(){ return false; }); - $(".moveArrow").on('click', function () { - - var dir = $(this).attr('direction') - - //first flip the rows - var movingKey = parseInt($(this).parent('.seqOrder').attr('key')); - var movingKeyHTML = $(this).parent().parent().html(); - - - //this is the key we're switching places with - if (dir == 'up'){ - var nextKey = movingKey - 1; - }else{ - var nextKey = movingKey + 1; - } - - var nextKeyHTML = $(".seqOrder[key='" + nextKey + "']").parent().html(); - - - //hold the 3 fields so after the html is flipped we can reset them - var movingKeyStepName = $(this).parent().parent().children().children('.stepName').val(); - var nextKeyStepName = $(".seqOrder[key='" + nextKey + "']").parent().children().children('.stepName').val(); - - var movingKeyMailReminderDelay = $(this).parent().parent().children().children('.mailReminderDelay').val(); - var nextKeyMailReminderDelay = $(".seqOrder[key='" + nextKey + "']").parent().children().children('.mailReminderDelay').val(); - - var movingKeyUserGroupID = $(this).parent().parent().children().children('.userGroupID').val(); - var nextKeyUserGroupID = $(".seqOrder[key='" + nextKey + "']").parent().children().children('.userGroupID').val(); - var movingKeyPriorStepID = $(this).parent().parent().children().children('.priorStepID').val(); - var movingKeyPriorStepText = $(this).parent().parent().children().children('.priorStepID').find(':selected').text(); - var nextKeyPriorStepID = $(".seqOrder[key='" + nextKey + "']").parent().children().children('.priorStepID').val(); - var nextKeyPriorStepText = $(".seqOrder[key='" + nextKey + "']").parent().children().children('.priorStepID').find(':selected').text(); - - //flip the html - $(".seqOrder[key='" + nextKey + "']").parent().html(movingKeyHTML); - $(this).parent().parent().html(nextKeyHTML); - - //now put those values back - $(".seqOrder[key='" + movingKey + "']").parent().children().children('.stepName').val(movingKeyStepName); - $(".seqOrder[key='" + nextKey + "']").parent().children().children('.stepName').val(nextKeyStepName); - - $(".seqOrder[key='" + movingKey + "']").parent().children().children('.mailReminderDelay').val(movingKeyMailReminderDelay); - $(".seqOrder[key='" + nextKey + "']").parent().children().children('.mailReminderDelay').val(nextKeyMailReminderDelay); - - $(".seqOrder[key='" + movingKey + "']").parent().children().children('.userGroupID').val(movingKeyUserGroupID); - $(".seqOrder[key='" + nextKey + "']").parent().children().children('.userGroupID').val(nextKeyUserGroupID); - - movingKeyPriorStepID = movingKeyPriorStepText != '' ? movingKeyPriorStepID : 'option:first'; - nextKeyPriorStepID = nextKeyPriorStepText != '' ? nextKeyPriorStepID : 'option:first'; - $(".seqOrder[key='" + movingKey + "']").parent().children().children('.priorStepID').val(movingKeyPriorStepID); - $(".seqOrder[key='" + nextKey + "']").parent().children().children('.priorStepID').val(nextKeyPriorStepID); - - - //flip the key values - $(".seqOrder[key='" + nextKey + "']").attr('key', function() { - return 'hold'; - }); - $(".seqOrder[key='" + movingKey + "']").attr('key', function() { - return nextKey; - }); - $(".seqOrder[key='hold']").attr('key', function() { - return movingKey; - }); - - - setArrows(); - return false; - }); - $('.stepName').on('change', function () { //don't update prior steps for the step in the 'add' section if ($(this).parent().parent().children('.seqOrder').attr('key') != ''){ @@ -281,7 +212,77 @@ function setArrows(){ }); + attachClickEventsToArrows(); +} + +function attachClickEventsToArrows() { + $(".moveArrow").on('click', function () { + var dir = $(this).attr('direction') + + //first flip the rows + var movingKey = parseInt($(this).parent('.seqOrder').attr('key')); + var movingKeyHTML = $(this).parent().parent().html(); + + + //this is the key we're switching places with + if (dir == 'up'){ + var nextKey = movingKey - 1; + }else{ + var nextKey = movingKey + 1; + } + + var nextKeyHTML = $(".seqOrder[key='" + nextKey + "']").parent().html(); + + + //hold the 3 fields so after the html is flipped we can reset them + var movingKeyStepName = $(this).parent().parent().children().children('.stepName').val(); + var nextKeyStepName = $(".seqOrder[key='" + nextKey + "']").parent().children().children('.stepName').val(); + + var movingKeyMailReminderDelay = $(this).parent().parent().children().children('.mailReminderDelay').val(); + var nextKeyMailReminderDelay = $(".seqOrder[key='" + nextKey + "']").parent().children().children('.mailReminderDelay').val(); + + var movingKeyUserGroupID = $(this).parent().parent().children().children('.userGroupID').val(); + var nextKeyUserGroupID = $(".seqOrder[key='" + nextKey + "']").parent().children().children('.userGroupID').val(); + var movingKeyPriorStepID = $(this).parent().parent().children().children('.priorStepID').val(); + var movingKeyPriorStepText = $(this).parent().parent().children().children('.priorStepID').find(':selected').text(); + var nextKeyPriorStepID = $(".seqOrder[key='" + nextKey + "']").parent().children().children('.priorStepID').val(); + var nextKeyPriorStepText = $(".seqOrder[key='" + nextKey + "']").parent().children().children('.priorStepID').find(':selected').text(); + //flip the html + $(".seqOrder[key='" + nextKey + "']").parent().html(movingKeyHTML); + $(this).parent().parent().html(nextKeyHTML); + + //now put those values back + $(".seqOrder[key='" + movingKey + "']").parent().children().children('.stepName').val(movingKeyStepName); + $(".seqOrder[key='" + nextKey + "']").parent().children().children('.stepName').val(nextKeyStepName); + + $(".seqOrder[key='" + movingKey + "']").parent().children().children('.mailReminderDelay').val(movingKeyMailReminderDelay); + $(".seqOrder[key='" + nextKey + "']").parent().children().children('.mailReminderDelay').val(nextKeyMailReminderDelay); + + $(".seqOrder[key='" + movingKey + "']").parent().children().children('.userGroupID').val(movingKeyUserGroupID); + $(".seqOrder[key='" + nextKey + "']").parent().children().children('.userGroupID').val(nextKeyUserGroupID); + + movingKeyPriorStepID = movingKeyPriorStepText != '' ? movingKeyPriorStepID : 'option:first'; + nextKeyPriorStepID = nextKeyPriorStepText != '' ? nextKeyPriorStepID : 'option:first'; + $(".seqOrder[key='" + movingKey + "']").parent().children().children('.priorStepID').val(movingKeyPriorStepID); + $(".seqOrder[key='" + nextKey + "']").parent().children().children('.priorStepID').val(nextKeyPriorStepID); + + + //flip the key values + $(".seqOrder[key='" + nextKey + "']").attr('key', function() { + return 'hold'; + }); + $(".seqOrder[key='" + movingKey + "']").attr('key', function() { + return nextKey; + }); + $(".seqOrder[key='hold']").attr('key', function() { + return movingKey; + }); + + + setArrows(); + return false; + }); }