Skip to content

Commit cc98702

Browse files
Merge branch 'IIMAGE-13'
2 parents 660bc4a + 731c123 commit cc98702

5 files changed

Lines changed: 47 additions & 33 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Gradle Project settings
22
projectName = imageshop
3-
version = 2.0.7
3+
version = 2.0.8
44

55
# XP App values
66
appDisplayName = Imageshop

src/main/resources/admin/widgets/iimage/iimage.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
<widget
2-
class="iimage-wrapper"
3-
th:data-import-image-service-url="${importImageServiceUrl}"
4-
th:data-sync-image-info-service-url="${syncImageInfoServiceUrl}"
5-
th:data-image-shop-url="${imageShopURL}"
6-
th:data-strings="${stringsJson}"
7-
>
1+
2+
<widget class="iimage-wrapper">
3+
<script type="application/json" id="widget-config-id" th:utext="${stringsJson}"></script>
4+
85
<link rel="stylesheet" th:href="${portal.assetUrl({'_path=/css/styles.css'})}" />
96

107
<th:block th:if="${!#lists.isEmpty(inputsAllowedToUploadImage)}">

src/main/resources/admin/widgets/iimage/iimage.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,29 @@ exports.get = function (req) {
5858
}
5959

6060
const showSyncButton = content && content.type === 'media:image' && !!libs.objects.trySafe(() => content.x['io-99x-imageshop'].iimage.document_id)
61+
const importImageServiceUrl = libs.portal.serviceUrl({
62+
service: 'import-image',
63+
type: 'absolute',
64+
params: {
65+
contentId: contentId || sitesWithIImageAppInstalled[0]._id
66+
}
67+
})
68+
69+
const syncImageInfoServiceUrl = showSyncButton ? libs.portal.serviceUrl({
70+
service: 'sync-image-info',
71+
type: 'absolute',
72+
params: {
73+
contentId
74+
}
75+
}) : undefined
76+
77+
const imageShopURL = libs.iimage.getImageShopURL(iimageAppConfig)
78+
79+
strings.importImageServiceUrl = importImageServiceUrl
80+
strings.syncImageInfoServiceUrl = syncImageInfoServiceUrl
81+
strings.imageShopURL = imageShopURL
6182

6283
const model = {
63-
importImageServiceUrl: libs.portal.serviceUrl({
64-
service: 'import-image',
65-
type: 'absolute',
66-
params: {
67-
contentId: contentId || sitesWithIImageAppInstalled[0]._id
68-
}
69-
}),
70-
syncImageInfoServiceUrl: showSyncButton ? libs.portal.serviceUrl({
71-
service: 'sync-image-info',
72-
type: 'absolute',
73-
params: {
74-
contentId
75-
}
76-
}) : undefined,
77-
imageShopURL: libs.iimage.getImageShopURL(iimageAppConfig),
7884
strings,
7985
stringsJson: JSON.stringify(strings),
8086
inputsAllowedToUploadImage: libs.iimage.getInputsAllowedToUploadImage(contentId),

src/main/resources/assets/js/main.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
function main() {
2-
const imageShopURL = document.querySelector('[data-image-shop-url]').getAttribute('data-image-shop-url');
2+
const config = getWidgetConfig()
3+
const imageShopURL = config.imageShopURL
34
const openImageShopButton = document.getElementById('imageshop-button');
45
const syncImageShopInfoButton = document.getElementById('imageshop-sync-info-button')
56

@@ -47,7 +48,9 @@ function syncImageInfo(e) {
4748
target.setAttribute('disabled', true)
4849
target.style.cursor = 'wait';
4950

50-
const syncImageInfoServiceURL = document.querySelector('[data-sync-image-info-service-url]').getAttribute('data-sync-image-info-service-url')
51+
const config = getWidgetConfig()
52+
53+
const syncImageInfoServiceURL = config.syncImageInfoServiceUrl
5154

5255
fetch(syncImageInfoServiceURL)
5356
.then(response => response.json())
@@ -71,9 +74,10 @@ function storeImageInEnonic(params) {
7174
const propertyName = params.propertyName
7275
const propertyPath = params.propertyPath
7376

74-
const importImageServiceUrl = document.querySelector('[data-import-image-service-url]').getAttribute('data-import-image-service-url');
77+
const config = getWidgetConfig()
78+
79+
const importImageServiceUrl = config.importImageServiceUrl
7580
const openImageShopButton = document.getElementById('imageshop-button');
76-
const strings = JSON.parse(document.querySelector('[data-strings]').getAttribute('data-strings'));
7781

7882
fetch(importImageServiceUrl, {
7983
method: 'POST',
@@ -99,7 +103,7 @@ function storeImageInEnonic(params) {
99103
.catch(error => {
100104
console.error('Error:', error);
101105
if (document.querySelector('.edit-image-link')) document.querySelector('.edit-image-link').remove();
102-
setMessageText(strings.generalError, 'error');
106+
setMessageText(config.generalError, 'error');
103107
})
104108
.finally(() => {
105109
setTimeout(() => {
@@ -115,13 +119,13 @@ function storeImageInEnonic(params) {
115119
* @returns
116120
*/
117121
function createEditLink(editURL) {
118-
const strings = JSON.parse(document.querySelector('[data-strings]').getAttribute('data-strings'));
122+
const config = getWidgetConfig()
119123

120124
const editLink = document.createElement('a');
121125
editLink.className = 'edit-image-link';
122126
editLink.href = editURL;
123127
editLink.target = '_blank';
124-
editLink.innerHTML = strings.editImage;
128+
editLink.innerHTML = config.editImage;
125129
return editLink
126130
}
127131

@@ -131,19 +135,19 @@ function createEditLink(editURL) {
131135
* @returns
132136
*/
133137
function changeUploadButtonState(state) {
134-
const strings = JSON.parse(document.querySelector('[data-strings]').getAttribute('data-strings'));
138+
const config = getWidgetConfig()
135139
const openImageShopButton = document.getElementById('imageshop-button');
136140

137141
if (state === 'loading') {
138142
openImageShopButton.setAttribute('disabled', true);
139-
openImageShopButton.innerHTML = strings.importingImage;
143+
openImageShopButton.innerHTML = config.importingImage;
140144
openImageShopButton.style.cursor = 'wait';
141145
return
142146
}
143147

144148
if (state === 'default') {
145149
openImageShopButton.removeAttribute('disabled');
146-
openImageShopButton.innerHTML = strings.openImageShop;
150+
openImageShopButton.innerHTML = config.openImageShop;
147151
openImageShopButton.style.cursor = 'pointer';
148152
return
149153
}
@@ -162,4 +166,10 @@ function setMessageText(message, status) {
162166
messageElement.setAttribute('data-status', status);
163167
}
164168

169+
function getWidgetConfig() {
170+
const config = JSON.parse(document.getElementById("widget-config-id").innerText);
171+
172+
return config;
173+
}
174+
165175
main()

src/main/resources/i18n/phrases.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ iimage.widget.context_panel.fragments.app_installed_in_multiples_sites = You hav
44
iimage.widget.context_panel.fragments.app_misconfigured = The Imageshop app is not configured properly. Please fill in the required fields in the Imageshop app settings
55
iimage.widget.context_panel.fragments.app_not_installed = The Imageshop app is not installed.
66
iimage.widget.context_panel.fragments.app_not_installed_in_site_fetched = Ensure the content you selected is placed under a site with the Imageshop installed
7+
iimage.widget.context_panel.fragments.no_content_selected = No content selected
78

89
iimage.site.iimage_imported_resources_folder = Imported resources folder
910
iimage.site.settings = Imageshop Settings

0 commit comments

Comments
 (0)