can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[ljcom] r11126: OPSC-397: Implement LJ JS API osapi.peop...

Committer: dpetrov
OPSC-397: Implement LJ JS API osapi.people service functions
A   trunk/htdocs/js/apps/ljifrgadgetservice.js
Added: trunk/htdocs/js/apps/ljifrgadgetservice.js
===================================================================
--- trunk/htdocs/js/apps/ljifrgadgetservice.js	                        (rev 0)
+++ trunk/htdocs/js/apps/ljifrgadgetservice.js	2011-10-31 07:19:51 UTC (rev 11126)
@@ -0,0 +1,209 @@
+shindig.LJIfrGadgetService = function() {
+	shindig.IfrGadgetService.call(this);
+	this.bindRpcMethods();
+};
+
+shindig.LJIfrGadgetService.inherits(shindig.IfrGadgetService);
+
+(function() {
+	//this mechanism was added because we want do extend object functionality from other files
+	var rpcCalls = {};
+
+	shindig.LJIfrGadgetService.registerRpcMethod = function(rpcName, methodName) {
+		var argsObj;
+
+		if (arguments.length === 1) {
+			argsObj = rpcName;
+		} else {
+			argsObj = {};
+			argsObj[rpcName] = methodName
+		}
+
+		for (var rpc in argsObj) if (argsObj.hasOwnProperty(rpc)) {
+			rpcCalls[rpc] = argsObj[rpc];
+		}
+	};
+
+	shindig.LJIfrGadgetService.prototype.bindRpcMethods = function() {
+		for (var rpc in rpcCalls) if (rpcCalls.hasOwnProperty(rpc)) {
+			gadgets.rpc.register(rpc, this[rpcCalls[rpc]]);
+		}
+	};
+}());
+
+shindig.LJIfrGadgetService.registerRpcMethod({
+	'resize_iframe': 'setHeight',
+	'set_title': 'setTitle',
+	'requestNavigateTo': 'requestNavigateTo',
+	'shindig.requestPermission': 'requestPermission',
+	'shindig.requestShareApp': 'requestShareApp',
+	'shindig.refreshSecurityToken': 'refreshSecurityToken',
+
+	//disable unsupported calls
+	'set_pref': 'setUserPref',
+	'requestSendMessage': 'requestSendMessage'
+});
+
+/**
+ * Adjust the height of the current page to the requested size.
+ *
+ * @param {Number} The height in px.
+ */
+shindig.LJIfrGadgetService.prototype.setHeight = function(height) {
+	var frame = jQuery( '#' + this.f );
+
+	if (height > shindig.container.maxheight_) {
+		height = shindig.container.maxheight_;
+	}
+
+	if( frame.length > 0 ) {
+		frame.height( height );
+	}
+};
+
+/**
+ * Set the title of the current page. Currently function searches for the same
+ *     element for all applications.
+ */
+shindig.LJIfrGadgetService.prototype.setTitle = function(title) {
+	var element = jQuery('.b-catalogue-app h1');
+	if (element.length > 0) {
+		// update the title, and make sure we don't break it's html
+		element.text(title.replace(/&/g, '&amp;').replace(/</g, '&lt;'));
+	}
+};
+
+/**
+ * Request navigate user to the new location. User will be only redirected to the view
+ *     that are allowed for this application (passed in data-view attribute).
+ *
+ * @param {String} cId Callback id.
+ * @param {Array} perms Requested permissions.
+ * @param {String=} reason Optional message from application about why it wants such priveleges.
+ * @param {String} st Security token of the application.
+ */
+shindig.LJIfrGadgetService.prototype.requestNavigateTo = function(view, opt_params, opt_ownerName) {
+	var id = shindig.container.gadgetService.getGadgetIdFromModuleId(this.f),
+		gadget = shindig.container.getGadget(id),
+		views = gadgets.views.getSupportedViews(),
+		ownerName = opt_ownerName || gadget.owner_name,
+		elm = jQuery('#' + this.f);
+
+	view = view.toUpperCase();
+	if(!views.hasOwnProperty(view) || jQuery.inArray(view, gadget.available_views) === -1) {
+		return null;
+	}
+
+	var url = shindig.container._getUrlForView(view, gadget, ownerName, opt_params);
+
+	opt_params = opt_params || {};
+	opt_params['app_id'] = gadget.app_id;
+
+	for(var i in opt_params) {
+		if (opt_params.hasOwnProperty(i) && !opt_params[i]) {
+			delete opt_params[i];
+		}
+	}
+
+	var paramStr = gadgets.json.stringify(opt_params),
+		hashMatch = /#(.+)$/.exec(url),
+		afterHash = hashMatch && hashMatch[0] || '';
+
+	url = url.replace( afterHash, '' );
+	if (paramStr.length > 0) {
+		url += (url.indexOf('?') === -1 ? '?' : '&') + 'appParams=' + encodeURIComponent(paramStr);
+	}
+	url += afterHash;
+
+	if (url) {
+		document.location.href = url;
+	}
+};
+
+/**
+ * Display request permission dialog. The dialog will send livejournal.
+ *     ResponseItem back to the application.
+ *
+ * @param {String} cId Callback id.
+ * @param {Array} perms Requested permissions.
+ * @param {String=} reason Optional message from application about why it wants such priveleges.
+ * @param {String} st Security token of the application.
+ */
+shindig.LJIfrGadgetService.prototype.requestPermission = function(cId, perms, reason, st) {
+	var id = shindig.container.gadgetService.getGadgetIdFromModuleId(this.f),
+		gadget = shindig.container.getGadget(id),
+		appid = gadget.app_id,
+		frame = this.f;
+
+	var widget = new LJAppWidget_RequestPermission( {
+		title: 'Ask Permission',
+		finishCallback: function( data ) {
+			if( data.status == "ERROR" ) {
+				gadgets.rpc.call(frame, "shindig.requestPermission_callback", null, cId, data.code, data.message);
+			} else {
+				gadgets.rpc.call(frame, "shindig.requestPermission_callback", null, cId, 0, '', data.permissions);
+			}
+		},
+		authToken: gadget.auth_token
+
+	}, {
+		reason: reason || "",
+		permissions: perms.join(','),
+		app_id: appid,
+		st: st
+	} );
+
+	widget.loadContent();
+};
+
+/**
+ * Display share application dialog. The dialog will send livejournal.
+ *     ResponseItem back to the application.
+ *
+ * @param {String} cId Callback id.
+ * @param {Array} recipients The nicknames of the recipients.
+ * @param {String=} extra Extra data the should be passed to the server
+ * @param {String} st Security token of the application.
+ * @param {Object=} opt_params Object with optional data, that should be passed to the server.
+ */
+shindig.LJIfrGadgetService.prototype.requestShareApp = function(cId, recipients, extra, st, opt_params) {
+	var id = shindig.container.gadgetService.getGadgetIdFromModuleId(this.f),
+		gadget = shindig.container.getGadget(id),
+		appid = gadget.app_id,
+		frame = this.f;
+
+	var widget = new LJAppWidget_RequestShareApp( {
+		title: 'Ask Share App',
+		finishCallback: function( data ) {
+			gadgets.rpc.call(frame, "shindig.requestShareApp_callback", null, cId, data.code, data.message, data.recipients);
+		},
+		authToken: gadget.auth_token
+
+	}, {
+		extra: extra || "",
+		recipients: recipients.join(','),
+		app_id: appid,
+		st: st
+	} );
+
+	widget.loadContent();
+}
+
+shindig.LJIfrGadgetService.prototype.refreshSecurityToken = function(cId, st) {
+	var frame = this.f;
+
+	var url = Site.siteroot.replace(/^http:\/\/www/, "http://api") + '/st/refresh/?st=' + st + '&callback=?';
+	jQuery.getJSON( url, function( data ) {
+		gadgets.rpc.call(frame, "shindig.refreshSecurityToken_callback", null, cId, data, data.error);
+	} );
+}
+
+shindig.LJIfrGadgetService.prototype.setUserPref = function() {
+  throw Error(shindig.errors.TO_BE_DONE);
+};
+
+shindig.LJIfrGadgetService.prototype.requestSendMessage = function() {
+  throw Error(shindig.errors.TO_BE_DONE);
+};
+
+

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