~jderose/ubuntu/vivid/couchdb/fix-1457464

« back to all changes in this revision

Viewing changes to src/fauxton/app/addons/config/resources.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
  "api"
 
16
],
 
17
 
 
18
function (app, FauxtonAPI) {
 
19
 
 
20
  var Config = FauxtonAPI.addon();
 
21
 
 
22
  Config.Model = Backbone.Model.extend({});
 
23
  Config.OptionModel = Backbone.Model.extend({
 
24
 
 
25
    url: function () {
 
26
      return app.host + '/_config/' + this.get("section") + '/' + this.get("name");
 
27
    },
 
28
 
 
29
    isNew: function () { return false; },
 
30
 
 
31
    sync: function (method, model, options) {
 
32
 
 
33
      var params = {
 
34
        url: model.url(),
 
35
        contentType: 'application/json',
 
36
        dataType: 'json',
 
37
        data: JSON.stringify(model.get('value'))
 
38
      };
 
39
 
 
40
      if (method === 'delete') {
 
41
        params.type = 'DELETE';
 
42
      } else {
 
43
        params.type = 'PUT';
 
44
      }
 
45
 
 
46
      return $.ajax(params);
 
47
    }
 
48
  });
 
49
 
 
50
  Config.Collection = Backbone.Collection.extend({
 
51
    model: Config.Model,
 
52
 
 
53
    url: function () {
 
54
      return app.host + '/_config';
 
55
    },
 
56
 
 
57
    parse: function (resp) {
 
58
      return _.map(resp, function (section, section_name) {
 
59
        return {
 
60
          section: section_name,
 
61
          options: _.map(section, function (option, option_name) {
 
62
            return {
 
63
              name: option_name,
 
64
              value: option
 
65
            };
 
66
          })
 
67
        };
 
68
      });
 
69
    }
 
70
  });
 
71
 
 
72
  Config.ViewItem = FauxtonAPI.View.extend({
 
73
    tagName: "tr",
 
74
    className: "config-item",
 
75
    template: "addons/config/templates/item",
 
76
 
 
77
    events: {
 
78
      "click .edit-button": "editValue",
 
79
      "click #delete-value": "deleteValue",
 
80
      "click #cancel-value": "cancelEdit",
 
81
      "click #save-value": "saveValue"
 
82
    },
 
83
 
 
84
    deleteValue: function (event) {
 
85
      var result = confirm("Are you sure you want to delete this configuration value?");
 
86
 
 
87
      if (!result) { return; }
 
88
 
 
89
      this.model.destroy();
 
90
      this.remove();
 
91
    },
 
92
 
 
93
    editValue: function (event) {
 
94
      this.$("#show-value").hide();
 
95
      this.$("#edit-value-form").show();
 
96
    },
 
97
 
 
98
    saveValue: function (event) {
 
99
      this.model.save({value: this.$(".value-input").val()});
 
100
      this.render();
 
101
    },
 
102
 
 
103
    cancelEdit: function (event) {
 
104
      this.$("#edit-value-form").hide();
 
105
      this.$("#show-value").show();
 
106
    },
 
107
 
 
108
    serialize: function () {
 
109
      return {option: this.model.toJSON()};
 
110
    }
 
111
 
 
112
  });
 
113
 
 
114
  Config.View = FauxtonAPI.View.extend({
 
115
    template: "addons/config/templates/dashboard",
 
116
 
 
117
    events: {
 
118
      "click #add-section": "addSection",
 
119
      "submit #add-section-form": "submitForm"
 
120
    },
 
121
 
 
122
    submitForm: function (event) {
 
123
      event.preventDefault();
 
124
      var option = new Config.OptionModel({
 
125
        section: this.$('input[name="section"]').val(),
 
126
        name: this.$('input[name="name"]').val(),
 
127
        value: this.$('input[name="value"]').val()
 
128
      });
 
129
 
 
130
      option.save();
 
131
 
 
132
      var section = this.collection.find(function (section) {
 
133
        return section.get("section") === option.get("section");
 
134
      });
 
135
 
 
136
      if (section) {
 
137
        section.get("options").push(option.attributes);
 
138
      } else {
 
139
        this.collection.add({
 
140
          section: option.get("section"),
 
141
          options: [option.attributes]
 
142
        });
 
143
      }
 
144
 
 
145
      this.$("#add-section-modal").modal('hide');
 
146
      this.render();
 
147
    },
 
148
 
 
149
    addSection: function (event) {
 
150
      event.preventDefault();
 
151
      this.$("#add-section-modal").modal({show:true});
 
152
    },
 
153
 
 
154
    beforeRender: function() {
 
155
      this.collection.each(function(config) {
 
156
        _.each(config.get("options"), function (option, index) {
 
157
          this.insertView("table.config tbody", new Config.ViewItem({
 
158
            model: new Config.OptionModel({
 
159
              section: config.get("section"),
 
160
              name: option.name,
 
161
              value: option.value,
 
162
              index: index
 
163
            })
 
164
          }));
 
165
        }, this);
 
166
      }, this);
 
167
    },
 
168
 
 
169
    establish: function() {
 
170
      return [this.collection.fetch()];
 
171
    }
 
172
  });
 
173
 
 
174
  return Config;
 
175
});