Stackedit/js/extensions/dialogManageSynchronization.js

70 lines
2.4 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",
"text!html/dialogManageSynchronizationLocation.html",
], function($, _, dialogManageSynchronizationLocationHTML) {
2013-05-29 19:55:23 +00:00
2013-06-10 21:22:32 +00:00
var dialogManageSynchronization = {
extensionId: "dialogManageSynchronization",
extensionName: 'Dialog "Manage synchronization"',
2013-05-29 19:55:23 +00:00
settingsBloc: '<p>Populates the "Manage synchronization" dialog box.</p>'
};
var fileMgr = undefined;
2013-06-10 21:22:32 +00:00
dialogManageSynchronization.onFileMgrCreated = function(fileMgrParameter) {
2013-05-29 19:55:23 +00:00
fileMgr = fileMgrParameter;
};
var fileDesc = undefined;
var removeButtonTemplate = '<a class="btn" title="Remove this location"><i class="icon-trash"></i></a>';
var refreshDialog = function(fileDescParameter) {
if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) {
return;
}
var syncAttributesList = _.values(fileDesc.syncLocations);
$(".msg-no-sync, .msg-sync-list").addClass("hide");
var syncList = $("#manage-sync-list").empty();
if(syncAttributesList.length > 0) {
$(".msg-sync-list").removeClass("hide");
}
else {
$(".msg-no-sync").removeClass("hide");
}
_.each(syncAttributesList, function(syncAttributes) {
var syncDesc = syncAttributes.id || syncAttributes.path;
2013-06-10 21:22:32 +00:00
var lineElement = $(_.template(dialogManageSynchronizationLocationHTML, {
2013-05-29 19:55:23 +00:00
provider: syncAttributes.provider,
syncDesc: syncDesc
}));
lineElement.append($(removeButtonTemplate).click(function() {
fileMgr.removeSync(syncAttributes);
}));
syncList.append(lineElement);
});
};
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-06-02 00:38:23 +00:00
// Handle enter key in the sync manual inputs
$(".sync-manual").each(function() {
var elt = $(this);
elt.find("input").keyup(function(e) {
if(e.which == 13) {
elt.find("a").click();
e.stopPropagation();
}
});
});
};
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
});