can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[ljcom] r10991: OPSC-360: Implement JS API to navigate b...

Committer: dpetrov
OPSC-360: Implement JS API to navigate between different application views
A   trunk/htdocs/js/apps/
A   trunk/htdocs/js/apps/livejournal/
A   trunk/htdocs/js/apps/livejournal/config/
A   trunk/htdocs/js/apps/livejournal/config/client.js
A   trunk/htdocs/js/apps/livejournal/config/container.js
A   trunk/htdocs/js/apps/livejournal/config/views.js
A   trunk/htdocs/js/apps/livejournal/livejournal-jsonrpc/
A   trunk/htdocs/js/apps/livejournal/livejournal-jsonrpc/jsonrpc.js
Added: trunk/htdocs/js/apps/livejournal/config/client.js
===================================================================
--- trunk/htdocs/js/apps/livejournal/config/client.js	                        (rev 0)
+++ trunk/htdocs/js/apps/livejournal/config/client.js	2011-09-12 08:22:14 UTC (rev 10991)
@@ -0,0 +1,14 @@
+(function() {
+
+	function initConfig() {
+		gadgets.config.init({
+			rpc: {},
+			views: gadgets.config.views
+		});
+	}
+
+	//we need to run this to bootstrap gadgets initialization.
+	initConfig();
+
+})();
+

Added: trunk/htdocs/js/apps/livejournal/config/container.js
===================================================================
--- trunk/htdocs/js/apps/livejournal/config/container.js	                        (rev 0)
+++ trunk/htdocs/js/apps/livejournal/config/container.js	2011-09-12 08:22:14 UTC (rev 10991)
@@ -0,0 +1,15 @@
+(function() {
+
+	function initConfig() {
+		gadgets.config.init({
+			rpc: {
+				parentRelayUrl: ''
+			},
+			views: gadgets.config.views
+		});
+	}
+
+	//we need to run this to bootstrap gadgets initialization.
+	initConfig();
+
+})();

Added: trunk/htdocs/js/apps/livejournal/config/views.js
===================================================================
--- trunk/htdocs/js/apps/livejournal/config/views.js	                        (rev 0)
+++ trunk/htdocs/js/apps/livejournal/config/views.js	2011-09-12 08:22:14 UTC (rev 10991)
@@ -0,0 +1,63 @@
+(function() {
+
+gadgets = gadgets || {};
+gadgets.config = gadgets.config || {};
+
+gadgets.config.views = {
+	'CANVAS': {
+		isOnlyVisible : true,
+		urlTemplate: 'http://{APP_SUBDOMAIN}.{DOMAIN}/{APP_KEY}'
+	},
+	'SETTINGS': {
+		urlTemplate: '{SITEROOT}/manage/settings/?cat=userapps&appid={APP_ID}'
+	},
+	'ABOUT': {
+		urlTemplate: '{SITEROOT}/games/#app_{APP_ID}'
+	},
+	'INSTALL': {
+		urlTemplate: '{SITEROOT}/games/install.bml?id={APP_ID}&act=install'
+	},
+	'HOME': {
+		urlTemplate: '{SITEROOT}#app_{APP_ID}'
+	},
+	// HOME COMMUNITY VIEWS
+	'COMMUNITY': {      // RecentPage
+		urlTemplate: 'http://{COMMUNITY_NAME}.{DOMAIN}'
+	},
+	'COMMUNITY.PROFILE': {
+		urlTemplate: 'http://{COMMUNITY_NAME}.{DOMAIN}/profile'
+	},
+	'COMMUNITY.ENTRY': { // EntryPage
+		urlTemplate: 'http://{COMMUNITY_NAME}.{DOMAIN}/{DITEMID}.html'
+	},
+
+	// USER's views
+	'PROFILE': {
+		urlTemplate: 'http://{OWNER_NAME}.{DOMAIN}/profile'
+	},
+	'JOURNAL': {		  // RecentPage
+		urlTemplate: 'http://{OWNER_NAME}.{DOMAIN}'
+	},
+	'JOURNAL.ENTRY': {	// EntryPage
+		urlTemplate: 'http://{OWNER_NAME}.{DOMAIN}/{DITEMID}.html' // different places
+	},
+	'JOURNAL.FRIENDS': {  // FriendsPage
+		urlTemplate: 'http://{OWNER_NAME}.{DOMAIN}/friends'
+	},
+
+	// EMBEDDED: used in LJ texts, events, comments, messages, activities.
+	'EMBEDDED.ENTRY': {
+		urlTemplate: 'http://{JOURNAL_NAME}.{DOMAIN}/{DITEMID}.html' // different places
+	},
+	'EMBEDDED.COMMENT': {
+		urlTemplate: 'http://{JOURNAL_NAME}.{DOMAIN}/{DITEMID}.html?thread={DTALKID}#t{DTALKID}' // different places
+	},
+	'EMBEDDED.MESSAGE': {
+		urlTemplate: '{SITEROOT}/inbox/'
+	},
+	'EMBEDDED.ACTIVITY': {
+		urlTemplate: '{SITEROOT}/games/info.bml?user={OWNER_NAME}'
+	}
+};
+
+})();

Added: trunk/htdocs/js/apps/livejournal/livejournal-jsonrpc/jsonrpc.js
===================================================================
--- trunk/htdocs/js/apps/livejournal/livejournal-jsonrpc/jsonrpc.js	                        (rev 0)
+++ trunk/htdocs/js/apps/livejournal/livejournal-jsonrpc/jsonrpc.js	2011-09-12 08:22:14 UTC (rev 10991)
@@ -0,0 +1,171 @@
+//define our own container
+window.JsonRpcContainer = function() {
+	opensocial.Container.call( this );
+
+	gadgets.rpc.register('shindig.requestPermission_callback',
+		this.requestPermissionCallback_);
+
+	gadgets.rpc.register('shindig.requestShareApp_callback',
+		this.requestShareAppCallback_);
+
+	gadgets.rpc.register('shindig.refreshSecurityToken_callback',
+		this.refreshSecurityTokenCallback_ );
+}
+
+JsonRpcContainer.inherits( opensocial.Container );
+
+(function() {
+
+	var callbackIdStore = {};
+
+	var params = gadgets.util.getUrlParameters();
+	//retrieve permissions from frame url
+	var permissions = function() {
+		var rights = params["access_rights"].split( ',' ),
+			result = {};
+
+		for( var j = 0; j < rights.length; ++j ) {
+			result[ rights[ j ] ] = 1;
+		}
+		return result;
+	} ();
+
+	/**
+	 * Returns true if the current gadget has access to the specified permission.
+	 *	 If the gadget calls opensocial.requestPermission and permissions are
+	 *	 granted then this function must return true on all subsequent calls.
+	 *
+	 *  @param {String} The permission.
+	 *  @return {Boolean} True if the gadget has access for the permission; false if it doesn't.
+	 */
+	JsonRpcContainer.prototype.hasPermission = function( permission ) {
+		return ( typeof permission == 'string' ) && ( permission in permissions );
+	}
+
+	JsonRpcContainer.prototype.hasAllPermissions = function( perms ) {
+		for( var i = 0; i < perms.length; ++i ) {
+			if( !this.hasPermission( perms[ i ] ) ) {
+				return false;
+			}
+		}
+
+		return true;
+	}
+
+	/**
+	 * Requests the user to grant access to the specified permissions.
+	 * @param {Array.<opensocial.Permission>} perms The permissions to request from the viewer.
+	 * @param {String} reason Displayed to the user as the reason why these permissions are needed.
+	 * @param {Function} opt_callback The function to call once the request has been processed; either
+	 *	this callback will be called or the gadget will be reloaded from scratch.
+	 */
+	JsonRpcContainer.prototype.requestPermission = function(perms, reason, opt_callback) {
+		var callbackId = 'cId_' + Math.random();
+		callbackIdStore[callbackId] = opt_callback;
+
+		gadgets.rpc.call('..', 'shindig.requestPermission',
+			null,
+			callbackId,
+			perms,
+			gadgets.util.unescapeString(reason),
+			livejournal.getSecurityToken().getToken());
+	}
+
+	JsonRpcContainer.prototype.requestPermissionCallback_ = function(callbackId, opt_errorCode,
+																		opt_errorMessage, perms) {
+		callback = callbackIdStore[callbackId];
+		if (callback) {
+			callbackIdStore[callbackId] = null;
+
+			var data = null;
+			if (perms) {
+				data = { 'permissions': perms };
+
+				if(!opt_errorCode || opt_errorCode == 109) {
+					for( var i = 0; i < perms.length; ++i ) {
+						permissions[ perms[ i ] ] = 1;
+					}
+				}
+			}
+
+			var responseItem = new opensocial.ResponseItem(null, data, opt_errorCode, opt_errorMessage);
+			callback(responseItem);
+		}
+	}
+
+	/**
+	 * Requests the container to share this gadget with the specified users. If the
+	 * container does not support this method the callback will be called with a
+	 * opensocial.ResponseItem. The response item will have its error code set to
+	 * NOT_IMPLEMENTED.
+	 *
+	 * @param {Array.<string> | string} recipients An ID, array of user IDs. If set to
+	 *	 null, user will be able to select recipients on container side.
+	 * @param {String} optional string to pass promo codes from application
+	 * @param {function(opensocial.ResponseItem)=} opt_callback The function to call once the request has been
+	 *	processed; either this callback will be called or the gadget will be
+	 *	reloaded from scratch. This function will be passed one parameter, an
+	 *	opensocial.ResponseItem. The error code will be set to reflect whether
+	 *	there were any problems with the request. If there was no error, the
+	 *	sharing request was sent. If there was an error, you can use the response
+	 *	item's getErrorCode method to determine how to proceed. The data on the
+	 *	response item will not be set.
+	 * @param {Object=} opt_params Not implemented.
+	 */
+	JsonRpcContainer.prototype.requestShareApp = function( recipients, extra, opt_callback, opt_params ) {
+		var callbackId = 'cId_' + Math.random();
+		callbackIdStore[callbackId] = opt_callback;
+
+		gadgets.rpc.call('..', 'shindig.requestShareApp',
+			null,
+			callbackId,
+			recipients,
+			gadgets.util.unescapeString(extra),
+			livejournal.getSecurityToken().getToken());
+	}
+
+	JsonRpcContainer.prototype.requestShareAppCallback_ = function(callbackId, opt_errorCode,
+																		opt_errorMessage, recipients) {
+		callback = callbackIdStore[callbackId];
+		if (callback) {
+			callbackIdStore[callbackId] = null;
+
+			var data = null;
+			if (recipients) {
+				data = { 'recipients': recipients };
+			}
+
+			var responseItem = new opensocial.ResponseItem(null, data, opt_errorCode, opt_errorMessage);
+			callback(responseItem);
+		}
+	}
+
+	/**
+	 * Makes a request to get a new security token.
+	 *
+	 * @param {function(opensocial.ResponseItem)=} opt_callback The function to call once the request has been
+	 *	done. If there were no error response contains new security token and error code and message otherwise.
+	 */
+	JsonRpcContainer.prototype.refreshSecurityToken = function(opt_callback) {
+		var callbackId = 'cId_' + Math.random();
+		callbackIdStore[callbackId] = opt_callback;
+
+		gadgets.rpc.call('..', 'shindig.refreshSecurityToken',
+			null,
+			callbackId,
+			livejournal.getSecurityToken().getToken()
+		);
+	};
+
+	JsonRpcContainer.prototype.refreshSecurityTokenCallback_ = function(callbackId, data,
+																opt_errorCode, opt_errorMessage) {
+		callback = callbackIdStore[callbackId];
+		if (callback) {
+			callbackIdStore[callbackId] = null;
+
+			var responseItem = new opensocial.ResponseItem(null, data, opt_errorCode, opt_errorMessage);
+			callback(responseItem);
+		}
+	};
+}());
+

Tags: can3p, js, ljcom
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