Resources/js/d/prefs.js
changeset 1 b3419d05eabb
parent 0 80c32ef237c6
equal deleted inserted replaced
0:80c32ef237c6 1:b3419d05eabb
       
     1 
       
     2 D = Ti.API.get( 'D' );
     1 
     3 
     2 $( window ).ready( function() {
     4 $( window ).ready( function() {
     3 	new PrefsRouter( $('#content') );
     5 	new PrefsRouter( $('#content') );
     4 });
     6 });
     5 
     7 
     7 /* ---------------------------------------------- */
     9 /* ---------------------------------------------- */
     8 /* Router for the various Pref sections */
    10 /* Router for the various Pref sections */
     9 /* ---------------------------------------------- */
    11 /* ---------------------------------------------- */
    10 PrefsRouter = can.Control({
    12 PrefsRouter = can.Control({
    11 	defaults: {
    13 	defaults: {
    12 		menu: $( '#sections' ),
    14 		menu: '#sections',
    13 		default_route: 'app'
    15 		default_route: 'app'
    14 	}
    16 	}
    15 }, {
    17 }, {
    16 	init: function() {
    18 	init: function() {
    17 		var self = this;
    19 		var self = this;
    24 	// the currently selected route.
    26 	// the currently selected route.
    25 	//
    27 	//
    26 	reset: function() {
    28 	reset: function() {
    27 		var self = this;
    29 		var self = this;
    28 		var current_route = can.route.attr( 'route' );
    30 		var current_route = can.route.attr( 'route' );
    29 		var menu = self.options.menu;
    31 		var menu = $( self.options.menu );
    30 
    32 
    31 		// FIXME
       
    32 		menu.find( 'a' ).removeClass( 'selected' );
    33 		menu.find( 'a' ).removeClass( 'selected' );
    33 		console.log( menu.find( 'a' ) );
    34 		menu.find( 'a[href="#' + current_route + '"]' ).addClass( 'selected' );
    34 		console.log( menu.find( 'a[href="#' + current_route + '"]' ) );
       
    35 
    35 
    36 		while ( control = self.controls.pop() ) control.destroy();
    36 		while ( control = self.controls.pop() ) control.destroy();
    37 	},
    37 	},
    38 
    38 
    39 	"app route": function() {
    39 	"app route": function() {
    60 		var self = this;
    60 		var self = this;
    61 
    61 
    62 		// Get the current preference values.
    62 		// Get the current preference values.
    63 		//
    63 		//
    64 		var bool_prefs = {
    64 		var bool_prefs = {
    65 			hidesplash: [ D.getBoolPref( 'hidesplash' ), 'Skip splash screen at startup' ],
    65 			hidesplash:      [ D.getBoolPref( 'hidesplash' ), 'Skip splash screen at startup' ],
    66 			fullscreen: [ D.getBoolPref( 'fullscreen' ), 'Go full screen by default' ],
    66 			remember_window: [ D.getBoolPref( 'remember_window' ), 'Remember main window position' ],
    67 			devmode:    [ D.getBoolPref( 'devmode' ), 'Developer mode' ]
       
    68 		}
    67 		}
       
    68 
       
    69 		// Running from the builder env (or manually with --debug), include
       
    70 		// developer options.
       
    71 		//
       
    72 		if ( Ti.App.getArguments()[0] == "--debug" )
       
    73 			bool_prefs.devmode = [ D.getBoolPref( 'devmode' ), 'Developer mode' ];
    69 
    74 
    70 		self.element.html(
    75 		self.element.html(
    71 			can.view( self.options.view, {
    76 			can.view( self.options.view, {
    72 				bool_prefs: bool_prefs
    77 				bool_prefs: bool_prefs
    73 			})
    78 			})
   107 	},
   112 	},
   108 
   113 
   109 	// Update the server URI preference.
   114 	// Update the server URI preference.
   110 	//
   115 	//
   111 	updateServer: function( uri ) {
   116 	updateServer: function( uri ) {
   112 		console.log( 'Updated server_uri to ' + uri + '.' );
   117 		if ( uri.length == 0 ) return;
   113 		D.setPref( 'server_uri', uri );
   118 		D.tf.attr( 'uri', uri );
   114 		D.tf.uri = uri;
   119 
       
   120 		if ( D.tf.version ) {
       
   121 			D.setPref( 'server_uri', uri );
       
   122 			console.log( 'Updated server_uri to ' + uri + '.' );
       
   123 			$( '#test .info' ).html( D.tf.version );
       
   124 			$( '#test .icon' ).html( '' );
       
   125 		}
       
   126 		else {
       
   127 			$( '#test .info' ).empty();
       
   128 			$( '#test .icon' ).html( '' );
       
   129 		}
   115 	},
   130 	},
   116 
   131 
   117 	// Hitting the return key on input fields defer to the 'blur' event,
   132 	// Hitting the return key on input fields defer to the 'blur' event,
   118 	// which in turn fires the 'change' event.
   133 	// which in turn fires the 'change' event.
   119 	//
   134 	//
   120 	"#server keypress": function( ele, event ) {
   135 	"#server keypress": function( ele, event ) {
   121 		if ( event.which == 13 ) ele.trigger( 'blur' );
   136 		if ( event.which == 13 ) ele.trigger( 'blur' );
   122 	},
   137 	},
   123 	'#server change': function( ele, event ) {
   138 	'#server change': function( ele, event ) {
   124 		this.updateServer( ele.val() );
   139 		var self = this;
       
   140 		self.updateServer( ele.val() );
   125 	},
   141 	},
   126 	'#server keyup': function( ele, event ) {
   142 	'#server keyup': function( ele, event ) {
       
   143 		var self = this;
   127 		D.delay( function() {
   144 		D.delay( function() {
   128 			this.updateServer( ele.val() );
   145 			self.updateServer( ele.val() );
   129 		}, 500, true );
   146 		}, 1000, true );
   130 	},
   147 	}
   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 });
   148 });
   141 
   149