0 | var ProjectsView = CollectionViewWithInlineEditor.extend({ |
initialize: function(options) { | |
this.tasks = options.tasks; | |
this.rawTemplates = options.templates; | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | this.compileTemplates(options.templates); |
this.bindCollection(); | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | options.controls.create.click(function() { |
options.collection.create({ | |
name: 'new project' | |
}, {wait: true}); | |
}); | |
}, | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | clear: function() { |
this.$el.empty(); | |
}, | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | renderItem: function(project) { |
var $item = $(this.templates.project(project.toJSON())); | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | $item.tasksView = new TasksView({ |
el: $item.find('.tasks'), | |
collection: project.tasks, | |
templates: this.rawTemplates, | |
controls: { | |
create: $item.find('.btn-new-task') | |
} | |
}); | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | $item |
.find('.progress') | |
.click(function() { | |
var $progress = $(this); | |
$progress.addClass('active'); | |
project.switchColor().then(function() { | |
$progress.removeClass('active'); | |
}); | |
}); | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | $item |
.find('.btn-delete-project') | |
.click(function() { | |
project.destroy({wait: true}); | |
}); | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | return $item; |
}, | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | updateProgress: function(project) { |
project.$item | |
61
61:ecb8269aa17f
update to Bootstrap 3
Anton Shestakov <av6@dwimlabs.net>
previous changes: 12:2c9942109f13
line |
diff
|
.find('.progress-bar') |
61:ecb8269aa17f
update to Bootstrap 3
Anton Shestakov <av6@dwimlabs.net>
previous changes: 12:2c9942109f13
line |
diff
|
.removeClass('progress-bar-info progress-bar-success progress-bar-warning progress-bar-danger') |
61:ecb8269aa17f
update to Bootstrap 3
Anton Shestakov <av6@dwimlabs.net>
previous changes: 12:2c9942109f13
line |
diff
|
.addClass(project.get('color') ? 'progress-bar-' + project.get('color') : '') |
61:ecb8269aa17f
update to Bootstrap 3
Anton Shestakov <av6@dwimlabs.net>
previous changes: 12:2c9942109f13
line |
diff
|
.attr('aria-valuenow', (100 * project.tasks.progress())) |
0 | .css('width', (100 * project.tasks.progress()) + '%'); |
}, | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | appendItem: function(project) { |
var tasks = this.tasks; | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | project.tasks = new Backbone.Shard({ |
collection: this.tasks, | |
7
7:5c5d433b3a14
Moving toward a multi-workspace work model. There's no auth, knowing workspace id gives full access.
Anton Shestakov <engored@ya.ru>
previous changes: 0:a02e94c5b96b
line |
diff
|
filter: function(task) { return task.get('project_id') === project.id; } |
0 | }); |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | project.tasks.progress = function() { |
return this.filter(function(task) { return task.get('done') === true; }).length / this.size(); | |
}; | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | project.tasks.create = function(attributes, options) { |
attributes = attributes || {}; | |
61
61:ecb8269aa17f
update to Bootstrap 3
Anton Shestakov <av6@dwimlabs.net>
previous changes: 12:2c9942109f13
line |
diff
|
attributes.project_id = project.id; |
0 | return tasks.create(attributes, options); |
}; | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | project.$item = this.renderItem(project); |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | this.bindInlineEditable(project, '.inline-editable[data-model="project"]'); |
this.updateProgress(project); | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | project.on('change:name', function() { |
project.$item.find('[data-model="project"][data-model-attribute="name"]').text(project.get('name')); | |
}); | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | project.on('change:color', function() { |
this.updateProgress(project); | |
}, this); | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
12
12:2c9942109f13
Update project progress on tasks reset, of course.
Anton Shestakov <engored@ya.ru>
previous changes: 7:5c5d433b3a14
line |
diff
|
project.tasks.on('add remove change:done reset', function() { |
0 | this.updateProgress(project); |
}, this); | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | this.$el.append(project.$item); |
}, | |
148
148:7a236aa969f8
js: remove trailing spaces
Anton Shestakov <av6@dwimlabs.net>
previous changes: 61:ecb8269aa17f
line |
diff
|
|
0 | removeItem: function(project) { |
project.$item.remove(); | |
} | |
}); |