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

com.tcdng.unify.web.ui.widget.writer.panel.ContentPanelWriter Maven / Gradle / Ivy

/*
 * Copyright 2018-2023 The Code Department.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.tcdng.unify.web.ui.widget.writer.panel;

import com.tcdng.unify.core.UnifyException;
import com.tcdng.unify.core.annotation.Component;
import com.tcdng.unify.core.annotation.Writes;
import com.tcdng.unify.core.util.StringUtils;
import com.tcdng.unify.core.util.json.JsonWriter;
import com.tcdng.unify.web.ControllerPathParts;
import com.tcdng.unify.web.ui.PageAttributeConstants;
import com.tcdng.unify.web.ui.PageRequestContextUtil;
import com.tcdng.unify.web.ui.widget.Container;
import com.tcdng.unify.web.ui.widget.Page;
import com.tcdng.unify.web.ui.widget.ResponseWriter;
import com.tcdng.unify.web.ui.widget.Widget;
import com.tcdng.unify.web.ui.widget.panel.ContentPanelImpl;
import com.tcdng.unify.web.ui.widget.panel.ContentPanelImpl.ContentInfo;
import com.tcdng.unify.web.ui.widget.writer.AbstractPanelWriter;

/**
 * Content panel writer.
 * 
 * @author The Code Department
 * @since 1.0
 */
@Writes(ContentPanelImpl.class)
@Component("contentpanel-writer")
public class ContentPanelWriter extends AbstractPanelWriter {

	private static final String CPREMOTE_CATEGORYBASE = "cpcat";

	@Override
	protected void doWriteBehavior(ResponseWriter writer, Widget widget) throws UnifyException {
		ContentPanelImpl contentPanel = (ContentPanelImpl) widget;

		// Write content variables
		writer.beginFunction("ux.rigContentPanel");
		writer.writeParam("pId", contentPanel.getId());
		writer.writeParam("pHintPanelId", contentPanel.getHintPanelId());
		writer.writeParam("pBdyPanelId", contentPanel.getBodyPanelId());
		if (contentPanel.getPageCount() > 0) {
			// Close image
			String closeImgId = contentPanel.getTabItemImgId(contentPanel.getPageIndex());
			writer.writeParam("pCloseImgId", closeImgId);
		}

		PageRequestContextUtil rcUtil = getRequestContextUtil();
		final boolean lowLatency = rcUtil.isLowLatencyRequest();
		if (lowLatency) {
			writer.writeParam("pLatency", lowLatency);
			writer.write(",\"pContentURL\":\"");
			writer.writeContextURL(contentPanel.getDocumentPath(), "/content");
			writer.write('"');
		}

		if (contentPanel.getPageCount() == 0) {
			writer.writeParam("pImmURL", getContextURL(contentPanel.getPath()));
		} else {
			writer.writeParam("pCurIdx", contentPanel.getPageIndex());
			ContentInfo currentContentInfo = contentPanel.getCurrentContentInfo();
			if (currentContentInfo.isRemoteSave()) {
				writer.writeParam("pSavePath", currentContentInfo.getSavePath());
				writer.writeParam("pSaveIsRem", true);
			} else {
				writer.writeParam("pSavePath", getContextURL(currentContentInfo.getSavePath()));
				writer.writeParam("pSaveIsRem", false);
			}

			JsonWriter jw = new JsonWriter();
			jw.beginArray();
			for (int i = 0; i < contentPanel.getPageCount(); i++) {
				ContentInfo contentInfo = contentPanel.getContentInfo(i);
				jw.beginObject();
				jw.write("tabId", contentPanel.getTabItemId(i));
				jw.write("tabImgId", contentPanel.getTabItemImgId(i));
				jw.write("openPath", getContextURL(contentInfo.getOpenPath()));
				jw.write("closePath", getContextURL(contentInfo.getClosePath()));
				jw.endObject();
			}
			jw.endArray();
			writer.writeParam("pContent", jw);
		}

		final boolean tabbed = contentPanel.isTabbed();
		writer.writeParam("pTabbed", tabbed);
		if (tabbed && contentPanel.getPageCount() > 0) {
			writer.writeParam("pTabPaneId", contentPanel.getTabPaneId());
			writer.writeParam("pMenuId", contentPanel.getMenuId());
		} else {
			rcUtil.setContentScrollReset();
		}

		writer.endFunction();

		if (contentPanel.isSidebar()) {
			writer.writeBehavior(contentPanel.getSidebar());
		}

		if (contentPanel.getPageCount() > 0) {
			if (lowLatency) {
				// TODO
			} else {
				// Set response page controller
				ControllerPathParts currentRespPathParts = rcUtil.getResponsePathParts();
				ContentInfo currentContentInfo = contentPanel.getCurrentContentInfo();
				try {
					rcUtil.setResponsePathParts(currentContentInfo.getPathParts());
					rcUtil.setContentPage(currentContentInfo.getPage());
					writer.writeBehavior(currentContentInfo.getPage());
				} finally {
					// Restore response controller
					rcUtil.setResponsePathParts(currentRespPathParts);
				}
			}
		}
	}

	@Override
	protected void writeLayoutContent(ResponseWriter writer, Container container) throws UnifyException {
		ContentPanelImpl contentPanel = (ContentPanelImpl) container;
		writer.write("
"); writer.write("
"); boolean isSidebar = contentPanel.isSidebar(); // Frame if (isSidebar) { writer.write("
"); writer.write("
"); writer.write("
"); } if (contentPanel.getPageCount() > 0) { writeContentPanel(writer, contentPanel); } if (isSidebar) { writer.write("
"); writer.write("
"); writer.write("
"); writer.writeStructureAndContent(contentPanel.getSidebar()); writer.write("
"); writer.write("
"); } writer.write("
"); } private void writeContentPanel(ResponseWriter writer, ContentPanelImpl contentPanel) throws UnifyException { logDebug("Writing structure for content panel [{0}]...", contentPanel.getLongName()); PageRequestContextUtil rcUtil = getRequestContextUtil(); ContentInfo currentContentInfo = contentPanel.getCurrentContentInfo(); // Tabs final boolean tabbed = contentPanel.isTabbed(); if (tabbed) { writer.write("
"); writer.write("
"); writer.write("
"); logDebug("Writing header tabs for content panel [{0}]...", contentPanel.getLongName()); writer.write(""); writer.write("
"); writer.write("
"); writer.write("
"); // Menu String menuId = contentPanel.getMenuId(); writer.write(""); writer.write(""); writer.write("
"); } // End tabs // Title bar if (contentPanel.isTitleBar()) { writer.write("
"); writer.write("
"); writer.write("
"); writer.write("
"); writer.write(""); writer.writeWithHtmlEscape(currentContentInfo.getPage().getCaption()); writer.write(""); writer.write("
"); writer.write("
"); writer.write("
"); writer.write("
"); } // End title bar // Body writer.write("
"); writer.write("
"); writer.write("
"); if (rcUtil.isLowLatencyRequest()) { // TODO } else { ControllerPathParts currentRespPathParts = rcUtil.getResponsePathParts(); try { rcUtil.setResponsePathParts(currentContentInfo.getPathParts()); rcUtil.setContentPage(currentContentInfo.getPage()); writer.writeStructureAndContent(currentContentInfo.getPage()); } finally { rcUtil.setResponsePathParts(currentRespPathParts); } } writer.write("
"); writer.write("
"); writer.write("
"); // End body } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy