Stackedit/public/res/extensions/dialogManageSynchronization.js

66 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

2013-05-27 19:45:33 +00:00
define([
"jquery",
"underscore",
"classes/Extension",
"text!html/dialogManageSynchronizationLocation.html",
2013-06-22 23:48:57 +00:00
], function($, _, Extension, dialogManageSynchronizationLocationHTML) {
2013-05-29 19:55:23 +00:00
var dialogManageSynchronization = new Extension("dialogManageSynchronization", 'Dialog "Manage synchronization"', false, true);
2013-05-29 19:55:23 +00:00
var eventMgr;
dialogManageSynchronization.onEventMgrCreated = function(eventMgrParameter) {
eventMgr = eventMgrParameter;
};
2014-04-12 22:30:18 +00:00
var synchronizer;
dialogManageSynchronization.onSynchronizerCreated = function(synchronizerParameter) {
synchronizer = synchronizerParameter;
};
2013-05-29 19:55:23 +00:00
var fileDesc;
var syncListElt;
var $showAlreadySynchronizedElt;
var refreshDialog = function(fileDescParameter) {
if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) {
return;
}
2013-05-29 19:55:23 +00:00
$showAlreadySynchronizedElt.toggleClass("hide", _.size(fileDesc.syncLocations) === 0);
2014-04-20 01:13:43 +00:00
var syncListHtml = _.reduce(fileDesc.syncLocations, function(result, syncAttributes) {
return result + _.template(dialogManageSynchronizationLocationHTML, {
syncAttributes: syncAttributes,
syncDesc: syncAttributes.id || syncAttributes.path,
syncLocationLink: syncAttributes.provider.getSyncLocationLink && syncAttributes.provider.getSyncLocationLink(syncAttributes)
});
}, '');
2013-05-29 19:55:23 +00:00
syncListElt.innerHTML = syncListHtml;
};
2013-05-29 19:55:23 +00:00
dialogManageSynchronization.onFileSelected = function(fileDescParameter) {
fileDesc = fileDescParameter;
refreshDialog(fileDescParameter);
};
2013-05-29 19:55:23 +00:00
dialogManageSynchronization.onSyncExportSuccess = refreshDialog;
dialogManageSynchronization.onSyncRemoved = refreshDialog;
2014-04-20 01:13:43 +00:00
dialogManageSynchronization.onReady = function() {
var modalElt = document.querySelector(".modal-manage-sync");
syncListElt = modalElt.querySelector(".sync-list");
2014-04-23 23:12:21 +00:00
$showAlreadySynchronizedElt = $(document.querySelectorAll(".show-already-synchronized"));
2013-06-02 00:38:23 +00:00
$(syncListElt).on('click', '.remove-button', function() {
var $removeButtonElt = $(this);
var syncAttributes = fileDesc.syncLocations[$removeButtonElt.data('syncIndex')];
fileDesc.removeSyncLocation(syncAttributes);
eventMgr.onSyncRemoved(fileDesc, syncAttributes);
});
};
return dialogManageSynchronization;
2013-05-29 19:55:23 +00:00
2014-04-12 22:30:18 +00:00
});