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,35 +27,46 @@ 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(window.viewerMode) {
if(providerId === undefined) {
providerId = "download";
}
@ -64,7 +75,7 @@ define([
return;
}
var importParameters = {};
_.each(provider.sharingAttributes, function(attributeName) {
_.each(provider.viewerSharingAttributes, function(attributeName) {
var parameter = utils.getURLParameter(attributeName);
if(!parameter) {
importParameters = undefined;
@ -84,6 +95,7 @@ define([
var fileDesc = fileMgr.createFile(title, content, undefined, undefined, true);
fileMgr.selectFile(fileDesc);
});
}
});
return sharing;