Stackedit/public/res/extensions/dialogManageSynchronization.js

74 lines
2.7 KiB
JavaScript
Raw Normal View History

2013-05-27 19:45:33 +00:00
define([
"jquery",
2013-06-10 21:22:32 +00:00
"underscore",
2013-06-22 23:48:57 +00:00
"classes/Extension",
2013-06-10 21:22:32 +00:00
"text!html/dialogManageSynchronizationLocation.html",
2013-06-22 23:48:57 +00:00
], function($, _, Extension, dialogManageSynchronizationLocationHTML) {
2013-05-29 19:55:23 +00:00
2013-08-21 00:16:10 +00:00
var dialogManageSynchronization = new Extension("dialogManageSynchronization", 'Dialog "Manage synchronization"', false, true);
2013-05-29 19:55:23 +00:00
2013-07-30 08:46:36 +00:00
var eventMgr = undefined;
dialogManageSynchronization.onEventMgrCreated = function(eventMgrParameter) {
eventMgr = eventMgrParameter;
2013-05-29 19:55:23 +00:00
};
2013-07-20 01:08:17 +00:00
var synchronizer = undefined;
dialogManageSynchronization.onSynchronizerCreated = function(synchronizerParameter) {
synchronizer = synchronizerParameter;
};
2013-05-29 19:55:23 +00:00
var fileDesc = undefined;
2013-08-14 23:44:51 +00:00
var syncListElt = undefined;
var $msgSyncListElt = undefined;
var $msgNoSyncElt = undefined;
2013-05-29 19:55:23 +00:00
var refreshDialog = function(fileDescParameter) {
if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) {
return;
}
2013-08-14 23:44:51 +00:00
if(_.size(fileDesc.syncLocations) > 0) {
$msgSyncListElt.removeClass("hide");
$msgNoSyncElt.addClass("hide");
2013-05-29 19:55:23 +00:00
}
else {
2013-08-14 23:44:51 +00:00
$msgSyncListElt.addClass("hide");
$msgNoSyncElt.removeClass("hide");
2013-05-29 19:55:23 +00:00
}
2013-08-14 23:44:51 +00:00
var syncListHtml = _.reduce(fileDesc.syncLocations, function(result, syncAttributes) {
return result + _.template(dialogManageSynchronizationLocationHTML, {
syncAttributes: syncAttributes,
syncDesc: syncAttributes.id || syncAttributes.path
});
}, '');
syncListElt.innerHTML = syncListHtml;
_.each(syncListElt.querySelectorAll('.remove-button'), function(removeButtonElt) {
var $removeButtonElt = $(removeButtonElt);
var syncAttributes = fileDesc.syncLocations[$removeButtonElt.data('syncIndex')];
$removeButtonElt.click(function() {
2013-07-20 01:08:17 +00:00
synchronizer.tryStopRealtimeSync();
2013-06-16 10:47:35 +00:00
fileDesc.removeSyncLocation(syncAttributes);
2013-07-30 08:46:36 +00:00
eventMgr.onSyncRemoved(fileDesc, syncAttributes);
2013-08-14 23:44:51 +00:00
});
2013-05-29 19:55:23 +00:00
});
};
2013-06-10 21:22:32 +00:00
dialogManageSynchronization.onFileSelected = function(fileDescParameter) {
2013-05-29 19:55:23 +00:00
fileDesc = fileDescParameter;
refreshDialog(fileDescParameter);
};
2013-06-10 21:22:32 +00:00
dialogManageSynchronization.onSyncExportSuccess = refreshDialog;
dialogManageSynchronization.onSyncRemoved = refreshDialog;
2013-05-29 19:55:23 +00:00
2013-06-10 21:22:32 +00:00
dialogManageSynchronization.onReady = function() {
2013-08-14 23:44:51 +00:00
var modalElt = document.querySelector(".modal-manage-sync");
syncListElt = modalElt.querySelector(".sync-list");
$msgSyncListElt = $(modalElt.querySelectorAll(".msg-sync-list"));
$msgNoSyncElt = $(modalElt.querySelectorAll(".msg-no-sync"));
2013-06-02 00:38:23 +00:00
};
2013-06-10 21:22:32 +00:00
return dialogManageSynchronization;
2013-05-29 19:55:23 +00:00
2013-05-26 22:59:17 +00:00
});