/dev/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/dev/trunk

« back to all changes in this revision

Viewing changes to js/source.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 SOURCE_CONFIG() {
 
2
    this.db_server = null;
 
3
    this.db_name = null;
 
4
    this.db_group = null;
 
5
    this.db_mask = null;
 
6
    this.db_item = null;
 
7
}
 
8
 
 
9
 
 
10
function SOURCE(interval, srv_sel_id, db_sel_id, group_sel_id, mask_sel_id, item_sel_id, opts) {
 
11
    this.cfg = new SOURCE_CONFIG;
 
12
 
 
13
//    interval.SetSource(this);
 
14
    this.interval = interval;
 
15
 
 
16
    this.source_itemsel = new SELECT(item_sel_id, sourceUpdateItem, this);
 
17
    this.source_masksel = new SELECT(mask_sel_id, sourceUpdateMask, this);
 
18
    this.source_grsel = new SELECT(group_sel_id, sourceUpdateGroup, this);
 
19
    this.source_dbsel = new SELECT(db_sel_id, sourceUpdateDatabase, this);
 
20
    this.source_srvsel = new SELECT(srv_sel_id, sourceUpdateServer, this);
 
21
 
 
22
    this.config = null;
 
23
    this.updater = null;
 
24
    
 
25
    if (typeof opts == "object") this.opts = opts;
 
26
    else this.opts = new Object();
 
27
}
 
28
 
 
29
SOURCE.prototype.Init = function(updater, opts) {
 
30
    if (typeof opts == "undefined") opts = new Object;
 
31
    opts.reload = true;
 
32
    opts.confirm = true;
 
33
 
 
34
    this.updater = updater;
 
35
    this.interval.SetUpdater(updater);
 
36
    updater.RegisterControl(this);
 
37
    
 
38
    this.Update(opts);
 
39
}
 
40
 
 
41
 
 
42
SOURCE.prototype.AttachConfig = function(config) {
 
43
    this.config = config;
 
44
    this.interval.SetConfig(config);
 
45
 
 
46
    config.Register(this);
 
47
 
 
48
//    this.Apply();
 
49
}
 
50
 
 
51
 
 
52
SOURCE.prototype.ApplyConfig = function(subcall) {
 
53
    if (this.config) {
 
54
        this.config.SetSource(this.cfg.db_server, this.cfg.db_name, this.cfg.db_group, this.cfg.db_mask);
 
55
        this.interval.ApplyConfig(true);
 
56
 
 
57
        if (typeof subcall == "undefined") {
 
58
//          alert('save');
 
59
            this.config.Save();
 
60
        }
 
61
    }
 
62
}
 
63
 
 
64
SOURCE.prototype.ReadConfig = function(opts) {
 
65
    if (this.config) {
 
66
        if (typeof opts == "undefined") opts = new Object;
 
67
            
 
68
        opts.db_server = this.config.cfg.db_server;
 
69
        opts.db_name = this.config.cfg.db_name;
 
70
        opts.db_group = this.config.cfg.db_group;
 
71
        
 
72
        if (this.config.cfg.db_mask != null) {
 
73
            var mask = this.config.cfg.db_mask;
 
74
            if (mask.search(',')>=0) {
 
75
                opts.db_mask = mask;
 
76
                opts.db_item = 0;
 
77
            } else if (isNaN(mask)) {
 
78
                opts.db_mask = mask;
 
79
                opts.db_item = 0;
 
80
            } else {
 
81
                opts.db_mask = -1;
 
82
                opts.db_item = mask;
 
83
            }
 
84
        }
 
85
        
 
86
        this.interval.ReadConfig(opts);
 
87
        this.Update(opts);
 
88
    }
 
89
}
 
90
 
 
91
 
 
92
SOURCE.prototype.Apply = function() {
 
93
    this.ApplyConfig();
 
94
    if (this.updater) this.updater.Update();
 
95
}
 
96
 
 
97
SOURCE.prototype.RegisterGraph = function(graph) {
 
98
    this.graphs.push(graph);
 
99
}
 
100
 
 
101
SOURCE.prototype.Update = function(opts) {
 
102
    if (opts) {
 
103
        if (opts.reload) {
 
104
            this.source_srvsel.Update(adei.GetService("server"), opts, opts?opts.db_server:null);
 
105
        } else if ((opts.reset)||(opts.db_server)) {
 
106
            if (!opts.db_server) opts.db_server = this.source_srvsel.GetValue(0);
 
107
 
 
108
            this.UpdateServer(opts.db_server, opts);
 
109
            
 
110
            if (this.source_srvsel.GetValue() != opts.db_server)
 
111
                this.source_srvsel.SetValue(opts.db_server);
 
112
        } else if (opts.confirm) {
 
113
            this.config.Confirm(this, 0);
 
114
            this.config.Confirm(this, 1);
 
115
            this.config.Confirm(this, 2);
 
116
        }
 
117
    }
 
118
}
 
119
 
 
120
SOURCE.prototype.UpdateServer = function(srv, opts) {
 
121
    if (typeof srv == "undefined") {
 
122
        srv = this.source_srvsel.GetValue();
 
123
    }
 
124
 
 
125
    with (this.cfg) {
 
126
        if (((opts)&&(opts.reload))||(srv != db_server)) {
 
127
            db_server = srv;
 
128
            
 
129
            if (typeof opts == "undefined") opts = new Object;
 
130
            opts.reload = true;
 
131
            
 
132
            this.source_dbsel.Update(adei.GetService("database", "db_server=" + db_server), opts, opts?opts.db_name:null);
 
133
        } else if ((opts)&&((opts.db_name)||(opts.reset))) {
 
134
            if (!opts.db_name) opts.db_name = this.source_dbsel.GetValue(0);
 
135
 
 
136
            this.UpdateDatabase(opts.db_name, opts);
 
137
            
 
138
            if (this.source_dbsel.GetValue() != opts.db_name)
 
139
                this.source_dbsel.SetValue(opts.db_name);
 
140
        } else if ((opts)&&(opts.confirm)) {
 
141
            this.config.Confirm(this, 0);
 
142
            this.config.Confirm(this, 1);
 
143
            this.config.Confirm(this, 2);
 
144
        }
 
145
    }
 
146
}
 
147
 
 
148
 
 
149
SOURCE.prototype.UpdateDatabase = function(db, opts) {
 
150
    with (this.cfg) {
 
151
        if (((opts)&&(opts.reload))||(db != db_name)) {
 
152
            db_name = db;
 
153
 
 
154
            if (typeof opts == "undefined") opts = new Object;
 
155
            opts.reload = true;
 
156
 
 
157
            this.source_grsel.Update(adei.GetService("loggroup", "db_server=" + db_server + "&db_name=" + db_name), opts, opts?opts.db_group:null);
 
158
        } else if ((opts)&&((opts.db_group)||(opts.reset))) {
 
159
            if (!opts.db_group) opts.db_group = this.source_grsel.GetValue(0);
 
160
 
 
161
            this.UpdateGroup(opts.db_group, opts);
 
162
 
 
163
            if (this.source_grsel.GetValue() != opts.db_group)
 
164
                this.source_grsel.SetValue(opts.db_group);
 
165
        } else if ((opts)&&(opts.confirm)) {
 
166
            this.config.Confirm(this, 0);
 
167
            this.config.Confirm(this, 1);
 
168
            this.config.Confirm(this, 2);
 
169
        }
 
170
    }
 
171
}
 
172
 
 
173
/* Handling of Interval/Window updates. 
 
174
    a) INTERVAL value passed - UPDATING
 
175
    b) 'keep_window' in global or local options - KEEPING
 
176
    c) Group have changed - UPDATING
 
177
    d) 'reset' in local options - UPDATING 
 
178
    e) IGNORING
 
179
 
 
180
 
 
181
*/
 
182
SOURCE.prototype.UpdateGroup = function(group, opts) {
 
183
    if (typeof opts == "undefined") opts = new Object;
 
184
 
 
185
    if (!opts.experiment) {
 
186
        if ((opts.keep_window)||(this.opts.keep_window)) {
 
187
            opts.experiment = this.config.cfg.experiment;
 
188
            opts.window_width = this.config.win_width;
 
189
            opts.window = "auto";
 
190
        }
 
191
    }
 
192
    
 
193
    with (this.cfg) {
 
194
        if (((opts)&&(opts.reload))||(group != db_group)) {
 
195
            db_group = group;
 
196
            
 
197
            opts.reload = true;
 
198
 
 
199
            this.source_itemsel.Update(adei.GetService("item", "db_server=" + db_server + "&db_name=" + db_name + "&db_group=" + db_group), opts, opts?opts.db_item:null);
 
200
            this.source_masksel.Update(adei.GetService("mask", "db_server=" + db_server + "&db_name=" + db_name + "&db_group=" + db_group), opts, opts?opts.db_mask:null);
 
201
 
 
202
            this.interval.Update(this.GetSourceProps(), opts);
 
203
        } else if ((opts)&&((opts.db_mask)||(opts.db_item)||(opts.experiment)||(opts.reset))) {
 
204
            if ((opts.db_mask)||(opts.reset)) {
 
205
                if (!opts.db_mask) opts.db_mask = this.source_masksel.GetValue(0);
 
206
 
 
207
                this.UpdateMask(opts.db_mask, opts);
 
208
                
 
209
                if (this.source_masksel.GetValue() != opts.db_mask)
 
210
                    this.source_masksel.SetValue(opts.db_mask);
 
211
            } else if (opts.confirm) {
 
212
                this.config.Confirm(this, 0);
 
213
            }
 
214
            
 
215
            if ((opts.db_item)||(opts.reset)) {
 
216
                if (!opts.db_item) opts.db_item = this.source_itemsel.GetValue(0);
 
217
 
 
218
                this.UpdateItem(opts.db_item, opts);
 
219
                
 
220
                if (this.source_itemsel.GetValue() != opts.db_item)
 
221
                    this.source_itemsel.SetValue(opts.db_item);
 
222
            } else if (opts.confirm) {
 
223
                this.config.Confirm(this, 1);
 
224
            }
 
225
            
 
226
            if ((opts.experiment)||(opts.reset)) {
 
227
                this.interval.Update(this.GetSourceProps(), opts);
 
228
            } else if (opts.confirm) {
 
229
                this.config.Confirm(this, 2);
 
230
            }
 
231
        } else if (opts.confirm) {
 
232
            this.config.Confirm(this, 0);
 
233
            this.config.Confirm(this, 1);
 
234
            this.config.Confirm(this, 2);
 
235
        }
 
236
    }
 
237
}
 
238
 
 
239
 
 
240
SOURCE.prototype.UpdateMask = function(mask, opts) {
 
241
    with (this.cfg) {
 
242
        if (((opts)&&(opts.reload))||(mask != db_mask)) {
 
243
            if (mask == -1) {
 
244
                db_mask = db_item;
 
245
 
 
246
                this.source_itemsel.Show();
 
247
                if (!this.module_on_display) this.fix_hidden = true;
 
248
 
 
249
                if (typeof this.geometry_cb == "function") {
 
250
                    this.geometry_cb(this.geometry_cbattr);
 
251
                }
 
252
            } else {
 
253
                if (!isNaN(db_mask)) {
 
254
                    if (!this.module_on_display) this.fix_hidden = true;
 
255
                    this.source_itemsel.Hide();
 
256
                }
 
257
                
 
258
                db_mask = mask;
 
259
 
 
260
                if ((typeof opts == "undefined")||((opts)&&(opts.apply))) this.Apply();
 
261
            }
 
262
        }
 
263
        
 
264
        if ((opts)&&(opts.confirm)) {
 
265
            this.config.Confirm(this, 0);
 
266
        }
 
267
    }
 
268
}
 
269
 
 
270
 
 
271
SOURCE.prototype.UpdateItem = function(item, opts) {
 
272
    with (this.cfg) {
 
273
        if (((opts)&&(opts.reload))||(item != db_item)) {
 
274
            db_item = item;
 
275
            db_mask = item;
 
276
 
 
277
            if ((typeof opts == "undefined")||((opts)&&(opts.apply))) this.Apply();
 
278
        }
 
279
 
 
280
        if ((opts)&&(opts.confirm)) this.config.Confirm(this, 1);
 
281
    }
 
282
}
 
283
 
 
284
 
 
285
SOURCE.prototype.GetSourceProps = function() {
 
286
    return "db_server=" + this.cfg.db_server + "&db_name=" + this.cfg.db_name + "&db_group=" + this.cfg.db_group;
 
287
}
 
288
 
 
289
SOURCE.prototype.RegisterGeometryCallback = function(cb, cbattr) {
 
290
    this.interval.RegisterGeometryCallback(cb, cbattr);
 
291
    this.geometry_cb = cb;
 
292
    this.geometry_cbattr = cbattr;
 
293
}
 
294
 
 
295
SOURCE.prototype.FixHidden = function() {
 
296
                    // Fix IE bug, preventing unhiden hidden subnodes while within hidden element
 
297
    if ((this.fix_hidden)&&(this.module_on_display)) {
 
298
        if (isNaN(this.cfg.db_mask)) {
 
299
            this.source_itemsel.Show();
 
300
            this.source_itemsel.Hide();
 
301
        } else {
 
302
            this.source_itemsel.Hide();
 
303
            this.source_itemsel.Show();
 
304
        }
 
305
        this.fix_hidden = false;
 
306
    }
 
307
    this.interval.FixHidden();
 
308
}
 
309
 
 
310
 
 
311
function sourceUpdateServer(src, srv, opts) {
 
312
    return src.UpdateServer(srv, opts);
 
313
}
 
314
 
 
315
function sourceUpdateDatabase(src, db, opts) {
 
316
    return src.UpdateDatabase(db, opts);
 
317
}
 
318
 
 
319
function sourceUpdateGroup(src, group, opts) {
 
320
    return src.UpdateGroup(group, opts);
 
321
}
 
322
 
 
323
function sourceUpdateMask(src, mask, opts) {
 
324
    return src.UpdateMask(mask, opts);
 
325
}
 
326
 
 
327
function sourceUpdateItem(src, item, opts) {
 
328
    return src.UpdateItem(item, opts);
 
329
}
 
330
 
 
331
function sourceFixHidden(source) {
 
332
    source.FixHidden();
 
333
}