なんだかshindig-1.1-SNAPSHOTだと動かないっぽいので、
動かす。
まず、jsonrpccontainer.jsを見てみる。
- JsonRpcContainer.prototype.requestShareApp = function(recipientIds, reason,
- opt_callback, opt_params) {
- var callbackId = "cId_" + Math.random();
- callbackIdStore[callbackId] = opt_callback;
- var body = gadgets.util.unescapeString(reason.getField(
- opensocial.Message.Field.BODY));
- if (!body || body.length === 0) {
- var bodyMsgKey = gadgets.util.unescapeString(reason.getField(
- opensocial.Message.Field.BODY_ID));
- body = gadgets.Prefs.getMsg(bodyMsgKey);
- }
- gadgets.rpc.call('..', 'shindig.requestShareApp',
- null,
- callbackId,
- recipientIds,
- body);
- };
opensocial.requestShareAppがコールされると、この関数がコールされる。
関数の最後にgadgets.rpc.callで、親の'shindig.requestShareApp'がコールされている。
ということで、今度は、gadgets.jsを見てみる。
- gadgets.IfrGadgetService = function() {
- var self = this;
- gadgets.GadgetService.call(this);
- gadgets.rpc.register('resize_iframe', this.setHeight);
- gadgets.rpc.register('set_pref', this.setUserPref);
- gadgets.rpc.register('set_title', this.setTitle);
- gadgets.rpc.register('requestNavigateTo', this.requestNavigateTo);
- };
となっていて、shindig.requestShareAppの登録はされていない。
ま、そりゃそうか。
jsonrpccontainer.jsも、gadgets.jsも、本来自分で実装すべきところっぽい。
だからサンプルが動く程度の実装しかされていないんで、「追加」という形で実装してみる。
呼び出し元のパラメータは
- gadgets.rpc.call('..', 'shindig.requestShareApp',
- null,
- callbackId,
- recipientIds,
- body);
となっているので、
gadgets.rpc.registerで記述すべきは、
- gadgets.rpc.register('shindig.requestShareApp', function(callbackId,recipientIds,body) {
- self.requestShareApp.apply(self,[this, callbackId, recipientIds, body]);
- });
と、こんな感じか。
でrequestShareAppの実装。
- gadgets.IfrGadgetService.prototype.shareAppDialog_ = null;
- gadgets.IfrGadgetService.prototype.setShareAppDialog = function(dialog) {
- gadgets.container.gadgetService.shareAppDialog_ = dialog;
- };
- gadgets.IfrGadgetService.prototype.requestShareApp = function(rpc, callbackId, recipients, body) {
- if (gadgets.container.gadgetService.shareAppDialog_) {
- /* 以下YUI前提 */
- var onSubmit = function() {
- if (callbackId) {
- window.setTimeout(function() {
- gadgets.rpc.call(rpc.f, 'shindig.requestShareApp_callback', null, callbackId, true, recipients, body);
- }, 0);
- }
- this.cancel();
- };
- var onCancel = function() {
- if (callbackId) {
- window.setTimeout(function() {
- gadgets.rpc.call(rpc.f, 'shindig.requestShareApp_callback', null, callbackId, false, recipients, body);
- }, 0);
- }
- this.cancel();
- };
- gadgets.container.gadgetService.shareAppDialog_.cfg.queueProperty("buttons", [
- {text: "送信", handler: onSubmit, isDefault: true},
- {text: "キャンセル", handler: onCancel}
- ]);
- document.getElementById('shareAppDialog_body').innerHTML = body;
- gadgets.container.gadgetService.shareAppDialog_.render();
- gadgets.container.gadgetService.shareAppDialog_.show();
- }
- else {
- if (callbackId) {
- window.setTimeout(function() {
- gadgets.rpc.call(rpc.f, 'shindig.requestShareApp_callback', null, callbackId, true, recipients, body);
- }, 0);
- }
- }
- };
と、ざっくりこんな感じ。馬鹿の一つ覚えでYUIをまた使用。
親側でダイアログを出して、子フレーム側のrequestShareApp_callbackをコールできればOK。
shindigのままだと、bodyをコールバックに渡せないので、
jsonrpccontainer.jsの法をちょっとだけいじる。
- JsonRpcContainer.requestShareAppCallback_ = function(callbackId,
- success, recipientIds, body) {
- callback = callbackIdStore[callbackId];
- if (callback) {
- callbackIdStore[callbackId] = null;
- var data = null;
- if (recipientIds) {
- data = {'recipientIds': recipientIds};
- }
- var responseItem = new opensocial.ResponseItem(null, data, opensocial.ResponseItem.Error.BAD_REQUEST);
- callback(responseItem);
- }
- };
こんな感じ。今のところはエラーを返す。
これでよいはず。
で動かした。
で動いた。
BAD_REQUESTになった。
次はサーバとの連携。
--
と思ったけど、何しよう。
.
0 コメント:
コメントを投稿