Commit 844c92a1 authored by preetwinder's avatar preetwinder

[erp5_officejs] Add Facebook posts files

parent e523f440
/*jslint nomen: true */
/*global RSVP, UriTemplate, console*/
(function (jIO, RSVP, UriTemplate) {
"use strict";
var GET_POST_URL = "https://graph.facebook.com/v2.9/{+post_id}" +
"?fields={+fields}&access_token={+access_token}",
get_post_template = UriTemplate.parse(GET_POST_URL),
GET_FEED_URL = "https://graph.facebook.com/v2.9/{+user_id}/feed" +
"?fields={+fields}&limit={+limit}&since={+since}&access_token=" +
"{+access_token}",
get_feed_template = UriTemplate.parse(GET_FEED_URL);
function FBStorage(spec) {
if (typeof spec.access_token !== 'string' || !spec.access_token) {
throw new TypeError("Access Token must be a string " +
"which contains more than one character.");
}
if (typeof spec.user_id !== 'string' || !spec.user_id) {
throw new TypeError("User ID must be a string " +
"which contains more than one character.");
}
this._access_token = spec.access_token;
this._user_id = spec.user_id;
console.log('FEFAULTFIELDLIST', spec.default_field_list);
this._default_field_list = spec.default_field_list;
delete this._default_field_list.__id;
this._default_limit = spec.default_limit || 500;
}
FBStorage.prototype.get = function (id) {
var that = this;
return new RSVP.Queue()
.push(function () {
console.log('Ajax fetch for get');
console.log(that._default_field_list);
return jIO.util.ajax({
type: "GET",
url: get_post_template.expand({post_id: id,
fields: that._default_field_list, access_token: that._access_token})
});
})
.push(function (result) {
return JSON.parse(result.target.responseText);
},
function (err) {
console.log('Ajax fetch for get failed', err);
});
};
function paginateResult(url, result, select_list) {
return new RSVP.Queue()
.push(function () {
console.log('Ajax fetch for paginateResults', url);
return jIO.util.ajax({
type: "GET",
url: url
});
})
.push(function (response) {
return JSON.parse(response.target.responseText);
},
function (err) {
console.log('Ajax fetch for paginateResults failed', err);
throw new jIO.util.jIOError("Getting feed failed " + err.toString(),
400);
})
.push(function (response) {
if (response.data.length === 0) {
console.log('response.data.length==0', result);
return result;
}
var i, j, obj = {};
for (i = 0; i < response.data.length; i += 1) {
obj.id = response.data[i].id;
obj.value = {};
for (j = 0; j < select_list.length; j += 1) {
obj.value[select_list[j]] = response.data[i][select_list[j]];
}
result.push(obj);
obj = {};
}
return paginateResult(response.paging.next, result, select_list);
});
}
FBStorage.prototype.buildQuery = function (query) {
console.log('QueryRecieved', query);
var that = this, template_argument = {user_id: this._user_id, limit: 100,
access_token: this._access_token}, fields = [],
limit = this._default_limit;
if (query.include_docs) {
fields = fields.concat(that._default_field_list);
}
if (query.select_list) {
fields = fields.concat(query.select_list);
}
if (query.limit) {
limit = query.limit[1];
}
template_argument.fields = fields;
template_argument.limit = limit;
return paginateResult(get_feed_template.expand(template_argument), [],
fields)
.push(function (result) {
if (!query.limit) {
return result;
}
return result.slice(query.limit[0], query.limit[1]);
});
};
FBStorage.prototype.hasCapacity = function (name) {
var this_storage_capacity_list = ["list", "select", "include", "limit"];
if (this_storage_capacity_list.indexOf(name) !== -1) {
return true;
}
};
jIO.addStorage('facebook', FBStorage);
}(jIO, RSVP, UriTemplate));
\ No newline at end of file
<!doctype html>
<html>
<head>
<base href="https://softinst83083.host.vifib.net/erp5/web_site_module/officejs_text_editor/development/gadget_erp5_page_ojs_facebook_configurator.html/" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS jIO Facebook Configurator Page</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script id="facebook-jssdk" src="//connect.facebook.net/en_US/sdk.js"></script>
<script src="gadget_erp5_page_ojs_facebook_configurator.js"></script>
</head>
<body>
<div id="status"> Please log into the app</div>
<button type="button" id="login">Log In</button>
<button type="button" id="logout">Log Out</button>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP, URI, location,
loopEventListener, btoa */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, console) {
"use strict";
function setFacebookConfiguration(gadget, access_token, user_id) {
return gadget.getSetting("portal_type")
.push(function (portal_type) {
var configuration = {};
configuration = {
type: "replicate",
use_remote_post: false,
conflict_handling: 2,
check_local_modification: false,
check_local_creation: false,
check_local_deletion: false,
check_remote_modification: true,
check_remote_creation: true,
check_remote_deletion: true,
signature_hash_key: 'updated_time',
parallel_operation_amount: 16,
local_sub_storage: {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
//database: "t13-officejs-facebook"
database: String(user_id) + "t5-officejs-facebook"
}
}
},
signature_sub_storage: {
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: String(user_id) + "signature-officejs-facebook"
}
}
},
remote_sub_storage: {
type: "query",
sub_storage: {
type: "facebook",
access_token: access_token,
user_id: user_id,
default_field_list: ['id', 'message', 'created_time', 'link', 'story']
}
}
}
return gadget.setSetting('jio_storage_description', configuration);
})
.push(function () {
return gadget.setSetting('jio_storage_name', "FACEBOOK");
})
.push(function () {
return gadget.setSetting('sync_reload', true);
})
.push(function () {
return gadget.redirect({
command: "display",
options: {page: 'ojs_sync', auto_repair: 'true'}
});
});
}
var gadget_klass = rJS(window);
gadget_klass
.setState({
logged: false,
})
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("setSetting", "setSetting")
.declareMethod("render", function (options) {
var gadget = this;
return gadget.updateHeader({
title: "Connect To Facebook Storage",
back_url: "#page=document_list",
panel_action: false
})
})
.declareService(function () {
var gadget = this;
FB.init({
appId : '1917551475189095',
cookie : true,
xfbml : true,
version : 'v2.8'
});
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
document.getElementById('status').innerHTML = 'logged in';
//gadget.changeState({logged: true});
}
else {
document.getElementById('status').innerHTML = 'logged out';
}
})
})
.onStateChange(function (modification_dict) {
var gadget = this;
var status;
if (modification_dict.hasOwnProperty('logged')) {
if(modification_dict.logged) {
document.getElementById('status').innerHTML = 'logged in';
return setFacebookConfiguration(gadget, FB.getAccessToken(), FB.getUserID());
}
else {
document.getElementById('status').innerHTML = 'logged out';
}
}
})
.onEvent("click", function (event) {
var gadget = this;
if (event.target.id == 'login') {
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
gadget.changeState({logged: true});
}
else {
FB.login(function(response) {
if (response.authResponse) {
gadget.changeState({logged: true});
}
}, {scope: 'user_posts'});
}
});
}
else if (event.target.id == 'logout') {
FB.logout(function(response) {
document.getElementById('status').innerHTML = 'logged out';
gadget.changeState({logged: false});
});
}
})
}(window, rJS, RSVP, console));
\ No newline at end of file
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Text Editor List</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_erp5_page_ojs_fb_posts_document_list.js"></script>
</head>
<body>
<div data-gadget-url="gadget_erp5_pt_form_list.html" data-gadget-scope="form_list"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Jio Gadget</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<script src="jio_mappingstorage.js" type="text/javascript"></script>
<script src="jio_fixstorage.js" type="text/javascript"></script>
<script src="jio_fbstorage.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_ojs_jio.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>ERP5 Panel</title>
<!--
data-i18n=Editable
-->
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="handlebars.js" type="text/javascript"></script>
<script src="gadget_global.js" type="text/javascript"></script>
<script id="panel-template-header" type="text/x-handlebars-template">
<div data-role="header" class="ui-bar-inherit">
<div class="ui-controlgroup ui-controlgroup-horizontal ui-btn-left">
<div class="ui-controlgroup-controls">
<button data-i18n="Close" class="ui-btn ui-btn-icon-notext ui-icon-delete">Close</button>
</div>
</div>
</div>
</script>
<script id="panel-template-body" type="text/x-handlebars-template">
<div class="ui-content">
<form class="dialog_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-action ui-btn-icon-right ui-screen-hidden">Submit</button>
<div data-gadget-url="gadget_erp5_searchfield.html"
data-gadget-scope="erp5_searchfield"
data-gadget-sandbox="public"></div>
</form>
<ul data-role="listview" class="ui-listview" data-enhanced="true"></ul>
<div data-gadget-url="gadget_erp5_field_checkbox.html"
data-gadget-scope="erp5_checkbox"
data-gadget-sandbox="public"></div>
<dl></dl>
</div>
</script>
<script id="panel-template-body-list" type="text/x-handlebars-template">
<li class="ui-first-child"><a href="{{document_list_href}}" class="ui-btn ui-btn-icon-left ui-icon-search" data-i18n="Document" accesskey="s">Posts</a></li>
<li class="ui-last-child"><a href="{{sync_href}}" class="ui-btn ui-btn-icon-left ui-icon-refresh" data-i18n="Synchronize">Synchronize</a></li>
<li><a href="{{storage_href}}" class="ui-btn ui-btn-icon-left ui-icon-gear" data-i18n="Login/Logout">Storages</a></li>
</script>
<script id="panel-template-body-desktop" type="text/x-handlebars-template">
<dt class="ui-content-title ui-body-c ui-btn ui-btn-icon-left ui-icon-eye" data-i18n="Views">Views</dt>
{{#each view_list}}
<dd data-role="listview" data-theme="c" data-inset="true" class="document-listview">
<a data-i18n="{{title}}" class="ui-body-inherit" href="{{href}}">{{title}}</a>
</dd>
{{/each}}
<dt class="ui-content-title ui-body-c ui-btn ui-btn-icon-left ui-icon-cogs" data-i18n="Decisions">Decisions</dt>
{{#each workflow_list}}
<dd data-role="listview" data-theme="c" data-inset="true" class="document-listview">
<a data-i18n="{{title}}" class="ui-body-inherit" href="{{href}}">{{title}}</a>
</dd>
{{/each}}
</script>
<!-- custom script -->
<script src="gadget_erp5_page_ojs_fb_posts_panel.js" type="text/javascript"></script>
</head>
<body>
<div class="jqm-navmenu-panel"></div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>OfficeJS Router Gadget</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_officejs_router.js" type="text/javascript"></script>
</head>
<body>
<script data-renderjs-configuration="portal_type" type="text/x-renderjs-configuration">Web Page</script>
<script data-renderjs-configuration="document_title" type="text/x-renderjs-configuration">Facebook Post</script>
<script data-renderjs-configuration="document_title_plural" type="text/x-renderjs-configuration">Facebook Posts</script>
<script data-renderjs-configuration="parent_relative_url" type="text/x-renderjs-configuration">web_page_module</script>
<div data-gadget-url="gadget_erp5_router.html" data-gadget-scope="erp5_router"></div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment