scinote-web/app/assets/javascripts/projects/show.js

67 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-08-19 21:36:12 +08:00
(function(){
2016-08-19 22:38:34 +08:00
var count = 0;
2016-08-19 21:36:12 +08:00
function init(){
$("[data-id]").each(function(){
var that = $(this);
initProjectExperiment(that);
});
2016-08-19 22:38:34 +08:00
}
2016-08-19 21:36:12 +08:00
function initProjectExperiment(element){
var container = element.find(".workflowimg-container");
var url = container.data("check-img");
var timestamp = container.data("timestamp");
var img_url = container.data('updated-img');
2016-08-19 22:38:34 +08:00
animateSpinner(container, true);
checkUpdatedImg(img_url, url, timestamp, container);
}
// checks if the experiment image is updated
function checkUpdatedImg(img_url, url, timestamp, container){
if (count < 30 && timestamp){
2016-08-19 22:38:34 +08:00
$.ajax({
url: url,
type: "GET",
data: { "timestamp": timestamp },
dataType: "json",
success: function (data) {
getNewWorkforwImg(container, img_url);
container.show();
animateSpinner(container, false);
2016-08-19 22:38:34 +08:00
},
error: function (ev) {
if (ev.status == 404) {
setTimeout(function () {
checkUpdatedImg(img_url, url, timestamp, container)
}, 5000);
} else {
animateSpinner(container, false);
}
count++;
2016-08-19 22:38:34 +08:00
}
});
} else {
animateSpinner(container, false);
2016-08-19 22:38:34 +08:00
}
2016-08-19 21:36:12 +08:00
}
// fetch the new experiment image
function getNewWorkforwImg(el, url){
2016-08-19 21:36:12 +08:00
$.ajax({
url: url,
type: "GET",
dataType: "json",
success: function (data) {
el.append(data.workflowimg);
2016-08-19 21:36:12 +08:00
},
error: function (ev) {
2016-08-19 22:38:34 +08:00
// TODO
2016-08-19 21:36:12 +08:00
}
});
}
init();
})();