Commit c9e807eb authored by Sven Franck's avatar Sven Franck

erp5_officejs_afs_directory: add publisher and statistics gadgets

parent b8032709
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Free Software Publisher Statistics</title>
<link rel="stylesheet" href="gadget_erp5_afs.css" />
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_global.js"></script>
<script src="gadget_erp5_page_afs_publisher_statistic.js"></script>
</head>
<body>
<div data-gadget-url="gadget_erp5_pt_form_list.html"
data-gadget-scope="form_list"
data-gadget-sandbox="public">
</div>
</body>
</html>
/*globals window, RSVP, rJS*/
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, RSVP, rJS) {
"use strict";
var SORT_STRING = 'field_listbox_sort_list:json';
rJS(window)
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
});
})
.declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.allowPublicAcquisition('updateHeader', function () {
return;
})
.allowPublicAcquisition('getUrlParameter', function (argument_list) {
return this.getUrlParameter(argument_list)
.push(function (result) {
if ((result === undefined) && (argument_list[0] === SORT_STRING)) {
return [['lines', 'descending']];
}
return result;
});
})
.declareMethod("render", function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return gadget.updateHeader({
page_title: "Statistics"
});
})
.push(function () {
return gadget.getDeclaredGadget("form_list");
})
.push(function (form_gadget) {
var column_list = [
['title', 'Title'],
['country', 'Country'],
['lines', 'Total Lines of Code']
],
sort_column_list = [
['lines', 'Total Lines of Code']
];
return form_gadget.render({
erp5_document: {"_embedded": {"_view": {
"listbox": {
"column_list": column_list,
"show_anchor": 0,
"default_params": {},
"editable": 0,
"key": "field_listbox",
"lines": 20,
"list_method": "portal_catalog",
"query": 'urn:jio:allDocs?query=' + 'portal_type:"publisher"',
"portal_type": [],
"search_column_list": column_list,
"sort_column_list": sort_column_list,
"sort_on": ["lines", "descending"],
"title": "Documents",
"type": "ListBox"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [
["bottom", [["listbox"]]],
["hidden", ["listbox_modification_date"]]
]
}
});
});
});
}(window, RSVP, rJS));
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Unsplash Banner Image</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="jiodev.js"></script>
<script src="gadget_erp5_page_afs_unsplash.js"></script>
<!-- templates -->
<script id="banner-template" type="text/x-handlebars-template">
<section class="ui-banner-section">
<h1>{{message}}</h1>
<img src="{{src}}" alt="{{alt}}" />
<span>
Photo by
<a target="_blank" href="{{source_url}}">{{source_title}}</a>
&nbsp;/&nbsp;
<a target="_blank" href="{{unsplash_url}}">Unsplash</a>
</span>
</section>
</script>
</head>
<body></body>
</html>
/*globals window, RSVP, rJS, Handlebars, jIO*/
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, RSVP, rJS, Handlebars, jIO) {
"use strict";
// UNSPLASH API
// API: https://unsplash.com/documentation#creating-a-developer-account
var CID = "3196c4c1a2915c32bd9ca6ba5a88cec7555e06eb7e580546018f079394e9954f",
TOKEN = "&amp;client_id=" + CID,
// UNSPLAH GUIDELINE
// https://community.unsplash.com/developersblog/unsplash-api-guidelines
UTM = "?utm_source=AFS&utm_medium=referral&utm_campaign=api-credit",
gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
source = templater.getElementById("banner-template").innerHTML,
template = Handlebars.compile(source);
gadget_klass
/////////////////////////////////////////////////////////////////
// ready
/////////////////////////////////////////////////////////////////
.ready(function (my_gadget) {
my_gadget.property_dict = {};
})
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function () {
// not much to do, but unsplash would also allow to query for
// random images, so just search for free + software and
// display first result
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: "GET",
headers: {"Accept-Version": "v1"},
url: "https://api.unsplash.com/photos/MTJxRri1UiI" + UTM + TOKEN
});
})
.push(function (my_response) {
var is_response = my_response.target.response ||
my_response.target.responseText,
image_dict;
if (is_response) {
image_dict = JSON.parse(is_response);
//gadget.element.innerHTML =
// I don't need the gadget hooray, just the container, so sorry.
return template({
"message": "What can Free Software do for you?",
"src": image_dict.urls.full + UTM,
"alt": "Free Software",
"source_url": image_dict.user.links.html + UTM,
"source_title": image_dict.user.name,
"unsplash_url": "https://unsplash.com/" + UTM
});
}
});
});
}(window, RSVP, rJS, Handlebars, jIO));
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