Created
November 15, 2011 17:35
-
-
Save meirish/1367724 to your computer and use it in GitHub Desktop.
require.js view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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