Anton Shestakov <av6@dwimlabs.net>, Wed, 02 Mar 2016 21:38:07 +0800
requirements: update Flask-Assets, Flask-RESTful, jsmin
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-bar-info progress-bar-success progress-bar-warning progress-bar-danger') .addClass(project.get('color') ? 'progress-bar-' + project.get('color') : '') .attr('aria-valuenow', (100 * project.tasks.progress())) .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) {