Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/750#discussion_r72045006
  
    --- Diff: app/addons/config/actions.js ---
    @@ -0,0 +1,140 @@
    +//  Licensed under the Apache License, Version 2.0 (the "License"); you 
may not
    +//  use this file except in compliance with the License. You may obtain a 
copy of
    +//  the License at
    +//
    +//    http://www.apache.org/licenses/LICENSE-2.0
    +//
    +//  Unless required by applicable law or agreed to in writing, software
    +//  distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT
    +//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See 
the
    +//  License for the specific language governing permissions and 
limitations under
    +//  the License.
    +
    +import ActionTypes from './actiontypes';
    +import FauxtonAPI from '../../core/api';
    +import Resources from './resources';
    +
    +export default {
    +  fetchAndEditConfig: function (node) {
    +    FauxtonAPI.dispatch({ type: ActionTypes.LOADING_CONFIG });
    +
    +    var configModel = new Resources.ConfigModel({ node });
    +
    +    FauxtonAPI.when(configModel.fetch())
    +      .then(function () {
    +        this.editSections({ sections: configModel.get('sections'), node });
    +      }.bind(this));
    +  },
    +
    +  editSections: function (options) {
    +    FauxtonAPI.dispatch({ type: ActionTypes.EDIT_CONFIG, options });
    +  },
    +
    +  editOption: function (options) {
    +    FauxtonAPI.dispatch({ type: ActionTypes.EDIT_OPTION, options });
    +  },
    +
    +  cancelEdit: function (options) {
    +    FauxtonAPI.dispatch({ type: ActionTypes.CANCEL_EDIT, options });
    +  },
    +
    +  saveOption: function (node, options) {
    +    FauxtonAPI.dispatch({ type: ActionTypes.SAVING_OPTION, options });
    +
    +    var modelAttrs = options;
    +    modelAttrs.node = node;
    +    var optionModel = new Resources.OptionModel(modelAttrs);
    +
    +    FauxtonAPI.when(optionModel.save())
    +      .done(function () {
    +        this.optionSaveSuccess(options);
    +      }.bind(this))
    +      .fail(function (xhr) {
    +          var error = JSON.parse(xhr.responseText).reason;
    +          this.optionSaveFailure(options, error);
    +        }.bind(this)
    +      );
    +  },
    +
    +  optionSaveSuccess: function (options) {
    +    FauxtonAPI.dispatch({ type: ActionTypes.OPTION_SAVE_SUCCESS, options 
});
    +    FauxtonAPI.addNotification({
    +      msg: `Option ${options.optionName} saved`,
    +      type: 'success'
    +    });
    +  },
    +
    +  optionSaveFailure: function (options, error) {
    +    FauxtonAPI.dispatch({ type: ActionTypes.OPTION_SAVE_FAILURE, options 
});
    +    FauxtonAPI.addNotification({
    +      msg: `Option save failed: ${error}`,
    +      type: 'error'
    +    });
    +  },
    +
    +  addOption: function (node, options) {
    +    FauxtonAPI.dispatch({ type: ActionTypes.ADDING_OPTION });
    +
    +    var modelAttrs = options;
    +    modelAttrs.node = node;
    +    var optionModel = new Resources.OptionModel(modelAttrs);
    +
    +    FauxtonAPI.when(optionModel.save())
    +      .done(function () {
    --- End diff --
    
    Also you don't need to use `FauxtonAPI.when` here since 
`optionModel.save()` will return a promise. `.when` is used when you need to 
wait for multiple promises to resolve before doing something.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to