Skip to content

Commit

Permalink
Merge pull request #523 from webgme/issue/515_export_in_safari
Browse files Browse the repository at this point in the history
Fixes #515
  • Loading branch information
Patrik Meijer committed Aug 31, 2015
2 parents f16879c + 49fd994 commit 06c80a4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/client/js/Controls/PropertyGrid/Widgets/AssetWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define([
INPUT_FILE_UPLOAD = $('<input type="file" />'),
//MAX_FILE_SIZE = 100000000,
ASSET_WIDGET_BASE = $('<div class="asset-widget" />'),
ASSET_LINK = $('<a href="" target="_blank"/>');
ASSET_LINK = $('<a href="" target="_self"/>');

AssetWidget = function (propertyDesc) {
AssetWidget.superclass.call(this, propertyDesc);
Expand Down
2 changes: 1 addition & 1 deletion src/client/js/Dialogs/PluginResults/PluginResultsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ define(['js/util',
//jscs:disable maximumLineLength
RESULT_ARTIFACTS_BASE = $('<div class="artifacts collapse"><div class="artifacts-title">Generated artifacts</div><div class="artifacts-body"><ul></ul></div></div>'),
//jscs:enable maximumLineLength
ARTIFACT_ENTRY_BASE = $('<li><a href="#" target="_blank">Loading...</a></li>'),
ARTIFACT_ENTRY_BASE = $('<li><a href="#" target="_self">Loading...</a></li>'),
MESSAGE_PREFIX = 'Message #';

PluginResultsDialog = function () {
Expand Down
12 changes: 7 additions & 5 deletions src/client/js/Panels/Header/ProjectNavigatorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ define([
'common/storage/util',
'isis-ui-components/simpleDialog/simpleDialog',
'text!js/Dialogs/Projects/templates/DeleteDialogTemplate.html',
'text!js/Dialogs/Projects/templates/TransferDialogTemplate.html'
'text!js/Dialogs/Projects/templates/TransferDialogTemplate.html',
'js/Utils/SaveToDisk'
], function (Logger,
CONSTANTS,
ng,
Expand All @@ -27,7 +28,8 @@ define([
StorageUtil,
ConfirmDialog,
DeleteDialogTemplate,
TransferDialogTemplate) {
TransferDialogTemplate,
saveToDisk) {
'use strict';


Expand Down Expand Up @@ -446,7 +448,7 @@ define([
transferProjectModal = self.$simpleDialog.open({
dialogTitle: 'Transfer',
dialogContentTemplate: 'TransferDialogTemplate.html',
controller: function ( $scope, $modalInstance, dialogTitle, dialogContentTemplate) {
controller: function ($scope, $modalInstance, dialogTitle, dialogContentTemplate) {

$scope.dialogTitle = dialogTitle;
$scope.dialogContentTemplate = dialogContentTemplate;
Expand All @@ -468,7 +470,7 @@ define([
};

$scope.cancel = function () {
$modalInstance.dismiss( 'cancel' );
$modalInstance.dismiss('cancel');
};

$scope.setNewOwnerId = function (ownerId) {
Expand Down Expand Up @@ -658,7 +660,7 @@ define([
self.gmeClient.getExportProjectBranchUrl(data.projectId,
data.branchId, data.projectId + '_' + data.branchId, function (err, url) {
if (!err && url) {
window.open(url);
saveToDisk(url);
} else {
self.logger.error('Failed to get project export url for', data);
}
Expand Down
34 changes: 34 additions & 0 deletions src/client/js/Utils/SaveToDisk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*globals define*/
/*jshint node: true, browser: true, bitwise: false*/

/**
* @author kecso / https://github.com/kecso
*/
define(function () {
'use strict';

var saveToDisk = function (fileURL, fileName) {
// for non-IE
if (!window.ActiveXObject) {
var save = document.createElement('a');
save.href = fileURL;
save.target = '_self';
//save.download = fileName || 'unknown';

var event = document.createEvent('Event');
event.initEvent('click', true, true);
save.dispatchEvent(event);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
}

// for IE
else if (!!window.ActiveXObject && document.execCommand) {
var _window = window.open(fileURL, '_self');
_window.document.close();
_window.document.execCommand('SaveAs', true, fileName || fileURL)
_window.close();
}
};

return saveToDisk;
});
10 changes: 3 additions & 7 deletions src/server/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,24 +852,20 @@ function StandAloneServer(gmeConfig) {
logger.error('worker/simpleResult err', err);
res.sendStatus(500);
} else {
res.header('Content-Disposition', 'attachment;filename=\'' + filename + '\'');
res.header('Content-Disposition', 'attachment;filename=' + filename);
res.json(result);
}
});
}

__app.get('/worker/simpleResult/:resultId', function (req, res) {
var filename = 'simpleResult-' + req.params.resultId + '.json';
var filename = 'simpleResult-' + req.params.resultId;
sendSimpleResult(res, req.params.resultId, filename);
});

// FIXME: filename should be in query string
__app.get('/worker/simpleResult/:resultId/:filename', function (req, res) {
var filename = req.params.filename;
if (filename.indexOf('.json') === -1) {
filename += '.json';
}
sendSimpleResult(res, req.params.resultId, filename);
sendSimpleResult(res, req.params.resultId, req.params.filename);
});


Expand Down

0 comments on commit 06c80a4

Please sign in to comment.