From a2901efdb11fecc8cfb7ac5835abb2a1fb4cedcd Mon Sep 17 00:00:00 2001 From: Alexandre Oliveira Date: Mon, 27 Aug 2018 14:43:13 -0300 Subject: [PATCH 1/2] - Form Configuration Widget --- .../onstartup/widget/ShWidgetOnStartup.java | 10 ++++ .../widget/ShFormConfigurationWidget.java | 29 +++++++++++ .../shiohara/widget/ShSystemWidget.java | 1 + .../ShWidgetFormConfigurationCtrl.js | 50 +++++++++++++++++++ .../widget/form/form-configuration.html | 1 + .../setting/form-configuration-setting.html | 41 +++++++++++++++ 6 files changed, 132 insertions(+) create mode 100644 src/main/java/com/viglet/shiohara/widget/ShFormConfigurationWidget.java create mode 100644 src/main/resources/js/client-side/src/feature/widget/form-configuration/ShWidgetFormConfigurationCtrl.js create mode 100644 src/main/resources/public/template/widget/form/form-configuration.html create mode 100644 src/main/resources/public/template/widget/form/setting/form-configuration-setting.html diff --git a/src/main/java/com/viglet/shiohara/onstartup/widget/ShWidgetOnStartup.java b/src/main/java/com/viglet/shiohara/onstartup/widget/ShWidgetOnStartup.java index f9143e186..3d4f3f7d7 100644 --- a/src/main/java/com/viglet/shiohara/onstartup/widget/ShWidgetOnStartup.java +++ b/src/main/java/com/viglet/shiohara/onstartup/widget/ShWidgetOnStartup.java @@ -139,6 +139,16 @@ public void createDefaultRows() { shWidget.setType("TEXT,TEXTAREA"); shWidgetRepository.save(shWidget); + + shWidget = new ShWidget(); + shWidget.setName(ShSystemWidget.FORM_CONFIGURATION); + shWidget.setDescription("Form Configuraion Widget"); + shWidget.setClassName("com.viglet.shiohara.widget.ShFormConfigurationWidget"); + shWidget.setImplementationCode("template/widget/form/form-configuration.html"); + shWidget.setSettingPath("template/widget/form/setting/form-configuration-setting.html"); + shWidget.setType("TEXT,TEXTAREA"); + + shWidgetRepository.save(shWidget); } } diff --git a/src/main/java/com/viglet/shiohara/widget/ShFormConfigurationWidget.java b/src/main/java/com/viglet/shiohara/widget/ShFormConfigurationWidget.java new file mode 100644 index 000000000..897fb2eb9 --- /dev/null +++ b/src/main/java/com/viglet/shiohara/widget/ShFormConfigurationWidget.java @@ -0,0 +1,29 @@ +package com.viglet.shiohara.widget; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.thymeleaf.context.Context; +import org.thymeleaf.spring5.SpringTemplateEngine; + +import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; + +@Component +public class ShFormConfigurationWidget implements ShWidgetImplementation { + @Autowired + private SpringTemplateEngine templateEngine; + + public String render(ShPostTypeAttr shPostTypeAttr, ShObject shObject) { + final Context ctx = new Context(); + ctx.setVariable("shPostTypeAttr", shPostTypeAttr); + return templateEngine.process("widget/text/text-widget", ctx); + } + + @Override + public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTypeAttr) { + // TODO Auto-generated method stub + return true; + } +} diff --git a/src/main/java/com/viglet/shiohara/widget/ShSystemWidget.java b/src/main/java/com/viglet/shiohara/widget/ShSystemWidget.java index abc111826..bd53694f3 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShSystemWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ShSystemWidget.java @@ -14,4 +14,5 @@ public class ShSystemWidget { public static final String RECAPTCHA = "reCAPTCHA"; public static final String PAYMENT_DEFINITION = "Payment Definition"; public static final String PAYMENT = "Payment"; + public static final String FORM_CONFIGURATION = "Form Configuration"; } diff --git a/src/main/resources/js/client-side/src/feature/widget/form-configuration/ShWidgetFormConfigurationCtrl.js b/src/main/resources/js/client-side/src/feature/widget/form-configuration/ShWidgetFormConfigurationCtrl.js new file mode 100644 index 000000000..f15838bec --- /dev/null +++ b/src/main/resources/js/client-side/src/feature/widget/form-configuration/ShWidgetFormConfigurationCtrl.js @@ -0,0 +1,50 @@ +shioharaApp + .controller( + 'ShWidgetFormConfigurationCtrl', + [ + '$scope', + '$http', + '$q', + 'shAPIServerService', + 'shPostTypeResource', + function($scope, $http, $q, shAPIServerService, + shPostTypeResource) { + $scope.pageLayouts = null; + $scope.pageLayoutMap = []; + $scope.shPostTypeAttrForm = null; + $scope.init = function(shPostTypeAttr) { + $scope.shPostTypeAttrForm = shPostTypeAttr; + if ($scope.shPostTypeAttrForm.widgetSettingsObject === undefined + || $scope.shPostTypeAttrForm.widgetSettingsObject === null) { + $scope.shPostTypeAttrForm.widgetSettingsObject = []; + } + if ($scope.shPostTypeAttrForm.widgetSettingsObject.form === undefined + || $scope.shPostTypeAttrForm.widgetSettingsObject.form === null) { + $scope.shPostTypeAttrForm.widgetSettingsObject.form = []; + } + if ($scope.shPostTypeAttrForm.widgetSettingsObject.form.method === undefined) { + $scope.shPostTypeAttrForm.widgetSettingsObject.form.method = "POST"; + } + + } + + $scope + .$evalAsync($http + .get( + shAPIServerService + .get() + .concat( + "/v2/post/post-type/PT-PAGE-LAYOUT")) + .then( + function(response) { + $scope.pageLayouts = response.data; + angular + .forEach( + $scope.paymentTypes, + function( + value, + key) { + $scope.pageLayoutMap[value.id] = value; + }); + })); + } ]); diff --git a/src/main/resources/public/template/widget/form/form-configuration.html b/src/main/resources/public/template/widget/form/form-configuration.html new file mode 100644 index 000000000..6bca0fb07 --- /dev/null +++ b/src/main/resources/public/template/widget/form/form-configuration.html @@ -0,0 +1 @@ +

Form Configuration

\ No newline at end of file diff --git a/src/main/resources/public/template/widget/form/setting/form-configuration-setting.html b/src/main/resources/public/template/widget/form/setting/form-configuration-setting.html new file mode 100644 index 000000000..25c576d5c --- /dev/null +++ b/src/main/resources/public/template/widget/form/setting/form-configuration-setting.html @@ -0,0 +1,41 @@ +
+ + + + + + + + + + + + + +
+

+ Method +

+
+

+ Action +

+

Select Page Layout that will receive the request

+
+

+ Create Post from Form? +

+ +
+
\ No newline at end of file From 1c3ec14a4166b83cb2d2a953c09535b4ec9a967f Mon Sep 17 00:00:00 2001 From: Alexandre Oliveira Date: Mon, 27 Aug 2018 21:24:03 -0300 Subject: [PATCH 2/2] - Form Improvements --- CHANGELOG.md | 2 + .../component/{ => form}/ShFormComponent.java | 14 +- .../component/form/ShFormConfiguration.java | 58 ++++++++ .../viglet/shiohara/sites/ShSitesContext.java | 98 ++---------- .../viglet/shiohara/utils/ShFormUtils.java | 140 ++++++++++++++++++ .../shiohara/widget/ShAceEditorWidget.java | 12 ++ .../shiohara/widget/ShComboBoxWidget.java | 9 ++ .../widget/ShContentSelectWidget.java | 10 ++ .../viglet/shiohara/widget/ShFileWidget.java | 10 ++ .../widget/ShFormConfigurationWidget.java | 12 +- .../viglet/shiohara/widget/ShHTMLWidget.java | 10 ++ .../shiohara/widget/ShHiddenWidget.java | 10 ++ .../shiohara/widget/ShReCaptchaWidget.java | 9 ++ .../shiohara/widget/ShRelatorWidget.java | 10 ++ .../shiohara/widget/ShTextAreaWidget.java | 10 ++ .../viglet/shiohara/widget/ShTextWidget.java | 10 ++ .../widget/ShWidgetImplementation.java | 5 + .../widget/ecommerce/ShPaymentWidget.java | 1 + .../ShWidgetFormConfigurationCtrl.js | 14 +- src/main/resources/js/server-side/shObject.js | 2 +- .../setting/form-configuration-setting.html | 29 ++-- src/main/resources/templates/form.html | 2 +- .../templates/widget/empty/empty-widget.html | 1 + 23 files changed, 366 insertions(+), 112 deletions(-) rename src/main/java/com/viglet/shiohara/component/{ => form}/ShFormComponent.java (84%) create mode 100644 src/main/java/com/viglet/shiohara/component/form/ShFormConfiguration.java create mode 100644 src/main/java/com/viglet/shiohara/utils/ShFormUtils.java create mode 100644 src/main/resources/templates/widget/empty/empty-widget.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d8f7f0b3..7d67b1595 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ * InContext Editing using Float Menu to Regions * Site Form: Create Forms into Site and save as Posts into Shiohara CMS * Combo Box Field Type +* Hidden Field Type +* Form Configuration Field Type #### IMPROVEMENTS * Spring Boot 2.0.4 and Gradle 4.9 diff --git a/src/main/java/com/viglet/shiohara/component/ShFormComponent.java b/src/main/java/com/viglet/shiohara/component/form/ShFormComponent.java similarity index 84% rename from src/main/java/com/viglet/shiohara/component/ShFormComponent.java rename to src/main/java/com/viglet/shiohara/component/form/ShFormComponent.java index 3454dbfe0..26bc18b79 100644 --- a/src/main/java/com/viglet/shiohara/component/ShFormComponent.java +++ b/src/main/java/com/viglet/shiohara/component/form/ShFormComponent.java @@ -1,13 +1,17 @@ -package com.viglet.shiohara.component; +package com.viglet.shiohara.component.form; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashSet; import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import org.json.JSONArray; +import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.security.web.csrf.CsrfToken; @@ -39,7 +43,7 @@ public class ShFormComponent { public String byPostType(String shPostTypeName, String shObjectId, HttpServletRequest request) throws InstantiationException, IllegalAccessException, ClassNotFoundException { final Context ctx = new Context(); - + ShFormConfiguration shFormConfiguration = null; ShObject shObject = shObjectRepository.findById(shObjectId).get(); ShPostType shPostType = shPostTypeRepository.findByName(shPostTypeName); CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); @@ -60,6 +64,11 @@ public int compare(ShPostTypeAttr o1, ShPostTypeAttr o2) { ShWidgetImplementation object = (ShWidgetImplementation) Class.forName(className).newInstance(); applicationContext.getAutowireCapableBeanFactory().autowireBean(object); fields.add(object.render(shPostTypeAttr, shObject)); + + if (shPostTypeAttr.getShWidget().getName().equals(ShSystemWidget.FORM_CONFIGURATION)) { + JSONObject formConfiguration= new JSONObject(shPostTypeAttr.getWidgetSettings()); + shFormConfiguration = new ShFormConfiguration(formConfiguration); + } } String token = null; @@ -71,6 +80,7 @@ public int compare(ShPostTypeAttr o1, ShPostTypeAttr o2) { ctx.setVariable("shPostType", shPostType); ctx.setVariable("shPostTypeAttrs", shPostType.getShPostTypeAttrs()); ctx.setVariable("fields", fields); + ctx.setVariable("shFormConfiguration", shFormConfiguration); return templateEngine.process("form", ctx); } diff --git a/src/main/java/com/viglet/shiohara/component/form/ShFormConfiguration.java b/src/main/java/com/viglet/shiohara/component/form/ShFormConfiguration.java new file mode 100644 index 000000000..d2dfaf39b --- /dev/null +++ b/src/main/java/com/viglet/shiohara/component/form/ShFormConfiguration.java @@ -0,0 +1,58 @@ +package com.viglet.shiohara.component.form; + +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.json.JSONObject; +import org.springframework.http.HttpMethod; + +public class ShFormConfiguration { + + private HttpMethod method; + private UUID pageLayout; + private boolean createPost; + private UUID folder; + + public ShFormConfiguration(JSONObject setting) { + super(); + this.setMethod(HttpMethod.valueOf(setting.getString("method"))); + this.setPageLayout(UUID.fromString(setting.getString("pageLayout"))); + this.setCreatePost(setting.getInt("createPost") == 1 ? true : false); + this.setFolder( + StringUtils.isNotBlank(setting.getString("folder")) ? UUID.fromString(setting.getString("folder")) + : null); + } + + public HttpMethod getMethod() { + return method; + } + + public void setMethod(HttpMethod method) { + this.method = method; + } + + public UUID getPageLayout() { + return pageLayout; + } + + public void setPageLayout(UUID pageLayout) { + this.pageLayout = pageLayout; + } + + public boolean isCreatePost() { + return createPost; + } + + public void setCreatePost(boolean createPost) { + this.createPost = createPost; + } + + public UUID getFolder() { + return folder; + } + + public void setFolder(UUID folder) { + this.folder = folder; + } + +} diff --git a/src/main/java/com/viglet/shiohara/sites/ShSitesContext.java b/src/main/java/com/viglet/shiohara/sites/ShSitesContext.java index 57d3c223a..fbbe99177 100644 --- a/src/main/java/com/viglet/shiohara/sites/ShSitesContext.java +++ b/src/main/java/com/viglet/shiohara/sites/ShSitesContext.java @@ -2,12 +2,8 @@ import java.io.File; import java.io.IOException; -import java.util.Date; -import java.util.Enumeration; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import javax.activation.MimetypesFileTypeMap; import javax.annotation.Resource; @@ -26,41 +22,28 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.view.RedirectView; -import com.viglet.shiohara.api.post.ShPostAPI; import com.viglet.shiohara.cache.ShCacheManager; import com.viglet.shiohara.cache.ShCachedObject; import com.viglet.shiohara.persistence.model.folder.ShFolder; import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.ShPostAttr; -import com.viglet.shiohara.persistence.model.post.type.ShPostType; -import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; import com.viglet.shiohara.persistence.model.site.ShSite; -import com.viglet.shiohara.persistence.repository.folder.ShFolderRepository; import com.viglet.shiohara.persistence.repository.post.ShPostRepository; -import com.viglet.shiohara.persistence.repository.post.type.ShPostTypeAttrRepository; -import com.viglet.shiohara.persistence.repository.post.type.ShPostTypeRepository; import com.viglet.shiohara.post.type.ShSystemPostType; import com.viglet.shiohara.post.type.ShSystemPostTypeAttr; import com.viglet.shiohara.utils.ShFolderUtils; +import com.viglet.shiohara.utils.ShFormUtils; import com.viglet.shiohara.utils.ShPostUtils; import com.viglet.shiohara.utils.ShSiteUtils; import com.viglet.shiohara.utils.ShStaticFileUtils; -import com.viglet.shiohara.widget.ShWidgetImplementation; -import com.viglet.shiohara.widget.ecommerce.ShPaymentWidget; @Controller public class ShSitesContext { @Resource private ApplicationContext applicationContext; @Autowired - private ShPostTypeRepository shPostTypeRepository; - @Autowired - private ShPostTypeAttrRepository shPostTypeAttrRepository; - @Autowired private ShPostRepository shPostRepository; @Autowired - private ShFolderRepository shFolderRepository; - @Autowired private ShFolderUtils shFolderUtils; @Autowired private ShPostUtils shPostUtils; @@ -69,93 +52,30 @@ public class ShSitesContext { @Autowired private ShSitesContextComponent shSitesContextComponent; @Autowired - private ShPostAPI shPostAPI; - @Autowired private ShStaticFileUtils shStaticFileUtils; @Autowired private ShSitesContextURL shSitesContextURL; @Autowired - private ShPaymentWidget shPaymentWidget; + private ShFormUtils shFormUtils; @PostMapping("/sites/**") private RedirectView sitesPostForm(HttpServletRequest request, HttpServletResponse response) throws IOException, ScriptException, InstantiationException, IllegalAccessException, ClassNotFoundException { shSitesContextURL.init(request, response); - this.siteContextPost(shSitesContextURL, request, response); + this.siteContextPost(shSitesContextURL); RedirectView redirectView = new RedirectView( new String((request.getRequestURL() + "/success").getBytes("UTF-8"), "ISO-8859-1")); redirectView.setHttp10Compatible(false); return redirectView; } - public byte[] siteContextPost(ShSitesContextURL shSitesContextURL, HttpServletRequest request, - HttpServletResponse response) throws IOException, ScriptException, InstantiationException, - IllegalAccessException, ClassNotFoundException { - ShPost shPost = null; - if (request.getParameter("__sh-post-type-attr-__FORM_FOLDER_ID") != null - || shSitesContextURL.getShObject() instanceof ShFolder - || (shSitesContextURL.getShObject() instanceof ShPost && ((ShPost) shSitesContextURL.getShObject()) - .getShPostType().getName().equals(ShSystemPostType.FOLDER_INDEX))) { - ShFolder shFolder = null; - - if (request.getParameter("__sh-post-type-attr-__FORM_FOLDER_ID") != null) { - shFolder = shFolderRepository.findById(request.getParameter("__sh-post-type-attr-__FORM_FOLDER_ID")) - .get(); - } else { - if (shSitesContextURL.getShObject() instanceof ShFolder) { - shFolder = (ShFolder) shSitesContextURL.getShObject(); - } else { - shFolder = ((ShPost) shSitesContextURL.getShObject()).getShFolder(); - } - } - String shPostTypeName = request.getParameter("__sh-post-type"); - ShPostType shPostType = shPostTypeRepository.findByName(shPostTypeName); - - Enumeration parameters = request.getParameterNames(); - if (shPostTypeName != null) { - shPost = new ShPost(); - shPost.setDate(new Date()); - shPost.setOwner("anonymous"); - shPost.setShFolder(shFolder); - - shPost.setShPostType(shPostType); - Set shPostAttrs = new HashSet(); - while (parameters.hasMoreElements()) { - String param = parameters.nextElement(); - String paramValue = request.getParameter(param); - - if (param.startsWith("__sh-post-type-attr-") - && !param.equals("__sh-post-type-attr-__FORM_FOLDER_ID")) { - String attribute = param.replaceFirst("__sh-post-type-attr-", ""); - - ShPostTypeAttr shPostTypeAttr = shPostTypeAttrRepository.findByShPostTypeAndName(shPostType, - attribute); - - String className = shPostTypeAttr.getShWidget().getClassName(); - ShWidgetImplementation object = (ShWidgetImplementation) Class.forName(className).newInstance(); - applicationContext.getAutowireCapableBeanFactory().autowireBean(object); - - @SuppressWarnings("unused") - boolean attrStatus = object.validateForm(request, shPostTypeAttr); - // TODO: Create validation Form logic - - ShPostAttr shPostAttr = new ShPostAttr(); - shPostAttr.setShPost(shPost); - shPostAttr.setShPostTypeAttr(shPostTypeAttr); - shPostAttr.setStrValue(paramValue); - - shPostAttrs.add(shPostAttr); - } - - } - shPost.setShPostAttrs(shPostAttrs); - shPostAPI.postSave(shPost); - } - } - - shPaymentWidget.postRender(shPost, shSitesContextURL); - this.sitesFullGeneric(request, response); + public byte[] siteContextPost(ShSitesContextURL shSitesContextURL) throws IOException, ScriptException, + InstantiationException, IllegalAccessException, ClassNotFoundException { + + shFormUtils.execute(shSitesContextURL); + + this.sitesFullGeneric(shSitesContextURL.getRequest(), shSitesContextURL.getResponse()); return null; } diff --git a/src/main/java/com/viglet/shiohara/utils/ShFormUtils.java b/src/main/java/com/viglet/shiohara/utils/ShFormUtils.java new file mode 100644 index 000000000..98afc6ea5 --- /dev/null +++ b/src/main/java/com/viglet/shiohara/utils/ShFormUtils.java @@ -0,0 +1,140 @@ +package com.viglet.shiohara.utils; + +import java.io.IOException; +import java.util.Date; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Set; + +import javax.annotation.Resource; + +import org.apache.commons.lang3.StringUtils; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Component; + +import com.viglet.shiohara.api.post.ShPostAPI; +import com.viglet.shiohara.component.form.ShFormConfiguration; +import com.viglet.shiohara.persistence.model.folder.ShFolder; +import com.viglet.shiohara.persistence.model.post.ShPost; +import com.viglet.shiohara.persistence.model.post.ShPostAttr; +import com.viglet.shiohara.persistence.model.post.type.ShPostType; +import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.persistence.repository.folder.ShFolderRepository; +import com.viglet.shiohara.persistence.repository.post.ShPostRepository; +import com.viglet.shiohara.persistence.repository.post.type.ShPostTypeAttrRepository; +import com.viglet.shiohara.persistence.repository.post.type.ShPostTypeRepository; +import com.viglet.shiohara.post.type.ShSystemPostType; +import com.viglet.shiohara.sites.ShSitesContextURL; +import com.viglet.shiohara.widget.ShSystemWidget; +import com.viglet.shiohara.widget.ShWidgetImplementation; + +@Component +public class ShFormUtils { + @Resource + private ApplicationContext applicationContext; + @Autowired + private ShPostTypeAttrRepository shPostTypeAttrRepository; + @Autowired + private ShPostAPI shPostAPI; + @Autowired + private ShPostTypeRepository shPostTypeRepository; + @Autowired + private ShFolderRepository shFolderRepository; + @Autowired + private ShPostRepository shPostRepository; + + private ShFormConfiguration shFormConfiguration = null; + private ShPostType shPostType = null; + + private ShPost createPost(ShSitesContextURL shSitesContextURL) + throws InstantiationException, IllegalAccessException, ClassNotFoundException { + Enumeration parameters = shSitesContextURL.getRequest().getParameterNames(); + ShPost shPost = null; + + if (shFormConfiguration != null || shSitesContextURL.getShObject() instanceof ShFolder + || (shSitesContextURL.getShObject() instanceof ShPost && ((ShPost) shSitesContextURL.getShObject()) + .getShPostType().getName().equals(ShSystemPostType.FOLDER_INDEX))) { + ShFolder shFolder = null; + + if (StringUtils.isNotBlank(shFormConfiguration.getFolder().toString())) { + shFolder = shFolderRepository.findById(shFormConfiguration.getFolder().toString()).get(); + } else { + if (shSitesContextURL.getShObject() instanceof ShFolder) { + shFolder = (ShFolder) shSitesContextURL.getShObject(); + } else { + shFolder = ((ShPost) shSitesContextURL.getShObject()).getShFolder(); + } + } + + if (shPostType != null) { + shPost = new ShPost(); + shPost.setDate(new Date()); + shPost.setOwner("anonymous"); + shPost.setShFolder(shFolder); + + shPost.setShPostType(shPostType); + Set shPostAttrs = new HashSet(); + while (parameters.hasMoreElements()) { + String param = parameters.nextElement(); + String paramValue = shSitesContextURL.getRequest().getParameter(param); + + if (param.startsWith("__sh-post-type-attr-")) { + String attribute = param.replaceFirst("__sh-post-type-attr-", ""); + + ShPostTypeAttr shPostTypeAttr = shPostTypeAttrRepository.findByShPostTypeAndName(shPostType, + attribute); + + String className = shPostTypeAttr.getShWidget().getClassName(); + ShWidgetImplementation object = (ShWidgetImplementation) Class.forName(className).newInstance(); + applicationContext.getAutowireCapableBeanFactory().autowireBean(object); + + @SuppressWarnings("unused") + boolean attrStatus = object.validateForm(shSitesContextURL.getRequest(), shPostTypeAttr); + // TODO: Create validation Form logic + + ShPostAttr shPostAttr = new ShPostAttr(); + shPostAttr.setShPost(shPost); + shPostAttr.setShPostTypeAttr(shPostTypeAttr); + shPostAttr.setStrValue(paramValue); + + shPostAttrs.add(shPostAttr); + } + + } + shPost.setShPostAttrs(shPostAttrs); + + shPostAPI.postSave(shPost); + + } + } + + return shPost; + } + + public void execute(ShSitesContextURL shSitesContextURL) + throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException { + + shPostType = shPostTypeRepository.findByName(shSitesContextURL.getRequest().getParameter("__sh-post-type")); + for (ShPostTypeAttr shPostTypeAttr : shPostType.getShPostTypeAttrs()) { + if (shPostTypeAttr.getShWidget().getName().equals(ShSystemWidget.FORM_CONFIGURATION)) { + JSONObject formConfiguration = new JSONObject(shPostTypeAttr.getWidgetSettings()); + shFormConfiguration = new ShFormConfiguration(formConfiguration); + } + } + ShPost shPost = this.createPost(shSitesContextURL); + + for (ShPostTypeAttr shPostTypeAttr : shPostType.getShPostTypeAttrs()) { + String className = shPostTypeAttr.getShWidget().getClassName(); + ShWidgetImplementation object = (ShWidgetImplementation) Class.forName(className).newInstance(); + applicationContext.getAutowireCapableBeanFactory().autowireBean(object); + object.postRender(shPost, shSitesContextURL); + + } + + if (!shFormConfiguration.isCreatePost()) { + shPostRepository.delete(shPost); + } + } +} diff --git a/src/main/java/com/viglet/shiohara/widget/ShAceEditorWidget.java b/src/main/java/com/viglet/shiohara/widget/ShAceEditorWidget.java index 57e50d9b9..b493fb850 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShAceEditorWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ShAceEditorWidget.java @@ -1,5 +1,7 @@ package com.viglet.shiohara.widget; +import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; @@ -8,7 +10,9 @@ import org.thymeleaf.spring5.SpringTemplateEngine; import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.sites.ShSitesContextURL; @Component public class ShAceEditorWidget implements ShWidgetImplementation { @@ -27,4 +31,12 @@ public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTyp // TODO Auto-generated method stub return true; } + + @Override + public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException { + // TODO Auto-generated method stub + + } + + } diff --git a/src/main/java/com/viglet/shiohara/widget/ShComboBoxWidget.java b/src/main/java/com/viglet/shiohara/widget/ShComboBoxWidget.java index 64bf51403..4505b9191 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShComboBoxWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ShComboBoxWidget.java @@ -1,5 +1,6 @@ package com.viglet.shiohara.widget; +import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -12,7 +13,9 @@ import org.thymeleaf.spring5.SpringTemplateEngine; import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.sites.ShSitesContextURL; @Component public class ShComboBoxWidget implements ShWidgetImplementation { @@ -44,4 +47,10 @@ public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTyp // TODO Auto-generated method stub return true; } + + @Override + public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/com/viglet/shiohara/widget/ShContentSelectWidget.java b/src/main/java/com/viglet/shiohara/widget/ShContentSelectWidget.java index 0751e2102..99ba94ba3 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShContentSelectWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ShContentSelectWidget.java @@ -1,5 +1,7 @@ package com.viglet.shiohara.widget; +import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; @@ -8,7 +10,9 @@ import org.thymeleaf.spring5.SpringTemplateEngine; import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.sites.ShSitesContextURL; @Component public class ShContentSelectWidget implements ShWidgetImplementation { @@ -27,4 +31,10 @@ public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTyp // TODO Auto-generated method stub return true; } + + @Override + public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/com/viglet/shiohara/widget/ShFileWidget.java b/src/main/java/com/viglet/shiohara/widget/ShFileWidget.java index dab659645..bb6082c10 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShFileWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ShFileWidget.java @@ -1,5 +1,7 @@ package com.viglet.shiohara.widget; +import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; @@ -8,7 +10,9 @@ import org.thymeleaf.spring5.SpringTemplateEngine; import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.sites.ShSitesContextURL; @Component public class ShFileWidget implements ShWidgetImplementation { @@ -27,4 +31,10 @@ public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTyp // TODO Auto-generated method stub return true; } + + @Override + public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/com/viglet/shiohara/widget/ShFormConfigurationWidget.java b/src/main/java/com/viglet/shiohara/widget/ShFormConfigurationWidget.java index 897fb2eb9..05f038a91 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShFormConfigurationWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ShFormConfigurationWidget.java @@ -1,5 +1,7 @@ package com.viglet.shiohara.widget; +import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; @@ -8,7 +10,9 @@ import org.thymeleaf.spring5.SpringTemplateEngine; import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.sites.ShSitesContextURL; @Component public class ShFormConfigurationWidget implements ShWidgetImplementation { @@ -18,7 +22,7 @@ public class ShFormConfigurationWidget implements ShWidgetImplementation { public String render(ShPostTypeAttr shPostTypeAttr, ShObject shObject) { final Context ctx = new Context(); ctx.setVariable("shPostTypeAttr", shPostTypeAttr); - return templateEngine.process("widget/text/text-widget", ctx); + return templateEngine.process("widget/empty/empty-widget", ctx); } @Override @@ -26,4 +30,10 @@ public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTyp // TODO Auto-generated method stub return true; } + + @Override + public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/com/viglet/shiohara/widget/ShHTMLWidget.java b/src/main/java/com/viglet/shiohara/widget/ShHTMLWidget.java index 90948ae1d..7a3589cb7 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShHTMLWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ShHTMLWidget.java @@ -1,5 +1,7 @@ package com.viglet.shiohara.widget; +import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; @@ -8,7 +10,9 @@ import org.thymeleaf.spring5.SpringTemplateEngine; import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.sites.ShSitesContextURL; @Component public class ShHTMLWidget implements ShWidgetImplementation { @@ -27,4 +31,10 @@ public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTyp // TODO Auto-generated method stub return true; } + + @Override + public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/com/viglet/shiohara/widget/ShHiddenWidget.java b/src/main/java/com/viglet/shiohara/widget/ShHiddenWidget.java index b947ff13b..9d48d5f84 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShHiddenWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ShHiddenWidget.java @@ -1,5 +1,7 @@ package com.viglet.shiohara.widget; +import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import org.json.JSONObject; @@ -9,7 +11,9 @@ import org.thymeleaf.spring5.SpringTemplateEngine; import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.sites.ShSitesContextURL; @Component public class ShHiddenWidget implements ShWidgetImplementation { @@ -34,4 +38,10 @@ public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTyp // TODO Auto-generated method stub return true; } + + @Override + public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/com/viglet/shiohara/widget/ShReCaptchaWidget.java b/src/main/java/com/viglet/shiohara/widget/ShReCaptchaWidget.java index 5145400d3..65a5fdebc 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShReCaptchaWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ShReCaptchaWidget.java @@ -1,6 +1,7 @@ package com.viglet.shiohara.widget; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; @@ -15,7 +16,9 @@ import com.google.gson.Gson; import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.sites.ShSitesContextURL; @Component public class ShReCaptchaWidget implements ShWidgetImplementation { @@ -92,4 +95,10 @@ public void setErrorCodes(String[] errorCodes) { } } + + @Override + public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/com/viglet/shiohara/widget/ShRelatorWidget.java b/src/main/java/com/viglet/shiohara/widget/ShRelatorWidget.java index 1fbedef33..13f5f9ef1 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShRelatorWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ShRelatorWidget.java @@ -1,5 +1,7 @@ package com.viglet.shiohara.widget; +import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; @@ -8,7 +10,9 @@ import org.thymeleaf.spring5.SpringTemplateEngine; import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.sites.ShSitesContextURL; @Component public class ShRelatorWidget implements ShWidgetImplementation { @@ -27,4 +31,10 @@ public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTyp // TODO Auto-generated method stub return true; } + + @Override + public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/com/viglet/shiohara/widget/ShTextAreaWidget.java b/src/main/java/com/viglet/shiohara/widget/ShTextAreaWidget.java index 3e958a565..0fd1efb67 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShTextAreaWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ShTextAreaWidget.java @@ -1,5 +1,7 @@ package com.viglet.shiohara.widget; +import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; @@ -8,7 +10,9 @@ import org.thymeleaf.spring5.SpringTemplateEngine; import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.sites.ShSitesContextURL; @Component public class ShTextAreaWidget implements ShWidgetImplementation { @@ -26,4 +30,10 @@ public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTyp // TODO Auto-generated method stub return false; } + + @Override + public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/com/viglet/shiohara/widget/ShTextWidget.java b/src/main/java/com/viglet/shiohara/widget/ShTextWidget.java index b71dd3856..48014d61d 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShTextWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ShTextWidget.java @@ -1,5 +1,7 @@ package com.viglet.shiohara.widget; +import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; @@ -8,7 +10,9 @@ import org.thymeleaf.spring5.SpringTemplateEngine; import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.sites.ShSitesContextURL; @Component public class ShTextWidget implements ShWidgetImplementation { @@ -26,4 +30,10 @@ public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTyp // TODO Auto-generated method stub return true; } + + @Override + public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/com/viglet/shiohara/widget/ShWidgetImplementation.java b/src/main/java/com/viglet/shiohara/widget/ShWidgetImplementation.java index d6268ae11..369809f72 100644 --- a/src/main/java/com/viglet/shiohara/widget/ShWidgetImplementation.java +++ b/src/main/java/com/viglet/shiohara/widget/ShWidgetImplementation.java @@ -1,14 +1,19 @@ package com.viglet.shiohara.widget; +import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Component; import com.viglet.shiohara.persistence.model.object.ShObject; +import com.viglet.shiohara.persistence.model.post.ShPost; import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr; +import com.viglet.shiohara.sites.ShSitesContextURL; @Component public interface ShWidgetImplementation { public String render(ShPostTypeAttr shPostTypeAttr, ShObject shObject); public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTypeAttr); + public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException; } diff --git a/src/main/java/com/viglet/shiohara/widget/ecommerce/ShPaymentWidget.java b/src/main/java/com/viglet/shiohara/widget/ecommerce/ShPaymentWidget.java index 610036f88..cbf93e8a9 100644 --- a/src/main/java/com/viglet/shiohara/widget/ecommerce/ShPaymentWidget.java +++ b/src/main/java/com/viglet/shiohara/widget/ecommerce/ShPaymentWidget.java @@ -106,6 +106,7 @@ public boolean validateForm(HttpServletRequest request, ShPostTypeAttr shPostTyp return true; } + @Override public void postRender(ShPost shPost, ShSitesContextURL shSitesContextURL) throws IOException { shPaymentSlip.payment(shPost, shSitesContextURL); } diff --git a/src/main/resources/js/client-side/src/feature/widget/form-configuration/ShWidgetFormConfigurationCtrl.js b/src/main/resources/js/client-side/src/feature/widget/form-configuration/ShWidgetFormConfigurationCtrl.js index f15838bec..f84a41b09 100644 --- a/src/main/resources/js/client-side/src/feature/widget/form-configuration/ShWidgetFormConfigurationCtrl.js +++ b/src/main/resources/js/client-side/src/feature/widget/form-configuration/ShWidgetFormConfigurationCtrl.js @@ -14,17 +14,13 @@ shioharaApp $scope.shPostTypeAttrForm = null; $scope.init = function(shPostTypeAttr) { $scope.shPostTypeAttrForm = shPostTypeAttr; - if ($scope.shPostTypeAttrForm.widgetSettingsObject === undefined + /*if ($scope.shPostTypeAttrForm.widgetSettingsObject === undefined || $scope.shPostTypeAttrForm.widgetSettingsObject === null) { $scope.shPostTypeAttrForm.widgetSettingsObject = []; - } - if ($scope.shPostTypeAttrForm.widgetSettingsObject.form === undefined - || $scope.shPostTypeAttrForm.widgetSettingsObject.form === null) { - $scope.shPostTypeAttrForm.widgetSettingsObject.form = []; - } - if ($scope.shPostTypeAttrForm.widgetSettingsObject.form.method === undefined) { - $scope.shPostTypeAttrForm.widgetSettingsObject.form.method = "POST"; - } + } + if ($scope.shPostTypeAttrForm.widgetSettingsObject.method === undefined) { + $scope.shPostTypeAttrForm.widgetSettingsObject.method = "POST"; + }*/ } diff --git a/src/main/resources/js/server-side/shObject.js b/src/main/resources/js/server-side/shObject.js index cd275f8a4..ea36ea4fe 100644 --- a/src/main/resources/js/server-side/shObject.js +++ b/src/main/resources/js/server-side/shObject.js @@ -5,7 +5,7 @@ var shQueryComponent = spring.getBean('shQueryComponent', Java var shSearchComponent = spring.getBean('shSearchComponent', Java .type('com.viglet.shiohara.component.ShSearchComponent')); var shFormComponent = spring.getBean('shFormComponent', Java - .type('com.viglet.shiohara.component.ShFormComponent')); + .type('com.viglet.shiohara.component.form.ShFormComponent')); var shFolderUtils = spring.getBean('shFolderUtils', Java .type('com.viglet.shiohara.utils.ShFolderUtils')); var shObjectUtils = spring.getBean('shObjectUtils', Java diff --git a/src/main/resources/public/template/widget/form/setting/form-configuration-setting.html b/src/main/resources/public/template/widget/form/setting/form-configuration-setting.html index 25c576d5c..dfac77135 100644 --- a/src/main/resources/public/template/widget/form/setting/form-configuration-setting.html +++ b/src/main/resources/public/template/widget/form/setting/form-configuration-setting.html @@ -8,7 +8,7 @@

- -

- Create Post from Form? -

+ +

+ Create Post from Form? +

+ + + + + + +

+ Destination Folder +

- - - + + + \ No newline at end of file diff --git a/src/main/resources/templates/form.html b/src/main/resources/templates/form.html index 417bdb339..5bcfff513 100644 --- a/src/main/resources/templates/form.html +++ b/src/main/resources/templates/form.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/main/resources/templates/widget/empty/empty-widget.html b/src/main/resources/templates/widget/empty/empty-widget.html new file mode 100644 index 000000000..2d2c27210 --- /dev/null +++ b/src/main/resources/templates/widget/empty/empty-widget.html @@ -0,0 +1 @@ + \ No newline at end of file