[Pkg-mozext-commits] [wot] 95/226: Made Activity Score alive.
David Prévot
taffit at moszumanska.debian.org
Fri May 1 00:35:38 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository wot.
commit 049a17bdda4a1640edc2041ca34c69186dcc7c1a
Author: Sergey Andryukhin <sorgoz at yandex.com>
Date: Fri Aug 2 16:21:17 2013 +0300
Made Activity Score alive.
---
content/api.js | 112 +++++++++++++--------------------
content/config.js | 14 ++---
content/ratingwindow.js | 151 ++++++++++++++++++++++++++++++++++-----------
content/rw/ratingwindow.js | 8 +--
content/ui.js | 52 ++++++++--------
5 files changed, 193 insertions(+), 144 deletions(-)
diff --git a/content/api.js b/content/api.js
index 9b5b2e5..b4bf50e 100644
--- a/content/api.js
+++ b/content/api.js
@@ -156,13 +156,19 @@ var wot_api_link =
var wot_api_query =
{
- message: "",
+ /* Variables */
+ message: "",
message_id: "",
message_type: "",
message_url: "",
users: [],
- send: function(hostname, callback)
+ /* Constants */
+ XML_QUERY_STATUS_LEVEL: "level",
+ XML_QUERY_USER_LABEL: "label",
+
+ /* Methods */
+ send: function(hostname, callback)
{
try {
if (!wot_util.isenabled()) {
@@ -363,67 +369,37 @@ var wot_api_query =
try {
this.users = [];
- if (!users) {
- return;
- }
-
- var i = 0;
- var u = users.item(0);
- var a;
-
- while (u) {
- var item = {};
- a = u.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_USER_ICON);
-
- if (a && a.value) {
- item.icon = a.value;
- }
-
- a = u.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_USER_BAR);
-
- if (a && a.value) {
- item.bar = a.value;
- }
-
- a = u.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_USER_LENGTH);
-
- if (a && a.value) {
- item.length = a.value;
- }
-
- a = u.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_USER_LABEL);
-
- if (a && a.value) {
- item.label = a.value;
- }
-
- a = u.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_USER_URL);
-
- if (a && a.value) {
- item.url = a.value;
- }
-
- a = u.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_USER_TEXT);
-
- if (a && a.value) {
- item.text = a.value;
- }
-
- a = u.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_USER_NOTICE);
-
- if (a && a.value) {
- item.notice = a.value;
- }
-
- if (item.text && (!item.bar ||
- (item.length != null && item.label))) {
- this.users[i] = item;
- }
-
- u = users.item(++i);
+ if (!users) return;
+
+ var u = users.item(0),// take only first items, ignore others
+ user_item = {},
+ a = null,
+ user_props = {
+// icon: WOT_SERVICE_XML_QUERY_USER_ICON,
+// bar: WOT_SERVICE_XML_QUERY_USER_BAR,
+// "length": WOT_SERVICE_XML_QUERY_USER_LENGTH,
+// url: WOT_SERVICE_XML_QUERY_USER_URL,
+// text: WOT_SERVICE_XML_QUERY_USER_TEXT,
+// notice: WOT_SERVICE_XML_QUERY_USER_NOTICE,
+ label: this.XML_QUERY_USER_LABEL // this is the only property we need
+ };
+
+ if (u) {
+ for (var k in user_props) {
+ a = u.attributes.getNamedItem(user_props[k]);
+ if (a && a.value) {
+ user_item[k] = a.value;
+ }
+ }
+ this.users.push(user_item);
+
+ // set activity score from "user's label"
+ if (!isNaN(user_item.label)) {
+ wot_prefs.setInt("activity_score", parseInt(user_item.label));
+ }
}
} catch (e) {
- dump("wot_api_query.parse_users: failed with " + e + "\n");
+ wdump("wot_api_query.parse_users: failed with " + e);
}
},
@@ -432,24 +408,20 @@ var wot_api_query =
try {
wot_prefs.clear("status_level");
- if (!stats) {
- return;
- }
+ if (!stats) return;
- var s = stats.item(0);
+ var s = stats.item(0);
- if (!s) {
- return;
- }
+ if (!s) return;
- var l = s.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_STATUS_LEVEL);
+ var l = s.attributes.getNamedItem(this.XML_QUERY_STATUS_LEVEL);
if (l && l.value) {
wot_prefs.setChar("status_level", l.value);
}
} catch (e) {
- dump("wot_api_query.parse_status: failed with " + e + "\n");
+ wdump("wot_api_query.parse_status: failed with " + e);
}
}
};
diff --git a/content/config.js b/content/config.js
index 7050632..3bbfb1b 100644
--- a/content/config.js
+++ b/content/config.js
@@ -152,15 +152,13 @@ const WOT_SERVICE_XML_QUERY_MSG_VERSION_LE = "le";
const WOT_SERVICE_XML_QUERY_MSG_VERSION_GE = "ge";
const WOT_SERVICE_XML_QUERY_MSG_THAN = "than";
const WOT_SERVICE_XML_QUERY_USER = "user";
-const WOT_SERVICE_XML_QUERY_USER_ICON = "icon";
-const WOT_SERVICE_XML_QUERY_USER_BAR = "bar";
-const WOT_SERVICE_XML_QUERY_USER_LENGTH = "length";
-const WOT_SERVICE_XML_QUERY_USER_LABEL = "label";
-const WOT_SERVICE_XML_QUERY_USER_URL = "url";
-const WOT_SERVICE_XML_QUERY_USER_TEXT = "text";
-const WOT_SERVICE_XML_QUERY_USER_NOTICE = "notice";
+//const WOT_SERVICE_XML_QUERY_USER_ICON = "icon";
+//const WOT_SERVICE_XML_QUERY_USER_BAR = "bar";
+//const WOT_SERVICE_XML_QUERY_USER_LENGTH = "length";
+//const WOT_SERVICE_XML_QUERY_USER_URL = "url";
+//const WOT_SERVICE_XML_QUERY_USER_TEXT = "text";
+//const WOT_SERVICE_XML_QUERY_USER_NOTICE = "notice";
const WOT_SERVICE_XML_QUERY_STATUS = "status";
-const WOT_SERVICE_XML_QUERY_STATUS_LEVEL = "level";
const WOT_SERVICE_XML_REGISTER = "register";
const WOT_SERVICE_XML_REGISTER_ID = "id";
const WOT_SERVICE_XML_REGISTER_KEY = "key";
diff --git a/content/ratingwindow.js b/content/ratingwindow.js
index ee7c148..a107d8c 100644
--- a/content/ratingwindow.js
+++ b/content/ratingwindow.js
@@ -116,6 +116,55 @@ var wot_rw = {
}
},
+ update_user_info: function () {
+
+// wot_api_query.users[0]
+// .bar - header
+// .label - activity score?
+// .length
+// .url
+// .notice
+// .text
+//
+
+// if (wot_api_query.users[i].bar &&
+// wot_api_query.users[i].length != null &&
+// wot_api_query.users[i].label) {
+// header.value = wot_api_query.users[i].bar;
+// label.value = wot_api_query.users[i].label;
+// bar.setAttribute("length", wot_api_query.users[i].length);
+// bar.hidden = false;
+// } else {
+// header.value = "";
+// label.value = "";
+// bar.hidden = true;
+// }
+//
+// if (wot_api_query.users[i].url) {
+// content.setAttribute("url", wot_api_query.users[i].url);
+// } else {
+// content.removeAttribute("url");
+// }
+//
+// if (wot_api_query.users[i].notice) {
+// notice.value = wot_api_query.users[i].notice;
+// notice.hidden = false;
+// } else {
+// notice.hidden = true;
+// }
+//
+// if (wot_api_query.users[i].text) {
+// text.value = wot_api_query.users[i].text;
+// user.hidden = false;
+// ++j;
+// } else {
+// text.value = "";
+// user.hidden = true;
+// }
+// }
+ wdump(JSON.stringify(wot_api_query.users[0]));
+ },
+
update: function () {
// Updates content of Rating Window. RW must be already initialized (locales, categories info, etc).
wdump("RW.update()");
@@ -164,8 +213,6 @@ var wot_rw = {
data.cached.value.cats = wot_categories.target_categories(target);
data.cached.value.blacklist = wot_categories.target_blacklists(target);
- wot_rw.update_messages();
-
} else {
data = {
target: target,
@@ -178,59 +225,91 @@ var wot_rw = {
};
}
+ wot_rw.push_preferences(rw, wot_rw.get_preferences()); // update preferences every time before showing RW
+
+ wot_rw.update_messages();
+ wot_rw.update_user_info();
+
+ // set the user's activity score additionally to bg.wot.core.
+ // FIXME: use activity score provided by preferences in RW instead of direct manupulation of core.usercontent[]
+ if (rw.wot_bg) {
+ rw.wot_bg.wot.core.usercontent = [
+ { "label": wot_prefs.activity_score }
+ ];
+ }
+
wdump("data: " + JSON.stringify(data));
rw_wot.ratingwindow.update(target, JSON.stringify(data));
},
get_preferences: function () {
+ var prefs = {};
+ try {
+ prefs = {
+ accessible: wot_prefs.accessible,
+ show_fulllist: wot_prefs.show_fulllist,
+ ratingwindow_shown: wot_prefs.ratingwindow_shown,
+ activity_score: wot_prefs.activity_score
+ };
+
+ } catch (e) {
+ wdump("ERROR: wot_rw.get_preferences() raised an exception: " + e);
+ }
- var prefs = {
- accessible: wot_prefs.accessible,
- show_fulllist: wot_prefs.show_fulllist,
- ratingwindow_shown: wot_prefs.ratingwindow_shown,
- activity_score: wot_prefs.activity_score
- };
+ wdump("prefs: " + JSON.stringify(prefs));
return prefs;
},
push_preferences: function (rw, prefs) {
- rw.wot_bg.wot.prefs.load_prefs(JSON.stringify(prefs));
+ try {
+ rw.wot_bg.wot.prefs.load_prefs(JSON.stringify(prefs));
+
+ } catch (e) {
+ wdump("ERROR: wot_rw.push_preferences() raised an exception: " + e);
+ }
},
on_ratingwindow_event: function (event) {
- var details = event.detail;
- if (!details) return false;
+ try {
+ var details = event.detail;
+ if (!details) return false;
- wdump("on_ratingwindow_event() " + JSON.stringify(details));
+ wdump("on_ratingwindow_event() " + JSON.stringify(details));
- var message_id = details.message_id,
- data = details.data;
+ var message_id = details.message_id,
+ data = details.data;
- // Important: don't use "this" here, because it points to other than wot_rw object!
+ // Important: don't use "this" here, because it points to other than wot_rw object!
- switch (message_id) {
- case "update": // bg.wot.core.update() is called from RW
- if (data && data.update_rw) {
- wot_rw.update();
- }
- // TODO: do other updates (e.g. toolbar icon, etc)
- wot_commands.update(); // Update button's context menu
- break;
-
- case "update_ratingwindow_comment":
- // TODO: implement
- break;
-
- case "unseenmessage":
- wot_rw.unseenmessage();
- break;
-
- case "navigate":
- wot_browser.open_wotsite(data.url, "", "", data.context, true, true);
- wot_rw.hide_ratingwindow();
- break;
+ switch (message_id) {
+ case "update": // bg.wot.core.update() is called from RW
+ if (data && data.update_rw) {
+ wot_rw.update();
+ }
+ // TODO: do other updates (e.g. toolbar icon, etc)
+ wot_commands.update(); // Update button's context menu
+ break;
+
+ case "update_ratingwindow_comment":
+ // TODO: implement
+ break;
+
+ case "unseenmessage":
+ wot_rw.unseenmessage();
+ break;
+
+ case "navigate":
+ wot_browser.open_wotsite(data.url, "", "", data.context, true, true);
+ wot_rw.hide_ratingwindow();
+ break;
+ }
+
+ return true;
+
+ } catch (e) {
+ wdump("ERROR: wot_rw.on_ratingwindow_event() raised an exception: " + e);
}
},
diff --git a/content/rw/ratingwindow.js b/content/rw/ratingwindow.js
index c4638b0..b5ae92c 100644
--- a/content/rw/ratingwindow.js
+++ b/content/rw/ratingwindow.js
@@ -443,16 +443,16 @@ $.extend(wot, { ratingwindow: {
/* content for user (messages / communications) */
$(".wot-user").hide();
- // TODO: rewrite below
+ // TODO: rewrite below: use activity score stored in Prefs instead.
var index = 0,
item = (bg.wot.core.usercontent && bg.wot.core.usercontent.length > 0) ? bg.wot.core.usercontent[0] : {},
user_header = wot.i18n("activityscore","text"),
- user_as = "",
+ user_as = 0,
$_user_text = $("#wot-user-0-text"),
as_notice = wot.i18n("activityscore", "next");
- if (item.label) {
- user_as = item.label;
+ if (item.label && !isNaN(item.label)) {
+ user_as = parseInt(item.label); // for better security we use numeric
}
// insert next level name
diff --git a/content/ui.js b/content/ui.js
index 9d6fc0e..6ae8814 100644
--- a/content/ui.js
+++ b/content/ui.js
@@ -354,32 +354,32 @@ var wot_ui = {
// {
// },
- update_message: function()
- {
- try {
- var msg = this.getElem("wot-message");
- var txt = this.getElem("wot-message-text");
-
- if (!msg || !txt || !txt.firstChild) {
- return;
- }
-
- if (wot_api_query.message.length == 0 ||
- wot_api_query.message_type.length == 0) {
- msg.hidden = true;
- txt.firstChild.nodeValue = "";
- return;
- }
-
- txt.firstChild.nodeValue = wot_api_query.message;
- txt.setAttribute("url-type",
- wot_api_query.message_url.substring(0,4));
- msg.setAttribute("message-status", wot_api_query.message_type);
- msg.hidden = false;
- } catch (e) {
- dump("wot_ui.update_message: failed with " + e + "\n");
- }
- },
+// update_message: function()
+// {
+// try {
+// var msg = this.getElem("wot-message");
+// var txt = this.getElem("wot-message-text");
+//
+// if (!msg || !txt || !txt.firstChild) {
+// return;
+// }
+//
+// if (wot_api_query.message.length == 0 ||
+// wot_api_query.message_type.length == 0) {
+// msg.hidden = true;
+// txt.firstChild.nodeValue = "";
+// return;
+// }
+//
+// txt.firstChild.nodeValue = wot_api_query.message;
+// txt.setAttribute("url-type",
+// wot_api_query.message_url.substring(0,4));
+// msg.setAttribute("message-status", wot_api_query.message_type);
+// msg.hidden = false;
+// } catch (e) {
+// dump("wot_ui.update_message: failed with " + e + "\n");
+// }
+// },
// update_users: function()
// {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/wot.git
More information about the Pkg-mozext-commits
mailing list