78 lines
2.1 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 04:17:58 +02:00
// style type: growl|attached|bar
style: "growl",
// effects for the specified style:
// for growl style: scale|slide|genie|jelly
// for attached style: flip|bouncyflip
// for bar style: slidetop|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 03:59:18 +02:00
return ['ns-style-growl.css', 'ns-style-bar.css', 'ns-style-attached.css', '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-01 22:05:09 +02:00
//If another alert is in view remove it first
if (this.alert){
this.alert.dismiss()
}
this.alert = new NotificationFx({
message : message,
2016-04-02 04:17:58 +02:00
layout : this.config.style,
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-01 22:05:09 +02:00
});
this.alert.show()
},
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 03:59:18 +02:00
this.show_notification(this.config.welcome_message)
2016-04-01 22:05:09 +02:00
Log.info('Starting module: ' + this.name);
}
});