82 lines
2.5 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-02 23:54:15 +02:00
//Position
position: "center",
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-03 00:20:11 +02:00
message = "<span class='thin' style='line-height: 35px; font-size:24px' color='#4A4A4A'>" + message.title + "</span><br /><span class='light' style='font-size:28px;line-height: 30px;'>" + message.message + "</span>"
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-02 23:54:15 +02:00
setPosition: function (pos) {
var sheet = document.createElement('style')
2016-04-03 00:20:11 +02:00
if (pos == "center"){sheet.innerHTML = ".ns-box {margin-left: auto; margin-right: auto;text-align: center;}";}
if (pos == "right"){sheet.innerHTML = ".ns-box {margin-left: auto;text-align: right;}";}
if (pos == "left"){sheet.innerHTML = ".ns-box {margin-right: auto;text-align: left;}";}
2016-04-02 23:54:15 +02:00
document.body.appendChild(sheet);
},
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-03 00:20:11 +02:00
this.show_notification({title: "MagicMirror Notification", message: this.config.welcome_message})
2016-04-02 19:12:59 +02:00
}
2016-04-02 23:54:15 +02:00
this.setPosition(this.config.position)
2016-04-01 22:05:09 +02:00
Log.info('Starting module: ' + this.name);
}
});