From 875e7be900ad51ad9aca8b9f31fc989719a26735 Mon Sep 17 00:00:00 2001 From: jensp Date: Tue, 29 Aug 2017 14:57:11 +0000 Subject: [PATCH] Foundry support for new item search widget git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4959 8810af33-2d31-482b-a856-94f89814c4df --- .../contentsection/rs/ContentItems.java | 2 +- .../themes/foundry/foundry/lib/cms.xsl | 1 + .../foundry/lib/cms/item-search-widget.xsl | 473 ++++++++++++++++++ .../foundry/foundry/scripts/cms-admin.js | 142 +++++- .../themes/foundry/foundry/styles/admin.css | 36 +- 5 files changed, 626 insertions(+), 28 deletions(-) create mode 100644 ccm-theme-foundry/src/main/resources/themes/foundry/foundry/lib/cms/item-search-widget.xsl diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/rs/ContentItems.java b/ccm-cms/src/main/java/org/librecms/contentsection/rs/ContentItems.java index d08f9a9e2..cff42b6e4 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/rs/ContentItems.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/rs/ContentItems.java @@ -56,7 +56,7 @@ import javax.ws.rs.QueryParam; * @author Jens Pelzetter */ @RequestScoped -@Path("/{content-section}/assets/") +@Path("/{content-section}/items/") public class ContentItems { @Inject diff --git a/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/lib/cms.xsl b/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/lib/cms.xsl index e7c03a45e..d978857c8 100644 --- a/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/lib/cms.xsl +++ b/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/lib/cms.xsl @@ -25,6 +25,7 @@ + diff --git a/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/lib/cms/item-search-widget.xsl b/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/lib/cms/item-search-widget.xsl new file mode 100644 index 000000000..a2c9ae156 --- /dev/null +++ b/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/lib/cms/item-search-widget.xsl @@ -0,0 +1,473 @@ + + + + + + + +
+ + +

+ +

+ +
+ +

+ + + +

+ +
+
+ + +

+ + +

+
+ + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+ $title + + $type + + $place +
+
+
+ +
+ +
+ +
diff --git a/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/scripts/cms-admin.js b/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/scripts/cms-admin.js index d128b7d26..c60695c41 100644 --- a/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/scripts/cms-admin.js +++ b/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/scripts/cms-admin.js @@ -37,7 +37,6 @@ function getAssetsForSelectAssetDialog(dialogId) { } request.open("GET", url); -// request.setRequestHeader(); request.addEventListener('load', function (event) { if (request.status >= 200 && request.status < 300) { var assets = JSON.parse(request.responseText); @@ -49,7 +48,7 @@ function getAssetsForSelectAssetDialog(dialogId) { + "" + "" + "" - + asset['title'] + "" + + asset['title'] + "" + "" + asset['typeLabel'] @@ -86,7 +85,82 @@ function toggleSelectAssetDialog(mode, dialogId) { if ('show' === mode) { dialog.setAttribute('open', 'open'); - getAssetsForSelectAssetDialog(dialogId) + getAssetsForSelectAssetDialog(dialogId); + } else { + dialog.setAttribute('open', 'false'); + } +} + +function getItemsForSelectItemDialog(dialogId) { + + var dialog = document.querySelector('#' + dialogId); + var type = dialog.getAttribute('data-assettype'); + var contentSection = dialog.getAttribute('data-contentsection'); + var targetId = dialog.getAttribute('data-targetId'); + var filter = document.querySelector('#' + dialogId + '-item-filter'); + var query = filter.value; + var dispatcherPrefix = dialog.getAttribute('data-dispatcherPrefix'); + + var request = new XMLHttpRequest(); + var url = dispatcherPrefix.substring(0, dispatcherPrefix.length - "/ccm".length) + "/content-sections/" + contentSection + "/items/"; + if (type !== null && type.length > 0) { + url = url + "?type=" + type; + } + + if ((type !== null && type.length > 0) + && (query !== null && query.length > 0)) { + url = url + "&query=" + query; + } else if (query !== null && query.length > 0) { + url = url + "?query=" + query; + } + + request.open("GET", url); + request.addEventListener('load', function (event) { + if (request.status >= 200 && request.status <= 300) { + var items = JSON.parse(request.responseText); + var tableRows = ""; + var i; + for (i = 0; i < items.length; ++i) { + var item = items[i]; + tableRows = tableRows + + "" + + "" + + "" + + item['title'] + + "" + + "" + + "" + item['place'] + "" + + ""; + } + document + .querySelector('#' + dialogId + "tbody") + .innerHTML = tableRows; + } else { + alert("Error while retrieving items. " + + "Response code: " + request.status + " " + + "Message: " + request.statusText); + } + }); + request.send(); +} + +function setSelectedItem(itemId, itemTitle, targetId, dialogId) { + var target = document.querySelector('#' + targetId); + var targetText = document.querySelector("#" + targetId + "-selected"); + + target.value = itemId; + targetText.textContent = itemTitle; + + toggleSelectItemDialog('hide', dialogId); +} + +function toggleSelectItemDialog(mode, dialogId) { + + var dialog = document.querySelector('#' + dialogId); + + if ('show' === mode) { + dialog.setAttribute('open', 'open'); + getItemsForSelectItemDialog(dialogId); } else { dialog.setAttribute('open', 'false'); } @@ -105,16 +179,6 @@ document.addEventListener('DOMContentLoaded', function () { var dialogId = button.getAttribute('data-dialogId'); toggleSelectAssetDialog('show', dialogId); - - -// var assetType = button.getAttribute('data-assettype'); -// var contentSection = button.getAttribute('data-contentsection'); -// var target = button.getAttribute('data-target'); -// -// alert("AssetSelection assetType = " + assetType -// + "; contentSection = " + contentSection -// + "; target = " + target + "; "); - event.stopPropagation(); return false; }); @@ -149,8 +213,56 @@ document.addEventListener('DOMContentLoaded', function () { event.stopPropagation(); return false; }); - - } }); +document.addEventListener('DOMContentLoaded', function() { + + var i; + + var buttons = document.querySelectorAll('.select-item-button'); + for (i = 0; i < buttons.length; ++i) { + + buttons[i].addEventListener('click', function(event) { + + var button = event.currentTarget; + var dialogId = button.getAttribute('data-dialogId'); + + toggleSelectItemDialog('show', dialogId); + event.stopPropagation(); + return false; + }); + } + + var closeButtons = document.querySelectorAll('.item-search-widget-dialog .close-button'); + for(i = 0; i < closeButtons.length; ++i) { + + closeButtons[i].addEventListener('click', function(event) { + + var button = event.currentTarget; + var dialogId = button.getAttribute('data-dialogId'); + + toggleSelectItemDialog('hide', dialogId); + + event.stopPropagation(); + return false; + }); + } + + var applyButtons = document.querySelectorAll('.item-search-widget-dialog .apply-filter'); + for (i = 0; i < applyButtons.length; ++i) { + + applyButtons[i].addEventListener('click', function (event) { + + var button = event.currentTarget; + var dialogId = button.getAttribute('data-dialogId'); + + getAssetsForSelectAssetDialog(dialogId); + + event.stopPropagation(); + return false; + }); + } +}); + + diff --git a/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/styles/admin.css b/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/styles/admin.css index dcef6009e..7ff55c18d 100644 --- a/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/styles/admin.css +++ b/ccm-theme-foundry/src/main/resources/themes/foundry/foundry/styles/admin.css @@ -1432,7 +1432,8 @@ img.cmsImageDisplay { width: auto; } -div.asset-search-widget dialog { +div.asset-search-widget dialog, +div.item-search-widget dialog { background-color: #e6e4f2; border: 1px solid #555; @@ -1454,27 +1455,32 @@ div.asset-search-widget dialog { z-index: 999; } -div.asset-search-widget dialog[open="open"] { +div.asset-search-widget dialog[open="open"], +div.item-search-widget dialog[open="open"] { display: block; } -div.asset-search-widget dialog .controls { +div.asset-search-widget dialog .controls, +div.item-search-widget dialog .controls { padding: 0.5em; } -div.asset-search-widget dialog .controls label { +div.asset-search-widget dialog .controls label, +div.item-search-widget dialog .controls label { font-weight: bold; margin-right: 0.5em; } -div.asset-search-widget dialog .dialogarea controls button { +div.asset-search-widget dialog .dialogarea controls button, +div.item-search-widget dialog .dialogarea controls button{ margin-left: 0.5em; } -div .asset-search-widget dialog .selectable-assets { +div.asset-search-widget dialog .selectable-assets, +div.item-search-widget dialog .selectable-assets { padding: 0; @@ -1487,14 +1493,16 @@ div .asset-search-widget dialog .selectable-assets { overflow: scroll; } -div.asset-search-widget dialog .dialogarea table { +div.asset-search-widget dialog .dialogarea table, +div.item-search-widget dialog .dialogarea table { margin-top: 1em; margin-left: 0.5em; margin-right: 0.5em; } -div.asset-search-widget dialog .selectable-assets table thead tr th { +div.asset-search-widget dialog .selectable-assets table thead tr th, +div.item-search-widget dialog .selectable-assets table thead tr th { background-color: transparent; @@ -1504,7 +1512,8 @@ div.asset-search-widget dialog .selectable-assets table thead tr th { } -div.asset-search-widget dialog .titlebar { +div.asset-search-widget dialog .titlebar, +div.item-search-widget dialog .titlebar { border-bottom: 1px solid #555; @@ -1513,7 +1522,8 @@ div.asset-search-widget dialog .titlebar { padding: 0.5em 1em; } -div.asset-search-widget dialog .titlebar .close-button { +div.asset-search-widget dialog .titlebar .close-button, +div.item-search-widget dialog .titlebar .close-button { background-color: transparent; @@ -1525,11 +1535,13 @@ div.asset-search-widget dialog .titlebar .close-button { right: 5px; } -div.asset-search-widget dialog .titlebar .close-button:after { +div.asset-search-widget dialog .titlebar .close-button:after, +div.item-search-widget dialog .titlebar .close-button:after { content: '\2715'; } -div.asset-search-widget dialog .titlebar .close-button span { +div.asset-search-widget dialog .titlebar .close-button span, +div.item-search-widget dialog .titlebar .close-button span { position: absolute; top: -999px;