Simple growl-like notifications

This commit is contained in:
Ruud
2012-06-30 21:25:36 +02:00
parent 3b441d2942
commit cf3041c848
6 changed files with 80 additions and 15 deletions
+5 -4
View File
@@ -136,23 +136,24 @@ class CoreNotifier(Notification):
#db.close()
return True
def frontend(self, type = 'notification', data = {}):
def frontend(self, type = 'notification', data = {}, message = None):
self.m_lock.acquire()
message = {
notification = {
'message_id': str(uuid.uuid4()),
'time': time.time(),
'type': type,
'data': data,
'message': message,
}
self.messages.append(message)
self.messages.append(notification)
while len(self.listeners) > 0 and not self.shuttingDown():
try:
listener, last_id = self.listeners.pop()
listener({
'success': True,
'result': [message],
'result': [notification],
})
except:
break
@@ -126,11 +126,12 @@ var NotificationBase = new Class({
processData: function(json){
var self = this;
// Process data
if(json){
Array.each(json.result, function(result){
App.fireEvent(result.type, result)
App.fireEvent(result.type, result);
if(result.message && result.read === undefined)
self.showMessage(result.message);
})
if(json.result.length > 0)
@@ -140,7 +141,31 @@ var NotificationBase = new Class({
// Restart poll
self.startPoll()
},
showMessage: function(message){
var self = this;
if(!self.message_container)
self.message_container = new Element('div.messages').inject(document.body);
var new_message = new Element('div.message', {
'text': message
}).inject(self.message_container);
setTimeout(function(){
new_message.addClass('show')
}, 10);
setTimeout(function(){
new_message.addClass('hide')
setTimeout(function(){
new_message.destroy();
}, 1000);
}, 4000);
},
// Notification setting tests
addTestButtons: function(){
var self = this;
+2 -2
View File
@@ -240,7 +240,6 @@ class MoviePlugin(Plugin):
db = get_session()
for id in getParam('id').split(','):
fireEvent('notify.frontend', type = 'movie.busy.%s' % id, data = True)
movie = db.query(Movie).filter_by(id = id).first()
if movie:
@@ -250,6 +249,7 @@ class MoviePlugin(Plugin):
for title in movie.library.titles:
if title.default: default_title = title.title
fireEvent('notify.frontend', type = 'movie.busy.%s' % id, data = True, message = 'Updating "%s"' % default_title)
fireEventAsync('library.update', identifier = movie.library.identifier, default_title = default_title, force = True, on_complete = self.createOnComplete(id))
@@ -342,7 +342,7 @@ class MoviePlugin(Plugin):
onComplete()
if added:
fireEvent('notify.frontend', type = 'movie.added', data = movie_dict)
fireEvent('notify.frontend', type = 'movie.added', data = movie_dict, message = 'Successfully added "%s" to your wanted list.' % params.get('title', ''))
#db.close()
return movie_dict
@@ -17,10 +17,13 @@ var Movie = new Class({
self.parent(self, options);
App.addEvent('movie.update.'+data.id, self.update.bind(self));
App.addEvent('movie.busy.'+data.id, function(notification){
if(notification.data)
self.busy(true)
});
['movie.busy', 'searcher.started'].each(function(listener){
App.addEvent(listener+'.'+data.id, function(notification){
if(notification.data)
self.busy(true)
});
})
},
busy: function(set_busy){
+1 -1
View File
@@ -84,7 +84,7 @@ class Searcher(Plugin):
if not default_title:
return
fireEvent('notify.frontend', type = 'searcher.started.%s' % movie['id'], data = True)
fireEvent('notify.frontend', type = 'searcher.started.%s' % movie['id'], data = True, message = 'Searching for "%s"' % default_title)
ret = False
for quality_type in movie['profile']['types']:
+37 -1
View File
@@ -601,4 +601,40 @@ body > .spinner, .mask{
}
.more_menu .wrapper li a:hover {
background: rgba(0,0,0,0.05);
}
}
.messages {
position: fixed;
right: 0;
bottom: 0;
padding: 2px;
width: 240px;
z-index: 2;
}
.messages .message {
text-align: center;
border-radius: 2px;
margin: 2px 0 0 0;
height: 0;
overflow: hidden;
position: relative;
transition: all .4s cubic-bezier(0.9,0,0.1,1);
font-size: 12px;
box-shadow: 0 1px 1px rgba(0,0,0,0.35), inset 0 1px 0px rgba(255,255,255,0.20);
background-image: linear-gradient(
270deg,
#5b9bd1 0%,
#406db8 100%
);
}
.messages .message.show {
height: auto;
padding: 3px 5px;
min-height: 10px;
max-height: 400px;
}
.messages .message.hide {
right: -240px;
opacity: 0;
}