Skip to content

Commit

Permalink
moving cParams to the configuration file, adding comments about each …
Browse files Browse the repository at this point in the history
…component
  • Loading branch information
addyosmani committed Jan 27, 2012
1 parent baf897f commit a82ef4f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 32 deletions.
48 changes: 39 additions & 9 deletions utils/backbone.paginator.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(function(mixins){


// @name: Paginator.queryParams
// @description:
// queryParams contains the actual values being passed
// back to the server between requests. It uses a set of
// standard keynames that the application internally uses
Expand All @@ -15,31 +17,32 @@
// changing (e.g a new paged set is received and we wish to
// update the totalPages value). If you would prefer

/*Parameters to pass back to the server*/
// Parameters to pass back to the server
mixins.Paginator.queryParams = {

/**current page to query from the service*/
// current page to query from the service
page: 1,

/*how many results to query from the service*/
// how many results to query from the service
perPage: 30,

/*maximum number of pages that can be queried from the server*/
// maximum number of pages that can be queried from the server
totalPages: 10, // a default. This should be overridden in the collection's parse()

/*sort direction*/
// sort direction
sortDirection: 'asc',

/*sort field*/
// sort field
sortField: 'ReleaseYear', //or year(Instant/AvailableFrom)

/*query*/
// query
query: 'the',

/*request format*/
// request format
format: 'json',

/*custom parameters for the request that are non-standard*/
// custom parameters for the request that may be specific to your
// application
customParam1: 'allpages',

customParam2: 'callback'
Expand All @@ -49,6 +52,8 @@
};


// @name: queryMap
// @description:
// As can be seen below, the queryMap can contain not just direct references
// to values in the queryParams object but can also contain mutated values
// such as $skip, which is composed by multipying the current page by the
Expand All @@ -75,4 +80,29 @@
};


// @name: cParams
// Configures how data returned from the server should be paginated in
// a view. For example, if the server returns a payload of 50 results
// (in the current setup) this will paginate the results with 20 shown
// per 'page', beginning with page 1

mixins.Paginator.cParams = {

// how many items to show per page in the view?
perPage : 20,

// page to start off on for pagination in the view?
page : 1,

// sort field
sortField: 'text',

// sort direction
sortDirection: 'asc'

};




})( App.mixins);
35 changes: 12 additions & 23 deletions utils/backbone.paginator.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
/**
* Backbone.Paginator
**/


(function ( mixins ) {

mixins.Paginator = {

/*Work against the result set retrieved so far - defaults*/
cParams:{

/** how many items to show per page in the view */
perPage : 20,

/** page to start off on for pagination in the view */
page : 1,

/*sort field*/
sortField: 'text',

/*sort direction*/
sortDirection: 'asc'

},
// @name: Paginator
// @description:
// The paginator is responsible for providing pagination
// and sort capabilities for a collection. It's main role
// in the demo application is showing how this can be applied
// to data returned from the server. It is not responsible
// for allowing us to page through server-side results as
// this is done using the logic in our View along with the
// backbone.paginator.config.js's queryMap and queryParams
// objects. These are loaded alongside the Paginator in
// our collection.

mixins.Paginator = {

nextPage : function () {
this.cParams.page = ++this.cParams.page;
Expand Down

0 comments on commit a82ef4f

Please sign in to comment.