3 if (typeof JSROOT !=
"object") {
4 var e1 =
new Error(
"pareditor.js requires JSROOT to be already loaded");
5 e1.source =
"pareditor.js";
9 if (typeof GO4 !=
"object") {
10 var e1 =
new Error(
"pareditor.js requires GO4 to be already loaded");
11 e1.source =
"pareditor.js";
17 GO4.ParameterEditor =
function(par) {
18 JSROOT.TBasePainter.call(
this);
20 this.changes = [
"dummy",
"init"];
23 GO4.ParameterEditor.prototype = Object.create(JSROOT.TBasePainter.prototype);
25 GO4.ParameterEditor.prototype.CheckResize =
function() {
29 GO4.ParameterEditor.prototype.DabcCommand =
function(cmd, option, callback) {
31 if (this.GetItemName()!=
"") {
32 pre = this.GetItemName() +
"/";
35 pre +=
"exe.json\?method=";
36 var fullcom = pre + cmd + option;
38 JSROOT.NewHttpRequest(fullcom,
'text',
function(res) {
39 console.log(
"DabcCommand completed.");
46 GO4.ParameterEditor.prototype.MarkChanged =
function(key) {
48 for (var index = 0; index < this.changes.length; index++) {
49 if (this.changes[index]== key)
return;
51 this.changes.push(key);
52 console.log(
"Mark changed :%s", key);
53 var
id =
"#" + this.get_main_id();
54 $(
id+
" .buttonChangeLabel").show();
58 GO4.ParameterEditor.prototype.ClearChanges =
function() {
60 var len=this.changes.length;
61 for (index = 0; index < len ; index++) {
62 var removed=this.changes.pop();
63 console.log(
"Clear changes removed :%s", removed);
65 var
id =
"#" + this.get_main_id();
66 $(
id+
" .buttonChangeLabel").hide();
70 GO4.ParameterEditor.prototype.EvaluateChanges =
function(optionstring) {
71 var
id =
"#" + this.get_main_id();
72 var len = this.changes.length;
73 for (var index = 0; index < len ; index++) {
75 var key = this.changes[index];
76 console.log(
"Evaluate change key:%s", key);
79 var val=$(
id+
" ."+key.toString())[0].value;
81 var arraysplit=key.split(
"_");
83 if(arraysplit.length>1)
87 if(arraysplit.length>2)
89 if(arraysplit.length>3)
92 var ix=arraysplit[arraysplit.length -3];
93 var iy=arraysplit[arraysplit.length -2];
94 var iz=arraysplit[arraysplit.length -1];
95 opt+=
"["+ix+
"]["+iy+
"]["+iz+
"]";
100 var ix=arraysplit[arraysplit.length -2];
101 var iy=arraysplit[arraysplit.length -1];
102 opt+=
"["+ix+
"]["+iy+
"]";
104 var iy=arraysplit[arraysplit.length -2];
110 var ix=arraysplit[arraysplit.length -1];
119 optionstring +=
"&"+opt+
"="+val;
121 console.log(
"Resulting option string:%s", optionstring);
125 GO4.ParameterEditor.prototype.fillComments =
function() {
127 if (editor.xreq || !
this.GetItemName())
return;
128 var pre = this.GetItemName() +
"/";
130 editor.xreq = JSROOT.NewHttpRequest(pre+
"h.json?more",
'object',
function(res) {
133 var
id =
"#" + editor.get_main_id();
134 $(
id +
" .par_values tbody").find(
"tr").each(
function(i,tr) {
135 var name = $(tr).find(
"td:first").text();
137 var arrayinfo = null;
139 for (var i in res._childs) {
140 var n = res._childs[i]._name;
141 var arsplit=name.split(
"[");
144 title = res._childs[i]._title;
145 arrayinfo=res._childs[i]._arraydim;
146 typeinfo=res._childs[i]._typename;
152 $(tr).find(
"td.par_comment").text(title).css(
'white-space',
'nowrap');
155 $(tr).find(
"td.par_class").text(typeinfo).css(
'white-space',
'nowrap');
157 $(tr).parents(
'table.par_arraytable') .find(
'td.par_comment:first').text(
"Array").css(
'white-space',
'nowrap');
161 $(tr).parents(
'table.par_arraytable') .find(
'td.par_class:first').text(typeinfo+
" [" + arrayinfo+
"]").css(
'white-space',
'nowrap');
163 $(tr).parents(
'table.par_arraytable') .find(
'td.par_class:first').text(typeinfo).css(
'white-space',
'nowrap');
171 editor.xreq.send(null);
174 GO4.ParameterEditor.prototype.fillMemberTable =
function() {
176 var
id =
"#" + this.get_main_id();
178 $(
id +
" .par_values tbody").html(
"");
179 var found_title =
false;
180 for (var key in par) {
181 if (typeof par[key] ==
'function')
continue;
182 if (key ==
'fTitle') { found_title =
true;
continue; }
183 if (!found_title)
continue;
184 var value = (par[key]!=null ? (par[key] instanceof Array ? par[key] : par[key].toString()):
"null");
186 if (value instanceof Array) {
189 var arraytableclass=key.toString()+
"_array";
191 $(
id +
" .par_values > tbody").append(
"<tr><td style='width:100%; padding:0px' colspan='4' > <table class='"+arraytableclass+
" par_arraytable'><thead><tr><td class='par_key'> <bf>[+]</bf> "+ key.toString()+
"</td><td class='par_class'></td><td class='par_value' >Click to expand</td><td class='par_comment'></td></tr></thead><tbody></tbody></table></td></tr>");
192 for(i = 0; i < value.length; i++) {
193 if(value[i] instanceof Array)
196 for (j = 0; j < subvalue.length; j++) {
197 if (subvalue[j] instanceof Array) {
198 subsubvalue = subvalue[j];
201 if (subsubvalue.length * subvalue.length * value.length > 1000) {
206 for (k = 0; k < subsubvalue.length; k++) {
208 classname = key.toString() +
"_" + i
217 $(
id +
" ." + arraytableclass +
" tbody").append(
218 "<tr><td class='par_key'>"
227 +
"]</td><td class='par_class'></td><td class='par_value'><input type='text' size='10' value='"
231 +
"'/></td><td class='par_comment'></td></tr>");
239 classname=key.toString()+
"_"+ i+
"_"+j;
241 $(
id +
" ."+arraytableclass+
" tbody").append(
"<tr><td class='par_key'>" + key.toString() +
"[" + i +
"]["+j+
"]</td><td class='par_class'></td><td class='par_value'><input type='text' size='10' value='" + subvalue[j] +
"' class='"+ classname +
"'/></td><td class='par_comment'></td></tr>");
251 classname=key.toString()+
"_"+ i;
253 $(
id +
" ."+arraytableclass+
" tbody").append(
"<tr><td class='par_key'>" + key.toString() +
"[" + i +
"]</td><td class='par_class'></td><td class='par_value'><input type='text' size='10' value='" + value[i] +
"' class='"+ classname +
"'/></td><td class='par_comment'></td></tr>");
260 $(
id +
" ." + arraytableclass +
" tbody")
262 "<tr><td class='par_key'>" + key.toString()+
"</td><td colspan='3'> Sorry, Array dimension ["
268 +
"] too big to display!</td></tr>");
272 $(
id +
" table."+arraytableclass+
" thead tr").click(
274 $(
this) .parents(
'table.par_arraytable') .children(
'tbody') .toggle();
275 $(
this) .parents(
'table.par_arraytable') .find(
'td:first').text(
276 function(i,origText){
277 var changed=origText;
278 if(origText.indexOf(
"[+]")!= -1)
279 changed=origText.replace(
"[+]",
"[-]");
280 if(origText.indexOf(
"[-]")!= -1)
281 changed=origText.replace(
"[-]",
"[+]");
285 $(
this) .parents(
'table.par_arraytable') .find(
'td.par_value:first').text(
286 function(i,origText){
287 var changed=origText;
288 if(origText.indexOf(
"expand")!= -1)
289 changed=origText.replace(
"expand",
"shrink");
290 if(origText.indexOf(
"shrink")!= -1)
291 changed=origText.replace(
"shrink",
"expand");
299 $(
id +
" table."+arraytableclass).children(
'tbody').hide();
302 classname=key.toString();
303 $(
id +
" .par_values > tbody").append(
"<tr><td class='par_key'>" + key.toString() +
"</td><td class='par_class'></td><td class='par_value'><input type='text' size='10' value='" + value +
"' class='"+classname+
"'/></td><td class='par_comment'></td></tr>");
309 $(
id +
" .par_values tbody input").change(
function(){ editor.MarkChanged($(
this).attr(
'class'))});
310 $(
id +
" .par_values tbody td").addClass(
"par_membertable_style");
311 $(
id +
" .par_values > thead th").addClass(
"par_memberheader_style");
312 $(
id +
" .par_arraytable thead td").addClass(
"par_arrayheader_style");
317 GO4.ParameterEditor.prototype.fillEditor =
function() {
320 var
id =
"#" + this.get_main_id();
321 var width = $(id).width();
322 var height = $(id).height();
324 $(
id+
" .par_name").text(par.fName);
325 $(
id+
" .par_type").text(par._typename);
327 $(id).children().eq(0).width(width - 4).height(height - 4);
330 $(
id+
" .buttonGetParameter")
331 .button({text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle"}}).click(
function() {
332 console.log(
"update item = " + editor.GetItemName());
333 if (JSROOT.hpainter) JSROOT.hpainter.display(editor.GetItemName());
334 else console.log(
"dabc object not found!");
337 .css(
'background-image',
"url(" + GO4.source_dir +
"icons/right.png)");
341 $(
id+
" .buttonSetParameter")
342 .button({text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle" }})
345 options = editor.EvaluateChanges(options);
346 console.log(
"set - condition "+ editor.GetItemName()+
", options="+options);
347 editor.DabcCommand(
"UpdateFromUrl",options,
function(result) {
348 console.log(result ?
"set parameter done. " :
"set parameter FAILED.");
349 if(result) editor.ClearChanges();
353 .css(
'background-image',
"url(" + GO4.source_dir +
"icons/left.png)");
355 $(
id+
" .buttonChangeLabel")
356 .button({text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle"}}).click()
358 .css(
'background-image',
"url(" + GO4.source_dir +
"icons/info1.png)");
361 this.fillMemberTable();
362 console.log(
"fillEditor finished");
366 GO4.ParameterEditor.prototype.RedrawObject =
function(obj) {
367 console.log(
"ParemeterEditor RedrawObject...");
368 if (this.UpdateObject(obj))
372 GO4.ParameterEditor.prototype.UpdateObject =
function(obj) {
373 if (obj._typename !=
this.par._typename)
return false;
374 console.log(
"ParemeterEditor UpdateObject...");
375 this.par= JSROOT.clone(obj);
379 GO4.ParameterEditor.prototype.Redraw =
function() {
380 console.log(
"ParemeterEditor Redraw...");
381 this.fillMemberTable();
384 GO4.ParameterEditor.prototype.drawEditor =
function(divid) {
387 $(
"#"+divid).empty();
388 $(
"#"+divid).load( GO4.source_dir +
"html/pareditor.htm",
"",
function() {
389 pthis.SetDivId(divid);
391 pthis.fillComments();
392 pthis.DrawingReady();
398 GO4.ParameterEditor.prototype.SetItemName =
function(name) {
399 JSROOT.TBasePainter.prototype.SetItemName.call(
this, name);
403 GO4.drawParameter =
function(divid, par, option) {
404 var h = $(
"#"+divid).height(), w = $(
"#"+divid).width();
405 if ((h<10) && (w>10)) $(
"#"+divid).height(w*0.4);
406 var editor =
new GO4.ParameterEditor(par);
407 return editor.drawEditor(divid);