Ext.data.JsonP.Backbone_PageableCollection({ "tagname": "class", "name": "Backbone.PageableCollection", "extends": "Backbone.Collection", "mixins": [ ], "alternateClassNames": [ ], "aliases": { }, "singleton": false, "requires": [ ], "uses": [ ], "enum": null, "override": null, "inheritable": null, "inheritdoc": null, "meta": { }, "private": null, "id": "class-Backbone.PageableCollection", "members": { "cfg": [ ], "property": [ { "name": "fullCollection", "tagname": "property", "owner": "Backbone.PageableCollection", "meta": { }, "id": "property-fullCollection" }, { "name": "mode", "tagname": "property", "owner": "Backbone.PageableCollection", "meta": { }, "id": "property-mode" }, { "name": "queryParams", "tagname": "property", "owner": "Backbone.PageableCollection", "meta": { }, "id": "property-queryParams" }, { "name": "state", "tagname": "property", "owner": "Backbone.PageableCollection", "meta": { }, "id": "property-state" } ], "method": [ { "name": "constructor", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { }, "id": "method-constructor" }, { "name": "_checkState", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "private": true }, "id": "method-_checkState" }, { "name": "_makeCollectionEventHandler", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "private": true }, "id": "method-_makeCollectionEventHandler" }, { "name": "_makeComparator", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "protected": true }, "id": "method-_makeComparator" }, { "name": "_makeFullCollection", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "private": true }, "id": "method-_makeFullCollection" }, { "name": "fetch", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { }, "id": "method-fetch" }, { "name": "getFirstPage", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "chainable": true }, "id": "method-getFirstPage" }, { "name": "getLastPage", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "chainable": true }, "id": "method-getLastPage" }, { "name": "getNextPage", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "chainable": true }, "id": "method-getNextPage" }, { "name": "getPage", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "chainable": true }, "id": "method-getPage" }, { "name": "getPageByOffset", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "chainable": true }, "id": "method-getPageByOffset" }, { "name": "getPreviousPage", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "chainable": true }, "id": "method-getPreviousPage" }, { "name": "hasNext", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { }, "id": "method-hasNext" }, { "name": "hasNextPage", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { }, "id": "method-hasNextPage" }, { "name": "hasPrevious", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { }, "id": "method-hasPrevious" }, { "name": "hasPreviousPage", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { }, "id": "method-hasPreviousPage" }, { "name": "parse", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { }, "id": "method-parse" }, { "name": "parseLinks", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { }, "id": "method-parseLinks" }, { "name": "parseRecords", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { }, "id": "method-parseRecords" }, { "name": "parseState", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { }, "id": "method-parseState" }, { "name": "setPageSize", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "chainable": true }, "id": "method-setPageSize" }, { "name": "setSorting", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "chainable": true }, "id": "method-setSorting" }, { "name": "switchMode", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "chainable": true }, "id": "method-switchMode" }, { "name": "sync", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { }, "id": "method-sync" } ], "event": [ ], "css_var": [ ], "css_mixin": [ ] }, "linenr": 120, "files": [ { "filename": "backbone-pageable.js", "href": null } ], "html_meta": { }, "statics": { "cfg": [ ], "property": [ ], "method": [ { "name": "noConflict", "tagname": "method", "owner": "Backbone.PageableCollection", "meta": { "static": true }, "id": "static-method-noConflict" } ], "event": [ ], "css_var": [ ], "css_mixin": [ ] }, "component": false, "superclasses": [ "Backbone.Collection" ], "subclasses": [ ], "mixedInto": [ ], "parentMixins": [ ], "html": "
Hierarchy
Backbone.CollectionBackbone.PageableCollection
Drop-in replacement for Backbone.Collection. Supports server-side and\nclient-side pagination and sorting. Client-side mode also support fully\nmulti-directional synchronization of changes between pages.
\nCLIENT MODE ONLY
\n\nThis collection is the internal storage for the bootstrapped or fetched\nmodels. You can use this if you want to operate on all the pages.
\nThe mode of\noperations for this collection. \"server\" paginates on the server-side,\n\"client\" paginates on the client-side and \"infinite\" paginates on the\nserver-side for APIs that do not support totalRecords.
Defaults to: "server"
A translation map to convert Backbone.PageableCollection state attributes\nto the query parameters accepted by your server API.
\n\nYou can override the default state by extending this class or specifying\nthem in options.queryParams object hash to the constructor.
Defaults to: {currentPage: "page", pageSize: "per_page", totalPages: "total_pages", totalRecords: "total_entries", sortKey: "sort_by", order: "order", directions: {"-1": "asc", "1": "desc"}}
Defaults to: "page"
Defaults to: "per_page"
Defaults to: "total_pages"
Defaults to: "total_entries"
Defaults to: "sort_by"
Defaults to: "order"
A\nmap for translating a Backbone.PageableCollection.state.order constant to\nthe ones your server API accepts.
\nDefaults to: {"-1": "asc", "1": "desc"}
The container object to store all pagination states.
\n\nYou can override the default state by extending this class or specifying\nthem in an options hash to the constructor.
The first page index. Set to 0 if\nyour server API uses 0-based indices. You should only override this value\nduring extension, initialization or reset by the server after\nfetching. This value should be read only at other times.
\nDefaults to: 1
The last page index. This value\nis read only and it's calculated based on whether firstPage is 0 or\n1, during bootstrapping, fetching and resetting. Please don't change this\nvalue under any circumstances.
Defaults to: null
The current page index. You\nshould only override this value during extension, initialization or reset\nby the server after fetching. This value should be read only at other\ntimes. Can be a 0-based or 1-based index, depending on whether\nfirstPage is 0 or 1. If left as default, it will be set to firstPage\non initialization.
Defaults to: null
How many records to show per\npage. This value is read only after initialization, if you want to\nchange the page size after initialization, you must call setPageSize.
\nDefaults to: 25
How many pages there are. This\nvalue is read only and it is calculated from totalRecords.
Defaults to: null
How many records there\nare. This value is required under server mode. This value is optional\nfor client mode as the number will be the same as the number of models\nduring bootstrapping and during fetching, either supplied by the server\nin the metadata, or calculated from the size of the response.
\nDefaults to: null
The model attribute to use for\nsorting.
\nDefaults to: null
The order to use for sorting. Specify\n-1 for ascending order or 1 for descending order. If 0, no client side\nsorting will be done and the order query parameter will not be sent to\nthe server during a fetch.
\nDefaults to: -1
Given a list of models or model attributues, bootstraps the full\ncollection in client mode or infinite mode, or just the page you want in\nserver mode.
\n\nIf you want to initialize a collection to a different state than the\ndefault, you can specify them in options.state. Any state parameters\nsupplied will be merged with the default. If you want to change the\ndefault mapping from state keys to your server API's query parameter\nnames, you can specifiy an object hash in option.queryParams. Likewise,\nany mapping provided will be merged with the default. Lastly, all\nBackbone.Collection constructor options are also accepted.
See:
\n\nIf specified, this\ncomparator is set to the current page under server mode, or the fullCollection\notherwise.
\nIf false and either a\noptions.comparator or sortKey is defined, the comparator is attached\nto the current page. Default is true under client or infinite mode and\nthe comparator will be attached to the fullCollection.
The state attributes overriding the defaults.
\nThe model attribute to use for\nsorting. If specified instead of options.comparator, a comparator will\nbe automatically created using this value, and optionally a sorting order\nspecified in options.state.order. The comparator is then attached to\nthe new collection instance.
The order to use for sorting. Specify\n-1 for ascending order and 1 for descending order.
\nSanity check this collection's pagination states. Only perform checks\nwhen all the required pagination state values are defined and not null.\nIf totalPages is undefined or null, it is set to totalRecords /\npageSize. lastPage is set according to whether firstPage is 0 or 1\nwhen no error occurs.
Returns the state object if no error was found.
If totalRecords, pageSize, currentPage or\nfirstPage is not a finite integer.
If pageSize, currentPage or firstPage is out\nof bounds.
Factory method that returns a Backbone event handler that responses to\nthe add, remove, reset, and the sort events. The returned event\nhandler will synchronize the current page collection and the full\ncollection's models.
Collection event handler
\nConvenient method for making a comparator sorted by a model attribute\nidentified by sortKey and ordered by order.
Like a Backbone.Collection, a Backbone.PageableCollection will maintain\nthe current page in sorted order on the client side if a comparator\nis attached to it. If the collection is in client mode, you can attach a\ncomparator to fullCollection to have all the pages reflect the global\nsorting order by specifying an option full to true. You must call\nsort manually or fullCollection.sort after calling this method to\nforce a resort.
While you can use this method to sort the current page in server mode,\nthe sorting order may not reflect the global sorting order due to the\nadditions or removals of the records on the server since the last\nfetch. If you want the most updated page in a global sorting order, it is\nrecommended that you set state.sortKey and optionally state.order, and\nthen call fetch.
\nSee state.sortKey.
Defaults to: this.state.sortKey
See state.order.
Defaults to: this.state.order
See setSorting.
\n\n\nMakes a Backbone.Collection that contains all the pages.
\nOptions for Backbone.Collection constructor.
\nFetch a page from the server in server mode, or all the pages in client\nmode. Under infinite mode, the current page is refetched by default and\nthen reset.
\n\nThe query string is constructed by translating the current pagination\nstate to your server API query parameter using queryParams. The current\npage will reset after fetch.
\nAccepts all\nBackbone.Collection#fetch\noptions.
\nFetch the first page in server mode, or reset the current page of this\ncollection to the first page in client or infinite mode.
\ngetPage options.
\nThe XMLHttpRequest\nfrom fetch or this.
\nFetch the last page in server mode, or reset the current page of this\ncollection to the last page in client mode.
\ngetPage options.
\nThe XMLHttpRequest\nfrom fetch or this.
\nFetch the next page in server mode, or reset the current page of this\ncollection to the next page in client mode.
\ngetPage options.
\nThe XMLHttpRequest\nfrom fetch or this.
\nGiven a page index, set state.currentPage to that index. If this\ncollection is in server mode, fetch the page using the updated state,\notherwise, reset the current page of this collection to the page\nspecified by index in client mode. If options.fetch is true, a fetch\ncan be forced in client mode before resetting the current page. Under\ninfinite mode, if the index is less than the current page, a reset is\ndone as in client mode. If the index is greater than the current page\nnumber, a fetch is made with the results appended to fullCollection.\nThe current page will then be reset after fetching.
The page index to go to, or the page name to\nlook up from #links in infinite mode.
\nThe XMLHttpRequest\nfrom fetch or this.
\nIf index is not a finite integer under server or\nclient mode, or does not yield a URL from #links under infinite mode.
If index is out of bounds.
Fetch the page for the provided item offset in server mode, or reset the current page of this\ncollection to the page for the provided item offset in client mode.
\ngetPage options.
\nThe XMLHttpRequest\nfrom fetch or this.
\nFetch the previous page in server mode, or reset the current page of this\ncollection to the previous page in client or infinite mode.
\ngetPage options.
\nThe XMLHttpRequest\nfrom fetch or this.
\ntrue if this collection can page forward, false\notherwise.
true if this collection can page backward, false\notherwise.
Parse server response data.
\n\nThis default implementation assumes the response data is in one of two\nstructures:
\n\n[\n {}, // Your new pagination state\n [{}, ...] // An array of JSON objects\n]\n\n\nOr,
\n\n[{}] // An array of JSON objects\n\n\nThe first structure is the preferred form because the pagination states\nmay have been updated on the server side, sending them down again allows\nthis collection to update its states. If the response has a pagination\nstate object, it is checked for errors.
\n\nThe second structure is the\nBackbone.Collection#parse\ndefault.
\n\n*Note:** this method has been further simplified since 1.1.7. While\n existing parse implementations will continue to work, new code is\n encouraged to override parseState and parseRecords instead.
\n\n @param {Object} resp The deserialized response data from the server.\n @param {Object} the options for the ajax request\n\n @return {Array.<Object>} An array of model objects\n\nParse pagination links from the server response. Only valid under\ninfinite mode.
\n\nGiven a response body and a XMLHttpRequest object, extract pagination\nlinks from them for infinite paging.
\n\nThis default implementation parses the RFC 5988 Link header and extract\n3 links from it - first, prev, next. Any subclasses overriding this\nmethod must return an object hash having only the keys\nabove. However, simply returning a next link or an empty hash if there\nare no more links should be enough for most implementations.
The deserialized response body.
\nThe XMLHttpRequest object for this\nresponse.
\nParse server response for an array of model objects.
\n\nThis default implementation first checks whether the response has any\nstate object as documented in parse. If it exists, the array of model\nobjects is assumed to be the second element, otherwise the entire\nresponse is returned directly.
\nThe deserialized response data from the server.
\nThe options passed through from the\nparse. (backbone >= 0.9.10 only)
An array of model objects
\nParse server response for server pagination state updates. Not applicable\nunder infinite mode.
\n\nThis default implementation first checks whether the response has any\nstate object as documented in parse. If it exists, a state object is\nreturned by mapping the server state keys to this pageable collection\ninstance's query parameter keys using queryParams.
It is NOT neccessary to return a full state object complete with all\nthe mappings defined in queryParams. Any state object resulted is merged\nwith a copy of the current pageable collection state and checked for\nsanity before actually updating. Most of the time, simply providing a new\ntotalRecords value is enough to trigger a full pagination state\nrecalculation.
parseState: function (resp, queryParams, state, options) {\n return {totalRecords: resp.total_entries};\n}\n\n\nIf you want to use header fields use:
\n\nparseState: function (resp, queryParams, state, options) {\n return {totalRecords: options.xhr.getResponseHeader(\"X-total\")};\n}\n\n\nThis method MUST return a new state object instead of directly\nmodifying the state object. The behavior of directly modifying state is\nundefined.
\nThe deserialized response data from the server.
\nA copy of queryParams.
\nA copy of state.
\nThe options passed through from\nparse. (backbone >= 0.9.10 only)
A new (partial) state object.
\nChange the page size of this collection.
\n\nUnder most if not all circumstances, you should call this method to\nchange the page size of a pageable collection because it will keep the\npagination state sane. By default, the method will recalculate the\ncurrent page number to one that will retain the current page's models\nwhen increasing the page size. When decreasing the page size, this method\nwill retain the last models to the current page that will fit into the\nsmaller page size.
\n\nIf options.first is true, changing the page size will also reset the\ncurrent page back to the first page instead of trying to be smart.
For server mode operations, changing the page size will trigger a fetch\nand subsequently a reset event.
For client mode operations, changing the page size will reset the\ncurrent page by recalculating the current page boundary on the client\nside.
If options.fetch is true, a fetch can be forced if the collection is in\nclient mode.
The new page size to set to state.
\nfetch options.
\nReset the current page number to\nthe first page if true.
Defaults to: false
If true, force a fetch in client mode.
The XMLHttpRequest\nfrom fetch or this.
\nIf pageSize is not a finite integer.
If pageSize is less than 1.
Adjusts the sorting for this pageable collection.
\n\nGiven a sortKey and an order, sets state.sortKey and\nstate.order. A comparator can be applied on the client side to sort in\nthe order defined if options.side is \"client\". By default the\ncomparator is applied to the fullCollection. Set options.full to\nfalse to apply a comparator to the current page under any mode. Setting\nsortKey to null removes the comparator from both the current page and\nthe full collection.
If a sortValue function is given, it will be passed the (model,\nsortKey) arguments and is used to extract a value from the model during\ncomparison sorts. If sortValue is not given, model.get(sortKey) is\nused for sorting.
See state.sortKey.
See state.order.
Defaults to: this.state.order
By default, \"client\" if\nmode is \"client\", \"server\" otherwise.
Defaults to: true
Switching between client, server and infinite mode.
\n\nIf switching from client to server mode, the fullCollection is emptied\nfirst and then deleted and a fetch is immediately issued for the current\npage from the server. Pass false to options.fetch to skip fetching.
If switching to infinite mode, and if options.models is given for an\narray of models, #links will be populated with a URL per page, using the\ndefault URL for this collection.
If switching from server to client mode, all of the pages are immediately\nrefetched. If you have too many pages, you can pass false to\noptions.fetch to skip fetching.
If switching to any mode from infinite mode, the #links will be deleted.
\nThe mode to switch to.
\nIf false, no fetching is done.
Defaults to: true
If 'false', the state is not\nreset, but checked for sanity instead.
\nDefaults to: true
The XMLHttpRequest\nfrom fetch or this if options.fetch is false.
Overidden to make getPage compatible with Zepto.
BROWSER ONLY
\n\nIf you already have an object named PageableCollection attached to the\nBackbone module, you can use this to return a local reference to this\nBackbone.PageableCollection class and reset the name\nBackbone.PageableCollection to its previous definition.
// The left hand side gives you a reference to this\n// Backbone.PageableCollection implementation, the right hand side\n// resets Backbone.PageableCollection to your other\n// Backbone.PageableCollection.\nvar PageableCollection = Backbone.PageableCollection.noConflict();\n\n