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) { ], function($, constants, eventMgr, utils, fileMgr, Provider, AsyncTask) {
var downloadProvider = new Provider("download"); var downloadProvider = new Provider("download");
downloadProvider.sharingAttributes = [ downloadProvider.viewerSharingAttributes = [
"url" "url"
]; ];

View File

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

View File

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

View File

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