Skip to content

Commit

Permalink
Cloning now works with blocks and subblocks. #26
Browse files Browse the repository at this point in the history
  • Loading branch information
prakhar1989 committed Jul 10, 2015
1 parent ac105fe commit 3c2d8d7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions js/stores/SurveyStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,19 @@ var SurveyStore = Reflux.createStore({
let blockIndex = blockPath[blockPath.length - 1];
let newBlock = this.cloneBlock(survey.getIn(blockPath));
let newSurvey;
if (_blockMap.has(itemId)) {
console.log("This is a subblock")
return;
} else {
if (_blockMap.has(itemId)) { // if subblock, append in parent
let parentId = _blockMap.get(itemId);
let parentblockPath = this.getBlockPath(parentId, survey);
newSurvey = survey.updateIn([...parentblockPath, 'subblocks'],
list => list.splice(blockIndex + 1, 0, newBlock)
);
_blockMap = _blockMap.set(newBlock.get('id'), parentId);
} else { // else simply put in survey array
newSurvey = survey.splice(blockIndex + 1, 0, newBlock);
}

// update and cache
this.updateSurveyData(newSurvey, true);
// update
this.updateSurveyData(newSurvey, false);

// alert and focus
SurveyActions.showAlert("Block copied.", AlertTypes.INFO);
Expand All @@ -421,7 +425,7 @@ var SurveyStore = Reflux.createStore({
this.updateSurveyData(newSurvey, false);

// update the _questionMap
_questionMap = _questionMap.set(newQuestion.get('id'), _blockMap.get(itemId));
_questionMap = _questionMap.set(newQuestion.get('id'), _questionMap.get(itemId));

// alert and focus
SurveyActions.showAlert("Question copied.", AlertTypes.INFO);
Expand Down

0 comments on commit 3c2d8d7

Please sign in to comment.