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-03 03:04:38 +02:00
|
|
|
// scale|slide|genie|jelly|flip|bouncyflip|exploader
|
|
|
|
alert_effect:"jelly",
|
2016-04-03 04:03:57 +02:00
|
|
|
//time a notification is displayed in seconds
|
|
|
|
display_time: 3.5,
|
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-03 03:04:38 +02:00
|
|
|
return ["classie.js", "modernizr.custom.js", 'notificationFx.js'];
|
2016-04-01 22:05:09 +02:00
|
|
|
},
|
|
|
|
getStyles: function() {
|
2016-04-03 03:04:38 +02:00
|
|
|
return ['ns-default.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-03 04:03:57 +02:00
|
|
|
ttl: this.config.display_time * 1000
|
2016-04-02 19:56:19 +02:00
|
|
|
}).show();
|
2016-04-01 22:05:09 +02:00
|
|
|
},
|
2016-04-03 03:04:38 +02:00
|
|
|
show_alert: function (params, sender) {
|
|
|
|
var self = this
|
|
|
|
//Set standard params if not provided by module
|
2016-04-03 04:03:57 +02:00
|
|
|
if (typeof params.timer === 'undefined') {
|
|
|
|
params.timer = null;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
params.timer = params.timer * 1000
|
|
|
|
}
|
2016-04-03 03:04:38 +02:00
|
|
|
if (typeof params.imageHeight === 'undefined') { params.imageHeight = "80px"; }
|
|
|
|
if (typeof params.imageUrl === 'undefined') {
|
|
|
|
params.imageUrl = null;
|
|
|
|
image = ""
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
image = "<img src='" + params["imageUrl"] + "' height=" + params.imageHeight + " style='margin-bottom: 10px;'/><br />"
|
|
|
|
}
|
|
|
|
//Create overlay
|
|
|
|
var overlay = document.createElement("div");
|
|
|
|
overlay.id = "overlay"
|
|
|
|
overlay.innerHTML += '<div class="black_overlay"></div>';
|
|
|
|
document.body.insertBefore(overlay, document.body.firstChild);
|
|
|
|
|
|
|
|
//If module already has an open alert close it
|
|
|
|
if (this.alerts[sender.name]){
|
|
|
|
this.hide_alert(sender)
|
|
|
|
}
|
|
|
|
|
|
|
|
message = "<span class='light' style='line-height: 35px; font-size:30px' color='#4A4A4A'>" + params.title + "</span><br /><span class='thin' style='font-size:22px;line-height: 30px;'>" + params.message + "</span>"
|
|
|
|
//Store alert in this.alerts
|
|
|
|
this.alerts[sender.name] = new NotificationFx({
|
|
|
|
message : image + message,
|
|
|
|
effect : this.config.alert_effect,
|
2016-04-03 04:03:57 +02:00
|
|
|
ttl: params.timer,
|
2016-04-03 03:04:38 +02:00
|
|
|
al_no: "ns-alert"
|
|
|
|
});
|
|
|
|
//Show alert
|
|
|
|
this.alerts[sender.name].show()
|
|
|
|
//Add timer to dismiss alert and overlay
|
|
|
|
if (params.timer) {
|
|
|
|
setTimeout( function() {
|
|
|
|
self.hide_alert(sender)
|
|
|
|
}, params.timer );
|
|
|
|
}
|
|
|
|
|
2016-04-02 03:59:18 +02:00
|
|
|
},
|
2016-04-03 03:04:38 +02:00
|
|
|
hide_alert: function (sender) {
|
|
|
|
//Dismiss alert and remove from this.alerts
|
|
|
|
this.alerts[sender.name].dismiss()
|
|
|
|
this.alerts[sender.name] = null
|
|
|
|
//Remove overlay
|
|
|
|
var overlay = document.getElementById("overlay");
|
|
|
|
overlay.parentNode.removeChild(overlay);
|
2016-04-02 03:59:18 +02:00
|
|
|
},
|
2016-04-02 23:54:15 +02:00
|
|
|
setPosition: function (pos) {
|
2016-04-03 03:04:38 +02:00
|
|
|
//Add css to body depending on the set position for notifications
|
2016-04-02 23:54:15 +02:00
|
|
|
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') {
|
2016-04-03 03:04:38 +02:00
|
|
|
this.show_alert(payload, sender)
|
2016-04-02 03:59:18 +02:00
|
|
|
}
|
|
|
|
else if (notification === 'HIDE_ALERT') {
|
2016-04-03 03:04:38 +02:00
|
|
|
this.hide_alert(sender)
|
2016-04-01 22:05:09 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
start: function() {
|
2016-04-03 03:04:38 +02:00
|
|
|
this.alerts = {}
|
|
|
|
this.setPosition(this.config.position)
|
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-01 22:05:09 +02:00
|
|
|
Log.info('Starting module: ' + this.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|