From 7ed11598fbd14247326e7674c1db8daf2a013385 Mon Sep 17 00:00:00 2001 From: benweet Date: Mon, 29 Apr 2013 00:08:54 +0100 Subject: [PATCH] Add publish providers icons beside document title --- js/file-manager.js | 1 + js/publisher.js | 13 +++++++++++++ js/synchronizer.js | 6 +++--- js/tumblr-helper.js | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/js/file-manager.js b/js/file-manager.js index d9031817..0305d770 100644 --- a/js/file-manager.js +++ b/js/file-manager.js @@ -137,6 +137,7 @@ define(["jquery", "core", "synchronizer", "publisher", "text!../WELCOME.md", "un function composeTitle(fileIndex) { var result = " " + localStorage[fileIndex + ".title"]; var providerIdList = synchronizer.getSyncProvidersFromFile(fileIndex); + providerIsList = _.extend(providerIdList, publisher.getPublishProvidersFromFile(fileIndex)); _.each(providerIdList, function(providerId) { result = '' + result; }); diff --git a/js/publisher.js b/js/publisher.js index da136502..16fd52a6 100644 --- a/js/publisher.js +++ b/js/publisher.js @@ -93,6 +93,7 @@ define(["jquery", "core", "github-provider", "blogger-provider", "dropbox-provid var errorMsg = error.toString(); if(errorMsg.indexOf("|removePublish") !== -1) { core.fileManager.removePublish(publishIndex); + core.fileManager.updateFileTitles(); core.showMessage(provider.providerName + " publish location has been removed."); } if(errorMsg.indexOf("|stopPublish") !== -1) { @@ -168,6 +169,7 @@ define(["jquery", "core", "github-provider", "blogger-provider", "dropbox-provid publishAttributes.provider = provider.providerId; createPublishIndex(fileIndex, publishAttributes); publisher.notifyPublish(); + core.fileManager.updateFileTitles(); core.showMessage('"' + title + '" is now published on ' + provider.providerName + '.'); } @@ -200,11 +202,22 @@ define(["jquery", "core", "github-provider", "blogger-provider", "dropbox-provid })); lineElement.append($(removeButtonTemplate).click(function() { core.fileManager.removePublish(publishIndex); + core.fileManager.updateFileTitles(); })); $("#manage-publish-list").append(lineElement); }); }; + publisher.getPublishProvidersFromFile = function(fileIndex) { + var publishIndexList = _.compact(localStorage[fileIndex + ".publish"].split(";")); + var providerIdList = {}; + _.each(publishIndexList, function(publishIndex) { + var publishAttributes = JSON.parse(localStorage[publishIndex]); + providerIdList[publishAttributes.provider] = publishAttributes.provider; + }); + return providerIdList; + }; + core.onReady(function() { // Init each provider _.each(providerMap, function(provider) { diff --git a/js/synchronizer.js b/js/synchronizer.js index 48cf3f43..903883a6 100644 --- a/js/synchronizer.js +++ b/js/synchronizer.js @@ -218,7 +218,7 @@ define(["jquery", "core", "dropbox-provider", "gdrive-provider", "underscore"], }); }; - // Used to enable/disable providers' synchronization + // Used to enable/disable provider synchronization synchronizer.resetSyncFlags = function() { _.each(providerMap, function(provider) { provider.useSync = false; @@ -226,11 +226,11 @@ define(["jquery", "core", "dropbox-provider", "gdrive-provider", "underscore"], }; synchronizer.getSyncProvidersFromFile = function(fileIndex) { var sync = localStorage[fileIndex + ".sync"]; - var providerIdList = []; + var providerIdList = {}; _.each(providerMap, function(provider) { if (sync.indexOf(";sync." + provider.providerId + ".") !== -1) { provider.useSync = true; - providerIdList.push(provider.providerId); + providerIdList[provider.providerId] = provider.providerId; } }); return providerIdList; diff --git a/js/tumblr-helper.js b/js/tumblr-helper.js index b5d7cfe4..5eb030d7 100644 --- a/js/tumblr-helper.js +++ b/js/tumblr-helper.js @@ -121,7 +121,7 @@ define(["jquery", "core", "async-runner"], function($, core, asyncRunner) { }; // Handle error if(error.code === 404 && postId !== undefined) { - error = 'Post ' + postId + ' not found on Blogger.|removePublish'; + error = 'Post ' + postId + ' not found on Tumblr.|removePublish'; } handleError(error, task); });