Download:
child 9:8a7155aff782
parent 7:5c5d433b3a14
8:39ac2486b9d3
Anton Shestakov <engored@ya.ru>, Thu, 27 Dec 2012 00:34:49 +0900
Use events to not smear workspaces all over the code.

3 файлов изменено, 17 вставок(+), 16 удалений(-) [+]
static/js/framework/collections.js file | annotate | diff | comparison | revisions
static/js/framework/router.js file | annotate | diff | comparison | revisions
static/js/ui.js file | annotate | diff | comparison | revisions
--- a/static/js/framework/collections.js Thu Dec 27 00:12:30 2012 +0900
+++ b/static/js/framework/collections.js Thu Dec 27 00:34:49 2012 +0900
@@ -1,13 +1,7 @@
var Projects = Backbone.Collection.extend({
- model: Project,
- url: function() {
- return '/' + encodeURIComponent(fruitbar.workspace) + '/projects/';
- }
+ model: Project
});
var Tasks = Backbone.Collection.extend({
- model: Task,
- url: function() {
- return '/' + encodeURIComponent(fruitbar.workspace) + '/tasks/';
- }
+ model: Task
});
--- a/static/js/framework/router.js Thu Dec 27 00:12:30 2012 +0900
+++ b/static/js/framework/router.js Thu Dec 27 00:34:49 2012 +0900
@@ -16,9 +16,6 @@
},
setWorkspace: function(workspace) {
- fruitbar.workspace = workspace;
-
- fruitbar.tasks.fetch();
- fruitbar.projects.fetch();
+ fruitbar.trigger('workspace', workspace);
}
});
--- a/static/js/ui.js Thu Dec 27 00:12:30 2012 +0900
+++ b/static/js/ui.js Thu Dec 27 00:34:49 2012 +0900
@@ -1,5 +1,5 @@
$(function() {
- window.fruitbar = {workspace: undefined};
+ window.fruitbar = new Backbone.View();
fruitbar.tasks = new Tasks();
fruitbar.projects = new Projects();
fruitbar.router = new Router();
@@ -22,8 +22,18 @@
}
});
- Backbone.history.start();
+ fruitbar.on('workspace', function(workspace) {
+ this.tasks.url = '/' + encodeURIComponent(workspace) + '/tasks/';
+ this.projects.url = '/' + encodeURIComponent(workspace) + '/projects/';
+
+ this.tasks.fetch();
+ this.projects.fetch();
+ });
- window.setInterval(function() {fruitbar.projects.fetch({update: true});}, 60000);
- window.setInterval(function() {fruitbar.tasks.fetch({update: true});}, 60000);
+ fruitbar.once('workspace', function() {
+ window.setInterval(function() {fruitbar.projects.fetch({update: true});}, 60000);
+ window.setInterval(function() {fruitbar.tasks.fetch({update: true});}, 60000);
+ });
+
+ Backbone.history.start();
});