forked from Novactive/NovaeZMailingBundle
/
contentSelection.js
57 lines (55 loc) · 2.75 KB
/
contentSelection.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
45
46
47
48
49
50
51
52
53
54
55
56
57
var eZMailingContentSelectionModule = function () {
function _init($, $app) {
$("button.js-novaezmailing-select-location-id", $app).click(function () {
var token = document.querySelector('meta[name="CSRF-Token"]').content;
var siteaccess = document.querySelector('meta[name="SiteAccess"]').content;
var udwContainer = $("#react-udw").get(0);
var startingLocationId = 1;
var targetSelector = $(this).data('target-id');
var targetSelectorName = $(this).data('target-name');
ReactDOM.render(React.createElement(eZ.modules.UniversalDiscovery, {
onCancel: function () {
ReactDOM.unmountComponentAtNode(udwContainer)
},
multiple: false,
startingLocationId: startingLocationId,
restInfo: {token: token, siteaccess: siteaccess},
onConfirm: function (response) {
$(targetSelector).val(response[0].id);
$(targetSelectorName).text(response[0].ContentInfo.Content.Name);
ReactDOM.unmountComponentAtNode(udwContainer);
}
}), udwContainer);
});
$("button.js-novaezmailing-create-content", $app).click(function () {
var token = document.querySelector('meta[name="CSRF-Token"]').content;
var siteaccess = document.querySelector('meta[name="SiteAccess"]').content;
var udwContainer = $("#react-udw").get(0);
var parentLocationId = $(this).data('parent-location-id');
var title = $(this).find('span').html();
ReactDOM.render(React.createElement(eZ.modules.UniversalDiscovery, {
onCancel: function () {
ReactDOM.unmountComponentAtNode(udwContainer)
},
title: title,
multiple: false,
startingLocationId: 1,
canSelectContent: function (data) {
var contentDisabled = true;
if (data.item.pathString.split('/').includes(parentLocationId.toString()) && $('.c-choose-content-type__list .is-selected').length > 0) {
contentDisabled = false;
}
$('button.m-ud__action--create-content').prop("disabled", contentDisabled);
},
restInfo: {token: token, siteaccess: siteaccess},
visibleTabs: ['create'],
activeTab: 'create',
onConfirm: function (response) {
ReactDOM.unmountComponentAtNode(udwContainer);
location.reload();
}
}), udwContainer);
});
}
return {init: _init};
}();