/adei/ui

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/ui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
function EXPORT_CONFIG() {
    this.format = null;
    this.resample = null;
    this.mask = null;
    this.window = null;
}

function EXPORT(format_sel_id, resample_sel_id, mask_sel_id, window_sel_id) {
    this.cfg = new EXPORT_CONFIG();

    this.formatsel = new SELECT(format_sel_id, exportUpdateFormat, this);
    this.samplesel = new SELECT(resample_sel_id, exportUpdateSampling, this);
    this.masksel = new SELECT(mask_sel_id, exportUpdateMask, this);
    this.winsel = new SELECT(window_sel_id, exportUpdateWindow, this);

    this.config = null;
}

EXPORT.prototype.AttachConfig = function(config) {
    this.config = config;
    config.Register(this);
}

EXPORT.prototype.Init = function(opts) {
    if (typeof opts == "undefined") opts = new Object;

    opts.reload = true;
    opts.confirm = true;

    this.Update(opts);
}

EXPORT.prototype.Export = function(embedded_mode, window_type) {

    var opts = "format=" + this.cfg.format + "&resample=" + this.cfg.resample + "&mask_mode=" + this.cfg.mask;
    if (typeof window_type != "undefined") {
	opts += "&" + this.config.GetProps(window_type);
    } else if (embedded_mode) {
	opts += "&" + this.config.GetProps(-1);
    } else {
	opts += "&" + this.config.GetProps(this.cfg.window);
    }

    document.location = adei.GetServiceURL("getdata", opts);
}

EXPORT.prototype.SetFormat = function(val) {
    this.Update(new Object({ 'format': val, 'apply': true}));
}

EXPORT.prototype.SetSampling = function(val) {
    this.Update(new Object({ 'export_sampling': val, 'apply': true}));
}

EXPORT.prototype.SetMask = function(val) {
    this.Update(new Object({ 'export_mask': val, 'apply': true}));
}

EXPORT.prototype.ReadConfig = function(opts) {
    if (this.config) {
	var opts = new Object({'apply': true});
	if (this.config.cfg_extra.format) 
	    opts.format = this.config.cfg_extra.format;

	if (this.config.cfg_extra.resample) 
	    opts.export_sampling = this.config.cfg_extra.resample;

	if (this.config.cfg_extra.mask_mode) 
	    opts.export_mask = this.config.cfg_extra.mask_mode;
	
	this.Update(opts);
    }
}


EXPORT.prototype.Update = function(opts) {
    if (opts) {
	if (opts.reload) {
	    this.formatsel.Update(adei.GetSelectService("formats"), opts, opts?opts.format:null);
	    this.samplesel.Update(adei.GetSelectService("sampling_rates"), opts, opts?opts.export_sampling:null);
	    this.masksel.Update(adei.GetSelectService("export_mask_modes"), opts, opts?opts.export_mask:null);
	    this.winsel.Update(adei.GetSelectService("export_window_modes"), opts, opts?opts.export_window:null);
	} else {
	    if (opts.format) {
	    	this.UpdateFormat(opts.format, opts);
	    	if (this.formatsel.GetValue() != opts.format)
    		    this.formatsel.SetValue(opts.format);
	    }
	    if (opts.export_sampling) {
	    	this.UpdateSampling(opts.export_sampling, opts);
	    	if (this.samplesel.GetValue() != opts.export_sampling)
    		    this.samplesel.SetValue(opts.export_sampling);
	    }
	    if (opts.export_mask) {
	    	this.UpdateMask(opts.export_mask, opts);
	    	if (this.masksel.GetValue() != opts.export_mask)
    		    this.masksel.SetValue(opts.export_mask);
	    }
	    if (opts.export_window) {
	    	this.UpdateWindow(opts.export_window, opts);
	    	if (this.winsel.GetValue() != opts.export_window)
    		    this.winsel.SetValue(opts.export_window);
	    }
	}
    }
}

EXPORT.prototype.UpdateFormat = function(val, opts) {
    this.cfg.format = val;

    if ((typeof opts == "undefined")||(opts.apply))
        this.Apply(val, null, null);
}

EXPORT.prototype.UpdateSampling = function(val, opts) {
    this.cfg.resample = val;

    if ((typeof opts == "undefined")||(opts.apply))
	this.Apply(null, val, null);
}

EXPORT.prototype.UpdateMask = function(val, opts) {
    this.cfg.mask = val;

    if ((typeof opts == "undefined")||(opts.apply))
	this.Apply(null, null, val);
}

EXPORT.prototype.UpdateWindow = function(val, opts) {
    this.cfg.window = val;
}

EXPORT.prototype.Apply = function(format, sampling, mask) {
    if ((format)||(sampling)||(mask))
	this.config.SetExportSettings(format, sampling, mask);
    else
	this.config.SetExportSettings(this.cfg.format, this.cfg.resample, this.cfg.mask);
    
    this.config.ReplaceURL();
}


EXPORT.prototype.GetTooltip = function() {
    var res = this.formatsel.GetTitle();

    if ((this.cfg.resample)&&(this.cfg.resample != "0")) {
	res += ", " + translate("Resampling %s", this.samplesel.GetTitle());
    }
    if ((this.cfg.mask)&&(this.cfg.mask != "0")) {
	res += ", " + translate("MultiMask");
    }
    
    return res;
}

function exportUpdateFormat(self, val, opts) {
    return self.UpdateFormat(val, opts);
}

function exportUpdateSampling(self, val, opts) {
    return self.UpdateSampling(val, opts);
}

function exportUpdateMask(self, val, opts) {
    return self.UpdateMask(val, opts);
}

function exportUpdateWindow(self, val, opts) {
    return self.UpdateWindow(val, opts);
}