can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[livejournal] r19193: OPSC-340: After processing payment API r...

Committer: dpetrov
OPSC-340: After processing payment API request from application dynamically update user's LJ Wallet balance at the top of the page.
U   trunk/htdocs/js/livejournal.js
Modified: trunk/htdocs/js/livejournal.js
===================================================================
--- trunk/htdocs/js/livejournal.js	2011-06-01 09:46:04 UTC (rev 19192)
+++ trunk/htdocs/js/livejournal.js	2011-06-02 03:16:03 UTC (rev 19193)
@@ -17,12 +17,8 @@
     var hookfuncs = LiveJournal.hooks[a[0]];
     if (!hookfuncs || !hookfuncs.length) return;
 
-    var hookargs = [];
+    var hookargs = [].slice.call( arguments, 1 );
 
-    for (var i = 1; i < a.length; i++) {
-        hookargs.push(a[i]);
-    }
-
     var rv = null;
 
     hookfuncs.forEach(function (hookfunc) {
@@ -33,6 +29,9 @@
 };
 
 LiveJournal.initPage = function () {
+	//register system hooks
+	LiveJournal.register_hook( 'update_wallet_balance', LiveJournal.updateWalletBalance );
+
     // set up various handlers for every page
     LiveJournal.initInboxUpdate();
 
@@ -60,29 +59,44 @@
 
 // Do AJAX request to find the number of unread items in the inbox
 LiveJournal.updateInbox = function () {
-    var postData = {
-        "action": "get_unread_items"
-    };
 
-    var opts = {
-        "data": HTTPReq.formEncoded(postData),
-        "method": "POST",
-        "onData": LiveJournal.gotInboxUpdate
-    };
+	jQuery.post( LiveJournal.getAjaxUrl( 'esn_inbox' ), {
+			"action": "get_unread_items"
+		}, function( resp ) {
+			if (! resp || resp.error) return;
 
-    opts.url = Site.currentJournal ? "/" + Site.currentJournal + "/__rpc_esn_inbox" : "/__rpc_esn_inbox";
-
-    HTTPReq.getJSON(opts);
+			var unread = $("LJ_Inbox_Unread_Count");
+			if( unread ) {
+				unread.innerHTML = resp.unread_count ? "  (" + resp.unread_count + ")" : "";
+			} else {
+				var unread = $("LJ_Inbox_Unread_Count_Controlstrip");
+				if( unread ) {
+					unread.innerHTML = resp.unread_count ? resp.unread_count  : "0";
+				}
+			}
+		}, 'json' );
 };
 
-// We received the number of unread inbox items from the server
-LiveJournal.gotInboxUpdate = function (resp) {
-    if (! resp || resp.error) return;
+//refresh number of tokens in the header
+LiveJournal.updateWalletBalance = function () {
+	jQuery.get( LiveJournal.getAjaxUrl( 'get_balance' ), function( resp ) {
+			if (! resp || resp.status != 'OK') return;
 
-    var unread = $("LJ_Inbox_Unread_Count");
-    if (! unread) return;
-
-    unread.innerHTML = resp.unread_count ? "  (" + resp.unread_count + ")" : "";
+			var balance = $("LJ_Wallet_Balance");
+			if( balance ) {
+				if( resp.balance ) {
+					balance.innerHTML = balance.innerHTML.replace( /\d+/, resp.balance );
+				} else {
+					balance.innerHTML = "";
+				}
+			} else {
+				var balance = $("LJ_Wallet_Balance_Controlstrip");
+				if( balance ) {
+					balance.innerHTML = resp.balance ? resp.balance  : "0";
+				}
+			}
+		}
+	);
 };
 
 // Placeholder onclick event

Tags: can3p, js, livejournal
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments