Skip to content

Instantly share code, notes, and snippets.

@superlou
Last active December 16, 2015 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superlou/5359559 to your computer and use it in GitHub Desktop.
Save superlou/5359559 to your computer and use it in GitHub Desktop.
{{#linkTo task task}}
<div class="task-item">
{{task.name}}Test
{{#each task.tags}}
<span class='label pull-right'>{{name}}</span>
{{/each}}
</div>
{{/linkTo}}
App.TasksRoute = Ember.Route.extend {
model: ->
return App.Task.find()
}
# App.TaskRoute = Ember.Route.extend {
# model: (params)->
# task = App.Task.find(params.task_id)
# console.log(task.get('isNew'))
# return task
# }
App.TasksNewRoute = Ember.Route.extend {
setupController: (controller, model) ->
controller.set 'name', 'Name this task'
controller.set 'details', 'Describe this task'
}
App.TasksNewController = Ember.Controller.extend {
name: ''
details: ''
needs: ['tags']
filterOnBinding: 'controllers.tags.filterOn'
createTask: ->
if this.get 'filterOn'
tags = [this.get 'filterOn']
else
tags = []
testTag = App.Tag.find(1)
newTask = App.Task.createRecord {
name: this.get('name')
details: this.get('details')
#tags: [testTag] #<-- Wish I knew why this doesn't work
}
for tagId in tags
newTask.get('tags').pushObject(App.Tag.find(tagId))
this.get('target').transitionTo('task', newTask)
}
App.TasksController = Ember.ArrayController.extend {
needs: ['tags']
filterOnBinding: 'controllers.tags.filterOn'
filteredContent: (->
content = this.get 'content'
filterOn = this.get 'filterOn'
if filterOn
filtered = content.filter( (task)->
taskTagIds = task.get('tags').mapProperty('id')
return taskTagIds.contains(filterOn)
)
return filtered
else
return content
).property('content', 'filterOn', 'content.@each.tags')
}
App.TasksListItemView = Ember.View.extend {
templateName: 'tasks-list-item'
classNames: ['task-item']
}
App.TasksListView = Ember.CollectionView.extend {
tagName: 'ul'
classNames: ['tasks-list']
itemViewClass: App.TasksListItemView
didInsertElement: ->
this._super();
this.$().sortable().disableSelection();
console.log(this.get('context').get('content').get('length'))
}
App.TasksListController = Ember.ArrayController.extend {
needs: ['tasks']
contentBinding: 'controllers.tasks.filteredContent'
}
App.TaskController = Ember.ObjectController.extend {
triggerAutosize: (->
$('.details textarea').trigger('autosize');
).observes('content.details')
deleteTask: ->
this.get('content').deleteRecord();
this.get('target').transitionTo('tasks')
}
Ember.TextArea.reopen {
didInsertElement: ->
$('.details textarea').autosize({append: "\n"})
# Hack to not transition textarea height on creation
setTimeout ->
$('.details textarea').addClass('transition')
, 1000
this._super()
}
<div class="left">
<div class='tools'>
{{render tags}}
{{#linkTo tasks.new class='btn btn-small btn-primary pull-right'}}New{{/linkTo}}
</div>
<div class='tasks-list'>
{{render 'tasks-list'}}
{{#each task in filteredContent}}
{{ partial "taskItem" }}
{{/each}}
</div>
</div>
<div class="right">
{{outlet}}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment