Skip to content

Instantly share code, notes, and snippets.

@raytiley
Last active December 15, 2015 08:19
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 raytiley/5230046 to your computer and use it in GitHub Desktop.
Save raytiley/5230046 to your computer and use it in GitHub Desktop.
Need some help figuring out why the content in the sortable-item view is coming from the CategoryController and not the DocumentController
App.CategoryController = Ember.ObjectController.extend({
needs: ['documents'],
uploads: new Array()
});
App.DocumentController = Ember.ObjectController.extend({
isEditing:true,
editDocument: function () {
console.log('handling edit');
this.set('isEditing', true);
},
finishedEditing: function() {
var model = this.get('model');
model.get('store').commit();
this.set('isEditing', false);
}
});
App.DocumentsController = Ember.ArrayController.extend({
needs: ['category'],
contentBinding: 'controllers.category.documents',
itemController: 'document'
});
App.SortableView = Ember.CollectionView.extend({
tagName: 'ul',
itemViewClass: 'App.SortableItemView',
didInsertElement: function(){
var view = this;
Ember.run.next(function() {
$(view.get('element')).sortable();
});
}
});
App.SortableItemView = Ember.View.extend({
templateName: 'sortable-item',
doubleClick: function() {
console.log('double click happening');
console.log(this.get('content'));
this.get('content').send('editDocument');
}
});
App.InlineDocumentEditView = Ember.TextField.extend({
classNames: ['edit'],
change: function () {
var value = this.get('value');
},
focusOut: function () {
this.get("controller").send("finishedEditing");
},
insertNewline: function () {
this.get("controller").send("finishedEditing");
},
didInsertElement: function () {
this.$().focus();
}
});
<script type="text/x-handlebars" data-template-name="category">
<h3>{{ name }}</h3>
{{view App.FileSelectionView }}
{{#each upload in uploads }}
{{ upload.fileName }} - {{ upload.progress }} %
<div class="progress progress-striped active">
<div class="bar" {{bindAttr style="upload.progressStyle"}}></div>
</div>
{{/each}}
<ul>
{{view App.SortableView contentBinding="controllers.documents" }}
</script>
<script type="text/x-handlebars" data-template-name="sortable-item">
{{#if content.isEditing}}
{{view App.InlineDocumentEditView valueBinding="content.name" }}
{{else}}
<!-- This content.name is coming fromt the category, not document -->
<label>{{ content.name }}</label>
<a {{bindAttr href="content.url"}}>download</a>
{{/if}}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment