Skip to content

Instantly share code, notes, and snippets.

@meirish
Created November 15, 2011 17:35
Show Gist options
  • Save meirish/1367724 to your computer and use it in GitHub Desktop.
Save meirish/1367724 to your computer and use it in GitHub Desktop.
require.js view
define([
'jquery',
'underscore',
'backbone',
'collections/widget-list',
'text!templates/widget-list.html',
'ui'
], function($,_,Backbone, WidgetCollection, widgetTemplate){
var WidgetList = Backbone.View.extend({
className: 'widget-list',
template: _.template(widgetTemplate),
events:{
'touchstart .w-add':'showWidgetList',
'click .w-add':'showWidgetList',
'touchstart .w-remove':'removeWidget',
'click .w-remove':'removeWidget'
},
initialize: function(options){
this.collection = new WidgetCollection([],{store:"morning"});
this.collection.fetch();
this.collection.bind('reset', this.refresh, this);
this.render();
this.bind('swapCollection', this.swapCollection);
},
render: function(){
$('.widget-container').append( this.refresh() );
return this;
},
refresh: function(){
var context = {
widgets: this.collection.toJSON(),
_: _
};
return $(this.el).html(this.template(context));
},
swapCollection:
showWidgetDialog: function(e){},
removeWidget: function(e){}
});
return WidgetList;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment