Created
September 19, 2018 12:51
-
-
Save MariaFamador/3a1a631ae7b016f631af44ebb320bab6 to your computer and use it in GitHub Desktop.
addBlock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addBlock: function(state, block) { | |
// It automatically adds a product block on initial load | |
// Don't add first block if blocks already exist in db | |
if (state.blocks.length > 0) { | |
var blocks = []; | |
for(var i = 0; i < block.grid_columns_number; i++){ | |
var addBlock = _.cloneDeep(block); | |
var position = i; | |
if (!_.isEmpty(_.flatten(state.blocks))) { | |
position = maxBy(_.flatten(state.blocks), function (object) { | |
return object.position; | |
}).position + 1 + i; | |
} | |
addBlock['position'] = position; | |
var blockParams = _.merge(addBlock, {campaign_id: this.state.campaign.id}); | |
var blockModel = new Block(blockParams); | |
blockModel.save().then(function(data) { | |
// addBlock['id'] = data.response.data.id; | |
_.merge(addBlock, {id: data.response.data.id}) | |
console.log('block.id == ', data.response.data.id) | |
console.log('addBlock', addBlock) | |
console.log('===============') | |
return addBlock; | |
// blocks.push(addBlock); | |
}) | |
blocks.push(addBlock); | |
}; | |
state.blocks.push(blocks); | |
// this.commit("switchEditor", { | |
// position: blocks[0].position | |
// }); | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment