function changeCourse(request){
callToServer(request).then(function (data) {
var jsonData = data;
for (var i = 0; i < jsonData.rows.length; i++) {
drawRows(jsonData.rows[i]);
}
function drawRows(rows) {
var data = rows;
changContent($("#selectExchange").val(), object.id, "changeOperation").then(function(){
count();
});
<b>
changContent($("#selectExchange").val(), object.id, "changeOperation").then(count());
</b>
<b> var defer = $/Deferred();
</b>
if (action == "changeCourse") {
changRows(exchange, operation);
} else {
changOperation(exchange, operation);
}
function changOperation(exchange, operation) {
callToServer(exchange).then(function (data) {
/** @namespace rows[index].sellCourse */
var rows = data.rows;
for (var i = 0; i < rows.length; i++) {
$('#personDataTable').find('li').each(function (index) {
//todo edith if method and remove duplicate code
if (operation === "buy") {
$(this).find('input:last').val(rows[index].buyCourse);
} else {
$(this).find('input:last').val(rows[index].sellCourse);
}
});
}
<b>
}).done(function(){
defer.resolve();
});
return defer.promise();
</b>
}
function changRows(exchange, operation) {
callToServer(exchange).then(function (data) {
/** @namespace rows[index].sellCourse */
var rows = data.rows;
for (var i = 0; i < rows.length; i++) {
$('#personDataTable').find('li').each(function (index) {
//todo edith if method and remove duplicate code
if (operation === "buy") {
$(this).find('input:last').val(rows[index].buyCourse);
} else {
$(this).find('input:last').val(rows[index].sellCourse);
}
$(this).find('label').text(rows[index].id.substr(3, 5));
});
}
<b>
}).done(function(){
defer.resolve();
});
return defer.promise();
</b>
}
}
if (data) {
for (var i = 3; i--;) {
$('exchange' + (i + 1)).val(data['exchange' + (i + 1)]);
}
}
.fail(function (xhr, status, errorThrown ) {
alert( "Sorry, there was a problem!" );
console.log( "Error: " + errorThrown );
console.log( "Status: " + status );
console.dir( xhr );
});