Skip to content

Commit

Permalink
Fix bug when sorting modifiable sections
Browse files Browse the repository at this point in the history
There was a bug that caused the error message to popup when all of the sections within a phase were modifiable.
  • Loading branch information
Bodacious committed Sep 10, 2018
1 parent 14de35d commit 36ba718
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions app/assets/javascripts/views/org_admin/phases/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,28 @@ $(() => {
//
// Returns Boolean
function prefixSectionExists(draggableSections) {
return !!draggableSections
.has('[data-modifiable=true]:nth-child(1)').length
&& !!draggableSections.has('[data-modifiable=true]:nth-child(2)').length;
// How many sections are there?
const numberOfSections = draggableSections.has('.panel.section').length;
// How many modifiable sections are there?
const modifiableSections = draggableSections.has('[data-modifiable=true]').length;
// If all sections are modifiable, return false;
if (numberOfSections == modifiableSections) {
return false;
}
////
// Assuming all sections are NOT modifiable...

// A boolean to check if there a modifible prefix Section
const firS = draggableSections.has('[data-modifiable=true]:nth-child(1)').length == 1;

// A boolean to check if there's a second prefix Section (this is invalid!)
const secS = draggableSections.has('[data-modifiable=true]:nth-child(2)').length == 1;

if (firS && secS) {
return true;
} else {
return false;
}
}

// Initialize the draggable-sections element as a jQuery sortable.
Expand Down

0 comments on commit 36ba718

Please sign in to comment.