Last active
November 14, 2016 19:35
-
-
Save ninapavlich/f6c357ab71fa84c3dcc88f6887497ec7 to your computer and use it in GitHub Desktop.
Simple nshell implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ======================================================================== | |
======= Custom Data Object ================================================ | |
======================================================================== */ | |
var CustomAppData = function(test) { | |
// Call the parent constructor | |
BaseModel.call(this); | |
this.items = []; | |
} | |
CustomAppData.prototype = new BaseModel(); | |
CustomAppData.prototype.constructor = CustomAppData; | |
CustomAppData.prototype.create_user_data = function (model, states) { return null; } | |
CustomAppData.prototype._custom_parse_application_data = function (json) { | |
//DO ANY CUSTOM PARSING OF THE CONTENT JSON HERE... | |
this.items = json.objects; | |
} | |
CustomAppData.prototype._get_images_to_preload = function(){ | |
var output = []; | |
if(this.debug_enable){ | |
console.warn("Skipping image preload because debug is turned on.") | |
return output; | |
} | |
for(var k=0; k<this.items.length; k++){ | |
var item = current_items[k]; | |
output.push(item.image_url); | |
} | |
return output; | |
} | |
CustomAppData.prototype._get_audio_to_preload = function(){ return [];} | |
CustomAppData.prototype._get_video_to_preload = function(){ return [];} | |
/* ======================================================================== | |
======= Custom States Object ============================================== | |
======================================================================== */ | |
var CustomAppStates = function(root_element) { | |
// Call the parent constructor | |
BaseStates.call(this); | |
} | |
CustomAppStates.prototype = new BaseStates(); | |
CustomAppStates.prototype.constructor = CustomAppStates; | |
/* -- Custon states -- */ | |
CustomAppStates.app_state_browse = "app_state_browse "; | |
CustomAppStates.prototype.get_app_states = function (state) { | |
return [ | |
BaseStates.app_state_bootstrapping, | |
BaseStates.app_state_attract, | |
CustomAppStates.app_state_browse | |
] | |
} | |
CustomAppStates.prototype.get_starting_app_state = function (state) { | |
return CustomAppStates.app_state_browse | |
} | |
/* ======================================================================== | |
======= Custom VIEW Object ================================================ | |
======================================================================== */ | |
var CustomAppView = function(root_element) { | |
//DO WHATEVER YOU WANT HERE | |
} | |
CustomAppView.prototype.init = function(options, data, states){ | |
this.options = options; | |
this.data = data; | |
this.states = states; | |
//State listeners | |
this.states.add_listener(BaseStates.event_app_state_change, this, this.handle_app_state_change); | |
this.states.add_listener(BaseStates.event_language_change, this, this.handle_language_change); | |
this.states.add_listener(BaseStates.event_data_ready, this, this.handle_data_ready); | |
//Data listeners | |
this.model.add_listener(BaseModel.event_kiosk_config_data_change, this, this.handle_kiosk_config_data_change); | |
this.model.add_listener(BaseModel.event_kiosk_data_change, this, this.handle_kiosk_data_change); | |
}; | |
// ---- STATE CHANGES ----------------------------------------------------- | |
CustomAppView.prototype.handle_app_state_change = function( event, object ) { | |
this.render_state(); | |
} | |
CustomAppView.prototype.handle_language_change = function( event, object ){ | |
this.render_language(); | |
} | |
CustomAppView.prototype.handle_data_ready = function( event, object ) { | |
console.log("TODO: Start application...") | |
} | |
// ---- DATA CHANGES ----------------------------------------------------- | |
CustomAppView.prototype.handle_kiosk_config_data_change = function( event, object ) { | |
this.render_settings(); | |
this.render_language(); | |
} | |
CustomAppView.prototype.handle_kiosk_data_change = function( event, object ) { | |
this.render_data(); | |
} | |
// ---- RENDERING CHANGES ----------------------------------------------------- | |
CustomAppView.prototype.render_state = function() { | |
console.log("TODO: App state is "+this.states.get_app_state()) | |
} | |
CustomAppView.prototype.render_settings = function() { | |
console.log("TODO: Update configuration settings...") | |
} | |
CustomAppView.prototype.render_data = function() { | |
console.log("TODO: Update kiosk data...") | |
} | |
CustomAppView.prototype.render_language = function() { | |
console.log("TODO: Update language labels...") | |
} | |
/* ======================================================================== | |
======= INSTANTIATION ===================================================== | |
======================================================================== */ | |
var Kiosk = function(options, element) { | |
this.options = Kiosk.OPTIONS = options; | |
this.data = new CustomAppData(); | |
this.states = new CustomAppStates(); | |
this.view = new CustomAppView(); | |
this.data.init(options, this.states); | |
this.states.init(options, this.data); | |
this.view.init(this.options, this.data, this.states); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment