Reimplemented sharing module

This commit is contained in:
benweet 2014-09-28 19:34:30 +01:00
parent d2cb92e828
commit b225379703
4 changed files with 56 additions and 44 deletions

View File

@ -9,7 +9,7 @@ define([
], function($, constants, eventMgr, utils, fileMgr, Provider, AsyncTask) {
var downloadProvider = new Provider("download");
downloadProvider.sharingAttributes = [
downloadProvider.viewerSharingAttributes = [
"url"
];

View File

@ -21,7 +21,7 @@ define([
var gdriveProvider = new Provider(providerId, providerName);
gdriveProvider.defaultPublishFormat = "template";
gdriveProvider.exportPreferencesInputIds = [
providerId + "-parentid",
providerId + "-parentid"
];
function createSyncIndex(id) {

View File

@ -8,7 +8,7 @@ define([
gistProvider.publishPreferencesInputIds = [
"gist-public"
];
gistProvider.sharingAttributes = [
gistProvider.viewerSharingAttributes = [
"gistId",
"filename"
];

View File

@ -27,63 +27,75 @@ define([
isOffline = isOfflineParam;
});
sharing.getViewerLink = function(attributes) {
sharing.getEditorParams = function(attributes) {
var provider = providerMap[attributes.provider.providerId];
if(provider === undefined) {
return;
}
var params = {
provider: provider.providerId
};
if(!provider.editorSharingAttributes) {
return;
}
_.each(provider.editorSharingAttributes, function(attributeName) {
params[attributeName] = attributes[attributeName];
});
return params;
};
sharing.getViewerParams = function(attributes) {
var provider = providerMap[attributes.provider.providerId];
// Don't create link if provider is not compatible for sharing
if(provider === undefined ||
// Or document is not published in markdown format
attributes.format != "markdown") {
return;
}
var url = [
constants.MAIN_URL,
'viewer#!provider=',
provider.providerId
];
_.each(provider.sharingAttributes, function(attributeName) {
url.push('&');
url.push(attributeName);
url.push('=');
url.push(encodeURIComponent(attributes[attributeName]));
var params = {
provider: provider.providerId
};
if(!provider.viewerSharingAttributes) {
return;
}
_.each(provider.viewerSharingAttributes, function(attributeName) {
params[attributeName] = attributes[attributeName];
});
attributes.sharingLink = url.join('');
callback();
return params;
};
eventMgr.addListener("onReady", function() {
if(window.viewerMode === false) {
return;
}
// Check parameters to see if we have to download a shared document
var providerId = utils.getURLParameter("provider");
if(providerId === undefined) {
providerId = "download";
}
var provider = providerMap[providerId];
if(provider === undefined) {
return;
}
var importParameters = {};
_.each(provider.sharingAttributes, function(attributeName) {
var parameter = utils.getURLParameter(attributeName);
if(!parameter) {
importParameters = undefined;
if(window.viewerMode) {
if(providerId === undefined) {
providerId = "download";
}
var provider = providerMap[providerId];
if(provider === undefined) {
return;
}
importParameters[attributeName] = parameter;
});
if(importParameters === undefined) {
return;
}
$("#preview-contents, .navbar .file-title-navbar").hide();
provider.importPublic(importParameters, function(error, title, content) {
$("#preview-contents, .navbar .file-title-navbar").show();
if(error) {
var importParameters = {};
_.each(provider.viewerSharingAttributes, function(attributeName) {
var parameter = utils.getURLParameter(attributeName);
if(!parameter) {
importParameters = undefined;
return;
}
importParameters[attributeName] = parameter;
});
if(importParameters === undefined) {
return;
}
var fileDesc = fileMgr.createFile(title, content, undefined, undefined, true);
fileMgr.selectFile(fileDesc);
});
$("#preview-contents, .navbar .file-title-navbar").hide();
provider.importPublic(importParameters, function(error, title, content) {
$("#preview-contents, .navbar .file-title-navbar").show();
if(error) {
return;
}
var fileDesc = fileMgr.createFile(title, content, undefined, undefined, true);
fileMgr.selectFile(fileDesc);
});
}
});
return sharing;