2013-05-27 19:45:33 +00:00
|
|
|
define([
|
|
|
|
"jquery",
|
|
|
|
"underscore",
|
2013-05-27 23:27:38 +00:00
|
|
|
"utils",
|
2013-11-07 23:10:38 +00:00
|
|
|
"logger",
|
2013-06-22 23:48:57 +00:00
|
|
|
"classes/Extension",
|
2013-06-10 21:22:32 +00:00
|
|
|
"jgrowl",
|
2013-06-22 23:48:57 +00:00
|
|
|
"text!html/notificationsSettingsBlock.html",
|
2013-11-07 23:10:38 +00:00
|
|
|
], function($, _, utils, logger, Extension, jGrowl, notificationsSettingsBlockHTML) {
|
2013-05-29 19:55:23 +00:00
|
|
|
|
2013-06-22 23:48:57 +00:00
|
|
|
var notifications = new Extension("notifications", "Notifications");
|
|
|
|
notifications.settingsBlock = notificationsSettingsBlockHTML;
|
|
|
|
notifications.defaultConfig = {
|
|
|
|
timeout: 8000
|
2013-05-27 23:27:38 +00:00
|
|
|
};
|
2013-05-29 19:55:23 +00:00
|
|
|
|
|
|
|
notifications.onLoadSettings = function() {
|
|
|
|
utils.setInputValue("#input-notifications-timeout", notifications.config.timeout);
|
|
|
|
};
|
|
|
|
|
2013-05-27 23:27:38 +00:00
|
|
|
notifications.onSaveSettings = function(newConfig, event) {
|
2013-05-29 19:55:23 +00:00
|
|
|
newConfig.timeout = utils.getInputIntValue("#input-notifications-timeout", event, 1, 60000);
|
|
|
|
};
|
|
|
|
|
2013-06-19 20:33:46 +00:00
|
|
|
var isInit = false;
|
|
|
|
function init() {
|
|
|
|
if(isInit === false) {
|
|
|
|
// jGrowl configuration
|
|
|
|
jGrowl.defaults.life = notifications.config.timeout;
|
|
|
|
jGrowl.defaults.closer = false;
|
|
|
|
jGrowl.defaults.closeTemplate = '';
|
|
|
|
jGrowl.defaults.position = 'bottom-right';
|
|
|
|
isInit = true;
|
|
|
|
}
|
|
|
|
}
|
2013-05-29 19:55:23 +00:00
|
|
|
|
2013-05-29 23:04:52 +00:00
|
|
|
function showMessage(message, iconClass, options) {
|
2013-06-09 09:49:19 +00:00
|
|
|
logger.info(message);
|
2013-06-19 20:33:46 +00:00
|
|
|
init();
|
2013-05-29 23:04:52 +00:00
|
|
|
if(!message) {
|
2013-05-29 19:55:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-05-29 23:04:52 +00:00
|
|
|
var endOfMsg = message.indexOf("|");
|
2013-05-29 19:55:23 +00:00
|
|
|
if(endOfMsg !== -1) {
|
2013-05-29 23:04:52 +00:00
|
|
|
message = message.substring(0, endOfMsg);
|
|
|
|
if(!message) {
|
2013-05-29 19:55:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
options = options || {};
|
2013-08-20 22:40:19 +00:00
|
|
|
iconClass = iconClass || "icon-info-circled";
|
2013-09-03 12:01:26 +00:00
|
|
|
jGrowl("<i class='icon-white " + iconClass + "'></i> " + _.escape(message).replace(/\n/g, '<br/>'), options);
|
2013-05-29 19:55:23 +00:00
|
|
|
}
|
|
|
|
|
2013-12-23 22:46:49 +00:00
|
|
|
var isReady = false;
|
2013-12-08 18:11:35 +00:00
|
|
|
var $offlineStatusElt;
|
|
|
|
var $extensionButtonsElt;
|
|
|
|
notifications.onReady = function() {
|
2013-12-23 22:46:49 +00:00
|
|
|
isReady = true;
|
2013-12-08 18:11:35 +00:00
|
|
|
$offlineStatusElt = $('.navbar .offline-status');
|
|
|
|
$extensionButtonsElt = $('.navbar .extension-buttons');
|
2013-12-23 22:46:49 +00:00
|
|
|
updateOnlineStatus();
|
2013-12-08 18:11:35 +00:00
|
|
|
};
|
|
|
|
|
2013-05-29 19:55:23 +00:00
|
|
|
notifications.onMessage = function(message) {
|
|
|
|
showMessage(message);
|
|
|
|
};
|
|
|
|
|
|
|
|
notifications.onError = function(error) {
|
|
|
|
logger.error(error);
|
|
|
|
if(_.isString(error)) {
|
2013-08-20 22:40:19 +00:00
|
|
|
showMessage(error, "icon-attention");
|
2013-05-29 19:55:23 +00:00
|
|
|
}
|
|
|
|
else if(_.isObject(error)) {
|
2013-08-20 22:40:19 +00:00
|
|
|
showMessage(error.message, "icon-attention");
|
2013-05-29 19:55:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-23 22:46:49 +00:00
|
|
|
var isOffline = false;
|
|
|
|
function updateOnlineStatus() {
|
|
|
|
if(isReady === false) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-08 18:11:35 +00:00
|
|
|
$offlineStatusElt.toggleClass('hide', !isOffline);
|
|
|
|
$extensionButtonsElt.toggleClass('hide', isOffline);
|
2013-12-23 22:46:49 +00:00
|
|
|
}
|
|
|
|
notifications.onOfflineChanged = function(isOfflineParam) {
|
|
|
|
isOffline = isOfflineParam;
|
|
|
|
updateOnlineStatus();
|
2013-05-29 19:55:23 +00:00
|
|
|
if(isOffline === true) {
|
2013-12-08 18:11:35 +00:00
|
|
|
showMessage("You are offline.", "icon-attention-circled msg-offline");
|
2013-05-29 19:55:23 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-12-08 18:11:35 +00:00
|
|
|
showMessage("You are back online!", "icon-signal");
|
2013-05-29 19:55:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
notifications.onSyncImportSuccess = function(fileDescList, provider) {
|
|
|
|
var titles = _.map(fileDescList, function(fileDesc) {
|
|
|
|
return fileDesc.title;
|
|
|
|
}).join(", ");
|
|
|
|
showMessage(titles + ' imported successfully from ' + provider.providerName + '.');
|
|
|
|
};
|
|
|
|
|
|
|
|
notifications.onSyncExportSuccess = function(fileDesc, syncAttributes) {
|
|
|
|
showMessage('"' + fileDesc.title + '" will now be synchronized on ' + syncAttributes.provider.providerName + '.');
|
|
|
|
};
|
|
|
|
|
|
|
|
notifications.onSyncRemoved = function(fileDesc, syncAttributes) {
|
|
|
|
showMessage(syncAttributes.provider.providerName + " synchronized location has been removed.");
|
|
|
|
};
|
|
|
|
|
|
|
|
notifications.onPublishSuccess = function(fileDesc) {
|
|
|
|
showMessage('"' + fileDesc.title + '" successfully published.');
|
|
|
|
};
|
|
|
|
|
2013-05-29 23:04:52 +00:00
|
|
|
notifications.onNewPublishSuccess = function(fileDesc, publishAttributes) {
|
2013-05-29 19:55:23 +00:00
|
|
|
showMessage('"' + fileDesc.title + '" is now published on ' + publishAttributes.provider.providerName + '.');
|
|
|
|
};
|
|
|
|
|
|
|
|
notifications.onPublishRemoved = function(fileDesc, publishAttributes) {
|
|
|
|
showMessage(publishAttributes.provider.providerName + " publish location has been removed.");
|
2013-05-27 23:27:38 +00:00
|
|
|
};
|
2013-05-29 19:55:23 +00:00
|
|
|
|
|
|
|
return notifications;
|
2013-05-25 00:34:04 +00:00
|
|
|
});
|