Commit 41a96585 authored by Marc Duez's avatar Marc Duez
Browse files

database.js : save last page address for reload

auto-reload page when an upload succeed
parent 83ebbc6d
...@@ -3,6 +3,7 @@ function Database(id, db_address) { ...@@ -3,6 +3,7 @@ function Database(id, db_address) {
this.id = id; this.id = id;
this.upload = {}; this.upload = {};
this.url = ""
} }
Database.prototype = { Database.prototype = {
...@@ -27,18 +28,25 @@ Database.prototype = { ...@@ -27,18 +28,25 @@ Database.prototype = {
arg += "" + key + "=" + args[key] + "&"; arg += "" + key + "=" + args[key] + "&";
} }
this.last_url = self.db_address + page + arg var url = self.db_address + page + arg
this.callUrl(url)
},
callUrl : function (url){
var self=this;
//envoye de la requete ajax
$.ajax({ $.ajax({
type: "POST", type: "POST",
timeout: 1000, timeout: 1000,
crossDomain: true, crossDomain: true,
context: self, //we can't do closure with ajax event handler so we use context to keep ref context: self, //we can't do closure with ajax event handler so we use context to keep ref
url: self.db_address + page + arg, url: url,
contentType: 'text/plain', contentType: 'text/plain',
xhrFields: {withCredentials: true}, xhrFields: {withCredentials: true},
success: self.display_result, success: function (result) {
self.display_result(result, url)
},
error: function (request, status, error) { error: function (request, status, error) {
if (status === "timeout") { if (status === "timeout") {
popupMsg("timeout"); popupMsg("timeout");
...@@ -50,11 +58,10 @@ Database.prototype = { ...@@ -50,11 +58,10 @@ Database.prototype = {
}); });
}, },
display_result: function (result, url) {
display_result: function (result) {
//rétablissement de l'adresse pour les futures requetes //rétablissement de l'adresse pour les futures requetes
result = result.replace("DB_ADDRESS/", this.db_address); result = result.replace("DB_ADDRESS/", this.db_address);
result = result.replace("action=\"#\"", "action=\""+this.last_url+"\""); result = result.replace("action=\"#\"", "action=\""+url+"\"");
//hack redirection //hack redirection
try { try {
...@@ -71,6 +78,7 @@ Database.prototype = { ...@@ -71,6 +78,7 @@ Database.prototype = {
{ {
//affichage résultat //affichage résultat
this.display(result) this.display(result)
this.url=url
//bind javascript //bind javascript
this.init_ajaxform() this.init_ajaxform()
...@@ -99,7 +107,7 @@ Database.prototype = { ...@@ -99,7 +107,7 @@ Database.prototype = {
data : $(this).serialize(), data : $(this).serialize(),
xhrFields: {withCredentials: true}, xhrFields: {withCredentials: true},
success: function (result) { success: function (result) {
self.display_result(result) self.display_result(result, $(this).attr('action'))
}, },
error: function (request, status, error) { error: function (request, status, error) {
if (status === "timeout") { if (status === "timeout") {
...@@ -124,7 +132,9 @@ Database.prototype = { ...@@ -124,7 +132,9 @@ Database.prototype = {
url : $(this).attr('action'), url : $(this).attr('action'),
data : $(this).serialize(), data : $(this).serialize(),
xhrFields: {withCredentials: true}, xhrFields: {withCredentials: true},
success: self.display_result, success: function (result) {
self.display_result(result, $(this).attr('action'))
},
error: function (request, status, error) { error: function (request, status, error) {
if (status === "timeout") { if (status === "timeout") {
popupMsg("timeout"); popupMsg("timeout");
...@@ -180,10 +190,12 @@ Database.prototype = { ...@@ -180,10 +190,12 @@ Database.prototype = {
upload_file: function (id, data){ upload_file: function (id, data){
var self = this; var self = this;
var url = self.db_address + "file/upload"
$.ajax({ $.ajax({
type: "POST", type: "POST",
crossDomain: true, crossDomain: true,
url: self.db_address + "file/upload", url: url,
processData: false, processData: false,
contentType: false, contentType: false,
data: data, data: data,
...@@ -193,7 +205,7 @@ Database.prototype = { ...@@ -193,7 +205,7 @@ Database.prototype = {
success: function (result) { success: function (result) {
self.upload[id] = 1 self.upload[id] = 1
self.upload_display() self.upload_display()
self.display_result(result) self.display_result(result, url)
}, },
error: function (request, status, error) { error: function (request, status, error) {
delete self.upload[id]; delete self.upload[id];
...@@ -209,6 +221,11 @@ Database.prototype = { ...@@ -209,6 +221,11 @@ Database.prototype = {
return data return data
}, },
/*reload the current db page*/
reload: function(){
this.callUrl(this.url)
},
/* appel une fonction du serveur /* appel une fonction du serveur
* idem que call() mais la réponse n'est pas une page html a afficher * idem que call() mais la réponse n'est pas une page html a afficher
* mais simplement une confirmation que la requete a été entendu * mais simplement une confirmation que la requete a été entendu
...@@ -357,11 +374,12 @@ Database.prototype = { ...@@ -357,11 +374,12 @@ Database.prototype = {
this.upload_display(); this.upload_display();
}, },
/* update upload status */
upload_display: function(){ upload_display: function(){
for (var key in this.upload){ for (var key in this.upload){
if (this.upload[key]==1){ if (this.upload[key]==1){
$("#sequence_file_"+key).html("uploaded !")
delete this.upload[key]; delete this.upload[key];
this.reload()
}else{ }else{
$("#sequence_file_"+key).html("<div class='loading_seq'></div>") $("#sequence_file_"+key).html("<div class='loading_seq'></div>")
} }
......
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