2013-05-27 19:45:33 +00:00
|
|
|
define([
|
|
|
|
"jquery",
|
|
|
|
"underscore",
|
2013-05-27 23:27:38 +00:00
|
|
|
"utils",
|
2013-05-27 19:45:33 +00:00
|
|
|
"jgrowl"
|
2013-05-27 23:27:38 +00:00
|
|
|
], function($, _, utils, jGrowl) {
|
2013-05-25 00:34:04 +00:00
|
|
|
|
|
|
|
var notifications = {
|
|
|
|
extensionId: "notifications",
|
|
|
|
extensionName: "Notifications",
|
|
|
|
defaultConfig: {
|
2013-05-27 23:27:38 +00:00
|
|
|
timeout: 5000
|
2013-05-25 18:13:59 +00:00
|
|
|
},
|
2013-05-27 23:27:38 +00:00
|
|
|
settingsBloc: [
|
|
|
|
'<p>Shows notification messages in the bottom-right corner of the screen.</p>',
|
|
|
|
'<div class="form-horizontal">',
|
|
|
|
'<div class="control-group">',
|
|
|
|
'<label class="control-label" for="input-notifications-timeout">Timeout</label>',
|
|
|
|
'<div class="controls">',
|
|
|
|
'<input type="text" id="input-notifications-timeout" class="input-mini">',
|
|
|
|
'<span class="help-inline">ms</span>',
|
|
|
|
'</div>',
|
|
|
|
'</div>',
|
|
|
|
'</div>'
|
|
|
|
].join("")
|
2013-05-25 00:34:04 +00:00
|
|
|
};
|
|
|
|
|
2013-05-27 23:27:38 +00:00
|
|
|
notifications.onLoadSettings = function() {
|
|
|
|
utils.setInputValue("#input-notifications-timeout", notifications.config.timeout);
|
|
|
|
};
|
|
|
|
|
|
|
|
notifications.onSaveSettings = function(newConfig, event) {
|
|
|
|
newConfig.timeout = utils.getInputIntValue("#input-notifications-timeout", event, 1, 60000);
|
|
|
|
};
|
|
|
|
|
2013-05-25 00:34:04 +00:00
|
|
|
notifications.onReady = function() {
|
|
|
|
// jGrowl configuration
|
2013-05-27 23:27:38 +00:00
|
|
|
jGrowl.defaults.life = notifications.config.timeout;
|
2013-05-27 19:45:33 +00:00
|
|
|
jGrowl.defaults.closer = false;
|
|
|
|
jGrowl.defaults.closeTemplate = '';
|
|
|
|
jGrowl.defaults.position = 'bottom-right';
|
2013-05-25 00:34:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function showMessage(msg, iconClass, options) {
|
|
|
|
if(!msg) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var endOfMsg = msg.indexOf("|");
|
|
|
|
if(endOfMsg !== -1) {
|
|
|
|
msg = msg.substring(0, endOfMsg);
|
|
|
|
if(!msg) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
options = options || {};
|
|
|
|
iconClass = iconClass || "icon-info-sign";
|
2013-05-27 19:45:33 +00:00
|
|
|
jGrowl("<i class='icon-white " + iconClass + "'></i> " + _.escape(msg), options);
|
2013-05-25 00:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
notifications.onMessage = function(message) {
|
2013-05-28 23:41:09 +00:00
|
|
|
logger.log(message);
|
2013-05-25 00:34:04 +00:00
|
|
|
showMessage(message);
|
|
|
|
};
|
|
|
|
|
|
|
|
notifications.onError = function(error) {
|
2013-05-28 23:41:09 +00:00
|
|
|
logger.error(error);
|
2013-05-27 19:45:33 +00:00
|
|
|
if(_.isString(error)) {
|
|
|
|
showMessage(error, "icon-warning-sign");
|
|
|
|
}
|
|
|
|
else if(_.isObject(error)) {
|
|
|
|
showMessage(error.message, "icon-warning-sign");
|
|
|
|
}
|
2013-05-25 00:34:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-26 22:59:03 +00:00
|
|
|
notifications.onSyncImportSuccess = function(fileDescList, provider) {
|
|
|
|
if(!fileDescList) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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.');
|
|
|
|
};
|
|
|
|
|
|
|
|
notifications.onNewPublishSuccess = function(fileDesc, publishIndex, publishAttributes) {
|
|
|
|
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-25 00:34:04 +00:00
|
|
|
return notifications;
|
|
|
|
});
|