{% extends 'base.html.twig' %}
{% block title %}Homepage{% endblock %}
{% block stylesheets %}
{{ parent() }}
<style>
#fb-root {
text-align: center;
}
.fb-form-wrapper {
display: none;
}
</style>
{% endblock %}
{% block body %}
<div class="login-wrapper">
<div id="fb-root">
<div class="fb-login-button" data-width="" data-scope="manage_pages, pages_show_list" data-size="large"
data-button-type="continue_with" data-auto-logout-link="true" data-use-continue-as="true"></div>
</div>
</div>
<div class="fb-form-wrapper">
<h4>Choose page</h4>
<form id="fb-form" action="{{ path("choose_fb_page") }}" method="post">
<input type="hidden" name="at">
<input type="hidden" name="uid">
<select name="page"></select>
<button type="submit">Save</button>
</form>
</div>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script>
$(document).ready(function () {
window.fbAsyncInit = function () {
FB.init({
appId: {{ fb.app_id }},
cookie: true,
xfbml: true,
version: 'v3.3'
});
FB.AppEvents.logPageView();
FB.getLoginStatus(function (response) {
statusChangeCallback(response);
});
function checkLoginState() {
FB.getLoginStatus(function (response) {
statusChangeCallback(response);
});
}
};
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
});
function statusChangeCallback(response) {
if (response.status === 'connected') {
$('#fb-form input[name="at"]').val(response.authResponse.accessToken);
$('#fb-form input[name="uid"]').val(response.authResponse.userID);
$('.fb-form-wrapper').show();
FB.api(
"/" + response.authResponse.userID + "/accounts",
function (response) {
if (response && !response.error) {
html = "";
$('#fb-form select[name="page"]').html(html);
$.each(response.data, function (index, value) {
html += "<option value=" + value.id + ">" + value.name + "</option>";
});
$('#fb-form select[name="page"]').html(html);
}
}
);
}
}
</script>
{% endblock %}