You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2018/03/19 12:07:04 UTC

[couchdb-fauxton] branch master updated: Remove JQuery usage from config addon (#1062)

This is an automated email from the ASF dual-hosted git repository.

garren pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-fauxton.git


The following commit(s) were added to refs/heads/master by this push:
     new 55ef0f9  Remove JQuery usage from config addon (#1062)
55ef0f9 is described below

commit 55ef0f96de7a17956122ca72aa6d6ebaa5aa3463
Author: Antonio Maranhao <30...@users.noreply.github.com>
AuthorDate: Mon Mar 19 08:07:00 2018 -0400

    Remove JQuery usage from config addon (#1062)
    
    * Remove JQuery usage from config addon
---
 app/addons/config/actions.js    |  6 ++----
 app/addons/config/components.js | 19 +++++++++++--------
 app/addons/config/resources.js  | 27 ++++++++++++++++-----------
 3 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/app/addons/config/actions.js b/app/addons/config/actions.js
index b7934d1..e633c78 100644
--- a/app/addons/config/actions.js
+++ b/app/addons/config/actions.js
@@ -103,10 +103,8 @@ export default {
     var optionModel = new Resources.OptionModel(modelAttrs);
 
     return optionModel.destroy()
-      .then(
-        () => this.optionDeleteSuccess(options),
-        xhr => this.optionDeleteFailure(options, JSON.parse(xhr.responseText).reason)
-      );
+      .then(() => this.optionDeleteSuccess(options))
+      .catch((err) => this.optionDeleteFailure(options, err.message));
   },
 
   optionDeleteSuccess (options) {
diff --git a/app/addons/config/components.js b/app/addons/config/components.js
index 0a9b8ea..8dbabce 100644
--- a/app/addons/config/components.js
+++ b/app/addons/config/components.js
@@ -230,9 +230,13 @@ class ConfigOptionValue extends React.Component {
 }
 
 class ConfigOptionTrash extends React.Component {
-  state = {
-    show: false
-  };
+  constructor (props) {
+    super(props);
+    this.onDelete = this.onDelete.bind(this);
+    this.showModal = this.showModal.bind(this);
+    this.hideModal = this.hideModal.bind(this);
+    this.state = { show: false };
+  }
 
   onDelete = () => {
     this.props.onDelete();
@@ -248,13 +252,12 @@ class ConfigOptionTrash extends React.Component {
 
   render() {
     return (
-      <td className="text-center config-item-trash config-delete-value"
-        onClick={this.showModal.bind(this)}>
-        <i className="icon icon-trash"></i>
+      <td className="text-center config-item-trash config-delete-value">
+        <i className="icon icon-trash" onClick={this.showModal}></i>
         <FauxtonComponents.ConfirmationModal
           text={`Are you sure you want to delete ${this.props.sectionName}/${this.props.optionName}?`}
-          onClose={this.hideModal.bind(this)}
-          onSubmit={this.onDelete.bind(this)}
+          onClose={this.hideModal}
+          onSubmit={this.onDelete}
           visible={this.state.show}/>
       </td>
     );
diff --git a/app/addons/config/resources.js b/app/addons/config/resources.js
index 5e5c134..9882006 100644
--- a/app/addons/config/resources.js
+++ b/app/addons/config/resources.js
@@ -12,6 +12,7 @@
 
 import app from "../../app";
 import FauxtonAPI from "../../core/api";
+import { deleteRequest, put } from "../../core/ajax";
 
 var Config = FauxtonAPI.addon();
 
@@ -30,20 +31,24 @@ Config.OptionModel = Backbone.Model.extend({
   isNew () { return false; },
 
   sync (method, model) {
-
-    var params = {
-      url: model.url(),
-      contentType: 'application/json',
-      dataType: 'json',
-      data: JSON.stringify(model.get('value'))
-    };
-
+    let operation;
     if (method === 'delete') {
-      params.type = 'DELETE';
+      operation = deleteRequest(
+        model.url()
+      );
     } else {
-      params.type = 'PUT';
+      operation = put(
+        model.url(),
+        model.get('value')
+      );
     }
-    return $.ajax(params);
+
+    return operation.then((res) => {
+      if (res.error) {
+        throw new Error(res.reason || res.error);
+      }
+      return res;
+    });
   }
 });
 

-- 
To stop receiving notification emails like this one, please contact
garren@apache.org.