From eb0e24f9fac9b0ae764858615b61ca13670a9f61 Mon Sep 17 00:00:00 2001 From: jensp Date: Tue, 11 Apr 2017 17:18:18 +0000 Subject: [PATCH] CCM NG/ccm-cms: Started implementation of an AssetSearchWidget (similar to the ItemSearchWidget) git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4668 8810af33-2d31-482b-a856-94f89814c4df --- .../cms/ui/assets/AssetSearchPage.java | 91 +++++++++++++++++ .../cms/ui/assets/forms/BookmarkForm.java | 25 ++--- .../assets/forms/ExternalVideoAssetForm.java | 98 +++++++++++++++++++ .../org/librecms/CmsResources.properties | 3 + .../org/librecms/CmsResources_de.properties | 3 + .../org/librecms/CmsResources_fr.properties | 3 + 6 files changed, 211 insertions(+), 12 deletions(-) create mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchPage.java create mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalVideoAssetForm.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchPage.java new file mode 100644 index 000000000..7d3c85c3b --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchPage.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.cms.ui.assets; + +import com.arsdigita.bebop.Form; +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.SimpleContainer; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.bebop.form.TextField; +import com.arsdigita.bebop.parameters.LongParameter; +import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.cms.dispatcher.CMSPage; +import com.arsdigita.globalization.GlobalizedMessage; +import com.arsdigita.toolbox.ui.LayoutPanel; +import org.librecms.CmsConstants; + +/** + * Page contains the widgets for selecting an asset. + * + * @author Jens Pelzetter + */ +public class AssetSearchPage extends CMSPage { + + private static final String QUERY_PARAM = "query"; + private static final String WIDGET_PARAM = "widget"; + private static final String ASSET_TYPE_PARAM = "assettype"; + + private final LongParameter contentSectionId; + + private TextField query; + + public AssetSearchPage() { + super(new Label(new GlobalizedMessage("cms.ui.assets.search_page.title", + CmsConstants.CMS_BUNDLE)), + new SimpleContainer()); + + addGlobalStateParam(new StringParameter(ASSET_TYPE_PARAM)); + addGlobalStateParam(new StringParameter(WIDGET_PARAM)); + addGlobalStateParam(new StringParameter(QUERY_PARAM)); + + contentSectionId = new LongParameter("content-section-id"); + + final LayoutPanel mainPanel = new LayoutPanel(); + + final Form queryForm = new Form("asset-search-page-query-form"); + queryForm.add(new Label(new GlobalizedMessage( + "cms.ui.assets.search_page.query", + CmsConstants.CMS_BUNDLE))); + query = new TextField("asset-search-page-query-form"); + queryForm.add(query); + final Submit querySubmit = new Submit(new GlobalizedMessage( + "cms.ui.assets.search_page.query.submit")); + queryForm.add(querySubmit); + + queryForm.addInitListener(new FormInitListener() { + @Override + public void init(final FormSectionEvent event) + throws FormProcessException { + + final PageState state = event.getPageState(); + final FormData data = event.getFormData(); + + final String query = (String) data.get(QUERY_PARAM); + + } + }); + + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/BookmarkForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/BookmarkForm.java index 91b02599e..fd9a08203 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/BookmarkForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/BookmarkForm.java @@ -141,16 +141,22 @@ public class BookmarkForm extends AssetForm { final Bookmark bookmark = new Bookmark(); - bookmark - .getDescription() - .addValue(getSelectedLocale(state), - (String) description.getValue(state)); - - bookmark.setUrl((String) url.getValue(state)); + updateData(bookmark, state); return bookmark; } + protected void updateData(final Bookmark bookmark, + final PageState state) { + bookmark + .getDescription() + .addValue(getSelectedLocale(state), + (String) description.getValue(state)); + + bookmark.setUrl((String) url.getValue(state)); + } + + @Override protected void updateAsset(final Asset asset, final PageState state) throws FormProcessException { @@ -168,12 +174,7 @@ public class BookmarkForm extends AssetForm { final Bookmark bookmark = (Bookmark) asset; - bookmark - .getDescription() - .addValue(getSelectedLocale(state), - (String) description.getValue(state)); - - bookmark.setUrl((String) url.getValue(state)); + updateData(bookmark, state); } } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalVideoAssetForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalVideoAssetForm.java new file mode 100644 index 000000000..4190de746 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalVideoAssetForm.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.cms.ui.assets.forms; + +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.PageState; +import com.arsdigita.cms.ui.assets.AssetPane; +import java.util.Objects; +import java.util.Optional; +import org.librecms.assets.ExternalVideoAsset; +import org.librecms.contentsection.Asset; + +/** + * + * @author Jens Pelzetter + */ +public class ExternalVideoAssetForm extends BookmarkForm { + + public ExternalVideoAssetForm(final AssetPane assetPane) { + super(assetPane); + } + + @Override + public void addWidgets() { + super.addWidgets(); + + //ToDo + } + + + @Override + protected void initForm(final PageState state, + final Optional selectedAsset) { + super.initForm(state, selectedAsset); + + // ToDo + } + + @Override + protected void showLocale(final PageState state) { + + super.showLocale(state); + + //ToDo + } + + @Override + protected Asset createAsset(final PageState state) + throws FormProcessException { + + Objects.requireNonNull(state); + + final ExternalVideoAsset externalVideoAsset = new ExternalVideoAsset(); + + updateData(externalVideoAsset, state); + + // ToDo + + return externalVideoAsset; + } + + @Override + protected void updateAsset(final Asset asset, final PageState state) { + + Objects.requireNonNull(asset); + Objects.requireNonNull(state); + + if (!(asset instanceof ExternalVideoAsset)) { + throw new IllegalArgumentException(String.format( + "Provided asset is not an instance of class (or sub class of) " + + "'%s' but is an instance of class '%s'", + ExternalVideoAsset.class.getName(), + asset.getClass().getName())); + } + + final ExternalVideoAsset externalVideoAsset = (ExternalVideoAsset) asset; + + updateData(externalVideoAsset, state); + + // ToDo + } +} diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties index e15348214..9667ad3a9 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties @@ -262,3 +262,6 @@ cms.ui.asset.initial_locale=Language cms.ui.asset.add_locale=Add data for language cms.ui.admin.assets.edit=Edit asset cms.ui.assets.sidenote.text=Text +cms.ui.assets.search_page.title=Select an asset +cms.ui.assets.search_page.query=Search for +cms.ui.assets.search_page.query.submit=Find diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties index 12062f2e8..8c23ad545 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties @@ -261,3 +261,6 @@ cms.ui.asset.initial_locale=Sprache cms.ui.asset.add_locale=Daten f\u00fcr folgende Sprache hinzuf\u00fcgen cms.ui.admin.assets.edit=Asset bearbeiten cms.ui.assets.sidenote.text=Text +cms.ui.assets.search_page.title=W\u00e4hlen Sie ein Asset +cms.ui.assets.search_page.query=Suche nach +cms.ui.assets.search_page.query.submit=Finden diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties index 06c97ddb8..174645e08 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties @@ -220,3 +220,6 @@ cms.ui.asset.initial_locale=Language cms.ui.asset.add_locale=Add data for language cms.ui.admin.assets.edit=Edit asset cms.ui.assets.sidenote.text=Text +cms.ui.assets.search_page.title=Select an asset +cms.ui.assets.search_page.query=Search for +cms.ui.assets.search_page.query.submit=Find