(function(){ if (typeof JSROOT != "object") { var e1 = new Error("pareditor.js requires JSROOT to be already loaded"); e1.source = "pareditor.js"; throw e1; } if (typeof GO4 != "object") { var e1 = new Error("pareditor.js requires GO4 to be already loaded"); e1.source = "pareditor.js"; throw e1; } // =========================================================================================== GO4.ParameterEditor = function(par) { JSROOT.TBasePainter.call(this); this.par = par; this.changes = ["dummy", "init"]; // TODO: put to common "base class" of condition and parameter editor } GO4.ParameterEditor.prototype = Object.create(JSROOT.TBasePainter.prototype); GO4.ParameterEditor.prototype.CheckResize = function() { // var id = "#"+this.divid; // var width = $(id).width(); // var height = $(id).height(); // $(id).children().eq(0).width(width - 4).height(height - 4); } // TODO: put to common "base class" of condition and parameter editor GO4.ParameterEditor.prototype.DabcCommand = function(cmd, option, callback) { var pre=""; if (this.GetItemName()!="") { // note: check against !=null does not work here! pre = this.GetItemName() + "/"; // suppress / if item name is empty //console.log("Found non null itemname= -"+this.GetItemName()+"-"); } pre +="exe.json\?method="; var fullcom = pre + cmd + option; JSROOT.NewHttpRequest(fullcom, 'text', function(res) { console.log("DabcCommand completed."); callback(res!=null); }).send(null); } // TODO: put to common "base class" of condition and parameter editor // add identifier of changed element to list, make warning sign visible GO4.ParameterEditor.prototype.MarkChanged = function(key) { // first avoid duplicate keys: var index; for (index = 0; index < this.changes.length; index++) { if (this.changes[index]== key) return; } this.changes.push(key); console.log("Mark changed :%s", key); var id = "#"+this.divid; $(id+" .buttonChangeLabel").show();// show warning sign } // TODO: put to common "base class" of condition and parameter editor GO4.ParameterEditor.prototype.ClearChanges = function() { var index; var len=this.changes.length; for (index = 0; index < len ; index++) { var removed=this.changes.pop(); console.log("Clear changes removed :%s", removed); } var id = "#"+this.divid; $(id+" .buttonChangeLabel").hide(); // hide warning sign } // scan changed value list and return optionstring to be send to server GO4.ParameterEditor.prototype.EvaluateChanges = function(optionstring) { var id = "#"+this.divid; var index; var len=this.changes.length; for (index = 0; index < len ; index++) { //var cursor=changes.pop(); var key=this.changes[index]; console.log("Evaluate change key:%s", key); // here mapping of key to editor field: // key will be name of variable which is class name of input field: var val=$(id+" ."+key.toString())[0].value; //var opt= key.replace(/_/g, "[").replace(/-/g, "]"); // old with other placeholders var arraysplit=key.split("_"); var opt=""; if(arraysplit.length>1) { // found array with index after separator, reformat it: opt=arraysplit[0]; if(arraysplit.length>2) { if(arraysplit.length>3) { // 3dim array: var ix=arraysplit[arraysplit.length -3]; // var iy=arraysplit[arraysplit.length -2]; // var iz=arraysplit[arraysplit.length -1]; // opt+="["+ix+"]["+iy+"]["+iz+"]"; } else { // 2dim array: var ix=arraysplit[arraysplit.length -2]; // var iy=arraysplit[arraysplit.length -1]; // opt+="["+ix+"]["+iy+"]"; } var iy=arraysplit[arraysplit.length -2]; // } else { // 1dim array: opt=arraysplit[0]; var ix=arraysplit[arraysplit.length -1]; // opt+="["+ix+"]"; } } else { opt=key; } optionstring +="&"+opt+"="+val; }// for index console.log("Resulting option string:%s", optionstring); return optionstring; } GO4.ParameterEditor.prototype.fillComments = function() { var editor = this; if (editor.xreq || !this.GetItemName()) return; // avoid double requests var pre = this.GetItemName() + "/"; editor.xreq = JSROOT.NewHttpRequest(pre+"h.json?more", 'object', function(res) { editor.xreq = null; if (res==null) return; var id = "#"+editor.divid; $(id + " .par_values tbody").find("tr").each( function(i,tr) { var name = $(tr).find("td:first").text(); var title = null; var arrayinfo=null; var typeinfo=null; for (var i in res._childs) { var n = res._childs[i]._name; var arsplit=name.split("["); // remove array information at the end, if any if (arsplit[0]==n) { //if ((name==n) || (name.indexOf(n)==0)) { title = res._childs[i]._title; arrayinfo=res._childs[i]._arraydim; typeinfo=res._childs[i]._typename; //console.log("found title="+title+", arrayinfo="+arrayinfo); break; } } if (title!=null) $(tr).find("td.par_comment").text(title).css('white-space', 'nowrap'); // comments from class member declaration if (typeinfo!=null) { $(tr).find("td.par_class").text(typeinfo).css('white-space', 'nowrap'); // member type $(tr).parents('table.par_arraytable') .find('td.par_comment:first').text("Array").css('white-space', 'nowrap'); // if we are inside array table, indicate that we are an array if (arrayinfo!=null) $(tr).parents('table.par_arraytable') .find('td.par_class:first').text(typeinfo+ " [" + arrayinfo+"]").css('white-space', 'nowrap'); else $(tr).parents('table.par_arraytable') .find('td.par_class:first').text(typeinfo).css('white-space', 'nowrap'); // put type information of array to subtable header } }); }); editor.xreq.send(null); } GO4.ParameterEditor.prototype.fillMemberTable = function() { var editor=this; var id = "#"+this.divid; var par = this.par; $(id + " .par_values tbody").html(""); var found_title = false; for (var key in par) { if (typeof par[key] == 'function') continue; if (key == 'fTitle') { found_title = true; continue; } if (!found_title) continue; var value = (par[key]!=null ? (par[key] instanceof Array ? par[key] : par[key].toString()): "null"); var classname=""; if (value instanceof Array) { // here put array table with clickable header: // (thanks to Jonathan at http://mediaformations.com/accordion-tables-with-jquery/ for this idea!) var arraytableclass=key.toString()+"_array"; var isTooBig=false; $(id + " .par_values > tbody").append("
| Click to expand |