Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERM-103 Fix arrows not reordering. Listeners attached after html crea… #730

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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