0
|
1 |
|
|
2 |
$( window ).ready( function() {
|
|
3 |
new PrefsRouter( $('#content') );
|
|
4 |
});
|
|
5 |
|
|
6 |
|
|
7 |
/* ---------------------------------------------- */
|
|
8 |
/* Router for the various Pref sections */
|
|
9 |
/* ---------------------------------------------- */
|
|
10 |
PrefsRouter = can.Control({
|
|
11 |
defaults: {
|
|
12 |
menu: $( '#sections' ),
|
|
13 |
default_route: 'app'
|
|
14 |
}
|
|
15 |
}, {
|
|
16 |
init: function() {
|
|
17 |
var self = this;
|
|
18 |
self.controls = [];
|
|
19 |
|
|
20 |
if ( window.location.hash == "" ) window.location.hash = "#" + self.options.default_route;
|
|
21 |
},
|
|
22 |
|
|
23 |
// Remove controllers (and their children DOM elements) and reflect
|
|
24 |
// the currently selected route.
|
|
25 |
//
|
|
26 |
reset: function() {
|
|
27 |
var self = this;
|
|
28 |
var current_route = can.route.attr( 'route' );
|
|
29 |
var menu = self.options.menu;
|
|
30 |
|
|
31 |
// FIXME
|
|
32 |
menu.find( 'a' ).removeClass( 'selected' );
|
|
33 |
console.log( menu.find( 'a' ) );
|
|
34 |
console.log( menu.find( 'a[href="#' + current_route + '"]' ) );
|
|
35 |
|
|
36 |
while ( control = self.controls.pop() ) control.destroy();
|
|
37 |
},
|
|
38 |
|
|
39 |
"app route": function() {
|
|
40 |
this.reset();
|
|
41 |
this.controls.push( new PrefsAppWidget(this.element) );
|
|
42 |
},
|
|
43 |
|
|
44 |
"server route": function() {
|
|
45 |
this.reset();
|
|
46 |
this.controls.push( new PrefsServerWidget(this.element) );
|
|
47 |
},
|
|
48 |
});
|
|
49 |
|
|
50 |
|
|
51 |
/* ---------------------------------------------- */
|
|
52 |
/* App behavior section */
|
|
53 |
/* ---------------------------------------------- */
|
|
54 |
PrefsAppWidget = can.Control({
|
|
55 |
defaults: {
|
|
56 |
view: 'app://window/prefs/app.ejs'
|
|
57 |
}
|
|
58 |
}, {
|
|
59 |
init: function() {
|
|
60 |
var self = this;
|
|
61 |
|
|
62 |
// Get the current preference values.
|
|
63 |
//
|
|
64 |
var bool_prefs = {
|
|
65 |
hidesplash: [ D.getBoolPref( 'hidesplash' ), 'Skip splash screen at startup' ],
|
|
66 |
fullscreen: [ D.getBoolPref( 'fullscreen' ), 'Go full screen by default' ],
|
|
67 |
devmode: [ D.getBoolPref( 'devmode' ), 'Developer mode' ]
|
|
68 |
}
|
|
69 |
|
|
70 |
self.element.html(
|
|
71 |
can.view( self.options.view, {
|
|
72 |
bool_prefs: bool_prefs
|
|
73 |
})
|
|
74 |
);
|
|
75 |
},
|
|
76 |
|
|
77 |
'input click': function( ele, event ) {
|
|
78 |
var pref = ele.data( 'field' );
|
|
79 |
|
|
80 |
if ( ele.attr('type') == 'checkbox' ) {
|
|
81 |
var bool = ele.is( ':checked' );
|
|
82 |
D.setBoolPref( pref, ele.is(':checked') );
|
|
83 |
|
|
84 |
if ( pref == 'devmode' && bool ) D.window.main.showInspector( true );
|
|
85 |
}
|
|
86 |
},
|
|
87 |
});
|
|
88 |
|
|
89 |
|
|
90 |
/* ---------------------------------------------- */
|
|
91 |
/* Server section */
|
|
92 |
/* ---------------------------------------------- */
|
|
93 |
PrefsServerWidget = can.Control({
|
|
94 |
defaults: {
|
|
95 |
view: 'app://window/prefs/servers.ejs'
|
|
96 |
}
|
|
97 |
}, {
|
|
98 |
init: function() {
|
|
99 |
var self = this;
|
|
100 |
var server = D.getPref( 'server_uri' );
|
|
101 |
|
|
102 |
self.element.html(
|
|
103 |
can.view( self.options.view, {
|
|
104 |
server: server
|
|
105 |
})
|
|
106 |
);
|
|
107 |
},
|
|
108 |
|
|
109 |
// Update the server URI preference.
|
|
110 |
//
|
|
111 |
updateServer: function( uri ) {
|
|
112 |
console.log( 'Updated server_uri to ' + uri + '.' );
|
|
113 |
D.setPref( 'server_uri', uri );
|
|
114 |
D.tf.uri = uri;
|
|
115 |
},
|
|
116 |
|
|
117 |
// Hitting the return key on input fields defer to the 'blur' event,
|
|
118 |
// which in turn fires the 'change' event.
|
|
119 |
//
|
|
120 |
"#server keypress": function( ele, event ) {
|
|
121 |
if ( event.which == 13 ) ele.trigger( 'blur' );
|
|
122 |
},
|
|
123 |
'#server change': function( ele, event ) {
|
|
124 |
this.updateServer( ele.val() );
|
|
125 |
},
|
|
126 |
'#server keyup': function( ele, event ) {
|
|
127 |
D.delay( function() {
|
|
128 |
this.updateServer( ele.val() );
|
|
129 |
}, 500, true );
|
|
130 |
},
|
|
131 |
|
|
132 |
|
|
133 |
// Talk to the remote server, check to see if it's really
|
|
134 |
// a ThingFish handler or not.
|
|
135 |
//
|
|
136 |
'#test click': function( ele, event ) {
|
|
137 |
var server = $( '#server' ).val();
|
|
138 |
D.checkServer( server );
|
|
139 |
},
|
|
140 |
});
|
|
141 |
|