Commit 3a3bd99f authored by Matt Vanderpol's avatar Matt Vanderpol

Setup tool on previously selected category

If someone picks a tool under a specific category, we need to preserve this. W/out ths update then the tool gets selected in the first available row.
parent 6ce20878
......@@ -90,6 +90,11 @@ var CategoryRoiCalculator = {
var $row = $(row);
var tools = CategoryRoiStore.toolsForStage(stage);
$.each(tools, function(k, tool) {
// Skip row if it's the "wrong row"
if ( tool.category_key && !$row.is('[data-category-key="' + tool.category_key + '"]') ) {
return;
}
var overwrite = false;
var focus = false;
if (tool.key) {
......@@ -228,7 +233,9 @@ var CategoryRoiCalculator = {
var choices = {};
this.$container.find('.js-competitor-dropdown .dropdown-title').each(function() {
var $$ = $(this);
var stage = $$.parents('.js-data-row:first').data('stage');
var $row = $$.parents('.js-data-row:first');
var stage = $row.data('stage');
var categoryKey = $row.data('category-key');
if ( $$.html().trim() === '' ) {
return;
}
......@@ -238,7 +245,7 @@ var CategoryRoiCalculator = {
if (!choices[stage]) {
choices[stage] = [];
}
choices[stage].push({ key: key });
choices[stage].push({ key: key, category_key: categoryKey });
}
var $otherTool = $$.find('.js-other-tool-input');
......@@ -246,7 +253,7 @@ var CategoryRoiCalculator = {
if (!choices[stage]) {
choices[stage] = [];
}
choices[stage].push({ text: $otherTool.val() });
choices[stage].push({ text: $otherTool.val(), category_key: categoryKey });
}
});
CategoryRoiStore.setChoices(choices);
......
......@@ -48,7 +48,7 @@ extra_js:
- data.categories.each do |category_key, category|
- next unless category.roi
.row.data-row.js-data-row{ data: { stage: category.stage } }
.row.data-row.js-data-row{ data: { 'category-key' => category_key, stage: category.stage } }
.col-xs-4.data-col
= category.name
.col-xs-4.data-col
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment