1
function CONFIG_CONFIG() {
7
this.experiment = "0-0";
11
this.frame_height = 0;
15
function CONFIG_EXTRA() {
18
this.mask_mode = null;
22
CONFIG_CONFIG.prototype.Clone = function() {
31
this.cfg = new CONFIG_CONFIG;
32
this.cfg_extra = new CONFIG_EXTRA;
34
this.open_module = null;
46
this.initializing = true;
48
this.objlist = new Array;
50
this.history = new HISTORY(this.HistoryEvent(this));
53
CONFIG.prototype.RegisterUpdater = function(updater) {
54
// DS: Multiple updaters support
55
this.updater = updater;
58
CONFIG.prototype.Register = function(obj) {
59
this.objlist.push(obj);
62
CONFIG.prototype.SetSource = function(server, db, group, mask) {
63
this.cfg.db_server = server;
64
this.cfg.db_name = db;
65
this.cfg.db_group = group;
66
this.cfg.db_mask = mask;
69
CONFIG.prototype.SetInterval = function(from, to) {
70
this.cfg.experiment = from + '-' + to;
73
CONFIG.prototype.SetWindow = function(width, from, to, miny, maxy) {
86
if ((this.win_from!=this.win_to)&&(this.win_min!=this.win_max)) {
87
this.cfg.window = this.win_from + '-' + this.win_to + ',' + this.win_min + ':' + this.win_max;
88
} else if (this.win_min!=this.win_max) {
89
this.cfg.window = this.win_min + ':' + this.win_max;
90
} else if (this.win_from!=this.win_to) {
91
this.cfg.window = this.win_from + '-' + this.win_to;
97
this.win_width = width;
104
this.cfg.window = width;
108
CONFIG.prototype.SetSelection = function(from, to) {
109
if (typeof from == "undefined") {
113
this.sel_from = from;
119
CONFIG.prototype.SetExportSettings = function(format, resample, mask_mode) {
120
if (format) this.cfg_extra.format = format;
121
if (resample) this.cfg_extra.resample = resample;
122
if (mask_mode) this.cfg_extra.mask_mode = mask_mode;
124
this.updater.Notify("ExportSettings");
129
CONFIG.prototype.ParseWindow = function(winprm) {
132
if (typeof win == "undefined") win = this.cfg.window;
144
var p = win.split(",");
146
if ((p.legth < 1)||(p.length > 2)) err = true;
148
var process = function(self, prm) {
149
var t = prm.split("-");
151
if ((t.length == 2)&&(t[0].length>0)) {
152
if ((isNaN(t[0]))||(isNaN(t[1]))) return true;
154
self.win_from = t[0];
161
if ((isNaN(t[0]))||(isNaN(t[1]))) return true;
171
err = process(this, p[0]);
172
if ((!err)&&(p.length == 2)) err = process(this, p[1]);
178
alert("Invalid window: '" + win + "'");
181
this.win_width = win;
189
if (typeof win != "undefined") {
190
this.SetWindow(this.win_width, this.win_from, this.win_to, this.min, this.max);
194
CONFIG.prototype.ApplyConfig = function(save_on_apply, filter) {
197
this.onConfirmation = this.UpdateAndSaveFunction(this, save_on_apply, filter);
199
var len = this.objlist.length;
200
for (var i = 0; i < len; i++) {
201
var obj = this.objlist[i];
202
// if (typeof obj.ReadConifg == "function") { // DS: Comparison fails in Firefox
203
if (obj.ReadConfig) {
204
var opts = new Object({
209
if (typeof filter != "undefined")
210
eval("if (obj instanceof " + filter + ") obj.ReadConfig(opts);");
212
obj.ReadConfig(opts);
216
// if (this.updater) this.updater.Update();
219
CONFIG.prototype.UpdateAndSaveFunction = function(self, save_on_apply, filter) {
221
//alert(this.cfg.db_server + "-" + this.cfg.db_name);
223
var len = self.objlist.length;
224
for (var i = 0; i < len; i++) {
225
var obj = self.objlist[i];
226
if (obj.ApplyConfig) {
227
if (typeof filter != "undefined")
228
eval("if (obj instanceof " + filter + ") obj.ApplyConfig(true);");
230
obj.ApplyConfig(true);
235
if (self.updater) self.updater.Update();
236
if (save_on_apply) self.Save();
241
CONFIG.prototype.UpdateFunction = function(self) {
243
if (self.updater) self.updater.Update();
248
CONFIG.prototype.SetupGeometry = function(node, y) {
249
if (typeof node == "object") {
250
this.cfg.frame_width = node.offsetWidth - 5;
251
this.cfg.frame_height = node.offsetHeight - 5;
253
this.cfg.frame_width = node - 5;
254
this.cfg.frame_height = y - 5;
259
CONFIG.prototype.Setup = function(src, ivl, wnd) {
261
SetSource(src.db_server, src.db_name, src.db_group, src.db_mask);
262
SetInterval(ivl.start, ivl.end);
263
SetWindow(wnd.width, wnd.from, wnd.to, wnd.miny, wnd.maxy);
269
CONFIG.prototype.SetupModule = function(m) {
270
this.open_module = m;
274
CONFIG.prototype.GetConfig = function() {
278
CONFIG.prototype.GetJSON = function(addon) {
279
if (typeof addon == "undefined") return Object.toJSON(this.cfg);
280
else return Object.toJSON(Object.extend(this.cfg.Clone(), addon));
283
CONFIG.prototype.GetProps = function(window_type) {
286
//if (!(cfg instanceof CONFIG_CONFIG)) cfg = this.cfg;
290
if (typeof window_type != "undefined") {
291
if (window_type > 0) {
293
} else if (window_type < 0) {
294
if (this.sel_from != this.sel_to)
295
win = this.sel_from + "-" + this.sel_to;
297
adeiReportError("The selection is empty. Storing full window", "CONFIG");
302
res = "db_server=" + db_server + "&db_name=" + db_name + "&db_group=" + db_group + "&db_mask=" + db_mask + "&experiment=" + experiment + "&window=" + win;
308
with (this.cfg_extra) {
309
if (format) res += "&format=" + format;
310
if (resample) res += "&resample=" + resample;
311
if (mask_mode) res += "&mask_mode=" + mask_mode;
317
CONFIG.prototype.ParseProps = function(props) {
319
var cfg = new CONFIG_CONFIG();
320
var extra = new CONFIG_EXTRA();
322
var vars = props.split("&");
323
for (var i = 0; i < vars.length; i++) {
324
var pair = vars[i].split("=",2);
325
if (pair.length != 2) continue;
327
if (typeof cfg[pair[0]] != "undefined") {
328
cfg[pair[0]] = pair[1];
331
else if (typeof extra[pair[0]] != "undefined") {
332
extra[pair[0]] = pair[1];
337
if (done) return new Object({'cfg': cfg, 'extra': extra});
342
CONFIG.prototype.Save = function() {
343
if ((this.cfg)&&(this.history)) {
344
this.history.Add(this.GetProps(), this.cfg.Clone());
348
CONFIG.prototype.FixLocation = function(props) {
349
if ((this.cfg)&&(this.history)) {
350
if (typeof props == "undefined")
351
var props = this.history.GetProps();
353
var new_props = this.GetProps();
355
if (props != new_props) {
356
var orig = window.location.toString();
358
if (orig.match('#')) {
359
replacement = orig.replace(/#.*$/, '#' + new_props);
360
this.history.AddSynonim(props, new_props);
361
} else replacement = '#' + new_props;
362
window.location.replace(replacement);
367
CONFIG.prototype.ReplaceURL = function() {
371
CONFIG.prototype.ReplaceConfig = function() {
372
if ((this.cfg)&&(this.history)) {
374
history.back(); // prevent complains from history module???
375
var props = this.history.GetProps();
376
var new_props = this.GetProps();
378
this.history.Replace(props, new_props, this.cfg.Clone());*/
379
alert('not supported, yet');
383
CONFIG.prototype.HistoryEvent = function (self) {
384
return function (newLocation, historyData) {
385
if ((!historyData)||(typeof historyData.Clone != "function")) {
386
//return self.Load();
390
self.cfg = historyData.Clone();
391
self.FixLocation(newLocation);
396
CONFIG.prototype.Load = function() {
397
var props = this.history.GetProps();
399
var cfg = this.ParseProps(props);
402
this.cfg_extra = cfg.extra;
404
this.ApplyConfig(true);
409
CONFIG.prototype.ApplyDataSource = function(srv, db, grp, mask, exp) {
410
if (typeof srv != "undefined") {
411
this.cfg.db_server = srv;
412
} else this.cfg.db_server = null;
414
if (typeof db != "undefined") {
415
this.cfg.db_name = db;
416
} else this.cfg.db_name = null;
418
if (typeof grp != "undefined") {
419
this.cfg.db_group = grp;
420
} else this.cfg.db_group = null;
422
if (typeof mask != "undefined") {
423
this.cfg.db_mask = mask;
424
} else this.cfg.db_mask = null;
426
if (typeof exp != "undefined") {
427
this.cfg.experiment = exp;
428
this.cfg.window = "0";
429
} /* keeping otherwise */
432
this.ApplyConfig(true, "SOURCE");
436
CONFIG.prototype.Confirm = function(me, val) {
438
SOURCE can confirm WINDOW with val=2
439
INTERVAL can confirm WINDOW with val=1
441
if (me instanceof SOURCE) this.confirmed |= (1<<val);
442
else if (me instanceof INTERVAL) this.confirmed |= 4;
443
else if (me instanceof WINDOW) this.confirmed |= 4;
445
if ((this.confirmed&7)==7) {
448
if (this.initializing) {
449
this.initializing = false;
451
} else if (this.onConfirmation) {
452
var func = this.onConfirmation;
453
this.onConfirmation = null;
459
function configSetupModule(config, m) {
460
config.SetupModule(m);