Simple growl-like notifications
This commit is contained in:
@@ -136,23 +136,24 @@ class CoreNotifier(Notification):
|
|||||||
#db.close()
|
#db.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def frontend(self, type = 'notification', data = {}):
|
def frontend(self, type = 'notification', data = {}, message = None):
|
||||||
|
|
||||||
self.m_lock.acquire()
|
self.m_lock.acquire()
|
||||||
message = {
|
notification = {
|
||||||
'message_id': str(uuid.uuid4()),
|
'message_id': str(uuid.uuid4()),
|
||||||
'time': time.time(),
|
'time': time.time(),
|
||||||
'type': type,
|
'type': type,
|
||||||
'data': data,
|
'data': data,
|
||||||
|
'message': message,
|
||||||
}
|
}
|
||||||
self.messages.append(message)
|
self.messages.append(notification)
|
||||||
|
|
||||||
while len(self.listeners) > 0 and not self.shuttingDown():
|
while len(self.listeners) > 0 and not self.shuttingDown():
|
||||||
try:
|
try:
|
||||||
listener, last_id = self.listeners.pop()
|
listener, last_id = self.listeners.pop()
|
||||||
listener({
|
listener({
|
||||||
'success': True,
|
'success': True,
|
||||||
'result': [message],
|
'result': [notification],
|
||||||
})
|
})
|
||||||
except:
|
except:
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -126,11 +126,12 @@ var NotificationBase = new Class({
|
|||||||
processData: function(json){
|
processData: function(json){
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|
||||||
// Process data
|
// Process data
|
||||||
if(json){
|
if(json){
|
||||||
Array.each(json.result, function(result){
|
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)
|
if(json.result.length > 0)
|
||||||
@@ -140,7 +141,31 @@ var NotificationBase = new Class({
|
|||||||
// Restart poll
|
// Restart poll
|
||||||
self.startPoll()
|
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(){
|
addTestButtons: function(){
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|||||||
@@ -240,7 +240,6 @@ class MoviePlugin(Plugin):
|
|||||||
db = get_session()
|
db = get_session()
|
||||||
|
|
||||||
for id in getParam('id').split(','):
|
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()
|
movie = db.query(Movie).filter_by(id = id).first()
|
||||||
|
|
||||||
if movie:
|
if movie:
|
||||||
@@ -250,6 +249,7 @@ class MoviePlugin(Plugin):
|
|||||||
for title in movie.library.titles:
|
for title in movie.library.titles:
|
||||||
if title.default: default_title = title.title
|
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))
|
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()
|
onComplete()
|
||||||
|
|
||||||
if added:
|
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()
|
#db.close()
|
||||||
return movie_dict
|
return movie_dict
|
||||||
|
|||||||
@@ -17,10 +17,13 @@ var Movie = new Class({
|
|||||||
self.parent(self, options);
|
self.parent(self, options);
|
||||||
|
|
||||||
App.addEvent('movie.update.'+data.id, self.update.bind(self));
|
App.addEvent('movie.update.'+data.id, self.update.bind(self));
|
||||||
App.addEvent('movie.busy.'+data.id, function(notification){
|
|
||||||
if(notification.data)
|
['movie.busy', 'searcher.started'].each(function(listener){
|
||||||
self.busy(true)
|
App.addEvent(listener+'.'+data.id, function(notification){
|
||||||
});
|
if(notification.data)
|
||||||
|
self.busy(true)
|
||||||
|
});
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
busy: function(set_busy){
|
busy: function(set_busy){
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class Searcher(Plugin):
|
|||||||
if not default_title:
|
if not default_title:
|
||||||
return
|
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
|
ret = False
|
||||||
for quality_type in movie['profile']['types']:
|
for quality_type in movie['profile']['types']:
|
||||||
|
|||||||
@@ -601,4 +601,40 @@ body > .spinner, .mask{
|
|||||||
}
|
}
|
||||||
.more_menu .wrapper li a:hover {
|
.more_menu .wrapper li a:hover {
|
||||||
background: rgba(0,0,0,0.05);
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user