~ubuntu-branches/ubuntu/trusty/couchdb/trusty

« back to all changes in this revision

Viewing changes to src/fauxton/app/modules/fauxton/components.js

  • Committer: Package Import Robot
  • Author(s): Jason Gerard DeRose
  • Date: 2013-12-01 16:55:05 UTC
  • mfrom: (1.3.5)
  • Revision ID: package-import@ubuntu.com-20131201165505-for2toyl58mhzwj2
Tags: 1.5.0-0ubuntu1
* New upstream release (LP: #1254371)
* Don't include `couchdb` info page in `couchdb-bin` binary package as it
  provides no meaningful benefit over the `couchdb` man page (note this change
  means we don't need to add a Build-Depends on `install-info` for Trusty)
* Remove Build-Depends: texlive-latex-base, texlive-latex-recommended,
  texlive-latex-extra, texlive-fonts-recommended, texinfo (as documentation
  thus produced doesn't get included in the binary packages anyway)
* debian/rules: don't call ./configure with --enable-strictness as we dropped
  Build-Depends on `texlive-*`, `texinfo`, plus didn't add `install-info` 
* Add Build-Depends: lsb-release (used for [vendor] info in default.ini)
* debian/rules: insert proper [vendor] info in default.ini (note this should
  be improved once there is a better mechanism upstream)
* debian/couchdb.upstart: start on filesystem and static-network-up,
  stop on deconfiguring-networking, plus add "author" line

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
3
// the License at
 
4
//
 
5
//   http://www.apache.org/licenses/LICENSE-2.0
 
6
//
 
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
 
11
// the License.
 
12
 
 
13
define([
 
14
       "app",
 
15
       // Libs
 
16
       "api"
 
17
],
 
18
 
 
19
function(app, FauxtonAPI) {
 
20
  var Components = app.module();
 
21
 
 
22
  Components.Pagination = FauxtonAPI.View.extend({
 
23
    template: "templates/fauxton/pagination",
 
24
 
 
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;
 
31
    },
 
32
 
 
33
    serialize: function() {
 
34
      return {
 
35
        page: this.page,
 
36
        perPage: this.perPage,
 
37
        total: this.total,
 
38
        totalPages: this.totalPages,
 
39
        urlFun: this.urlFun
 
40
      };
 
41
    }
 
42
  });
 
43
 
 
44
  Components.IndexPagination = FauxtonAPI.View.extend({
 
45
    template: "templates/fauxton/index_pagination",
 
46
    events: {
 
47
      "click a": 'scrollTo',
 
48
      "click a#next": 'nextClicked',
 
49
      "click a#previous": 'previousClicked'
 
50
    },
 
51
 
 
52
    previousIds: [],
 
53
 
 
54
    scrollTo: function () {
 
55
      if (!this.scrollToSelector) { return; }
 
56
      $(this.scrollToSelector).animate({ scrollTop: 0 }, 'slow');
 
57
    },
 
58
 
 
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;
 
65
      _.bindAll(this);
 
66
    },
 
67
 
 
68
    previousClicked: function (event) {
 
69
      event.preventDefault();
 
70
      FauxtonAPI.navigate(this.previousUrlfn(), {trigger: false});
 
71
      FauxtonAPI.triggerRouteEvent('paginate', 'previous');
 
72
    },
 
73
 
 
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');
 
79
    },
 
80
 
 
81
    serialize: function () {
 
82
      return {
 
83
        canShowNextfn: this.canShowNextfn,
 
84
        canShowPreviousfn: this.canShowPreviousfn,
 
85
      };
 
86
    }
 
87
 
 
88
  });
 
89
 
 
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({
 
94
 
 
95
    initialize: function (options) {
 
96
      this.source = options.source;
 
97
      _.bindAll(this);
 
98
    },
 
99
 
 
100
    afterRender: function () {
 
101
      this.$el.typeahead({
 
102
        source: this.source
 
103
      });
 
104
    }
 
105
 
 
106
  });
 
107
 
 
108
 
 
109
  Components.DbSearchTypeahead = Components.Typeahead.extend({
 
110
    initialize: function (options) {
 
111
      this.dbLimit = options.dbLimit || 30;
 
112
      _.bindAll(this);
 
113
    },
 
114
    source: function(query, process) {
 
115
      var url = [
 
116
        app.host,
 
117
        "/_all_dbs?startkey=%22",
 
118
        query,
 
119
        "%22&endkey=%22",
 
120
        query,
 
121
        "\u9999%22&limit=",
 
122
        this.dbLimit
 
123
      ].join('');
 
124
 
 
125
      if (this.ajaxReq) { this.ajaxReq.abort(); }
 
126
 
 
127
      this.ajaxReq = $.ajax({
 
128
        url: url,
 
129
        dataType: 'json',
 
130
        success: function(data) {
 
131
          process(data);
 
132
        }
 
133
      });
 
134
    }
 
135
  });
 
136
 
 
137
  Components.DocSearchTypeahead = Components.Typeahead.extend({
 
138
    initialize: function (options) {
 
139
      this.docLimit = options.docLimit || 30;
 
140
      this.database = options.database;
 
141
      _.bindAll(this);
 
142
    },
 
143
    source: function(query, process) {
 
144
      var url = [
 
145
        app.host,
 
146
        "/",
 
147
        this.database.id,
 
148
        "/_all_docs?startkey=%22",
 
149
        query,
 
150
        "%22&endkey=%22",
 
151
        query,
 
152
        "\u9999%22&limit=",
 
153
        this.docLimit
 
154
      ].join('');
 
155
 
 
156
      if (this.ajaxReq) { this.ajaxReq.abort(); }
 
157
 
 
158
      this.ajaxReq = $.ajax({
 
159
        url: url,
 
160
        dataType: 'json',
 
161
        success: function(data) {
 
162
          var ids = _.map(data.rows, function (row) {
 
163
            return row.id;
 
164
          });
 
165
          process(ids);
 
166
        }
 
167
      });
 
168
    }
 
169
  });
 
170
 
 
171
  return Components;
 
172
});
 
173