Skip to content

Commit

Permalink
[#1801] Update currencies only when object has no currency itself
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Jun 1, 2016
1 parent 9e793af commit 62849c9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
26 changes: 23 additions & 3 deletions akvo/rsr/static/scripts-src/project-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2284,15 +2284,35 @@ function setCurrencyOnChange() {
}
}

function hasObjectCurrency(currencyDisplay) {
if (currencyDisplay !== null) {
var parent = findAncestorByClass(currencyDisplay, 'parent');
console.log(parent);
if (parent !== null) {
var parentId = parent.getAttribute('id');
var parentIdList = parentId.split('.');
var currencyId = ['rsr_' + parentIdList[0].replace('_', ''), 'currency', parentIdList[1]].join('.');
var currencyNode = document.getElementById(currencyId);
if (currencyNode !== null) {
return currencyNode.value !== '';
}
}
}
return false;
}

function updateCurrency(currencyDropdown) {
return function(e) {
e.preventDefault();

var currency = currencyDropdown.options[currencyDropdown.selectedIndex].text;
var newCurrency = currencyDropdown.value;
var currencyDisplays = document.querySelectorAll('.currency-display');

for (var i=0; i < currencyDisplays.length; i++) {
currencyDisplays[i].innerHTML = currency;
for (var i = 0; i < currencyDisplays.length; i++) {
var currencyDisplay = currencyDisplays[i];
if (!hasObjectCurrency(currencyDisplay)) {
currencyDisplay.innerHTML = newCurrency;
}
}
};
}
Expand Down
26 changes: 23 additions & 3 deletions akvo/rsr/static/scripts-src/project-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2284,15 +2284,35 @@ function setCurrencyOnChange() {
}
}

function hasObjectCurrency(currencyDisplay) {
if (currencyDisplay !== null) {
var parent = findAncestorByClass(currencyDisplay, 'parent');
console.log(parent);
if (parent !== null) {
var parentId = parent.getAttribute('id');
var parentIdList = parentId.split('.');
var currencyId = ['rsr_' + parentIdList[0].replace('_', ''), 'currency', parentIdList[1]].join('.');
var currencyNode = document.getElementById(currencyId);
if (currencyNode !== null) {
return currencyNode.value !== '';
}
}
}
return false;
}

function updateCurrency(currencyDropdown) {
return function(e) {
e.preventDefault();

var currency = currencyDropdown.options[currencyDropdown.selectedIndex].text;
var newCurrency = currencyDropdown.value;
var currencyDisplays = document.querySelectorAll('.currency-display');

for (var i=0; i < currencyDisplays.length; i++) {
currencyDisplays[i].innerHTML = currency;
for (var i = 0; i < currencyDisplays.length; i++) {
var currencyDisplay = currencyDisplays[i];
if (!hasObjectCurrency(currencyDisplay)) {
currencyDisplay.innerHTML = newCurrency;
}
}
};
}
Expand Down

0 comments on commit 62849c9

Please sign in to comment.