You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/03/19 12:07:02 UTC

[GitHub] garrensmith closed pull request #1062: Remove JQuery usage from config addon

garrensmith closed pull request #1062: Remove JQuery usage from config addon
URL: https://github.com/apache/couchdb-fauxton/pull/1062
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/app/addons/config/actions.js b/app/addons/config/actions.js
index b7934d104..e633c78e0 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 0a9b8ea57..8dbabcea4 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 5e5c13447..98820066d 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;
+    });
   }
 });
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services