[extensions-web] Sort messages by their message type.
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Sort messages by their message type.
- Date: Fri, 23 Sep 2011 23:09:36 +0000 (UTC)
commit f1399c6c37259388918ecb03b6a1d4f0ab8e028d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Fri Sep 23 16:29:32 2011 -0400
Sort messages by their message type.
Errors are at the top, then warnings, then come info.
sweettooth/static/js/messages.js | 47 ++++++++++++++++++++++++++++++++++++-
1 files changed, 45 insertions(+), 2 deletions(-)
---
diff --git a/sweettooth/static/js/messages.js b/sweettooth/static/js/messages.js
index 69444f2..2f68648 100644
--- a/sweettooth/static/js/messages.js
+++ b/sweettooth/static/js/messages.js
@@ -1,15 +1,57 @@
"use strict";
define(['jquery'], function($) {
+ var $container = $('#message_container');
+
+ var SORT_ORDER = ['error', 'warning', 'info'];
+
+ function grabMessageSort($message) {
+ var classList = $message.attr('class').split(' ');
+ console.log(classList);
+
+ for (var i = 0; i < classList.length; i ++) {
+ var order = SORT_ORDER.indexOf(classList[i]);
+ if (order > -1)
+ return order;
+ }
+
+ return null;
+ }
+
+ function compareMessage(a, b) {
+ var aSort = grabMessageSort($(a));
+ var bSort = grabMessageSort($(b));
+
+ if (aSort !== null && bSort !== null)
+ return aSort - bSort;
+ return 0;
+ }
+
+ function sortMessages() {
+ var messages = $container.find('.message');
+ messages.sort(compareMessage);
+
+ $container.empty();
+ $container.append(messages);
+ }
+
function addMessage(tag, message) {
- return $('<p>').addClass('message').addClass(tag)
- .append(message).appendTo($('#message_container'));
+ var message = $('<p>').addClass('message').addClass(tag)
+ .append(message).appendTo($container);
+
+ sortMessages();
+
+ return message;
}
function addInfo(message) {
return addMessage('info', message);
}
+ function addWarning(message) {
+ return addMessage('info', message);
+ }
+
function addError(message) {
return addMessage('error', message);
}
@@ -17,6 +59,7 @@ define(['jquery'], function($) {
return {
addMessage: addMessage,
addError: addError,
+ addWarning: addWarning,
addInfo: addInfo
};
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]