Commit 4539198b authored by Marc Duez's avatar Marc Duez
Browse files

segmenter.js : beautify

parent 2e3367bb
......@@ -16,103 +16,111 @@
* You should have received a copy of the GNU General Public License
* along with "Vidjil". If not, see <http://www.gnu.org/licenses/>
*/
/*
*
* segmenter.js
*
*
* segmenter tools
*
*
* content:
*
*
*
*
*/
var memTab = [];
var memTab=[];
/* segment constructor
*
* */
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 = cgi_address
*
* */
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 = cgi_address
}
Segment.prototype = {
/*
*
* */
init : function(){
/*
*
* */
init: function () {
this.build()
},
build : function () {
build: function () {
var self = this
var parent=document.getElementById(this.id)
parent.innerHTML="";
var parent = document.getElementById(this.id)
parent.innerHTML = "";
//bot-bar
var div = document.createElement('div');
div.className = "bot-bar"
//menu-segmenter
var div_menu = document.createElement('div');
div_menu.className = "menu-segmenter"
div_menu.onmouseover = function () { self.m.focusOut() };
div_menu.onmouseover = function () {
self.m.focusOut()
};
//merge button
var span = document.createElement('span');
span.id = "merge"
span.className = "button"
span.onclick = function () { self.m.merge() }
span.onclick = function () {
self.m.merge()
}
span.appendChild(document.createTextNode("merge"));
div_menu.appendChild(span)
//align button
span = document.createElement('span');
span.id = "align"
span.className = "button"
span.onclick = function () { self.align() }
span.onclick = function () {
self.align()
}
span.appendChild(document.createTextNode("align"));
div_menu.appendChild(span)
//toIMGT button
span = document.createElement('span');
span.id = "toIMGT"
span.className = "button"
span.onclick = function () { self.sendTo('IMGT') }
span.onclick = function () {
self.sendTo('IMGT')
}
span.appendChild(document.createTextNode("❯ to IMGT/V-QUEST"));
div_menu.appendChild(span)
//toIgBlast button
span = document.createElement('span');
span.id = "toIgBlast"
span.className = "button"
span.onclick = function () { self.sendTo('igBlast') }
span.onclick = function () {
self.sendTo('igBlast')
}
span.appendChild(document.createTextNode("❯ to IgBlast"));
div_menu.appendChild(span)
//toClipBoard button
span = document.createElement('span');
span.id = "toClipBoard"
span.className = "button"
span.appendChild(document.createTextNode("❯ to clipBoard"));
// div_menu.appendChild(span)
div.appendChild(div_menu)
var div_focus = document.createElement('div');
div_focus.className = "focus"
div.appendChild(div_focus)
parent.appendChild(div)
div = document.createElement('div');
......@@ -121,213 +129,229 @@ Segment.prototype = {
ul = document.createElement('ul');
ul.id = "listSeq"
div.appendChild(ul)
parent.appendChild(div)
$('#toClipBoard').zclip({
path:'js/lib/ZeroClipboard.swf',
copy: function(){return self.toFasta()}
});
$('#toClipBoard')
.zclip({
path: 'js/lib/ZeroClipboard.swf',
copy: function () {
return self.toFasta()
}
});
},
/*
*
* */
resize : function(){
},
/*
*
* */
update : function(){
for (var i=0; i< this.m.n_windows; i++){
/*
*
* */
resize: function () {},
/*
*
* */
update: function () {
for (var i = 0; i < this.m.n_windows; i++) {
this.updateElem([i]);
}
},
/*
*
* */
updateElem : function(list){
for (var i=0; i< list.length; i++){
if (this.m.windows[list[i]].select){
if ( document.getElementById("seq"+list[i]) ){
var spanF=document.getElementById("f"+list[i]);
/*
*
* */
updateElem: function (list) {
for (var i = 0; i < list.length; i++) {
if (this.m.windows[list[i]].select) {
if (document.getElementById("seq" + list[i])) {
var spanF = document.getElementById("f" + list[i]);
this.div_elem(spanF, list[i]);
}else{
} else {
this.addToSegmenter(list[i]);
this.show();
}
}else{
if ( document.getElementById("seq"+list[i]) ){
var element = document.getElementById("seq"+list[i]);
} else {
if (document.getElementById("seq" + list[i])) {
var element = document.getElementById("seq" + list[i]);
element.parentNode.removeChild(element);
}
}
}
},
updateElemStyle : function(list){
updateElemStyle: function (list) {
this.updateElem(list)
},
/* genere le code HTML des infos d'un clone
* @div_elem : element HTML a remplir
* @cloneID : identifiant du clone a décrire
* */
div_elem : function(div_elem, cloneID){
var self=this;
div_elem.innerHTML='';
div_elem.className="seq-fixed";
div_elem.style.display="block";
var seq_name = document.createElement('span');
seq_name.className = "nameBox";
seq_name.onclick = function(){ self.m.select(cloneID); }
seq_name.appendChild(document.createTextNode(this.m.getName(cloneID)));
seq_name.title = this.m.getName(cloneID);
seq_name.style.color=this.m.windows[cloneID].color;
var svg_star=document.createElementNS('http://www.w3.org/2000/svg', 'svg')
svg_star.setAttribute('class','starBox');
svg_star.onclick=function(){ changeTag(cloneID); }
var path=document.createElementNS('http://www.w3.org/2000/svg','path')
path.setAttribute('d', this.starPath);
path.setAttribute('id','color'+cloneID);
if (typeof this.m.windows[cloneID].tag != 'undefined') path.setAttribute("fill", tagColor[this.m.windows[cloneID].tag]);
else path.setAttribute("fill", color['@default']);
svg_star.appendChild(path);
var seq_size=document.createElement('span')
seq_size.className = "sizeBox";
seq_size.onclick=function(){ this.m.select(cloneID); }
seq_size.style.color=this.m.windows[cloneID].color;
seq_size.appendChild(document.createTextNode(this.m.getStrSize(cloneID)));
div_elem.appendChild(seq_name);
div_elem.appendChild(svg_star);
div_elem.appendChild(seq_size);
},
addToSegmenter : function (cloneID){
var self=this;
var divParent = document.getElementById("listSeq");
var li = document.createElement('li');
li.id="seq"+cloneID;
li.className="sequence-line";
li.onmouseover = function(){ self.m.focusIn(cloneID); }
var spanF = document.createElement('span');
spanF.id = "f"+cloneID;
this.div_elem(spanF, cloneID);
var spanM = this.buildSequence(cloneID)
li.appendChild(spanF);
li.appendChild(spanM);
divParent.appendChild(li);
},
buildSequence: function (cloneID){
/* genere le code HTML des infos d'un clone
* @div_elem : element HTML a remplir
* @cloneID : identifiant du clone a décrire
* */
div_elem: function (div_elem, cloneID) {
var self = this;
div_elem.innerHTML = '';
div_elem.className = "seq-fixed";
div_elem.style.display = "block";
var seq_name = document.createElement('span');
seq_name.className = "nameBox";
seq_name.onclick = function () {
self.m.select(cloneID);
}
seq_name.appendChild(document.createTextNode(this.m.getName(cloneID)));
seq_name.title = this.m.getName(cloneID);
seq_name.style.color = this.m.windows[cloneID].color;
var svg_star = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
svg_star.setAttribute('class', 'starBox');
svg_star.onclick = function () {
changeTag(cloneID);
}
var path = document.createElementNS('http://www.w3.org/2000/svg', 'path')
path.setAttribute('d', this.starPath);
path.setAttribute('id', 'color' + cloneID);
if (typeof this.m.windows[cloneID].tag != 'undefined') path.setAttribute("fill", tagColor[this.m.windows[cloneID].tag]);
else path.setAttribute("fill", color['@default']);
svg_star.appendChild(path);
var seq_size = document.createElement('span')
seq_size.className = "sizeBox";
seq_size.onclick = function () {
this.m.select(cloneID);
}
seq_size.style.color = this.m.windows[cloneID].color;
seq_size.appendChild(document.createTextNode(this.m.getStrSize(cloneID)));
div_elem.appendChild(seq_name);
div_elem.appendChild(svg_star);
div_elem.appendChild(seq_size);
},
addToSegmenter: function (cloneID) {
var self = this;
var divParent = document.getElementById("listSeq");
var li = document.createElement('li');
li.id = "seq" + cloneID;
li.className = "sequence-line";
li.onmouseover = function () {
self.m.focusIn(cloneID);
}
var spanF = document.createElement('span');
spanF.id = "f" + cloneID;
this.div_elem(spanF, cloneID);
var spanM = this.buildSequence(cloneID)
li.appendChild(spanF);
li.appendChild(spanM);
divParent.appendChild(li);
},
buildSequence: function (cloneID) {
var spanM = document.createElement('span');
spanM.id = "m"+cloneID;
spanM.className="seq-mobil";
if(typeof this.m.windows[cloneID].sequence !='undefined' && this.m.windows[cloneID].sequence!=0){
spanM.id = "m" + cloneID;
spanM.className = "seq-mobil";
var v_length = this.m.windows[cloneID].Vend+1;
if (typeof this.m.windows[cloneID].sequence != 'undefined' && this.m.windows[cloneID].sequence != 0) {
var v_length = this.m.windows[cloneID].Vend + 1;
var size_marge = 300 - v_length;
var marge="";
if (size_marge>0){
for (var i=0; i<size_marge; i++) marge+="&nbsp";
var marge = "";
if (size_marge > 0) {
for (var i = 0; i < size_marge; i++) marge += "&nbsp";
}
var seq = new Sequence(cloneID, this.m)
spanM.innerHTML=marge+seq.load().toString()
}else{
var size_marge=320-this.m.windows[cloneID].window.length;
var marge="";
for (var i=0; i<size_marge; i++) marge+="&nbsp";
var spanJunc=document.createElement('span');
spanJunc.innerHTML=marge+this.m.windows[cloneID].window;
spanM.innerHTML = marge + seq.load()
.toString()
} else {
var size_marge = 320 - this.m.windows[cloneID].window.length;
var marge = "";
for (var i = 0; i < size_marge; i++) marge += "&nbsp";
var spanJunc = document.createElement('span');
spanJunc.innerHTML = marge + this.m.windows[cloneID].window;
spanM.appendChild(spanJunc);
}
return spanM
},
sendTo : function(address){
var list =this.m.getSelected()
var request = "";
for (var i = 0; i<list.length; i++){
if ( typeof(this.m.windows[list[i]].sequence) != 'undefined' && this.m.windows[list[i]].sequence!=0)
request += ">" +this.m.getName(list[i])+"\n"+ this.m.windows[list[i]].sequence+"\n";
else
request += ">" +this.m.getName(list[i])+"\n"+ this.m.windows[list[i]].window+"\n";
}
if (address=='IMGT') imgtPost(request, this.m.system);
if (address=='igBlast') igBlastPost(request, this.m.system);
},
show : function(){
var li =document.getElementById("listSeq").getElementsByTagName("li");
if (li.length >0){
var id=li[0].id.substr(3);
var mid=$("#m"+id+" span:first-child").width()-250;
$("#segmenter").animate({scrollLeft: mid}, 0);
}
},
align : function(){
var list =this.m.getSelected()
var request = "";
memTab=list;
if (list.length==0) return ;
for (var i = 0; i<list.length; i++){
if ( typeof(this.m.windows[list[i]].sequence) != 'undefined' && this.m.windows[list[i]].sequence!=0)
request += ">" +list[i]+"\n"+ this.m.windows[list[i]].sequence+"\n";
else
request += ">" +list[i]+"\n"+ this.m.windows[list[i]].window+"\n";
}
$.ajax({
type: "POST",
data : request,
url: this.cgi_address+"align.cgi",
success: function(result) {
displayAjaxResult(result);
}
});
},
clipBoard : function () {
sendTo: function (address) {
var list = this.m.getSelected()
var request = "";
for (var i = 0; i < list.length; i++) {
if (typeof (this.m.windows[list[i]].sequence) != 'undefined' && this.m.windows[list[i]].sequence != 0)
request += ">" + this.m.getName(list[i]) + "\n" + this.m.windows[list[i]].sequence + "\n";
else
request += ">" + this.m.getName(list[i]) + "\n" + this.m.windows[list[i]].window + "\n";
}
if (address == 'IMGT') imgtPost(request, this.m.system);
if (address == 'igBlast') igBlastPost(request, this.m.system);
},
show: function () {
var li = document.getElementById("listSeq")
.getElementsByTagName("li");
if (li.length > 0) {
var id = li[0].id.substr(3);
var mid = $("#m" + id + " span:first-child")
.width() - 250;
$("#segmenter")
.animate({
scrollLeft: mid
}, 0);
}
},
align: function () {
var list = this.m.getSelected()
var request = "";
memTab = list;
if (list.length == 0) return;
for (var i = 0; i < list.length; i++) {
if (typeof (this.m.windows[list[i]].sequence) != 'undefined' && this.m.windows[list[i]].sequence != 0)
request += ">" + list[i] + "\n" + this.m.windows[list[i]].sequence + "\n";
else
request += ">" + list[i] + "\n" + this.m.windows[list[i]].window + "\n";
}
$.ajax({
type: "POST",
data: request,
url: this.cgi_address + "align.cgi",
success: function (result) {
displayAjaxResult(result);
}
});
},
clipBoard: function () {
var div = document.getElementById('clipBoard');
div.innerHTML = "";
div.appendChild(document.createTextNode(""));
/*
if (document.createRange && window.getSelection) {
var range = document.createRange();
......@@ -336,122 +360,124 @@ Segment.prototype = {
window.getSelection().addRange(range);
}
*/
},
toFasta : function () {
toFasta: function () {
var selected = this.m.getSelected();
var result = "";
for (var i=0; i < selected.length; i++){
result += "> "+this.m.getName(selected[i]) + " // " + this.m.getStrSize(selected[i]) + "\n";
for (var i = 0; i < selected.length; i++) {
result += "> " + this.m.getName(selected[i]) + " // " + this.m.getStrSize(selected[i]) + "\n";
result += this.m.windows[selected[i]].sequence + "\n";
}
return result
},
}//fin prototype
} //fin prototype
function displayAjaxResult(file) {
var json = JSON.parse(file)
for (var i = 0; i < json.seq.length; i++) {
function displayAjaxResult(file){
var json=JSON.parse(file)