1
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
2
// use this file except in compliance with the License. You may obtain a copy of
5
// http://www.apache.org/licenses/LICENSE-2.0
7
// Unless required by applicable law or agreed to in writing, software
8
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
// License for the specific language governing permissions and limitations under
19
function(app, FauxtonAPI) {
20
var Components = app.module();
22
Components.Pagination = FauxtonAPI.View.extend({
23
template: "templates/fauxton/pagination",
25
initialize: function(options) {
26
this.page = parseInt(options.page, 10);
27
this.perPage = options.perPage;
28
this.total = options.total;
29
this.totalPages = Math.ceil(this.total / this.perPage);
30
this.urlFun = options.urlFun;
33
serialize: function() {
36
perPage: this.perPage,
38
totalPages: this.totalPages,
44
Components.IndexPagination = FauxtonAPI.View.extend({
45
template: "templates/fauxton/index_pagination",
47
"click a": 'scrollTo',
48
"click a#next": 'nextClicked',
49
"click a#previous": 'previousClicked'
54
scrollTo: function () {
55
if (!this.scrollToSelector) { return; }
56
$(this.scrollToSelector).animate({ scrollTop: 0 }, 'slow');
59
initialize: function (options) {
60
this.previousUrlfn = options.previousUrlfn;
61
this.nextUrlfn = options.nextUrlfn;
62
this.canShowPreviousfn = options.canShowPreviousfn;
63
this.canShowNextfn = options.canShowNextfn;
64
this.scrollToSelector = options.scrollToSelector;
68
previousClicked: function (event) {
69
event.preventDefault();
70
FauxtonAPI.navigate(this.previousUrlfn(), {trigger: false});
71
FauxtonAPI.triggerRouteEvent('paginate', 'previous');
74
nextClicked: function (event) {
75
event.preventDefault();
76
this.previousIds.push(this.collection.first().id);
77
FauxtonAPI.navigate(this.nextUrlfn(), {trigger: false});
78
FauxtonAPI.triggerRouteEvent('paginate', 'next');
81
serialize: function () {
83
canShowNextfn: this.canShowNextfn,
84
canShowPreviousfn: this.canShowPreviousfn,
90
//TODO allow more of the typeahead options.
91
//Current this just does what we need but we
92
//need to support the other typeahead options.
93
Components.Typeahead = FauxtonAPI.View.extend({
95
initialize: function (options) {
96
this.source = options.source;
100
afterRender: function () {
109
Components.DbSearchTypeahead = Components.Typeahead.extend({
110
initialize: function (options) {
111
this.dbLimit = options.dbLimit || 30;
114
source: function(query, process) {
117
"/_all_dbs?startkey=%22",
125
if (this.ajaxReq) { this.ajaxReq.abort(); }
127
this.ajaxReq = $.ajax({
130
success: function(data) {
137
Components.DocSearchTypeahead = Components.Typeahead.extend({
138
initialize: function (options) {
139
this.docLimit = options.docLimit || 30;
140
this.database = options.database;
143
source: function(query, process) {
148
"/_all_docs?startkey=%22",
156
if (this.ajaxReq) { this.ajaxReq.abort(); }
158
this.ajaxReq = $.ajax({
161
success: function(data) {
162
var ids = _.map(data.rows, function (row) {