Skip to content

Commit

Permalink
Merge pull request #730 from coral-erm/bugfix/ERM-103-reorder-workflo…
Browse files Browse the repository at this point in the history
…w-steps

ERM-103 Fix arrows not reordering. Listeners attached after html crea…
  • Loading branch information
Randall Rupper authored Sep 1, 2023
2 parents f24ecbe + 4217e9b commit fe977cf
Showing 1 changed file with 72 additions and 71 deletions.
143 changes: 72 additions & 71 deletions resources/js/forms/currentWorkflowForm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$(document).ready(function(){

lastKey = $('#finalKey').val();
lastKey = $('#finalKey').val() || 0;

$(".addStep").on('click', function() {
var originalTR = $('.newStepTR').clone();
Expand Down Expand Up @@ -39,7 +39,7 @@ $(document).ready(function(){
lastKey = newKey;

setArrows();
updatePriorSteps(sName);
updatePriorSteps('addStep');


});
Expand Down Expand Up @@ -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') != ''){
Expand Down Expand Up @@ -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;
});
}


Expand Down

0 comments on commit fe977cf

Please sign in to comment.