Stackedit/public/res/extensions/dialogManageSharing.js

82 lines
2.7 KiB
JavaScript
Raw Normal View History

2013-12-01 15:43:46 +00:00
define([
"jquery",
"underscore",
"constants",
"classes/Extension",
"text!html/dialogManageSharingLocation.html"
], function($, _, constants, Extension, dialogManageSharingLocationHTML) {
var dialogManageSharing = new Extension("dialogManageSharing", 'Button "Share"', false, true);
var eventMgr;
dialogManageSharing.onEventMgrCreated = function(eventMgrParam) {
eventMgr = eventMgrParam;
};
var sharing;
dialogManageSharing.onSharingCreated = function(sharingParam) {
sharing = sharingParam;
};
var fileDesc;
2014-10-12 17:57:58 +00:00
var shareEditorListElt;
var shareViewerListElt;
var $msgNoShareEditorElt;
var $msgNoShareViewerElt;
var refreshDocumentSharing = function(fileDescParameter) {
if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) {
return;
}
2014-10-12 17:57:58 +00:00
var editorLinkListHtml = _.reduce(fileDesc.syncLocations, function(result, attributes) {
var params = sharing.getEditorParams(attributes);
if(params) {
2014-10-12 17:57:58 +00:00
var link = constants.MAIN_URL + 'editor#!' + $.param(params);
result += _.template(dialogManageSharingLocationHTML, {
2014-10-12 17:57:58 +00:00
link: link
});
}
return result;
}, '');
2014-10-12 17:57:58 +00:00
shareEditorListElt.innerHTML = editorLinkListHtml;
$msgNoShareEditorElt.toggleClass('hide', editorLinkListHtml.length !== 0);
2014-10-12 17:57:58 +00:00
var viewerLinkListHtml = _.reduce(fileDesc.publishLocations, function(result, attributes) {
var params = sharing.getViewerParams(attributes);
if(params) {
var link = constants.MAIN_URL + 'viewer#!' + $.param(params);
result += _.template(dialogManageSharingLocationHTML, {
link: link
});
}
return result;
}, '');
shareViewerListElt.innerHTML = viewerLinkListHtml;
$msgNoShareViewerElt.toggleClass('hide', viewerLinkListHtml.length !== 0);
};
dialogManageSharing.onFileSelected = function(fileDescParameter) {
fileDesc = fileDescParameter;
refreshDocumentSharing(fileDescParameter);
};
2014-10-12 17:57:58 +00:00
dialogManageSharing.onSyncExportSuccess = refreshDocumentSharing;
dialogManageSharing.onSyncRemoved = refreshDocumentSharing;
dialogManageSharing.onNewPublishSuccess = refreshDocumentSharing;
dialogManageSharing.onPublishRemoved = refreshDocumentSharing;
dialogManageSharing.onReady = function() {
var modalElt = document.querySelector('.modal-manage-sharing');
2014-10-12 17:57:58 +00:00
shareEditorListElt = modalElt.querySelector('.share-editor-list');
shareViewerListElt = modalElt.querySelector('.share-viewer-list');
$msgNoShareEditorElt = $(modalElt.querySelectorAll('.msg-no-share-editor'));
$msgNoShareViewerElt = $(modalElt.querySelectorAll('.msg-no-share-viewer'));
$(modalElt).on('show.bs.modal', function() {
$(modalElt.querySelector('input')).each(function() {
this.value = $(this).data('value');
});
});
};
return dialogManageSharing;
2013-12-01 15:43:46 +00:00
});