Index: trunk/extensions/PageTriage/modules/ext.pageTriage.views/ext.pageTriage.listView.js |
— | — | @@ -0,0 +1,59 @@ |
| 2 | +$( function() { |
| 3 | + // view for the article list |
| 4 | + |
| 5 | + // instantiate the collection of articles |
| 6 | + var articles = new mw.pageTriage.ArticleList; |
| 7 | + |
| 8 | + // set the default sort order. |
| 9 | + articles.comparator = function( article ) { |
| 10 | + return -article.get( "creation_date" ); |
| 11 | + }; |
| 12 | + |
| 13 | + // overall list view |
| 14 | + // currently, this is the main application view. |
| 15 | + mw.pageTriage.ListView = Backbone.View.extend( { |
| 16 | + |
| 17 | + initialize: function() { |
| 18 | + |
| 19 | + // these events are triggered when items are added to the articles collection |
| 20 | + this.position = 0; |
| 21 | + articles.bind( 'add', this.addOne, this ); |
| 22 | + articles.bind( 'reset', this.addAll, this ); |
| 23 | + |
| 24 | + // this event is triggered when the collection finishes loading. |
| 25 | + articles.bind( 'all', this.render, this ); |
| 26 | + |
| 27 | + // on init, make sure to load the contents of the collection. |
| 28 | + articles.fetch(); |
| 29 | + }, |
| 30 | + |
| 31 | + render: function() { |
| 32 | + this.position = 0; |
| 33 | + // TODO: refresh the view (show/hide the parts that aren't attached to the ListItem view) |
| 34 | + }, |
| 35 | + |
| 36 | + // add a single article to the list |
| 37 | + addOne: function( article ) { |
| 38 | + // define position, for making alternating background colors. |
| 39 | + // this is added at the last minute, so it gets updated when the sort changes. |
| 40 | + if(! this.position ) { |
| 41 | + this.position = 0; |
| 42 | + } |
| 43 | + article.set( 'position', this.position++ ); |
| 44 | + |
| 45 | + // pass in the specific article instance |
| 46 | + var view = new mw.pageTriage.ListItem( { model: article } ); |
| 47 | + this.$( "#listView" ).append( view.render().el ); |
| 48 | + }, |
| 49 | + |
| 50 | + // add all the items in the articles collection |
| 51 | + addAll: function() { |
| 52 | + $("#listView").empty(); // remove the spinner before displaying. |
| 53 | + articles.each( this.addOne ); |
| 54 | + } |
| 55 | + |
| 56 | + } ); |
| 57 | + |
| 58 | + // create an instance of the list view, which makes everything go. |
| 59 | + var list = new mw.pageTriage.ListView(); |
| 60 | +} ); |
Property changes on: trunk/extensions/PageTriage/modules/ext.pageTriage.views/ext.pageTriage.listView.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 61 | + native |