/adei/ui

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/ui

« back to all changes in this revision

Viewing changes to js/window.js

  • Committer: Suren A. Chilingaryan
  • Date: 2008-04-02 10:23:22 UTC
  • Revision ID: csa@dside.dyndns.org-20080402102322-okib92sicg2dx3o3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function WINDOW_CONFIG() {
 
2
    this.width = 0;
 
3
    
 
4
    this.start = 0;
 
5
    this.end = 0;
 
6
    this.miny = 0;
 
7
    this.maxy = 0;
 
8
}
 
9
 
 
10
 
 
11
function WINDOW(win_sel_id, start_id, end_id, ymin_id, ymax_id) {
 
12
    this.cfg = new WINDOW_CONFIG;
 
13
    this.props =  null;
 
14
    this.source_winsel = new SELECT(win_sel_id, windowUpdateWidth, this);
 
15
 
 
16
    this.sin = document.getElementById(start_id);
 
17
    if (!this.sin) alert("Custom window start time input field (\"" + start_id + "\") is not found");
 
18
    this.ein = document.getElementById(end_id);
 
19
    if (!this.ein) alert("Custom window end time input field (\"" + end_id + "\") is not found");
 
20
    this.minin = document.getElementById(ymin_id);
 
21
    if (!this.minin) alert("Custom window ymin input field (\"" + ymin_id + "\") is not found");
 
22
    this.maxin = document.getElementById(ymax_id);
 
23
    if (!this.maxin) alert("Custom window ymax input field (\"" + ymax_id + "\") is not found");
 
24
}
 
25
 
 
26
/*
 
27
WINDOW.prototype.SetSource = function(src) {
 
28
    this.src = src;
 
29
}
 
30
 
 
31
WINDOW.prototype.SetInterval = function(interval) {
 
32
    this.ivl = interval;
 
33
}
 
34
*/
 
35
 
 
36
WINDOW.prototype.SetConfig = function(config) {
 
37
    this.config = config;
 
38
}
 
39
 
 
40
WINDOW.prototype.SetUpdater = function(updater) {
 
41
    this.updater = updater;
 
42
}
 
43
 
 
44
 
 
45
WINDOW.prototype.RegisterGraph = function(graph) {
 
46
    // DS. Provide support for multiple attached graphs
 
47
    if (!this.graph) {
 
48
        this.graph = graph;
 
49
        if (!graph.window) graph.AttachWindow(this);
 
50
    }
 
51
}
 
52
 
 
53
WINDOW.prototype.Update = function(props, opts) {
 
54
    if (opts) {
 
55
        if (opts.reload) {
 
56
            this.source_winsel.Update(adei.GetService("timewindow", props), opts, opts?opts.window_width:null);
 
57
        } else if ((opts.window_width)||(opts.reset)) {
 
58
            if (!opts.window_width) opts.window_width = this.source_winsel.GetValue(0);
 
59
 
 
60
            this.UpdateWidth(opts.window_width, opts);
 
61
            
 
62
            if ((opts.window_width)&&(this.source_winsel.GetValue() != opts.window_width))
 
63
                this.source_winsel.SetValue(opts.window_width);
 
64
        } else if (opt.confirm) {
 
65
            this.config.Confirm(this);
 
66
        }
 
67
    }
 
68
}
 
69
 
 
70
WINDOW.prototype.UpdateWidth = function (value, opts) {
 
71
    var reset_custom = true;
 
72
    
 
73
    if ((opts)&&(opts.window == "auto")) {
 
74
        this.SetCustomWindow(0,0,0,0);
 
75
        reset_custom = false;
 
76
    }
 
77
    
 
78
    if (((opts)&&(opts.reload))||(this.cfg.width != value)) {
 
79
        var css;
 
80
        var show = false;
 
81
    
 
82
    
 
83
        if (value < 0) {
 
84
            if (this.cfg.width >= 0) {
 
85
                if ((reset_custom)&&((!opts)||(!opts.keep_custom))) {
 
86
                    this.sin.value = '';
 
87
                    this.ein.value = '';
 
88
                    this.minin.value = '';
 
89
                    this.maxin.value = '';
 
90
                }
 
91
            
 
92
                cssShowClass('.hide_window_custom');
 
93
                
 
94
                if (!this.module_on_display) this.fix_hidden = true;
 
95
 
 
96
 
 
97
                if (typeof this.geometry_cb == "function") {
 
98
                    this.geometry_cb(this.geometry_cbattr);
 
99
                }
 
100
            }
 
101
        } else {
 
102
            if (this.cfg.width < 0) {
 
103
                cssHideClass('.hide_window_custom');
 
104
 
 
105
                if (!this.module_on_display) this.fix_hidden = true;
 
106
            }
 
107
            
 
108
        
 
109
            if (this.cfg.width != value) show = true;
 
110
        }
 
111
 
 
112
        this.cfg.width = value;
 
113
    
 
114
        if ((opts)&&(opts.confirm)) {
 
115
            this.config.Confirm(this);
 
116
        }
 
117
 
 
118
        if (show) {
 
119
            if ((typeof opts == "undefined")||((opts)&&(opts.apply))) this.Apply();
 
120
        }
 
121
    } else if ((opts)&&(opts.confirm)) {
 
122
        this.config.Confirm(this);
 
123
    }
 
124
 
 
125
}
 
126
 
 
127
WINDOW.prototype.UpdateRange = function() {
 
128
    if (this.graph) {
 
129
        this.graph.Clear();
 
130
    }
 
131
}
 
132
 
 
133
WINDOW.prototype.ApplyConfig = function(subcall) {
 
134
    if (this.config) {
 
135
        var sin, ein;
 
136
        var min, max;
 
137
        
 
138
        var width = this.cfg.width;
 
139
        
 
140
        if (width<0) {
 
141
            var tmp = this.sin.value;
 
142
            if (tmp) sin = adeiDateParse(tmp);
 
143
            else sin = 0;
 
144
            
 
145
            tmp = this.ein.value;
 
146
            if (tmp) ein = adeiDateParse(tmp);
 
147
            else ein = 0;
 
148
 
 
149
            tmp = this.minin.value;
 
150
            if (tmp) minin = tmp;
 
151
            else minin = 0;
 
152
            
 
153
            tmp = this.maxin.value;
 
154
            if (tmp) maxin = tmp;
 
155
            else maxin = 0;
 
156
        } else {
 
157
            sin = 0; ein = 0;
 
158
            minin = 0; maxin = 0;
 
159
        }
 
160
        
 
161
        this.config.SetWindow(width, sin, ein, minin, maxin);
 
162
 
 
163
        if (typeof subcall == "undefined") {
 
164
//          alert('save');
 
165
            this.config.Save();
 
166
        }
 
167
    }
 
168
 
 
169
    if (this.graph) this.graph.Clear();
 
170
}
 
171
 
 
172
WINDOW.prototype.ReadConfig = function(opts) {
 
173
    opts.window = "auto";
 
174
    opts.window_width = this.config.win_width;
 
175
//    this.SetCustomWindow(0,0,0,0);
 
176
}
 
177
 
 
178
WINDOW.prototype.Apply = function() {
 
179
    this.ApplyConfig();
 
180
    if (this.updater) this.updater.Update();
 
181
}
 
182
 
 
183
 
 
184
WINDOW.prototype.ResetY = function() {
 
185
    this.config.win_min = 0;
 
186
    this.config.win_max = 0;
 
187
 
 
188
    this.SetCustomWindow(0,0,0,0);
 
189
    this.Apply();
 
190
}
 
191
 
 
192
WINDOW.prototype.SetCustomWindow = function (from, to, miny, maxy) {
 
193
    if ((from)||(to)||(miny)||(maxy)) {
 
194
        if ((from)||(to)) {
 
195
            this.config.SetSelection(from, to);
 
196
 
 
197
            this.sin.value = adeiDateFormat(from, adeiMathPreciseSubstract(to, from));
 
198
            this.ein.value = adeiDateFormat(to, adeiMathPreciseSubstract(to, from));
 
199
            
 
200
        } else {
 
201
            this.config.SetSelection();
 
202
            
 
203
            if ((this.config.win_from)&&(this.config.win_to)&&(this.config.win_from!=this.config.win_to)) {
 
204
                this.sin.value = adeiDateFormat(this.config.win_from, this.config.win_to - this.config.win_from);
 
205
                this.ein.value = adeiDateFormat(this.config.win_to, this.config.win_to - this.config.win_from);
 
206
            } else /*if (this.cfg.width >= 0)*/ {
 
207
                this.sin.value = adeiDateFormat(this.graph.xmin, this.graph.xmax - this.graph.xmin);
 
208
                this.ein.value = adeiDateFormat(this.graph.xmax, this.graph.xmax - this.graph.xmin);
 
209
            } /*else {
 
210
                this.sin.value = '';
 
211
                this.ein.value = '';
 
212
            }*/
 
213
        }
 
214
 
 
215
        if ((miny)||(maxy)) {
 
216
            this.minin.value = miny;
 
217
            this.maxin.value = maxy;
 
218
        } else {
 
219
            if (/*(this.config.win_min)&&(this.config.win_max)&&*/(this.config.win_min!=this.config.win_max)) {
 
220
                this.minin.value = this.config.win_min;
 
221
                this.maxin.value = this.config.win_max;
 
222
            } else {
 
223
                this.minin.value = '';
 
224
                this.maxin.value = '';
 
225
            }
 
226
        }
 
227
 
 
228
        this.UpdateWidth(-1, new Object({keep_custom: true}));
 
229
        this.source_winsel.SetValue(-1);
 
230
    } else {
 
231
        if (!this.config) return;
 
232
        
 
233
        this.config.SetSelection();
 
234
 
 
235
        if (this.config.win_width<0) {
 
236
            if ((this.config.win_from)&&(this.config.win_to)&&(this.config.win_from!=this.config.win_to)) {
 
237
                this.sin.value = adeiDateFormat(this.config.win_from, this.config.win_to - this.config.win_from);
 
238
                this.ein.value = adeiDateFormat(this.config.win_to, this.config.win_to - this.config.win_from);
 
239
            } else {
 
240
                this.sin.value = '';
 
241
                this.ein.value = '';
 
242
            }
 
243
            
 
244
            if (/*(this.config.win_min)&&(this.config.win_max)&&*/(this.config.win_min!=this.config.win_max)) {
 
245
                this.minin.value = this.config.win_min;
 
246
                this.maxin.value = this.config.win_max;
 
247
            } else {
 
248
                this.minin.value = '';
 
249
                this.maxin.value = '';
 
250
            }
 
251
        } else {
 
252
            this.sin.value = '';
 
253
            this.ein.value = '';
 
254
            this.minin.value = '';
 
255
            this.maxin.value = '';
 
256
 
 
257
            this.UpdateWidth(this.config.win_width, new Object({keep_custom: true}));
 
258
            this.source_winsel.SetValue(this.config.win_width);
 
259
        }
 
260
    }
 
261
}
 
262
 
 
263
WINDOW.prototype.Lock = function() {
 
264
    if ((this.graph)&&(this.cfg.width >= 0)) {
 
265
        var xmin = this.graph.xmin;
 
266
        var xmax = this.graph.xmax;
 
267
        if ((xmin)&&(xmax)) {
 
268
            this.SetCustomWindow(xmin, xmax, 0, 0);
 
269
            this.Apply();
 
270
        }
 
271
    }
 
272
}
 
273
 
 
274
WINDOW.prototype.ZoomIn = function(x,y) {
 
275
    var width = this.config.win_width;
 
276
    if (width >= 0) {
 
277
        var sel = this.source_winsel;
 
278
        var len = sel.GetLastIndex();
 
279
        var i = sel.GetIndex(width);
 
280
        
 
281
        var current = this.graph.xsize;
 
282
        while (i < len) {
 
283
            var val = sel.GetValue(++i);
 
284
            if (current > val) break;
 
285
        }
 
286
        
 
287
        if (i < len) {
 
288
            sel.SetIndex(i);
 
289
            this.cfg.width = sel.GetValue();
 
290
            
 
291
            this.Apply();
 
292
            return;
 
293
        }
 
294
    }
 
295
    
 
296
    var new_size = this.graph.xsize /  adei.cfg.zoom_ratio;
 
297
    var diff = adeiMathPreciseSubstract(this.graph.xsize, new_size) / 2;
 
298
    
 
299
    var from = adeiMathPreciseAdd(this.graph.xmin, diff);
 
300
    var to = adeiMathPreciseSubstract(this.graph.xmax, diff);
 
301
    
 
302
    this.SetCustomWindow(from, to, 0, 0);
 
303
    this.Apply();    
 
304
}
 
305
 
 
306
WINDOW.prototype.ZoomOut = function(x,y) {
 
307
    var width = this.config.win_width;
 
308
    if (width < 0) {
 
309
/*
 
310
        var new_size = this.graph.xsize *  adei.cfg.zoom_ratio;
 
311
        var diff = adeiMathPreciseSubstract(new_size, this.graph.xsize) / 2;
 
312
*/    
 
313
 
 
314
        var diff = (adei.cfg.zoom_ratio - 1) * this.graph.xsize / 2;
 
315
 
 
316
        var from = adeiMathPreciseSubstract(this.graph.xmin, diff);
 
317
//      alert(this.graph.xsize + " = " + diff);
 
318
//      alert(this.graph.xmin + "," + diff + "=" + from);
 
319
        var to = adeiMathPreciseAdd(this.graph.xmax, diff);
 
320
    
 
321
        this.SetCustomWindow(from, to, 0, 0);
 
322
        this.Apply();    
 
323
    } else if (width > 0) {
 
324
        var sel = this.source_winsel;
 
325
        var i = sel.GetIndex(width);
 
326
        if (i > 0) {
 
327
            sel.SetIndex(i-1);
 
328
            this.cfg.width = sel.GetValue();
 
329
            this.Apply();
 
330
        }
 
331
        
 
332
    }
 
333
}
 
334
 
 
335
 
 
336
WINDOW.prototype.RegisterGeometryCallback = function(cb, cbattr) {
 
337
    this.geometry_cb = cb;
 
338
    this.geometry_cbattr = cbattr;
 
339
}
 
340
 
 
341
WINDOW.prototype.FixHidden = function() {
 
342
    if ((this.fix_hidden)&&(this.module_on_display)) {
 
343
        if (this.cfg.width<0) {
 
344
            cssHideClass('.hide_window_custom');
 
345
            cssShowClass('.hide_window_custom');
 
346
        } else {
 
347
            cssShowClass('.hide_window_custom');
 
348
            cssHideClass('.hide_window_custom');
 
349
        }
 
350
        this.fix_hidden = false;
 
351
    }
 
352
}
 
353
 
 
354
function windowUpdateWidth(window, value, opts) {
 
355
    window.UpdateWidth(value, opts);
 
356
}
 
357
 
 
358
function windowUpdateRange(window) {
 
359
    window.UpdateRange();
 
360
}
 
361
 
 
362
function windowUpdateRangeFunction(window) { 
 
363
    return function() { window.UpdateRange(); } 
 
364
}