6 var e1 =
new Error(
"pareditor.js requires JSROOT to be already loaded");
7 e1.source =
"pareditor.js";
11 if (typeof
GO4 !=
"object") {
12 var e1 =
new Error(
"pareditor.js requires GO4 to be already loaded");
13 e1.source =
"pareditor.js";
21 GO4.ParameterEditor =
function(divid, par) {
22 BasePainter.call(
this, divid);
23 if (this.SetDivId) this.SetDivId(divid);
25 this.changes = [
"dummy",
"init"];
28 GO4.ParameterEditor.prototype = Object.create(BasePainter.prototype);
30 GO4.ParameterEditor.prototype.CheckResize =
function() { }
31 GO4.ParameterEditor.prototype.checkResize =
function() { }
35 GO4.ParameterEditor.prototype.MarkChanged =
function(key) {
37 for (var index = 0; index < this.changes.length; index++) {
38 if (this.changes[index] == key)
return;
40 this.changes.push(key);
41 console.log(
"Mark changed :%s", key);
42 var
id =
"#" + this.get_main_id();
43 $(
id +
" .buttonChangeLabel").show();
47 GO4.ParameterEditor.prototype.ClearChanges =
function() {
49 var len = this.changes.length;
50 for (index = 0; index < len; index++) {
51 var removed = this.changes.pop();
52 console.log(
"Clear changes removed :%s", removed);
54 var
id =
"#" + this.get_main_id();
55 $(
id +
" .buttonChangeLabel").hide();
59 GO4.ParameterEditor.prototype.EvaluateChanges =
function(optionstring) {
60 var
id =
"#" + this.get_main_id();
61 var len = this.changes.length;
62 for (var index = 0; index < len; index++) {
64 var key = this.changes[index];
65 console.log(
"Evaluate change key:%s", key);
68 var val = $(
id +
" ." + key.toString())[0].value;
70 var arraysplit = key.split(
"_");
72 if (arraysplit.length > 1) {
75 if (arraysplit.length > 2) {
76 if (arraysplit.length > 3) {
78 var ix = arraysplit[arraysplit.length - 3];
79 var iy = arraysplit[arraysplit.length - 2];
80 var iz = arraysplit[arraysplit.length - 1];
81 opt +=
"[" + ix +
"][" + iy +
"][" + iz +
"]";
85 var ix = arraysplit[arraysplit.length - 2];
86 var iy = arraysplit[arraysplit.length - 1];
87 opt +=
"[" + ix +
"][" + iy +
"]";
89 var iy = arraysplit[arraysplit.length - 2];
94 var ix = arraysplit[arraysplit.length - 1];
95 opt +=
"[" + ix +
"]";
102 optionstring +=
"&" + opt +
"=" + val;
104 console.log(
"Resulting option string:%s", optionstring);
108 GO4.ParameterEditor.prototype.fillComments =
function() {
110 if (editor.xreq || !
this.getItemName())
return;
111 var pre = this.getItemName() +
"/";
114 GO4.httpRequest(pre +
"h.json?more",
'object').then(res => {
115 var
id =
"#" + editor.get_main_id();
116 $(
id +
" .par_values tbody").find(
"tr").each(
function(i, tr) {
117 var name = $(tr).find(
"td:first").text();
119 var arrayinfo = null;
121 for (var i in res._childs) {
122 var n = res._childs[i]._name;
123 var arsplit = name.split(
"[");
124 if (arsplit[0] == n) {
126 title = res._childs[i]._title;
127 arrayinfo = res._childs[i]._arraydim;
128 typeinfo = res._childs[i]._typename;
134 $(tr).find(
"td.par_comment").text(title).css(
'white-space',
'nowrap');
135 if (typeinfo != null) {
136 $(tr).find(
"td.par_class").text(typeinfo).css(
'white-space',
'nowrap');
138 $(tr).parents(
'table.par_arraytable').find(
'td.par_comment:first').text(
"Array").css(
'white-space',
'nowrap');
141 if (arrayinfo != null)
142 $(tr).parents(
'table.par_arraytable').find(
'td.par_class:first').text(typeinfo +
" [" + arrayinfo +
"]").css(
'white-space',
'nowrap');
144 $(tr).parents(
'table.par_arraytable').find(
'td.par_class:first').text(typeinfo).css(
'white-space',
'nowrap');
150 }).
finally(() => { editor.xreq =
false; });
154 GO4.ParameterEditor.prototype.fillMemberTable =
function() {
156 var
id =
"#" + this.get_main_id();
158 $(
id +
" .par_values tbody").html(
"");
159 var found_title =
false;
160 for (var key in par) {
161 if (typeof par[key] ==
'function')
continue;
162 if (key ==
'fTitle') { found_title =
true;
continue; }
163 if (!found_title)
continue;
164 var value = (par[key] != null ? (par[key] instanceof Array ? par[key] : par[key].toString()) :
"null");
166 if (value instanceof Array) {
169 var arraytableclass = key.toString() +
"_array";
170 var isTooBig =
false;
171 $(
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>");
172 for (i = 0; i < value.length; i++) {
173 if (value[i] instanceof Array) {
175 for (j = 0; j < subvalue.length; j++) {
176 if (subvalue[j] instanceof Array) {
177 subsubvalue = subvalue[j];
180 if (subsubvalue.length * subvalue.length * value.length > 1000) {
185 for (k = 0; k < subsubvalue.length; k++) {
187 classname = key.toString() +
"_" + i
196 $(
id +
" ." + arraytableclass +
" tbody").append(
197 "<tr><td class='par_key'>"
199 +
"[" + i +
"][" + j +
"][" + k +
"]"
200 +
"</td><td class='par_class'></td><td class='par_value'><input type='text' size='10' value='"
202 +
"' class='" + classname +
"'/></td><td class='par_comment'></td></tr>");
209 classname = key.toString() +
"_" + i +
"_" + j;
211 $(
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>");
220 classname = key.toString() +
"_" + i;
222 $(
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>");
228 $(
id +
" ." + arraytableclass +
" tbody")
230 "<tr><td class='par_key'>" + key.toString() +
"</td><td colspan='3'> Sorry, Array dimension ["
236 +
"] too big to display!</td></tr>");
240 $(
id +
" table." + arraytableclass +
" thead tr").click(
242 $(
this).parents(
'table.par_arraytable').children(
'tbody').toggle();
243 $(
this).parents(
'table.par_arraytable').find(
'td:first').text(
244 function(i, origText) {
245 var changed = origText;
246 if (origText.indexOf(
"[+]") != -1)
247 changed = origText.replace(
"[+]",
"[-]");
248 if (origText.indexOf(
"[-]") != -1)
249 changed = origText.replace(
"[-]",
"[+]");
253 $(
this).parents(
'table.par_arraytable').find(
'td.par_value:first').text(
254 function(i, origText) {
255 var changed = origText;
256 if (origText.indexOf(
"expand") != -1)
257 changed = origText.replace(
"expand",
"shrink");
258 if (origText.indexOf(
"shrink") != -1)
259 changed = origText.replace(
"shrink",
"expand");
267 $(
id +
" table." + arraytableclass).children(
'tbody').hide();
270 classname = key.toString();
271 $(
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>");
276 $(
id +
" .par_values tbody input").change(
function() { editor.MarkChanged($(
this).attr(
'class')) });
277 $(
id +
" .par_values tbody td").addClass(
"par_membertable_style");
278 $(
id +
" .par_values > thead th").addClass(
"par_memberheader_style");
279 $(
id +
" .par_arraytable thead td").addClass(
"par_arrayheader_style");
284 GO4.ParameterEditor.prototype.fillEditor =
function() {
287 var
id =
"#" + this.get_main_id();
288 var width = $(id).width();
289 var height = $(id).height();
291 $(
id +
" .par_name").text(par.fName);
292 $(
id +
" .par_type").text(par._typename);
294 $(id).children().eq(0).width(width - 4).height(height - 4);
296 $(
id +
" .buttonGetParameter")
297 .button({ text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle" } }).click(
function() {
298 console.log(
"update item = " + editor.getItemName());
300 JSROOT.hpainter.display(editor.getItemName());
302 console.log(
"dabc object not found!");
305 .css(
'background-image',
"url(" +
GO4.source_dir +
"icons/right.png)");
307 $(
id +
" .buttonSetParameter")
308 .button({ text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle" } })
311 options = editor.EvaluateChanges(options);
312 console.log(
"set - condition " + editor.getItemName() +
", options=" + options);
313 GO4.ExecuteMethod(editor,
"UpdateFromUrl", options,
function(result) {
314 console.log(result ?
"set parameter done. " :
"set parameter FAILED.");
315 if (result) editor.ClearChanges();
319 .css(
'background-image',
"url(" +
GO4.source_dir +
"icons/left.png)");
321 $(
id +
" .buttonChangeLabel")
322 .button({ text:
false, icons: { primary:
"ui-icon-blank MyButtonStyle" } }).click()
324 .css(
'background-image',
"url(" +
GO4.source_dir +
"icons/info1.png)");
327 this.fillMemberTable();
332 GO4.ParameterEditor.prototype.redrawObject =
function(obj) {
333 if (obj._typename !=
this.par._typename)
return false;
334 this.par =
JSROOT.clone(obj);
339 GO4.ParameterEditor.prototype.setItemName =
function(name, opt, hpainter) {
340 BasePainter.prototype.setItemName.call(
this, name, opt, hpainter);
347 GO4.ParameterEditor.prototype.RedrawPad =
function(resize) {
352 GO4.ParameterEditor.prototype.UpdateObject =
function(obj) {
353 if (obj._typename !=
this.par._typename)
return false;
354 this.par =
JSROOT.clone(obj);
358 GO4.ParameterEditor.prototype.SetItemName =
function(name, opt, hpainter) {
359 BasePainter.prototype.SetItemName.call(
this, name, opt, hpainter);
366 GO4.ParameterEditor.prototype.redraw =
function() {
367 console.log(
"ParemeterEditor Redraw...");
368 this.fillMemberTable();
373 if (!
JSROOT._)
GO4.ParameterEditor.prototype.Redraw =
GO4.ParameterEditor.prototype.redraw;
375 GO4.ParameterEditor.prototype.drawEditor =
function() {
377 var sel =
JSROOT._ ? this.selectDom() : this.select_main();
379 var
main = $(sel.node());
381 var h = main.height(), w = main.width();
382 if ((h < 10) && (w > 10)) main.height(w * 0.4);
386 function loadEditor(resolve) {
388 main.load(
GO4.source_dir +
"html/pareditor.htm",
"",
function() {
390 pthis.fillComments();
392 pthis.setTopPainter();
395 pthis.SetDivId(this.divid);
396 pthis.DrawingReady();
403 return new Promise(resolve => loadEditor(resolve));
409 GO4.drawParameter =
function(divid, par ) {
410 var editor =
new GO4.ParameterEditor(divid, par);
411 return editor.drawEditor();
int main(int argc, char **argv)