A
A
Alisa942019-02-05 10:23:56
JavaScript
Alisa94, 2019-02-05 10:23:56

How to add delete method with NodeJS and JQuery?

How to add a delete method? All project files are here , you can add delete method in public/js/ForgeTree.js and routes/oss.js file. I've tried different approaches myself, but it doesn't work for me, so I'm asking for help. Thanks in advance.

/routes/oss.js

router.delete('/objects/:id', function (req, res) {
  var tokenSession = new token(req.session)
  console.log(tokenSession);

  var id = req.params.id

  var buckets = new BucketsApi();
  buckets.deleteBucket(id, tokenSession.getOAuth(), tokenSession.getCredentials())
  .then(function (data) {
    res.json({ status: "success" });
    console.log(`SUCCESS: id = ${id}, tokenSession = ${tokenSession}, tokenSession.getOauth() = ${tokenSession.getOAuth()}, tokenSession.getCredentials() = ${tokenSession.getCredentials()}`);
  })
  .catch(function (error) {
    console.log(`ERROR: id = ${id}, tokenSession = ${tokenSession}, tokenSession.getOauth() = ${tokenSession.getOAuth()}, tokenSession.getCredentials() = ${tokenSession.getCredentials()}`);
    res.status(error.statusCode).end(error.statusMessage);
  })
});


/public/js/ForgeTree.js

case "object":
  items = {
    translateFile: {
      label: "Translate",
      action: function () {
        var treeNode = $('#appBuckets').jstree(true).get_selected(true)[0];
        translateObject(treeNode);
      },
      icon: 'glyphicon glyphicon-eye-open'
    },
    deleteFile: {
      label: "Delete",
      action: function () {
        var treeId = $('#appBuckets').jstree(true).get_selected(true)[0].id; deleteBucket(treeId);
      },
      icon: 'glyphicon glyphicon-eye-open'
    }
  };
  break;


/public/js/ForgeTree.js

function deleteBucket(id) {
  id = $('#appBuckets').jstree(true).get_selected(true)[0].id;
  console.log('delete id ' + id);
  $.ajax({
      url: '/api/forge/oss/objects/' + encodeURIComponent(id),
      type: 'DELETE'
  }).done(function (data) {
      console.log(data);
      if (data.status === 'success') {
          $('#forgeFiles').jstree(true).refresh()
          showProgress("Bucket deleted", "success")
      }
  }).fail(function(err) {
      console.log('DELETE /dm/buckets/ call failed\n' + err.statusText);
  });
}


/public/index.html

<form id="uploadFile" method='post' enctype="multipart/form-data">
    <input id="hiddenUploadField" type="file" name="theFile" style="visibility:hidden" />
  </form>
  <form id="deleteFile" method='post' enctype="multipart/form-data">
    <input id="hiddenDeleteField" type="file" name="theFile" style="visibility:hidden" />
  </form>


Can you please tell me where is the error in this code?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question