All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.anotheria.asg.generator.view.jsp.DialogPageJspGenerator Maven / Gradle / Ivy

package net.anotheria.asg.generator.view.jsp;

import net.anotheria.asg.data.LockableObject;
import net.anotheria.asg.generator.GeneratedJSPFile;
import net.anotheria.asg.generator.GeneratorDataRegistry;
import net.anotheria.asg.generator.meta.*;
import net.anotheria.asg.generator.view.CMSMappingsConfiguratorGenerator;
import net.anotheria.asg.generator.view.action.ModuleBeanGenerator;
import net.anotheria.asg.generator.view.meta.*;
import net.anotheria.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Generates the jsps for the edit view.
 *
 * @author another
 */
public class DialogPageJspGenerator extends AbstractJSPGenerator {

	/**
	 * Currently generated section.
	 */
	private MetaSection currentSection;
	/**
	 * Currently generated dialog.
	 */
	private MetaDialog currentDialog;
	/**
	 * Is need render JS for enabling DateTime widgets.
	 */
	private boolean isNeedEnableDateTimeWidgets = false;

	public GeneratedJSPFile generate(MetaSection metaSection, MetaDialog dialog, MetaModuleSection section, MetaView view) {
		this.currentSection = metaSection;
		this.currentDialog = dialog;

		GeneratedJSPFile jsp = new GeneratedJSPFile();
		startNewJob(jsp);
		jsp.setName(getDialogName(dialog, section.getDocument()));
		jsp.setPackage(getContext().getJspPackageName(section.getModule()));

		resetIdent();
		currentDialog = dialog;

		append(getBaseJSPHeader());

		appendGenerationPoint("generateDialog");
		appendString("");
		appendString("");
		increaseIdent();
		appendString("");
		increaseIdent();
		appendString("" + dialog.getTitle() + "");
		generatePragmas(view);
		// appendString("");
		// *** CMS2.0 START ***

		appendString("");
		appendString("");
		appendString("");
		appendString("");
		appendString("");
//		appendString("");
		appendString("");

		appendString("");
		appendString("");
		appendString("");
		appendString("");
		appendString("");

		// appendString("");
		appendString("");
		appendString("");
		appendString("");
		appendString("");
		// *** CMS2.0 FINISH ***

		// *** CMS3.0 START ***
//		appendString("");
//		appendString("");
//		appendString("");
        appendString("");
//		appendString("");
		appendString("");

		appendString("");
		appendString("");
		appendString("");
		appendString("");
		appendString("");
		// *** CMS3.0 FINISH ***


		if(dialog.getJavascript() != null) {
			appendString("");
		}

		decreaseIdent();
		appendString("");
		appendString("");
		appendString("");
		appendString("
"); appendString("
"); increaseIdent(); appendString("
"); increaseIdent(); appendString("
"); appendString("
"); appendString("
"); increaseIdent(); appendString("
    "); increaseIdent(); appendString("
  • Scroll to: 
  • "); List elements = createMultilingualList(dialog.getElements(), section.getDocument()); for (int i = 0; i < elements.size(); i++) { MetaViewElement element = elements.get(i); while (elements.get(i) instanceof MultilingualFieldElement) { String caption = element.getCaption() != null ? element.getCaption() : element.getName(); appendString(""); //please don't add any style to this tag - JS validation can remove it appendString("
  • " + caption + "
  • "); appendString("
    "); appendString(""); appendString("
  • "); increaseIdent(); String lang = getElementLanguage(element); String nameWithLang = section.getDocument().getField(element.getName()).getName(lang); //please don't add any style to this tag - JS validation can remove it appendString("" + caption + "   "); appendString("
    "); increaseIdent(); appendString("
    "); increaseIdent(); appendString("
    "); decreaseIdent(); appendString("
    "); appendString("
    "); increaseIdent(); appendString("
    "); increaseIdent(); appendString("
    "); increaseIdent(); appendString("
      "); for (String sl : GeneratorDataRegistry.getInstance().getContext().getLanguages()) { appendString("
    • " + sl + "
    • "); i++; element = elements.get(i); } appendString("
    "); decreaseIdent(); appendString("
    "); decreaseIdent(); appendString("
    "); decreaseIdent(); appendString("
    "); appendString("
    "); appendString("
    "); appendString("
    "); decreaseIdent(); appendString("
    "); decreaseIdent(); appendString("
  • "); appendString("
    "); } if (element instanceof MetaFieldElement) { String caption = element.getCaption() != null ? element.getCaption() : element.getName(); //please don't add any style to this tag - JS validation can remove it appendString("
  • " + caption + "
  • "); } } decreaseIdent(); appendString("
"); appendString("
"); decreaseIdent(); for (int i = 0; i < elements.size(); i++) { MetaViewElement element = elements.get(i); if (element instanceof MetaListElement) append(getElementEditor(section.getDocument(), element)); } // SAVE AND CLOSE BUTTONS SHOULD BE HERE appendString("
"); if (GeneratorDataRegistry.getInstance().getContext().areLanguagesSupported() && section.getDocument().isMultilingual()) { appendString("
\"\"/"); increaseIdent(); appendString("
"); increaseIdent(); appendString("
"); increaseIdent(); appendString("
"); decreaseIdent(); appendString("
"); appendString("
"); increaseIdent(); appendString("
"); increaseIdent(); appendString("
"); increaseIdent(); // *** START MULILINGUAL COPY *** // int colspan = 2; addMultilanguageOperations(section, colspan); // *** END MULILINGUAL COPY *** // appendString("
"); appendString("
"); decreaseIdent(); appendString("
"); decreaseIdent(); appendString("
"); appendIncreasedString("
"); appendString("
"); decreaseIdent(); appendString("
"); decreaseIdent(); appendString("
"); } decreaseIdent(); appendString("
"); appendString("
"); appendString("
"); appendString("
"); appendString("
"); appendString("
"); String entryName = quote(CMSMappingsConfiguratorGenerator.getDialogFormName(currentDialog, ((MetaModuleSection) metaSection).getDocument())); if(isAppropriateModule(section)){ if (!section.getDocument().getName().equalsIgnoreCase("RedirectUrl") && !section.getDocument().getName().equalsIgnoreCase("EntryPoint")){ String elementName = section.getDocument().getName().equalsIgnoreCase("NaviItem") ? "" : ""; appendString("\"add\"Show usages"); appendString(""); appendString("\"/>"); appendString("

"); appendString("
"); } } if (StorageType.CMS.equals(((MetaModuleSection) metaSection).getDocument().getParentModule().getStorageType())) { String result = " \n"; String path = CMSMappingsConfiguratorGenerator.getPath(((MetaModuleSection) metaSection).getDocument(), CMSMappingsConfiguratorGenerator.ACTION_LOCK); path += "?pId=" + "&nextAction=showEdit"; result += " Really lock " + CMSMappingsConfiguratorGenerator.getDialogFormName(currentDialog, ((MetaModuleSection) metaSection).getDocument()) + " with id: ?','" + path + "');") + ">" + getLockImage() + " Lock"; result += ""; appendString(result); appendString(""); path = CMSMappingsConfiguratorGenerator.getPath(((MetaModuleSection) metaSection).getDocument(), CMSMappingsConfiguratorGenerator.ACTION_UNLOCK); path += "?pId=" + "&nextAction=showEdit"; String alt = ((MetaModuleSection) metaSection).getDocument().getName() + " is locked by: , at: "; appendString(" Unlock " + ((MetaModuleSection) metaSection).getDocument().getName() + " with id: ?','" + path + "');") + ">" + getUnLockImage(alt) + "" + " Unlock Locked by "); appendString("at: "); appendString(""); } appendString("
"); appendIncreasedString("") + ">"); appendIncreasedString(""); appendIncreasedString(""); appendIncreasedString(""); appendIncreasedString(""); appendIncreasedString(""); appendString(""); appendString(""); increaseIdent(); appendString(""); decreaseIdent(); appendString(""); increaseIdent(); appendString(""); decreaseIdent(); appendString(""); // *** CMS2.0 START *** List richTextElementsRegistry = new ArrayList(); List linkElementsRegistry = new ArrayList(); // *** CMS2.0 FINISH *** MetaDocument document = ((MetaModuleSection) metaSection).getDocument(); for (int i = 0; i < elements.size(); i++) { MetaViewElement element = elements.get(i); // *** CMS2.0 START *** if (element instanceof MetaListElement) { // now we draw control elements upside our page i++; continue; } if (element instanceof MetaFieldElement) { MetaProperty p = document.getField(element.getName()); if (element.isRich() && p.getType() == MetaProperty.Type.TEXT) richTextElementsRegistry.add(element); if (p.isLinked()) linkElementsRegistry.add(element.getName()); } // *** CMS2.0 FINISH *** String lang = getElementLanguage(element); // ALTERNATIVE EDITOR FOR DISABLED MODE if (lang != null && lang.equals(GeneratorDataRegistry.getInstance().getContext().getDefaultLanguage())) { appendString(""); appendString(""); appendString(""); appendString(""); appendString(""); }// END ALTERNATIVE EDITOR FOR MULTILANG DISABLED FORM if (lang != null) appendString(""); // Language Filtering Settings String displayLanguageCheck = ""; if (element instanceof MultilingualFieldElement) { MultilingualFieldElement multilangualElement = (MultilingualFieldElement) element; displayLanguageCheck = " style=\"display:none\""; appendString(""); } else { appendString(""); } increaseIdent(); increaseIdent(); appendString(""); appendString(""); decreaseIdent(); appendString(""); if (lang != null) appendString(""); } appendString(""); appendString(""); appendString(""); appendString(""); appendString(""); appendString(""); appendString(""); appendString(""); decreaseIdent(); appendString(""); decreaseIdent(); appendString("
"); appendString("
"); // appendString(""); // UNLOCK HERE!!!!! appendString("
"); increaseIdent(); String name = section.getDocument().getField(element.getName()).getName(); // if (name == null || name.length() == 0) // name = " "; String caption = (element.getCaption() != null ? element.getCaption() : name) + "(DEF)"; appendString(caption); if (element.isRich()) { appendString("
"); appendString("off"); appendString("on"); appendString("Rich:"); } if (element.getDescription() != null) append("\"\"/",element.getDescription(),""); decreaseIdent(); append(" "); appendString("
"); if (element.getName() != null){ String inputName = section.getDocument().getField(element.getName()).getName(lang); generateValidationParts(element, inputName, document.getField(element.getName())); } append(getElementEditor(section.getDocument(), element)); appendString(" "); appendString("
"); String name = (lang == null) ? element.getName() : section.getDocument().getField(element.getName()).getName(lang); if (name == null || name.length() == 0) { // appendString(""); name=" "; } else { appendString(""); } String caption = element.getCaption(); if (caption == null) { caption = name; } else if (lang != null) { caption += "("+StringUtils.capitalize(lang)+")"; } appendString(caption); if (element.getDescription() != null) append("\"\"/",element.getDescription(),""); append(" "); decreaseIdent(); if (element.isRich()) { appendString("
"); appendString("off"); appendString("on"); appendString("Rich:"); } appendString("
"); increaseIdent(); if (element.getName() != null) generateValidationParts(element, name, document.getField(element.getName())); append(getElementEditor(section.getDocument(), element)); appendString(" "); decreaseIdent(); appendString("
"); appendString("
"); appendString("
"); appendString("
"); // Link to the Links to Me page appendString(""); String linksToMePagePath = CMSMappingsConfiguratorGenerator.getPath(section.getDocument(), CMSMappingsConfiguratorGenerator.ACTION_LINKS_TO_ME) + "?pId="; appendString("" + linksToMePagePath + "") + ">Show direct links to this document"); appendString(""); appendString("
"); appendString("
"); appendString("
"); appendString("
"); appendString("
"); appendString("
"); appendString("
"); increaseIdent(); appendString("
"); increaseIdent(); appendString("
"); appendString(""); appendString(""); appendString("
"); decreaseIdent(); appendString("
"); appendString("
"); increaseIdent(); appendString("
"); increaseIdent(); appendString("
"); appendString("
"); decreaseIdent(); appendString("
"); decreaseIdent(); appendString("
"); appendString("
"); increaseIdent(); appendString("
"); appendString(""); decreaseIdent(); appendString("
"); decreaseIdent(); appendString("
"); appendString("
"); appendString(""); decreaseIdent(); addDialogContentToDisplayUsagesOfElement(section); generateRichTextEditorJS(section.getDocument(), richTextElementsRegistry); generateLinkElementEditorJS(section.getDocument(), linkElementsRegistry); generateDateTimeWidgetJS(); decreaseIdent(); appendString(""); appendString(""); return jsp; } private boolean isAppropriateModule(MetaModuleSection section) { return section.getModule().getName().equalsIgnoreCase("aswebdata") || section.getModule().getName().equalsIgnoreCase("aslayoutdata") || section.getModule().getName().equalsIgnoreCase("asgenericdata") || section.getModule().getName().equalsIgnoreCase("ascustomdata") || section.getModule().getName().equalsIgnoreCase("assitedata") || section.getModule().getName().equalsIgnoreCase("asresourcedata"); } private void generateValidationParts(MetaViewElement element, String name, MetaProperty p) { if (element.isJSValidated()){ boolean isTextField = element.isRich() || p.getType() == MetaProperty.Type.TEXT; appendString(""); } appendString("
"); appendString("${validationErrors[\""+name+"\"].message}"); appendString("\"\""); appendString("
"); } private String getValueSelector(String fieldName) { return "$('input[name="+fieldName+"]').val();"; } private String getLinkValueSelector(String fieldName) { return "$('input[id="+StringUtils.capitalize(fieldName)+"CurrentValueInput]').val();"; } private String getTextValueSelector(String fieldName) { return "(tinyMCE.get('"+fieldName+"_ID') == null || tinyMCE.get('"+fieldName+"_ID').isHidden()) ? $('textarea[name="+fieldName+"]').val() : tinyMCE.get('"+fieldName+"_ID').getContent();"; } private String getElementEditor(MetaDocument doc, MetaViewElement element){ if (element instanceof MetaEmptyElement) return " "; if (element instanceof MetaFieldElement) return getFieldEditor((MetaFieldElement)element); if (element instanceof MetaListElement) return getListEditor(doc, (MetaListElement)element); if (element instanceof MetaFunctionElement) return getFunctionEditor(doc, (MetaFunctionElement)element); return ""; } private String getListEditor(MetaDocument doc, MetaListElement element){ String ret = ""; List elements = element.getElements(); for (int i=0; i"; ret += ""; ret += ""; ret += " "; ret += "(old: )"; */ //*** CMS2.0 START *** String editLink = ""; if (p.getName().equalsIgnoreCase("handler")) { String anoNotEqualNoneStartTag = ""; String anoNotEqualNoneEndTag = ""; String anoNotEmptyStartTag = ""; String anoNotEmptyEndTag = ""; String path = "ascustomdataCustomBoxHandlerDefEdit"+"?pId="+""; editLink = anoNotEmptyStartTag+ anoNotEqualNoneStartTag+ ""+path+"")+">"+" Edit handler"+"" + anoNotEqualNoneEndTag+ anoNotEmptyEndTag; } if (p.getName().equalsIgnoreCase("type")) { String anoNotEqualNoneStartTag = ""; String anoNotEqualNoneEndTag = ""; String anoNotEmptyStartTag = ""; String anoNotEmptyEndTag = ""; String path = "ascustomdataCustomBoxTypeEdit"+"?pId="+""; editLink = anoNotEmptyStartTag +anoNotEqualNoneStartTag+ ""+path+"")+">"+" Edit type"+"" + anoNotEqualNoneEndTag+ anoNotEmptyEndTag; } //quoted "name" attr in em, cause w3c validation says it's error ret += "
"; ret += " (old: "+ ") "+editLink; //*** CMS2.0 FINISH *** return ret; } private String getEnumerationEditor(MetaFieldElement element, MetaProperty p){ String ret = ""; String lang = getElementLanguage(element); ret += ""; ret += " "; ret += "(old: )"; return ret; } private String getFieldEditor(MetaFieldElement element){ MetaDocument doc = ((MetaModuleSection)currentSection).getDocument(); MetaProperty p = doc.getField(element.getName()); if (p.isLinked()) return getLinkEditor(element, p); if (p instanceof MetaEnumerationProperty){ return getEnumerationEditor(element, p); } if (p instanceof MetaContainerProperty) { return getContainerLinkEditor(element, (MetaContainerProperty)p); } switch (p.getType()) { case STRING: return getStringEditor(element, p); case PASSWORD: return getPasswordEditor(element, p); case TEXT: return getTextEditor(element, p); case LONG: return getStringEditor(element, p); case INT: return getStringEditor(element, p); case DOUBLE: return getStringEditor(element, p); case FLOAT: return getStringEditor(element, p); case BOOLEAN: return getBooleanEditor(element, p); case IMAGE: return getImageEditor(element, p); default: return p.getType().getName(); } } private String getContainerLinkEditor(MetaFieldElement element, MetaContainerProperty p){ String ret = ""; String lang = getElementLanguage(element); String name = quote(CMSMappingsConfiguratorGenerator.getDialogFormName(currentDialog, ((MetaModuleSection)currentSection).getDocument())); ret += ""; ret += "none"; ret += ""; ret += ""; ret += ""; ret += " "; ret += "element"; ret += ""; ret += "s"; ret += ""; ret += " "; String actionName = CMSMappingsConfiguratorGenerator.getContainerPath(((MetaModuleSection)currentSection).getDocument(), p, CMSMappingsConfiguratorGenerator.ACTION_SHOW); actionName += "?ownerId="; ret += " » Edit "; ret += ""; return ret; } private String getImageEditor(MetaFieldElement element, MetaProperty p){ String beanName = CMSMappingsConfiguratorGenerator.getDialogFormName(currentDialog, ((MetaModuleSection)currentSection).getDocument()); String propertyWriter = ""; String ret =""; ret += "\r"; ret += " + quote(propertyWriter) + \r"; ret += "\r"; ret += getUpdateAndDeleteFileAndStayFunction(((MetaModuleSection)currentSection).getDocument(),p); ret += " \r"; ret += "
\r"; ret += "\r"; return ret; } private String getStringEditor(MetaFieldElement element, MetaProperty p){ return getInputEditor(element, p, "text"); } private String getPasswordEditor(MetaFieldElement element, MetaProperty p){ return getInputEditor(element, p, "password"); } private String getBooleanEditor(MetaFieldElement element, MetaProperty p){ return getInputEditor(element, p, "checkbox"); } private String getInputEditor(MetaFieldElement element, MetaProperty p, String inputType){ String ret =""; String lang = getElementLanguage(element); ret += "\""; // Required for DateTime widget if (element.isDatetime()) { ret += " class=" + quote("datetime"); isNeedEnableDateTimeWidgets = true; } } if (element.isReadonly()) ret += " readonly="+quote("readonly"); if (element.isAutocompleteOff()) ret += " autocomplete="+quote("off"); ret += "/>"; if (element.isReadonly()) ret += " readonly"; return ret; } private String getTextEditor(MetaFieldElement element, MetaProperty p){ String lang = getElementLanguage(element); String ret =""; ret += ""; return ret; } private void generateLinkElementEditorJS(MetaDocument doc, List linkElements){ appendString(""); } private void generateRichTextEditorJS(MetaDocument doc, List richTextElements){ appendString(""); appendString(""); appendString(""); } private void generateDateTimeWidgetJS() { if (!isNeedEnableDateTimeWidgets) return; appendString(""); appendString(""); appendString(""); } private String getFunctionEditor(MetaDocument doc, MetaFunctionElement element){ if (element.getName().equals("cancel")) { String onClick = "return confirm('All unsaved data will be lost!!!. Document will be unlocked"; String cancel = CMSMappingsConfiguratorGenerator.getPath(((MetaModuleSection) currentSection).getDocument(), CMSMappingsConfiguratorGenerator.ACTION_CLOSE); cancel += "?pId="; return "Close"; } if (element.getName().equals("update")) { return getUpdateAndCloseFunction(doc, element); } if (element.getName().equals("updateAndStay")) { return getUpdateAndStayFunction(doc, element); } if (element.getName().equals("updateAndClose")) { return getUpdateAndCloseFunction(doc, element); } if (element.getName().equals("lock") && StorageType.CMS.equals(doc.getParentModule().getStorageType())) { //For now we dont draw Lock and Unlock functions here //return getLockFunctionLink(doc, element); } if (element.getName().equals("unlock") && StorageType.CMS.equals(doc.getParentModule().getStorageType())) { //For now we dont draw Lock and Unlock functions here //return getUnLockFunctionLink(doc, element); } return ""; } private String getUpdateAndDeleteFileAndStayFunction(MetaDocument doc, MetaProperty p){ String beanName = CMSMappingsConfiguratorGenerator.getDialogFormName(currentDialog, ((MetaModuleSection)currentSection).getDocument()); String propertyWriter = ""; if(StorageType.CMS.equals(doc.getParentModule().getStorageType())){ //creating logic for hiding or showing current operation link in Locking CASE!!!!! String result = ""; result += " \n"; result+=" ") + "> \n"; result+="\t\"Delete \n"; result+=" \n"; result+=" \n"; result+=" \n"; result+="\t\"Delete\n"; result+=" \n"; result+=" \n"; return result; } //Delete customSubmit in the bottom, if not using tinyMCE return ""+ "\"Delete"+ ""; } private String getUpdateAndStayFunction(MetaDocument doc, MetaFunctionElement element){ if(StorageType.CMS.equals(doc.getParentModule().getStorageType())){ //creating logic for hiding or showing current operation link in Locking CASE!!!!! String result = " \n"; result+=" ") + "> \n"; result+="\t \n"; result+=" \n"; result+=" \n"; result+=" \n"; result+="\t\n"; result+=" \n"; return result; } //Delete customSubmit in the bottom, if not using tinyMCE return ""; } private String getUpdateAndCloseFunction(MetaDocument doc, MetaFunctionElement element){ if(StorageType.CMS.equals(doc.getParentModule().getStorageType())){ //creating logic for hiding or showing current operation link in Locking CASE!!!!! String result = " \n"; result+=" ") + "> \n"; result+="\t \n"; result+=" \n"; result+=" \n"; result+=" \n"; result+="\t \n"; result+=" \n"; return result; } //Delete customSubmit in the bottom, if not using tinyMCE return ""; } /** * Creating entries in JSP for Multilanguage Support!!! * @param section * @param colspan */ private void addMultilanguageOperations(MetaModuleSection section, int colspan) { appendString(""); increaseIdent(); appendString(""); increaseIdent(); appendString("
"); increaseIdent(); appendString("\"/>\"/>"); appendString("
"); increaseIdent(); appendString("Copy "); appendString("to"); appendString(""); decreaseIdent(); appendString("
"); appendString("Copy"); decreaseIdent(); appendString("
"); appendString("
"); increaseIdent(); appendString("
"); appendString("\"/>\"/>"); decreaseIdent(); appendString("
"); appendString("Disable languages"); appendString("
"); decreaseIdent(); appendString("
"); decreaseIdent(); appendString("
"); appendString(""); increaseIdent(); appendString("
"); appendString("
"); appendString("\"/>\"/>"); appendString("Enable languages"); decreaseIdent(); appendString("
"); appendString(""); appendString("
"); } private void addDialogContentToDisplayUsagesOfElement(MetaModuleSection section){ if(isAppropriateModule(section)){ if (!section.getDocument().getName().equalsIgnoreCase("RedirectUrl") && !section.getDocument().getName().equalsIgnoreCase("EntryPoint")){ increaseIdent(); appendString(""); } } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy