Polymer .9: Notifications

This commit is contained in:
Paulus Schoutsen 2015-05-20 22:41:58 -07:00
parent 5baf16ad6e
commit de243855c4
3 changed files with 34 additions and 24 deletions

View File

@ -1,37 +1,47 @@
<link rel="import" href="../bower_components/polymer/polymer.html"> <link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-toast/paper-toast.html"> <link rel="import" href="../bower_components/paper-toast/paper-toast.html">
<polymer-element name="ha-notifications"> <dom-module id="ha-notifications">
<style>
paper-toast {
z-index: 1;
}
</style>
<template> <template>
<paper-toast id="toast" role="alert" text=""></paper-toast> <paper-toast id="toast" text='{{text}}'></paper-toast>
</template> </template>
</dom-module>
<script> <script>
var storeListenerMixIn = window.hass.storeListenerMixIn; (function() {
Polymer({
is: 'ha-notifications',
Polymer(Polymer.mixin({ behaviors: [StoreListenerBehavior],
lastId: null,
attached: function() { properties: {
this.listenToStores(true); text: {
type: String,
value: '',
}, },
detached: function() { lastId: {
this.stopListeningToStores(); type: Number,
},
}, },
notificationStoreChanged: function(notificationStore) { notificationStoreChanged: function(notificationStore) {
if (notificationStore.hasNewNotifications(this.lastId)) { if (notificationStore.hasNewNotifications(this.lastId)) {
var toast = this.$.toast;
var notification = notificationStore.lastNotification; var notification = notificationStore.lastNotification;
if (notification) {
this.lastId = notification.id; this.lastId = notification.id;
toast.text = notification.message; this.text = notification.message;
toast.show();
} this.$.toast.show();
} }
}, },
}, storeListenerMixIn)); });
})();
</script> </script>
</polymer-element>

@ -1 +1 @@
Subproject commit dd4cefc7af348dd9a9cfbc99094b73a7ed128621 Subproject commit 015edf9c28a63122aa8f6bc153f0c0ddfaad1caa

View File

@ -16,8 +16,8 @@
<link rel="import" href="../layouts/partial-dev-fire-event.html"> <link rel="import" href="../layouts/partial-dev-fire-event.html">
<link rel="import" href="../layouts/partial-dev-set-state.html"> <link rel="import" href="../layouts/partial-dev-set-state.html">
<!--<link rel="import" href="../components/ha-notifications.html"> <link rel="import" href="../components/ha-notifications.html">
<link rel="import" href="../components/ha-modals.html"> --> <!--<link rel="import" href="../components/ha-modals.html"> -->
<link rel="import" href="../components/stream-status.html"> <link rel="import" href="../components/stream-status.html">
<dom-module is="home-assistant-main"> <dom-module is="home-assistant-main">
@ -56,7 +56,7 @@
<template> <template>
<!-- <ha-notifications></ha-notifications> --> <ha-notifications></ha-notifications>
<!-- <ha-modals></ha-modals> --> <!-- <ha-modals></ha-modals> -->
<paper-drawer-panel id="drawer" narrow='{{narrow}}'> <paper-drawer-panel id="drawer" narrow='{{narrow}}'>