/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/interval.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 INTERVAL_CONFIG() {
 
2
    this.start = 0;
 
3
    this.end = 0;
 
4
    this.custom = 0;
 
5
}
 
6
 
 
7
function INTERVAL(window, exp_sel_id, start_id, end_id) {
 
8
    this.cfg = new INTERVAL_CONFIG;
 
9
 
 
10
    this.window = window;
 
11
    //this.window.SetConfig(null);
 
12
    
 
13
    this.props = null;
 
14
    this.source_expsel = new SELECT(exp_sel_id, intervalUpdateExperiment, this);
 
15
    this.sin = document.getElementById(start_id);
 
16
    if (!this.sin) alert("Custom experiment start time input field (\"" + start_id + "\") is not found");
 
17
    this.ein = document.getElementById(end_id);
 
18
    if (!this.ein) alert("Custom experiment end time input field (\"" + end_id + "\") is not found");
 
19
}
 
20
 
 
21
/*
 
22
INTERVAL.prototype.SetSource = function(src) {
 
23
    this.src = src;
 
24
    this.window.SetSource(src);
 
25
    this.window.SetInterval(this);
 
26
}
 
27
*/
 
28
 
 
29
INTERVAL.prototype.SetConfig = function(config) {
 
30
    this.config = config;
 
31
    this.window.SetConfig(config);
 
32
}
 
33
 
 
34
 
 
35
INTERVAL.prototype.SetUpdater = function(updater) {
 
36
    this.updater = updater;
 
37
    this.window.SetUpdater(updater);
 
38
}
 
39
 
 
40
INTERVAL.prototype.ApplyConfig = function(subcall) {
 
41
    this.window.ApplyConfig(subcall);
 
42
    this.config.SetInterval(this.cfg.start, this.cfg.end);
 
43
}
 
44
 
 
45
INTERVAL.prototype.ReadConfig = function(opts) {
 
46
    opts.experiment = this.config.cfg.experiment;
 
47
    this.window.ReadConfig(opts);
 
48
}
 
49
 
 
50
 
 
51
INTERVAL.prototype.Update = function(props, opts) {
 
52
    if (props) this.props = props;
 
53
 
 
54
    if (opts) {    
 
55
        if (opts.reload) {
 
56
            this.source_expsel.Update(adei.GetService("experiment", props), opts, opts?opts.experiment:null);
 
57
        } else if ((opts.experiment)||(opts.reset)) {
 
58
            if (!opts.experiment) opts.experiment = this.source_expsel.GetValue(0);
 
59
        
 
60
            this.UpdateExperiment(opts.experiment, opts);
 
61
 
 
62
            if (this.source_expsel.GetValue() != opts.experiment)
 
63
                this.source_expsel.SetValue(opts.experiment);
 
64
        } else if (opts.confirm) {
 
65
            this.config.Confirm(this);
 
66
        }
 
67
    }
 
68
}
 
69
 
 
70
INTERVAL.prototype.UpdateExperiment  = function(value, opts) {
 
71
    if (((opts)&&(opts.reload))||(value != this.experiment)) {
 
72
        var css;
 
73
        
 
74
        this.experiment = value;
 
75
        
 
76
        if (value == "0") {
 
77
            if (this.cfg.custom == 0) {
 
78
                cssShowClass('.hide_experiment_custom');
 
79
                this.cfg.custom = 1;
 
80
 
 
81
                if (!this.module_on_display) this.fix_hidden = true;
 
82
 
 
83
                if (typeof this.geometry_cb == "function") {
 
84
                    this.geometry_cb(this.geometry_cbattr);
 
85
                }
 
86
            }
 
87
        } else {
 
88
            if (this.cfg.custom) {
 
89
                cssHideClass('.hide_experiment_custom');
 
90
                this.cfg.custom = 0;
 
91
 
 
92
                if (!this.module_on_display) this.fix_hidden = true;
 
93
            }
 
94
 
 
95
            var atmp = value.split('-',2);
 
96
            this.cfg.start = atmp[0];
 
97
            this.cfg.end = atmp[1];
 
98
        }
 
99
    
 
100
            
 
101
        if (typeof opts == "undefined") opts = new Object;
 
102
        opts.reload = true;
 
103
 
 
104
        this.window.Update(this.props + "&" + this.GetExperimentProps(0), opts);
 
105
    } else if ((opts)&&(opts.window)) {
 
106
        this.window.Update(this.props + "&" + this.GetExperimentProps(0), opts);
 
107
    } else if ((opts)&&(opts.confirm)) {
 
108
        this.config.Confirm(this);
 
109
    }
 
110
}
 
111
 
 
112
 
 
113
INTERVAL.prototype.GetExperimentProps = function(read_custom) {
 
114
    if (typeof read_custom == "undefined") read_custom = 1;
 
115
    
 
116
    if (this.cfg.custom) {
 
117
        if (read_custom) {
 
118
            var from, to;
 
119
            
 
120
            if (this.sin.value) from = adeiDateParse(this.sin.value);
 
121
            else from = 0;
 
122
            
 
123
            if (this.ein.value) to = adeiDateParse(this.ein.value);
 
124
            else to = 0;
 
125
            
 
126
            if (isNaN(from)) {
 
127
                alert('Invalid start time (\"' + this.sin.value + '\") is specified');
 
128
                from = 0;
 
129
            }
 
130
            if (isNaN(to)) {
 
131
                alert('Invalid end time (\"' + this.ein.value + '\") is specified');
 
132
                to = 0;
 
133
            }
 
134
            
 
135
            return 'experiment='+from+'-'+to;       
 
136
        } else {
 
137
            return 'experiment=0-0';
 
138
        }
 
139
    } else {
 
140
        return 'experiment=' + this.cfg.start + '-' + this.cfg.end;
 
141
    }
 
142
}
 
143
 
 
144
INTERVAL.prototype.RegisterGeometryCallback = function(cb, cbattr) {
 
145
    this.window.RegisterGeometryCallback(cb, cbattr);
 
146
    this.geometry_cb = cb;
 
147
    this.geometry_cbattr = cbattr;
 
148
}
 
149
 
 
150
 
 
151
INTERVAL.prototype.FixHidden = function() {
 
152
    if ((this.fix_hidden)&&(this.module_on_display)) {
 
153
        if (this.cfg.custom) {
 
154
            cssHideClass('.hide_experiment_custom');
 
155
            cssShowClass('.hide_experiment_custom');
 
156
        } else {
 
157
            cssShowClass('.hide_experiment_custom');
 
158
            cssHideClass('.hide_experiment_custom');
 
159
        }
 
160
        this.fix_hidden = false;
 
161
    }
 
162
    this.window.FixHidden();
 
163
}
 
164
 
 
165
function intervalUpdateExperiment(interval, value, opts) {
 
166
    interval.UpdateExperiment(value, opts);
 
167
}
 
168