Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.63 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var Node;
  2. var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
  3.   for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
  4.   function ctor() { this.constructor = child; }
  5.   ctor.prototype = parent.prototype;
  6.   child.prototype = new ctor;
  7.   child.__super__ = parent.prototype;
  8.   return child;
  9. };
  10. module.exports = Node = (function() {
  11.   __extends(Node, PropertyContainer);
  12.   function Node() {
  13.     Node.__super__.constructor.apply(this, arguments);
  14.   }
  15.   Node.prototype["delete"] = function(_, force) {
  16.     var message, relationship, relationships, response, _i, _len;
  17.     if (force == null) {
  18.       force = false;
  19.     }
  20.     if (!this.exists) {
  21.       return;
  22.     }
  23.     console.log("about to delete " + this + "...");
  24.     try {
  25.       relationships = this.all(null, _);
  26.       if (relationships.length && !force) {
  27.         throw new Error("Could not delete " + this + "; still has relationships.");
  28.       }
  29.       for (_i = 0, _len = relationships.length; _i < _len; _i++) {
  30.         relationship = relationships[_i];
  31.         relationship["delete"](_);
  32.       }
  33.       response = request.del(this.self, _);
  34.       if (response.statusCode !== status.NO_CONTENT) {
  35.         message = '';
  36.         switch (response.statusCode) {
  37.           case status.NOT_FOUND:
  38.             message = 'Node not found';
  39.             break;
  40.           case status.CONFLICT:
  41.             message = 'Node could not be deleted (still has relationships?)';
  42.         }
  43.         throw new Error(message);
  44.       }
  45.       console.log("finished deleting " + this + ".");
  46.     } catch (error) {
  47.       throw adjustError(error);
  48.     }
  49.   };
  50.   return Node;
  51. })();