Stackedit/js/extensions/manage-synchronization.js

62 lines
1.9 KiB
JavaScript
Raw Normal View History

2013-05-27 19:45:33 +00:00
define([
"jquery",
"underscore"
], function($, _) {
2013-05-26 22:59:17 +00:00
var manageSynchronization = {
extensionId: "manageSynchronization",
2013-05-27 23:27:38 +00:00
extensionName: "Manage synchronization",
2013-05-27 19:45:33 +00:00
settingsBloc: '<p>Populates the "Manage synchronization" dialog box.</p>'
2013-05-26 22:59:17 +00:00
};
2013-05-27 19:45:33 +00:00
var fileMgr = undefined;
manageSynchronization.onFileMgrCreated = function(fileMgrParameter) {
fileMgr = fileMgrParameter;
2013-05-26 22:59:17 +00:00
};
var fileDesc = undefined;
var lineTemplate = [
'<div class="input-prepend input-append">',
'<span class="add-on" title="<%= provider.providerName %>">',
'<i class="icon-<%= provider.providerId %>"></i>',
'</span>',
'<input class="span5" type="text" value="<%= syncDesc %>" disabled />',
'</div>'].join("");
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;
var lineElement = $(_.template(lineTemplate, {
2013-05-27 22:13:41 +00:00
provider: syncAttributes.provider,
2013-05-26 22:59:17 +00:00
syncDesc: syncDesc
}));
lineElement.append($(removeButtonTemplate).click(function() {
2013-05-27 19:45:33 +00:00
fileMgr.removeSync(syncAttributes);
2013-05-26 22:59:17 +00:00
}));
syncList.append(lineElement);
});
};
manageSynchronization.onFileSelected = function(fileDescParameter) {
fileDesc = fileDescParameter;
refreshDialog(fileDescParameter);
};
manageSynchronization.onSyncExportSuccess = refreshDialog;
manageSynchronization.onSyncRemoved = refreshDialog;
return manageSynchronization;
});