2013-12-01 15:43:46 +00:00
|
|
|
define([
|
2014-10-12 11:14:03 +00:00
|
|
|
"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;
|
2014-10-12 11:14:03 +00:00
|
|
|
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);
|
2014-10-12 11:14:03 +00:00
|
|
|
if(params) {
|
2014-10-12 17:57:58 +00:00
|
|
|
var link = constants.MAIN_URL + 'editor#!' + $.param(params);
|
2014-10-12 11:14:03 +00:00
|
|
|
result += _.template(dialogManageSharingLocationHTML, {
|
2014-10-12 17:57:58 +00:00
|
|
|
link: link
|
2014-10-12 11:14:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}, '');
|
2014-10-12 17:57:58 +00:00
|
|
|
shareEditorListElt.innerHTML = editorLinkListHtml;
|
|
|
|
$msgNoShareEditorElt.toggleClass('hide', editorLinkListHtml.length !== 0);
|
2014-10-12 11:14:03 +00:00
|
|
|
|
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);
|
2014-10-12 11:14:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2014-10-12 11:14:03 +00:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
2014-10-12 11:14:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return dialogManageSharing;
|
2013-12-01 15:43:46 +00:00
|
|
|
|
|
|
|
});
|