2013-05-27 19:45:33 +00:00
|
|
|
define([
|
|
|
|
"jquery",
|
|
|
|
"underscore",
|
2013-05-27 23:27:38 +00:00
|
|
|
"utils",
|
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",
|
|
|
|
], function($, _, utils, 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 || {};
|
|
|
|
iconClass = iconClass || "icon-info-sign";
|
2013-05-29 23:04:52 +00:00
|
|
|
jGrowl("<i class='icon-white " + iconClass + "'></i> " + _.escape(message), options);
|
2013-05-29 19:55:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
notifications.onMessage = function(message) {
|
|
|
|
showMessage(message);
|
|
|
|
};
|
|
|
|
|
|
|
|
notifications.onError = function(error) {
|
|
|
|
logger.error(error);
|
|
|
|
if(_.isString(error)) {
|
|
|
|
showMessage(error, "icon-warning-sign");
|
|
|
|
}
|
|
|
|
else if(_.isObject(error)) {
|
|
|
|
showMessage(error.message, "icon-warning-sign");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
notifications.onOfflineChanged = function(isOffline) {
|
|
|
|
if(isOffline === true) {
|
|
|
|
showMessage("You are offline.", "icon-exclamation-sign msg-offline", {
|
|
|
|
sticky: true,
|
|
|
|
close: function() {
|
|
|
|
showMessage("You are back online!", "icon-signal");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$(".msg-offline").parents(".jGrowl-notification").trigger('jGrowl.beforeClose');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
});
|