Anton Shestakov <engored@ya.ru>, Wed, 26 Dec 2012 22:01:21 +0900
Added tag 0.1.0 for changeset 1622dbdfa709
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') === 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'] = 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', function() { this.updateProgress(project); this.$el.append(project.$item); removeItem: function(project) {