71 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-04-01 22:05:09 +02:00
/* global Module */
/* Magic Mirror
* Module: alert
*
* By Paul-Vincent Roll http://paulvincentroll.com
* MIT Licensed.
*/
Module.register('alert',{
defaults: {
2016-04-02 19:56:19 +02:00
// scale|slide|genie|jelly|flip|bouncyflip|exploader
2016-04-01 22:05:09 +02:00
effect: "slide",
2016-04-02 04:17:58 +02:00
//time a notification is displayed
display_time: 3500,
2016-04-01 22:05:09 +02:00
//shown at startup
welcome_message: "Welcome, start was successfull!"
},
getScripts: function() {
2016-04-02 03:59:18 +02:00
return ["classie.js", "modernizr.custom.js", 'notificationFx.js', 'sweetalert.js'];
2016-04-01 22:05:09 +02:00
},
getStyles: function() {
2016-04-02 19:56:19 +02:00
return ['ns-default.css', 'sweetalert.css'];
2016-04-01 22:05:09 +02:00
},
2016-04-02 03:59:18 +02:00
show_notification: function (message) {
2016-04-02 20:05:05 +02:00
message = "<font size='4px' color='#4A4A4A'>" + message.title + "</font><br /><font size='5px'>" + message.message + "</font>"
2016-04-02 19:56:19 +02:00
new NotificationFx({
2016-04-01 22:05:09 +02:00
message : message,
2016-04-02 19:56:19 +02:00
layout : "growl",
2016-04-01 22:05:09 +02:00
effect : this.config.effect,
2016-04-02 04:17:58 +02:00
ttl: this.config.display_time
2016-04-02 19:56:19 +02:00
}).show();
2016-04-01 22:05:09 +02:00
},
2016-04-02 03:59:18 +02:00
show_alert: function (params) {
if (typeof params["type"] === 'undefined') { params["type"] = null; }
if (typeof params["imageUrl"] === 'undefined') { params["imageUrl"] = null; }
if (typeof params["imageSize"] === 'undefined') { params["imageSize"] = null; }
if (typeof params["timer"] === 'undefined') { params["timer"] = null; }
swal({
title: params["title"],
imageUrl: params["imageUrl"],
imageSize: params["imageSize"],
type: params["type"],
text: params["message"],
timer: params["timer"],
html: true,
showConfirmButton: false
});
},
hide_alert: function () {
swal.close()
},
2016-04-01 22:05:09 +02:00
notificationReceived: function(notification, payload, sender) {
2016-04-02 03:59:18 +02:00
if (notification === 'SHOW_NOTIFICATION') {
this.show_notification(payload)
}
else if (notification === 'SHOW_ALERT') {
this.show_alert(payload)
}
else if (notification === 'HIDE_ALERT') {
this.hide_alert()
2016-04-01 22:05:09 +02:00
}
},
start: function() {
2016-04-02 19:12:59 +02:00
if (this.config.welcome_message){
2016-04-02 20:05:05 +02:00
this.show_notification({title: "Welcome", message: this.config.welcome_message})
2016-04-02 19:12:59 +02:00
}
2016-04-01 22:05:09 +02:00
Log.info('Starting module: ' + this.name);
}
});