forked from Novactive/NovaeZMailingBundle
/
subitems.js
44 lines (40 loc) · 1.64 KB
/
subitems.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var eZMailingSubItemsModule = function () {
var token, siteaccess;
function _init($, $app) {
token = document.querySelector('meta[name="CSRF-Token"]').content;
siteaccess = document.querySelector('meta[name="SiteAccess"]').content;
$(".ezmailing-subitem-children", $app).each(function ($container) {
_generate($(this));
});
}
function _generate($container) {
var subitemsList = $container.data('items').SubitemsList;
var items = subitemsList.SubitemsRow.map(function (elt) {
return {
content: elt.Content,
location: elt.Location
}
});
var contentTypes = $container.data('contentTypes').ContentTypeInfoList.ContentType;
var contentTypesMap = contentTypes.reduce(function (total, item) {
total[item._href] = item;
return total;
}, {});
ReactDOM.render(React.createElement(eZ.modules.SubItems, {
parentLocationId: $container.data('location'),
limit: $container.data('limit'),
items: items,
contentTypesMap: contentTypesMap,
totalCount: subitemsList.ChildrenCount,
handleEditItem: function (content) {
var contentId = content._id;
var langCode = content.mainLanguageCode;
},
generateLink: function (locationId) {
return window.Routing.generate('_ezpublishLocation', {locationId: locationId});
},
restInfo: {token: token, siteaccess: siteaccess}
}), $container.get(0));
}
return {init: _init};
}();