Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

started router w/ custom dispatcher

  • Loading branch information...
commit 607780b167c8202e7b9c391a42c03deca5c9cd5c 1 parent 30c28d6
@nilclass authored
View
92 app/dspace.js
@@ -1,20 +1,96 @@
define([
+ 'backbone',
+
'models/world',
'views/ui'
-], function(World, UI) {
+], function(Backbone, World, UI) {
/**
* Class: DSpace
*
* it doesn't matter ;)
*/
- return {
- init: function(config) {
- var world = new World({ config : config });
- var ui = new UI({ world: world });
- ui.render();
- return world;
+ return Backbone.Router.extend({
+
+ initialize: function(config) {
+ this.world = new World({ config : config });
+ this.ui = new UI({ world: this.world, dspace: this });
+ this.ui.render();
+ Backbone.history.start();
+ },
+
+ routes: {
+ '!*path': 'dispatch',
+ },
+
+ parseRoute: function(path) {
+ var routeParts = {};
+ path.split(':').forEach(function(part) {
+ var featureRoute = part.match(/^feature\/(.+)$/);
+ if(featureRoute) {
+ routeParts.feature = featureRoute[1]
+ } else {
+ routeParts[part] = true;
+ }
+ }.bind(this));
+ return routeParts;
+ },
+
+ generateRoute: function(routeParts) {
+ var pathParts = [];
+ for(var key in routeParts) {
+ if(routeParts[key] === true) {
+ pathParts.push(key);
+ } else {
+ pathParts.push(key + '/' + routeParts[key]);
+ }
+ }
+ return pathParts.join(':');
+ },
+
+ dispatch: function(path) {
+ this.reset();
+ var routeParts = this.parseRoute(path);
+ this.parsedRoute = routeParts;
+ console.log('DISPATCH', routeParts);
+ for(var key in routeParts) {
+ if(routeParts[key] === true) {
+ this.processFlag(key);
+ } else {
+ this[key](routeParts[key]);
+ }
+ }
+ },
+
+ reset: function() {
+ this.ui.reset();
+ },
+
+ feature: function(uuid) {
+ console.log('load feature: ' + uuid);
+ },
+
+ processFlag: function(flag) {
+ switch(flag) {
+ case 'userOptions':
+ this.ui.showUserOptions();
+ break;
+ default:
+ console.error("Don't know how to handle URI flag: " + flag);
+ }
+ },
+
+ addFlag: function(flag) {
+ console.log('parsedRoute', JSON.stringify(this.parsedRoute));
+ this.parsedRoute[flag] = true;
+ this.navigate('!' + this.generateRoute(this.parsedRoute), { trigger: true });
+ },
+
+ removeFlag: function(flag) {
+ delete this.parsedRoute[flag];
+ this.navigate('!' + this.generateRoute(this.parsedRoute), { trigger: true });
}
- };
+
+ });
});
View
3  app/main.js
@@ -4,7 +4,8 @@ define(['ender', './dspace', './config'], function($, DSpace, config) {
* BIG BANG!
*/
$.domReady(function () {
- window.world = DSpace.init(config);
+ window.dspace = new DSpace(config);
+ window.world = dspace.world;
});
});
View
2  app/views/modal/userOptions.js
@@ -5,7 +5,7 @@ define([
], function(Backbone, panels, templates) {
/**
- * Class: OptionsPanel
+ * Class: Modal.UserOptions
*
* UI element for Options
*
View
55 app/views/ui.js
@@ -97,6 +97,13 @@ define([
this.world = this.options.world;
/**
+ * Property: dspace
+ *
+ * reference to the global Backbone.Router called <DSpace>
+ */
+ this.dspace = this.options.dspace;
+
+ /**
* Property: map
*
* reference to the <Map> from
@@ -163,6 +170,11 @@ define([
this.controlPanel.visible = true;
},
+ reset: function() {
+ //this.map.reset();
+ this.hideUserOptions();
+ },
+
/**
* Method: boxToggle
*
@@ -193,22 +205,49 @@ define([
/**
* Method: toggleUserOptions
*
- * toggles <UserOptions>
+ * toggles <Modal.UserOptions> using <showUserOptions>/<hideUserOptions>
*/
toggleUserOptions: function() {
if(this.userOptions) {
- this.userOptions.hide();
- delete this.userOptions;
+ //this.hideUserOptions();
+ this.dspace.removeFlag('userOptions');
} else {
- this.userOptions = new UserOptions({
- user: this.world.user,
- aether: this.aether
- });
- this.userOptions.show();
+ this.dspace.addFlag('userOptions');
+ //this.showUserOptions();
}
},
/**
+ * Method: hideUserOptions
+ *
+ * Hides the <Modal.UserOptions> view and cleans up it's reference.
+ *
+ */
+ hideUserOptions: function() {
+ if(! this.userOptions) {
+ return;
+ }
+ this.userOptions.hide();
+ delete this.userOptions;
+ },
+
+ /**
+ * Method: showUserOptions
+ *
+ * Creates a <Modal.UserOptions> view and displays it.
+ */
+ showUserOptions: function() {
+ if(this.userOptions) {
+ return;
+ }
+ this.userOptions = new UserOptions({
+ user: this.world.user,
+ aether: this.aether
+ });
+ this.userOptions.show();
+ },
+
+ /**
* Method: fullscreenToggle
*
* toggles fulls creen mode
Please sign in to comment.
Something went wrong with that request. Please try again.