putCommand.js 1.09 KB
Newer Older
Sven Franck's avatar
Sven Franck committed
1 2 3 4 5 6
/*jslint indent: 2, maxlen: 80, sloppy: true */
/*global command: true */
var putCommand = function (spec, my) {
  var that = command(spec, my);
  spec = spec || {};
  my = my || {};
Tristan Cavelier's avatar
Tristan Cavelier committed
7

Sven Franck's avatar
Sven Franck committed
8 9 10 11
  // Methods //
  that.getLabel = function () {
    return 'put';
  };
Tristan Cavelier's avatar
Tristan Cavelier committed
12

Sven Franck's avatar
Sven Franck committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
  that.validateState = function () {
    if (!(typeof that.getDocId() === "string" && that.getDocId() !==
        "")) {
      that.error({
        "status": 20,
        "statusText": "Document Id Required",
        "error": "document_id_required",
        "message": "The document id is not provided",
        "reason": "Document id is undefined"
      });
      return false;
    }
    if (that.getAttachmentId() !== undefined) {
      that.error({
        "status": 21,
        "statusText": "Invalid Document Id",
        "error": "invalid_document_id",
        "message": "The document id contains '/' characters " +
          "which are forbidden",
        "reason": "Document id contains '/' character(s)"
      });
      return false;
    }
    return true;
  };
  that.executeOn = function (storage) {
    storage.put(that);
  };
  return that;
42
};