Ejemplo n.º 1
0
 errorHandler: function(model, xhr, options) {
     // interrupted ajax or no connection
     if (xhr && xhr.status === 0 && xhr.readyState === 0) {
         // return ERROR_MODAL.offlineErrorModal();
         // fail silently
         return;
     }
     // otherwise, leave something to report in the console
     this.error(model, xhr, options);
     // and feedback to a modal
     // if sent two strings (and possibly details as 'options'), use those as message and title
     if (_.isString(model) && _.isString(xhr)) {
         var message = model;
         var title = xhr;
         return ERROR_MODAL.errorModal(message, title, options);
     }
     // bad gateway
     // TODO: possibly to global handler
     if (xhr && xhr.status === 502) {
         return ERROR_MODAL.badGatewayErrorModal();
     }
     return ERROR_MODAL.ajaxErrorModal(model, xhr, options);
 },
Ejemplo n.º 2
0
    copy: function(json) {
        // TODO: somehow showhorn all this into 'save'
        var id;

        var type;
        var contentType;
        if (_.isString(json)) {
            id = json;
            contentType = "hda";
            type = "dataset";
        } else {
            id = json.id;
            contentType =
                {
                    HistoryDatasetAssociation: "hda",
                    LibraryDatasetDatasetAssociation: "ldda",
                    HistoryDatasetCollectionAssociation: "hdca"
                }[json.model_class] || "hda";
            type = contentType === "hdca" ? "dataset_collection" : "dataset";
        }
        var collection = this;

        var xhr = jQuery
            .ajax(this.url(), {
                method: "POST",
                contentType: "application/json",
                data: JSON.stringify({
                    content: id,
                    source: contentType,
                    type: type
                })
            })
            .done(response => {
                collection.add([response], { parse: true });
            })
            .fail((error, status, message) => {
                collection.trigger("error", collection, xhr, {}, "Error copying contents", {
                    type: type,
                    id: id,
                    source: contentType
                });
            });

        return xhr;
    },
Ejemplo n.º 3
0
 .map((content, i) => {
     var fn = _.isString(ajaxFn) ? content[ajaxFn] : ajaxFn;
     return () => fn.apply(content, args);
 })