101:c9a81d64b0c3
Anton Shestakov <av6@dwimlabs.net>, Tue, 19 Jul 2016 17:51:59 +0800
tests: pass data to create_resource() and update_resource() explicitly

next change 102:325b3b4ce18b
previous change 43:d1ff547fa61d

static/js/ui.js

Permissions: -rw-r--r--

Other formats: Feeds:
$(function() {
window.fruitbar = new Backbone.View();
fruitbar.workspaces = new Workspaces();
fruitbar.tasks = new Tasks();
fruitbar.projects = new Projects();
fruitbar.router = new Router();
fruitbar.xhrs = [];
fruitbar.xhrs.done = function() {
return _(this).all(function(xhr) {
return xhr.readyState == 4;
});
};
fruitbar.xhrs.abort = function() {
_(this).each(function(xhr) {
xhr.abort();
});
this.length = 0;
};
fruitbar.fetchAll = function(url) {
return Backbone.ajax({
url: url,
type: 'GET',
dataType: 'json'
}).done(function(data) {
fruitbar.projects.set(data['projects']);
fruitbar.tasks.set(data['tasks']);
});
};
fruitbar.workspaceTitleDisplayer = new Displayer({
el: $('.workspace-title')
});
fruitbar.workspaceTabs = new WorkspaceTabsView({
el: $('.workspace-tabs'),
collection: fruitbar.workspaces,
templates: {
tab: $.trim($('#workspace-tab-template').html())
}
});
fruitbar.projectCounter = new CollectionCounterView({
el: $('.project-counter'),
collection: fruitbar.projects,
plurals: ['project', 'projects']
});
fruitbar.projectsView = new ProjectsView({
el: $('.projects'),
collection: fruitbar.projects,
tasks: fruitbar.tasks,
templates: {
project: $.trim($('#project-template').html()),
task: $.trim($('#task-template').html())
},
controls: {
create: $('.btn-new-project')
}
});
fruitbar.on('workspace', function(workspace) {
$('body').stop().animate({opacity: 0});
this.xhrs.abort();
this.workspace = workspace;
this.workspaces.create({name: workspace});
this.tasks.url = '/' + encodeURIComponent(workspace) + '/tasks/';
this.projects.url = '/' + encodeURIComponent(workspace) + '/projects/';
this.xhrs.push(this.fetchAll('/' + encodeURIComponent(workspace) + '/all/'));
_(this.xhrs).each(function(fetch, index, xhrs) {
fetch.then(function() {
if (xhrs.done()) {
fruitbar.workspaceTitleDisplayer.render(workspace);
fruitbar.workspaceTabs.activate(workspace);
$('body').stop().animate({opacity: 1});
}
});
});
});
fruitbar.once('workspace', function() {
window.setInterval(function() {
fruitbar.xhrs.push(fruitbar.fetchAll('/' + encodeURIComponent(fruitbar.workspace) + '/all/'));
}, 60000);
});
fruitbar.workspaces.fetch();
Backbone.history.start();
});