Commit 414d7eed authored by Marc Duez's avatar Marc Duez
Browse files

database.js : new file used to interact with database

parent 86b1e046
......@@ -51,6 +51,7 @@
<script type="text/javascript" src='js/vidjil-style.js'></script>
<script type="text/javascript" src='js/crossDomain.js'></script>
<script type="text/javascript" src='js/pdf.js'></script>
<script type="text/javascript" src='js/database.js'></script>
<script type="text/javascript" src='js/conf.js'></script>
</head>
......
function Database(id, db_adress) {
this.db_adress = db_adress;
this.id = id;
this.upload = 0;
}
Database.prototype = {
//appel une page générée a partir des données du serveur
//page : nom de la page coté serveur
//args : parametres format json ( { "name_arg1" : "arg1", ... } )
call: function (page, args) {
var self = this;
var arg = "?";
for (var key in args) {
arg += "" + key + "=" + args[key] + "&";
}
//envoye de la requete ajax
$.ajax({
type: "GET",
timeout: 1000,
crossDomain: true,
url: self.db_adress + page + arg,
contentType: 'text/plain',
xhrFields: { withCredentials: false },
success: function (result) {
var self2 = self;
//rétablissement de l'adresse pour les futures requetes
result = result.replace("DB_ADRESS/", self.db_adress);
//affichage résultat
self.display(result);
//bind javascript
//le nouveau contenu apporté par l'ajax n'était pas présent durant l'initialisation du javascript
//les appels javascript qu'il contient ne sont donc pas linké
//on déclare donc les fonctions neccessaire apres l'affichage
//submit formulaire sans fichier
if ( document.getElementById('data_form') ){
$('#data_form')
.on('submit', function (e) {
e.preventDefault();
$.ajax({
type: "POST",
cache: false,
timeout: 1000,
crossDomain: true,
url: $(this)
.attr('action'),
data: $(this)
.serialize(),
success: function (result) {
var res = jQuery.parseJSON(result);
if (res.success == "true") {
self2.call("patient_list")
} else {
popupMsg(res.error);
}
},
error: function (request, status, error) {
if (status === "timeout") {
popupMsg("timeout");
} else {
popupMsg(request.responseText);
}
}
});
});
}
var upload_n = self.upload;
//submit formulaire avec fichier
if ( document.getElementById('upload_form') ){
$('#upload_form')
.ajaxForm({
type: "POST",
cache: false,
crossDomain: true,
url: $(this)
.attr('action'),
data: $(this)
.serialize(),
beforeSend: function () {
//crée un div qui contiendra la progression de l'upload du fichier
self2.upload++;
var div = document.createElement('div');
var spanName = document.createElement('span');
spanName.innerHTML = $("#upload_file")
.val()
.split('/')
.pop()
.split('\\')
.pop();
var spanPercent = document.createElement('span');
spanPercent.id = "upload_percent_" + upload_n;
spanPercent.innerHTML = '0%';
div.appendChild(spanName);
div.appendChild(spanPercent);
var div_parent = document.getElementById("upload_list");
div_parent.appendChild(div);
self2.call("patient_list")
},
//mise a jour progressive du % d'upload
uploadProgress: function (event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
$('#upload_percent_' + upload_n)
.html(percentVal);
},
success: function (result) {
var res = jQuery.parseJSON(result);
if (res.success == "true") {
} else {
popupMsg(res.error);
}
},
error: function (request, status, error) {
if (status === "timeout") {
popupMsg("timeout");
} else {
popupMsg(request.responseText);
}
}
});
}
},
error: function (request, status, error) {
if (status === "timeout") {
popupMsg("timeout");
} else {
popupMsg(request.responseText);
}
}
});
},
//appel une fonction du serveur
//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
request: function (controller_name, args) {
var self = this;
var arg = "?";
for (var key in args) {
arg += "" + key + "=" + args[key] + "&";
}
//envoye de la requete ajax
$.ajax({
type: "POST",
timeout: 1000,
crossDomain: true,
url: self.db_adress + controller_name + arg,
success: function (result) {
popupMsg(result);
},
error: function (request, status, error) {
if (status === "timeout") {
popupMsg("timeout");
} else {
popupMsg(request.responseText);
}
}
});
},
load: function (args) {
var self = this;
var arg = "?";
for (var key in args) {
arg += "" + key + "=" + args[key] + "&";
}
$.ajax({
type: "POST",
timeout: 5000,
crossDomain: true,
url: self.db_adress + "result" + arg,
success: function (result) {
json = jQuery.parseJSON(result)
m.parseJsonData(json, 50)
.loadGermline();
m.initClones()
},
error: function (request, status, error) {
if (status === "timeout") {
popupMsg("timeout");
} else {
popupMsg(request.responseText);
}
}
});
},
//affiche la fenetre de dialogue avec le serveur et affiche ses réponses
display: function (msg) {
document.getElementById("db_div")
.style.display = "block";
document.getElementById("db_msg")
.innerHTML = msg;
},
//efface et ferme la fenetre de dialogue avec le serveur
close: function () {
document.getElementById("db_div")
.style.display = "none";
document.getElementById("db_msg")
.innerHTML = "";
}
}
var DB_ADDRESS = "http://134.206.11.64:8000/Vidjil_test/default/";
var CGI_ADDRESS = "http://127.0.1.1/cgi-bin/";
/*load user config if exist
*
* */
if (typeof config != 'undefined' && config.cgi_address){
if (config.cgi_address) CGI_ADDRESS = config.cgi_address
if (config.db_address) DB_ADDRESS = config.db_address
}
/* Model
*
* */
......@@ -5,12 +16,18 @@ var m = new Model();
/* views
*
*
* */
var graph = new Graph("visu2", m);
var list = new List("list", m);
var sp = new ScatterPlot("visu", m);
var segment = new Segment("bot-container", m);
var graph = new Graph("visu2",m);
var list = new List("list",m);
var sp = new ScatterPlot("visu",m);
var segment = new Segment("bot-container",m, CGI_ADDRESS);
var builder = new Builder(m);
initTag(); //TODO a enlever
\ No newline at end of file
/* connections
*
* */
var db = new Database("plop!", DB_ADDRESS);
initTag();//TODO a enlever
\ No newline at end of file
......@@ -293,7 +293,7 @@ ScatterPlot.prototype = {
*
* */
updateBar: function () {
var = self = this
var self = this
this.vKey = Object.keys(this.m.germline.vgene);
this.vKey.push("undefined V");
......
......@@ -33,13 +33,13 @@ var memTab=[];
/* segment constructor
*
* */
function Segment(id, model){
function Segment(id, model, cgi_address){
this.id=id; //ID de la div contenant le segmenteur
this.m=model; //Model utilisé
this.m.view.push(this); //synchronisation au Model
this.starPath = "M 0,6.1176482 5.5244193, 5.5368104 8.0000008,0 10.172535,5.5368104 16,6.1176482 11.406183,9.9581144 12.947371,16 8.0000008,12.689863 3.0526285,16 4.4675491,10.033876 z"
this.cgi_address = "http://127.0.1.1/cgi-bin/"
this.cgi_address = cgi_address
}
Segment.prototype = {
......@@ -49,10 +49,6 @@ Segment.prototype = {
* */
init : function(){
if (typeof config != 'undefined' && config.cgi_address){
this.cgi_address = config.cgi_address
}
this.build()
},
......@@ -284,7 +280,7 @@ Segment.prototype = {
},
sendTo : function(adress){
sendTo : function(address){
var list =this.m.getSelected()
var request = "";
......@@ -296,8 +292,8 @@ Segment.prototype = {
request += ">" +this.m.getName(list[i])+"\n"+ this.m.windows[list[i]].window+"\n";
}
if (adress=='IMGT') imgtPost(request, this.m.system);
if (adress=='igBlast') igBlastPost(request, this.m.system);
if (address=='IMGT') imgtPost(request, this.m.system);
if (address=='igBlast') igBlastPost(request, this.m.system);
},
......
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