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() {
34 GO4.ParameterEditor.prototype.DabcCommand =
function(cmd, option, callback) {
36 if (this.GetItemName()!=
"") {
37 pre = this.GetItemName() +
"/";
40 pre +=
"exe.json\?method=";
41 var fullcom = pre + cmd + option;
43 JSROOT.NewHttpRequest(fullcom,
'text',
function(res) {
44 console.log(
"DabcCommand completed.");
51 GO4.ParameterEditor.prototype.MarkChanged =
function(key) {
54 for (index = 0; index < this.changes.length; index++) {
55 if (this.changes[index]== key)
return;
57 this.changes.push(key);
58 console.log(
"Mark changed :%s", key);
59 var
id =
"#"+this.divid;
60 $(
id+
" .buttonChangeLabel").show();
63 GO4.ParameterEditor.prototype.ClearChanges =
function() {
65 var len=this.changes.length;
66 for (index = 0; index < len ; index++) {
67 var removed=this.changes.pop();
68 console.log(
"Clear changes removed :%s", removed);
70 var
id =
"#"+this.divid;
71 $(
id+
" .buttonChangeLabel").hide();
76 GO4.ParameterEditor.prototype.EvaluateChanges =
function(optionstring) {
77 var
id =
"#"+this.divid;
79 var len=this.changes.length;
80 for (index = 0; index < len ; index++) {
82 var key=this.changes[index];
83 console.log(
"Evaluate change key:%s", key);
86 var val=$(
id+
" ."+key.toString())[0].value;
88 var arraysplit=key.split(
"_");
90 if(arraysplit.length>1)
94 if(arraysplit.length>2)
96 if(arraysplit.length>3)
99 var ix=arraysplit[arraysplit.length -3];
100 var iy=arraysplit[arraysplit.length -2];
101 var iz=arraysplit[arraysplit.length -1];
102 opt+=
"["+ix+
"]["+iy+
"]["+iz+
"]";
107 var ix=arraysplit[arraysplit.length -2];
108 var iy=arraysplit[arraysplit.length -1];
109 opt+=
"["+ix+
"]["+iy+
"]";
111 var iy=arraysplit[arraysplit.length -2];
117 var ix=arraysplit[arraysplit.length -1];
126 optionstring +=
"&"+opt+
"="+val;
128 console.log(
"Resulting option string:%s", optionstring);
132 GO4.ParameterEditor.prototype.fillComments =
function() {
134 if (editor.xreq || !
this.GetItemName())
return;
135 var pre = this.GetItemName() +
"/";
137 editor.xreq = JSROOT.NewHttpRequest(pre+
"h.json?more",
'object',
function(res) {
139 if (res==null)
return;
140 var
id =
"#"+editor.divid;
141 $(
id +
" .par_values tbody").find(
"tr").each(
function(i,tr) {
142 var name = $(tr).find(
"td:first").text();
146 for (var i in res._childs) {
147 var n = res._childs[i]._name;
148 var arsplit=name.split(
"[");
151 title = res._childs[i]._title;
152 arrayinfo=res._childs[i]._arraydim;
153 typeinfo=res._childs[i]._typename;
159 $(tr).find(
"td.par_comment").text(title).css(
'white-space',
'nowrap');
162 $(tr).find(
"td.par_class").text(typeinfo).css(
'white-space',
'nowrap');
164 $(tr).parents(
'table.par_arraytable') .find(
'td.par_comment:first').text(
"Array").css(
'white-space',
'nowrap');
168 $(tr).parents(
'table.par_arraytable') .find(
'td.par_class:first').text(typeinfo+
" [" + arrayinfo+
"]").css(
'white-space',
'nowrap');
170 $(tr).parents(
'table.par_arraytable') .find(
'td.par_class:first').text(typeinfo).css(
'white-space',
'nowrap');
178 editor.xreq.send(null);
181 GO4.ParameterEditor.prototype.fillMemberTable =
function() {
183 var
id =
"#"+this.divid;
185 $(
id +
" .par_values tbody").html(
"");
186 var found_title =
false;
187 for (var key in par) {
188 if (typeof par[key] ==
'function')
continue;
189 if (key ==
'fTitle') { found_title =
true;
continue; }
190 if (!found_title)
continue;
191 var value = (par[key]!=null ? (par[key] instanceof Array ? par[key] : par[key].toString()):
"null");
193 if (value instanceof Array) {
196 var arraytableclass=key.toString()+
"_array";
198 $(
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>");
199 for(i = 0; i < value.length; i++) {
200 if(value[i] instanceof Array)
203 for (j = 0; j < subvalue.length; j++) {
204 if (subvalue[j] instanceof Array) {
205 subsubvalue = subvalue[j];
208 if (subsubvalue.length * subvalue.length * value.length > 1000) {
213 for (k = 0; k < subsubvalue.length; k++) {
215 classname = key.toString() +
"_" + i
224 $(
id +
" ." + arraytableclass +
" tbody").append(
225 "<tr><td class='par_key'>"
234 +
"]</td><td class='par_class'></td><td class='par_value'><input type='text' size='10' value='"
238 +
"'/></td><td class='par_comment'></td></tr>");
246 classname=key.toString()+
"_"+ i+
"_"+j;
248 $(
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>");
258 classname=key.toString()+
"_"+ i;
260 $(
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>");
267 $(
id +
" ." + arraytableclass +
" tbody")
269 "<tr><td class='par_key'>" + key.toString()+
"</td><td colspan='3'> Sorry, Array dimension ["
275 +
"] too big to display!</td></tr>");
279 $(
id +
" table."+arraytableclass+
" thead tr").click(
281 $(
this) .parents(
'table.par_arraytable') .children(
'tbody') .toggle();
282 $(
this) .parents(
'table.par_arraytable') .find(
'td:first').text(
283 function(i,origText){
284 var changed=origText;
285 if(origText.indexOf(
"[+]")!= -1)
286 changed=origText.replace(
"[+]",
"[-]");
287 if(origText.indexOf(
"[-]")!= -1)
288 changed=origText.replace(
"[-]",
"[+]");
292 $(
this) .parents(
'table.par_arraytable') .find(
'td.par_value:first').text(
293 function(i,origText){
294 var changed=origText;
295 if(origText.indexOf(
"expand")!= -1)
296 changed=origText.replace(
"expand",
"shrink");
297 if(origText.indexOf(
"shrink")!= -1)
298 changed=origText.replace(
"shrink",
"expand");
306 $(
id +
" table."+arraytableclass).children(
'tbody').hide();
309 classname=key.toString();
310 $(
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>");
316 $(
id +
" .par_values tbody input").change(
function(){ editor.MarkChanged($(
this).attr(
'class'))});
317 $(
id +
" .par_values tbody td").addClass(
"par_membertable_style");
318 $(
id +
" .par_values > thead th").addClass(
"par_memberheader_style");
319 $(
id +
" .par_arraytable thead td").addClass(
"par_arrayheader_style");
324 GO4.ParameterEditor.prototype.fillEditor =
function() {
327 var
id =
"#"+this.divid;
328 var width = $(id).width();
329 var height = $(id).height();
331 $(
id+
" .par_name").text(par.fName);
332 $(
id+
" .par_type").text(par._typename);
334 $(id).children().eq(0).width(width - 4).height(height - 4);
337 $(
id+
" .buttonGetParameter")
338 .button({text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle"}}).click(
function() {
339 console.log(
"update item = " + editor.GetItemName());
340 if (JSROOT.hpainter) JSROOT.hpainter.display(editor.GetItemName());
341 else console.log(
"dabc object not found!");
344 .css(
'background-image',
"url(" + GO4.source_dir +
"icons/right.png)");
348 $(
id+
" .buttonSetParameter")
349 .button({text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle" }})
352 options = editor.EvaluateChanges(options);
353 console.log(
"set - condition "+ editor.GetItemName()+
", options="+options);
354 editor.DabcCommand(
"UpdateFromUrl",options,
function(result) {
355 console.log(result ?
"set parameter done. " :
"set parameter FAILED.");
356 if(result) editor.ClearChanges();
360 .css(
'background-image',
"url(" + GO4.source_dir +
"icons/left.png)");
362 $(
id+
" .buttonChangeLabel")
363 .button({text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle"}}).click()
365 .css(
'background-image',
"url(" + GO4.source_dir +
"icons/info1.png)");
368 this.fillMemberTable();
369 console.log(
"fillEditor finished");
373 GO4.ParameterEditor.prototype.RedrawObject =
function(obj) {
374 console.log(
"ParemeterEditor RedrawObject...");
375 if (this.UpdateObject(obj))
379 GO4.ParameterEditor.prototype.UpdateObject =
function(obj) {
380 if (obj._typename !=
this.par._typename)
return false;
381 console.log(
"ParemeterEditor UpdateObject...");
382 this.par= JSROOT.clone(obj);
386 GO4.ParameterEditor.prototype.Redraw =
function() {
387 console.log(
"ParemeterEditor Redraw...");
388 this.fillMemberTable();
391 GO4.ParameterEditor.prototype.drawEditor =
function(divid) {
394 $(
"#"+divid).empty();
395 $(
"#"+divid).load( GO4.source_dir +
"html/pareditor.htm",
"",
function() {
396 pthis.SetDivId(divid);
398 pthis.fillComments();
399 pthis.DrawingReady();
405 GO4.ParameterEditor.prototype.SetItemName =
function(name) {
406 JSROOT.TBasePainter.prototype.SetItemName.call(
this, name);
410 GO4.drawParameter =
function(divid, par, option, painter) {
411 var h = $(
"#"+divid).height(), w = $(
"#"+divid).width();
412 if ((h<10) && (w>10)) $(
"#"+divid).height(w*0.4);
413 var editor =
new GO4.ParameterEditor(par);
414 if (painter) editor = JSROOT.extend(painter, editor);
415 return editor.drawEditor(divid);