Anton Shestakov <engored@ya.ru>, Fri, 11 Jan 2013 17:34:13 +0900
Docs.
static/js/framework/views/projects.js
Permissions: -rw-r--r--
var ProjectsView = CollectionViewWithInlineEditor.extend({ initialize: function(options) { this.tasks = options.tasks; this.rawTemplates = options.templates; this.compileTemplates(options.templates); options.controls.create.click(function() { options.collection.create({ renderItem: function(project) { var $item = $(this.templates.project(project.toJSON())); $item.tasksView = new TasksView({ el: $item.find('.tasks'), collection: project.tasks, templates: this.rawTemplates, create: $item.find('.btn-new-task') $progress.addClass('active'); project.switchColor().then(function() { $progress.removeClass('active'); .find('.btn-delete-project') project.destroy({wait: true}); updateProgress: function(project) { .removeClass('progress-info progress-success progress-warning progress-danger') .addClass(project.get('color') ? 'progress-' + project.get('color') : '') .css('width', (100 * project.tasks.progress()) + '%'); appendItem: function(project) { project.tasks = new Backbone.Shard({ filter: function(task) { return task.get('project_id') === project.id; } project.tasks.progress = function() { return this.filter(function(task) { return task.get('done') === true; }).length / this.size(); project.tasks.create = function(attributes, options) { attributes = attributes || {}; attributes['project_id'] = project.id; return tasks.create(attributes, options); project.$item = this.renderItem(project); this.bindInlineEditable(project, '.inline-editable[data-model="project"]'); this.updateProgress(project); project.on('change:name', function() { project.$item.find('[data-model="project"][data-model-attribute="name"]').text(project.get('name')); project.on('change:color', function() { this.updateProgress(project); project.tasks.on('add remove change:done reset', function() { this.updateProgress(project); this.$el.append(project.$item); removeItem: function(project) {