Commit 7e7ba14f authored by Téo Vasseur's avatar Téo Vasseur
Browse files

builder.js -> info.js : move dependencies

See #2446
Added missing semi-colons too.
parent faf48f97
......@@ -237,86 +237,6 @@ Builder.prototype = {
.select();
},
/*
* */
edit: function (elem, data) {
var self = this;
var id = "edit_value";
var init_value = self.m.getStrTime(self.m.t, data);
var save_callback = function() {
var value = document.getElementById(id).value;
self.m.samples[data][self.m.t] = value
self.post_save(self);
}
this.build_input_edit(id, elem, init_value, save_callback)
},
//TODO rename
build_edit: function (input, id, elem, callback) {
var divParent = elem.parentNode;
divParent.removeAllChildren();
divParent.appendChild(input);
divParent.onclick = "";
$(input).on('save', callback);
$(input).select();
},
build_input_edit: function(id, elem, value, callback) {
var input = this.create_edit_input(id, value);
this.build_edit(input, id, elem, callback);
},
create_edit_input: function (id, value) {
var input = this.setupInput(id, "", "text", value);
this.setup_edit_input(input);
input.style.width = "200px";
input.style.border = "0px";
input.style.margin = "0px";
return input;
},
setup_edit_input: function (input) {
input.onkeydown = function (e) {
e = e || window.event;
var key = e.keyCode
if (key === 0) key = e.which
// if (key == 13) $(input).trigger("save");
else if (key == 27) m.update()
}
$(input).focusout(function() {
setTimeout(function(){
$(input).trigger("save");
// m.update()
}, 500);
})
},
post_save: function(self) {
self.build_top_container()
self.build_info_container()
self.m.update()
self.m.analysisHasChanged = true
},
update_model_data: function(fieldName, value, field_parent) {
if(typeof field_parent != 'undefined')
this.m[field_parent][fieldName]= value;
else
this.m[fieldName] = value;
this.post_save(this);
},
update_model_sample_data: function(fieldName, value, field_parent) {
if(typeof field_parent != 'undefined')
this.m[field_parent][fieldName][this.m.t]= value;
else
this.m[fieldName][this.m.t] = value;
this.post_save(this);
},
buildListTab: function(i) {
var span3 = document.createElement('span');
span3.onclick = function (tag) {
......@@ -459,36 +379,6 @@ Builder.prototype = {
this.m.resize();
},
build_line_read_number: function (id, label, qualifier, read_number) {
var val = "no read";
var warning_title = false ;
var warning_class = '' ;
if (read_number[this.m.t] > 0)
{
var percent = (read_number[this.m.t] / this.m.reads.total[this.m.t]) * 100
val = this.m.toStringThousands(read_number[this.m.t]) + " (" + percent.toFixed(2) + "%)"
if (percent < 10) {
warning_title = "Very few reads " + qualifier ;
warning_class = "alert" ;
}
else if (percent < 50) {
warning_title = "Few reads " + qualifier ;
warning_class = "warning" ;
}
}
div = this.build_named_info_line(id, label, val, false);
if (warning_class !== "") {
var warning_span = document.createElement('span')
warning_span.className = "warningReads " + warning_class;
warning_span.appendChild(icon('icon-warning-1', warning_title));
div.appendChild(warning_span);
}
return div;
},
build_top_container: function () {
var self = this;
var parent = document.getElementById("top_info");
......@@ -529,228 +419,6 @@ Builder.prototype = {
document.title = this.m.getPrintableAnalysisName()
},
create_sample_info_container: function(info, className, id, placeholder, target) {
var self = this;
var container = this.create_info_container(info, className, id, placeholder);
$(textarea).on("change", function() {
self.update_model_sample_data(target, this.value, "samples");
});
return container;
},
create_generic_info_container: function(info, className, id, placeholder, target) {
var self = this;
var container = this.create_info_container(info, className, id, placeholder);
$(textarea).on("change", function() {
self.update_model_data(target, this.value);
});
return container;
},
// TODO ambiguous with build_info_container => find another name ?
create_info_container: function (info, className, id, placeholder, target) {
var self = this;
var container = document.createElement('div');
container.className = className;
textarea = document.createElement('textarea');
textarea.id = id;
textarea.className = 'info_container';
textarea.innerHTML = info ;
textarea.setAttribute('placeholder', placeholder);
container.appendChild(textarea);
return container;
},
build_multi_system: function () {
var div = document.createElement('div');
div.className = "info_line locus_line";
var span2 = document.createElement('span')
span2.className = "locus_row"
var keys = 0 ;
var key_list = this.m.system_available;
key_list.sort();
var last_key = "";
var checkbox_onchange = function () {
m.toggle_system(this.id.replace("checkbox_system_",""))
}
var span_onclick = function (e) {
if (e.shiftKey) {
m.keep_one_active_system(this.firstChild.nextSibling.textContent)
} else {
this.firstChild.nextSibling.click();
}
}
for (var k in key_list) {
key = key_list[k];
// Are we at the start of a new group of locus ?
if (key.substring(0,2) != last_key.substring(0,2)) {
if (keys > 0) {
// Flush existing span2
div.appendChild(span2)
span2 = document.createElement('span')
span2.className = "locus_row"
}
}
last_key = key ;
keys += 1 ;
var checkbox = this.setupInput("checkbox_system_" + key, "", "checkbox", "");
checkbox.className = "hiddenCheckBox"
checkbox.appendChild(document.createTextNode(key))
if (this.m.system_selected.indexOf(key) != -1)
checkbox.checked=true
checkbox.onchange = checkbox_onchange;
var span_system = this.m.systemBox(key)
var span = document.createElement('span');
span.className = "systemBoxNameMenu "+key;
if (this.m.system_selected.indexOf(key) == -1)
span.className = "systemBoxNameMenu inactive " + key;
span.appendChild(span_system)
span.appendChild(checkbox)
span.appendChild(document.createTextNode(key))
span.onclick = span_onclick;
span2.appendChild(span)
}
div.appendChild(span2)
return div
},
build_info_line: function (id, value, className) {
var val = value !== ""? value : "-/-"
var span = document.createElement('span');
if (typeof(className) !== "undefined")
{
if (className)
{
span.className = className ;
}
}
span.appendChild(document.createTextNode(val));
var div = document.createElement('div');
div.id = id
div.className = "info_line"
div.appendChild(span)
return div
},
build_composite_info_line: function(id, children) {
var div = document.createElement('div')
div.id = id
div.className = "info_line"
for(var i = 0; i < children.length; i++) {
div.appendChild(children[i])
}
return div;
},
build_named_info_line: function (id, name, value, className) {
var div = this.build_info_line(id, value, className);
var inner_span = div.firstChild;
div.removeAllChildren();
var info_row = document.createElement("span");
info_row.className = "info_row";
info_row.appendChild(document.createTextNode(name));
div.appendChild(info_row);
div.appendChild(inner_span);
return div;
},
build_info_color: function () {
var self = this
var div = document.createElement('div');
div.className = "info_color centered vertical_space"
var span0 = document.createElement('span');
var span1 = document.createElement('span');
var span2 = document.createElement('span');
var span3 = document.createElement('span');
switch (this.m.colorMethod) {
case "N":
span0.appendChild(document.createTextNode("N length"));
span1.appendChild(document.createTextNode(" 0 "));
span2.className = "gradient";
span3.appendChild(document.createTextNode(" " + this.m.n_max + " "));
break;
case "Tag":
var span_onclick = function () {
self.nextDisplayTag(this)
}
for (var i = 0; i < this.m.tag.length; i++) {
var spantag = document.createElement('span');
spantag.className = "tagColorBox tagColor" + i
spantag.id = "fastTag" + i
spantag.onclick = span_onclick;
span2.appendChild(spantag);
}
break;
case 'productive':
span0.appendChild(document.createTextNode('not productive '));
var spanNotProductive = document.createElement('span')
spanNotProductive.style.backgroundColor = colorProductivity('false')
spanNotProductive.className = 'tagColorBox'
var spanProductive = document.createElement('span')
spanProductive.style.backgroundColor = colorProductivity('true')
spanProductive.className = 'tagColorBox'
span1.appendChild(spanNotProductive)
span1.appendChild(spanProductive)
span2.appendChild(document.createTextNode('productive'));
var spanNoCDR3 = document.createElement('span')
spanNoCDR3.className = 'tagColorBox tagColor8'
span3.style.marginLeft = '20px'
span3.appendChild(document.createTextNode(' no CDR3 '));
span3.appendChild(spanNoCDR3);
break;
case "abundance":
span0.appendChild(document.createTextNode("abundance"));
span1.appendChild(document.createTextNode(" 0% "));
span2.className = "gradient";
span3.appendChild(document.createTextNode(" 100%"));
break;
}
div.appendChild(span0)
div.appendChild(span1)
div.appendChild(span2)
div.appendChild(span3)
return div;
},
initTag: function (){
for (var i =0; i<this.m.tag.length; i++){
$(".tagColor"+i).prop("title", this.m.tag[i].name);
......@@ -806,21 +474,4 @@ Builder.prototype = {
div.appendChild(textNode);
return div;
},
createClickableElem: function(type, children, id, className, onclick) {
var element = document.createElement(type);
for (var i = 0; i < children.length; ++i)
element.appendChild(children[i]);
if (id !== "" && typeof id !== "undefined") element.id = id;
if(className !== "" && typeof className !== "undefined") element.className = className;
if (typeof onclick === "function")
element.onclick = onclick;
else if (typeof onclick != "undefined")
console.log("Error: invalid parameter " + onclick + " is not a function");
return element;
},
}
......@@ -199,4 +199,346 @@ Info.prototype = {
updateElemStyle : function () {},
resize : function () {},
/*
* */
edit: function (elem, data) {
var self = this;
var id = "edit_value";
var init_value = self.m.getStrTime(self.m.t, data);
var save_callback = function() {
var value = document.getElementById(id).value;
self.m.samples[data][self.m.t] = value
self.post_save(self);
}
this.build_input_edit(id, elem, init_value, save_callback);
},
//TODO rename
build_edit: function (input, id, elem, callback) {
var divParent = elem.parentNode;
divParent.removeAllChildren();
divParent.appendChild(input);
divParent.onclick = "";
$(input).on('save', callback);
$(input).select();
},
build_input_edit: function(id, elem, value, callback) {
var input = this.create_edit_input(id, value);
this.build_edit(input, id, elem, callback);
},
create_edit_input: function (id, value) {
var input = this.setupInput(id, "", "text", value);
this.setup_edit_input(input);
input.style.width = "200px";
input.style.border = "0px";
input.style.margin = "0px";
return input;
},
setup_edit_input: function (input) {
input.onkeydown = function (e) {
e = e || window.event;
var key = e.keyCode;
if (key === 0) key = e.which;
// if (key == 13) $(input).trigger("save");
else if (key == 27) m.update();
}
$(input).focusout(function() {
setTimeout(function() {
$(input).trigger("save");
// m.update()
}, 500);
})
},
post_save: function(self) {
self.build_top_container();
self.build_info_container();
self.m.update();
self.m.analysisHasChanged = true;
},
update_model_data: function(fieldName, value, field_parent) {
if (typeof field_parent != 'undefined')
this.m[field_parent][fieldName]= value;
else
this.m[fieldName] = value;
this.post_save(this);
},
update_model_sample_data: function(fieldName, value, field_parent) {
if (typeof field_parent != 'undefined')
this.m[field_parent][fieldName][this.m.t]= value;
else
this.m[fieldName][this.m.t] = value;
this.post_save(this);
},
create_sample_info_container: function(info, className, id, placeholder, target) {
var self = this;
var container = this.create_info_container(info, className, id, placeholder);
$(textarea).on("change", function() {
self.update_model_sample_data(target, this.value, "samples");
});
return container;
},
create_generic_info_container: function(info, className, id, placeholder, target) {
var self = this;
var container = this.create_info_container(info, className, id, placeholder);
$(textarea).on("change", function() {
self.update_model_data(target, this.value);
});
return container;
},
// TODO ambiguous with build_info_container => find another name ?
create_info_container: function (info, className, id, placeholder, target) {
var self = this;
var container = document.createElement('div');
container.className = className;
textarea = document.createElement('textarea');
textarea.id = id;
textarea.className = 'info_container';
textarea.innerHTML = info ;
textarea.setAttribute('placeholder', placeholder);
container.appendChild(textarea);
return container;
},
build_multi_system: function () {
var div = document.createElement('div');
div.className = "info_line locus_line";
var span2 = document.createElement('span');
span2.className = "locus_row";
var keys = 0;
var key_list = this.m.system_available;
key_list.sort();
var last_key = "";
var checkbox_onchange = function () {
m.toggle_system(this.id.replace("checkbox_system_",""));
}
var span_onclick = function (e) {
if (e.shiftKey) {
m.keep_one_active_system(this.firstChild.nextSibling.textContent);
} else {
this.firstChild.nextSibling.click();
}
}
for (var k in key_list) {
key = key_list[k];
// Are we at the start of a new group of locus ?
if (key.substring(0,2) != last_key.substring(0,2)) {
if (keys > 0) {
// Flush existing span2
div.appendChild(span2);
span2 = document.createElement('span');
span2.className = "locus_row";
}
}
last_key = key;
keys += 1 ;
var checkbox = this.setupInput("checkbox_system_" + key, "", "checkbox", "");
checkbox.className = "hiddenCheckBox";
checkbox.appendChild(document.createTextNode(key));
if (this.m.system_selected.indexOf(key) != -1)
checkbox.checked=true;
checkbox.onchange = checkbox_onchange;
var span_system = this.m.systemBox(key);
var span = document.createElement('span');
span.className = "systemBoxNameMenu "+key;
if (this.m.system_selected.indexOf(key) == -1)
span.className = "systemBoxNameMenu inactive " + key;
span.appendChild(span_system);
span.appendChild(checkbox);
span.appendChild(document.createTextNode(key));
span.onclick = span_onclick;
span2.appendChild(span);
}
div.appendChild(span2);
return div;
},
build_line_read_number: function (id, label, qualifier, read_number) {
var val = "no read";
var warning_title = false;
var warning_class = '' ;
if (read_number[this.m.t] > 0) {
var percent = (read_number[this.m.t] / this.m.reads.total[this.m.t]) * 100;
val = this.m.toStringThousands(read_number[this.m.t]) + " (" + percent.toFixed(2) + "%)";
if (percent < 10) {
warning_title = "Very few reads " + qualifier;
warning_class = "alert";
} else if (percent < 50) {
warning_title = "Few reads " + qualifier;
warning_class = "warning";
}
}
div = this.build_named_info_line(id, label, val, false);
if (warning_class !== "") {
var warning_span = document.createElement('span');
warning_span.className = "warningReads " + warning_class;
warning_span.appendChild(icon('icon-warning-1', warning_title));
div.appendChild(warning_span);
}
return div;
},
build_info_line: function (id, value, className) {
var val = value !== ""? value : "-/-";
var span = document.createElement('span');
if (typeof(className) !== "undefined") {
if (className) span.className = className;
}
span.appendChild(document.createTextNode(val));
var