Phi: nicer scroll animation for METAR widget
[fg:fgdata.git] / webgui / widgets / radiostack.js
1 define([
2         'knockout', 'text!./radiostack.html', 'kojqui/tooltip', 'kojqui/spinner'
3 ], function(ko, htmlString) {
4
5     function DualFrequencyViewModel(label, pfx) {
6         var self = this;
7         self.useKey = pfx + "use";
8         self.sbyKey = pfx + "sby";
9         self.stnKey = pfx + "stn";
10
11         self.label = ko.observable(label);
12         self.use = ko.observable(188.888).extend({
13             fgprop : self.useKey
14         });
15         
16         self.stby = ko.observable(188.888).extend({
17             fgprop : self.sbyKey
18         });
19
20         self.stn = ko.observable("").extend({
21             fgprop : self.stnKey
22         });
23
24         self.swap = function() {
25             ko.utils.knockprops.write(self.useKey, self.stby());
26             ko.utils.knockprops.write(self.sbyKey, self.use());
27         };
28
29         self.onUseBlur = function() {
30             ko.utils.knockprops.write(self.useKey, self.use());
31         }
32
33         self.onUseKey = function(ui,evt) {
34             if( evt.keyCode == 13 )
35                 ko.utils.knockprops.write(self.useKey, self.use());
36         }
37
38         self.onStbyKey = function(ui,evt) {
39             if( evt.keyCode == 13 )
40                 ko.utils.knockprops.write(self.sbyKey, self.stby());
41         }
42
43         self.onStbyBlur = function() {
44             ko.utils.knockprops.write(self.sbyKey, self.stby());
45         }
46     }
47
48     function ViewModel(params) {
49         this.radios = ko.observableArray([
50                 new DualFrequencyViewModel("COM1", "com1"), new DualFrequencyViewModel("COM2", "com2"),
51                 new DualFrequencyViewModel("NAV1", "nav1"), new DualFrequencyViewModel("NAV2", "nav2"),
52                 new DualFrequencyViewModel("ADF", "adf1"), 
53         ]);
54
55     }
56
57     // Return component definition
58     return {
59         viewModel : ViewModel,
60         template : htmlString
61     };
62 });