Sha256: 7ab43f812513ba58ac359c4cd132ca61ee9494178c0112a5255d3d2ef7dff85e

Contents?: true

Size: 1.49 KB

Versions: 3

Compression:

Stored size: 1.49 KB

Contents

'use strict';

(function () {
  scrivito.BinaryRequest = {
    // COMPLETELY NEW IMPLEMENTATION HERE
    upload: function upload(objId, blob, filename, contentType) {
      scrivito.write_monitor.start_write();
      return uploadToBackend(objId, blob, filename, contentType)['finally'](scrivito.write_monitor.end_write);
    },

    copy: function copy(copyId, objId, filename, contentType) {
      var encodedCopyId = encodeURIComponent(copyId);
      var params = {};

      if (filename) {
        params.filename = filename;
      }

      if (contentType) {
        params.content_type = contentType;
      }

      params.destination_obj_id = objId;

      return scrivito.CmsRestApi.put('blobs/' + encodedCopyId + '/copy', params);
    },

    // For test purpose only.
    getFormData: function getFormData() {
      return new FormData();
    }
  };

  function uploadToBackend(objId, blob, filename, contentType) {
    var formData = scrivito.BinaryRequest.getFormData();
    formData.append('obj_id', objId);
    formData.append('filename', filename);
    formData.append('content_type', contentType);
    formData.append('file', blob);

    return scrivito.Promise.resolve($.ajax({
      method: 'POST',
      url: '/_f7/uploads/temp',
      data: formData,
      // These are needed in order for jQuery to work properly with a FormData.
      contentType: false,
      processData: false,
      xhrFields: { withCredentials: true }
    })).then(function (blob_data) {
      return blob_data;
    });
  };
})();

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 app/assets/javascripts/scrivito_patches/binary_request.js
infopark_fiona7-1.6.1.1.1 app/assets/javascripts/scrivito_patches/binary_request.js
infopark_fiona7-1.6.1.1.0 app/assets/javascripts/scrivito_patches/binary_request.js