001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.workplace.editors.directedit; 029 030import org.opencms.i18n.CmsEncoder; 031import org.opencms.util.CmsStringUtil; 032import org.opencms.workplace.editors.Messages; 033 034/** 035 * Creates HTML for simple text based direct edit buttons.<p> 036 * 037 * This provider support {@link CmsDirectEditMode#MANUAL} mode.<p> 038 * 039 * @since 6.2.3 040 */ 041public class CmsDirectEditTextButtonProvider extends CmsDirectEditDefaultProvider { 042 043 /** The HTML for the direct edit end (only enabled). */ 044 private String m_endHtml; 045 046 /** 047 * @see org.opencms.workplace.editors.directedit.CmsDirectEditDefaultProvider#endDirectEditDisabled() 048 */ 049 @Override 050 public String endDirectEditDisabled() { 051 052 return ""; 053 } 054 055 /** 056 * @see org.opencms.workplace.editors.directedit.CmsDirectEditDefaultProvider#endDirectEditEnabled() 057 */ 058 @Override 059 public String endDirectEditEnabled() { 060 061 String result = ""; 062 if (CmsStringUtil.isNotEmpty(m_endHtml)) { 063 result = m_endHtml; 064 m_endHtml = null; 065 } 066 return result; 067 } 068 069 /** 070 * @see org.opencms.workplace.editors.directedit.I_CmsDirectEditProvider#isManual(org.opencms.workplace.editors.directedit.CmsDirectEditMode) 071 */ 072 @Override 073 public boolean isManual(CmsDirectEditMode mode) { 074 075 return (mode == CmsDirectEditMode.MANUAL) 076 || ((m_mode == CmsDirectEditMode.MANUAL) && (mode == CmsDirectEditMode.TRUE)); 077 } 078 079 /** 080 * @see org.opencms.workplace.editors.directedit.I_CmsDirectEditProvider#newInstance() 081 */ 082 @Override 083 public I_CmsDirectEditProvider newInstance() { 084 085 CmsDirectEditTextButtonProvider result = new CmsDirectEditTextButtonProvider(); 086 result.m_configurationParameters = m_configurationParameters; 087 return result; 088 } 089 090 /** 091 * @see org.opencms.workplace.editors.directedit.CmsDirectEditDefaultProvider#startDirectEditDisabled(org.opencms.workplace.editors.directedit.CmsDirectEditParams, org.opencms.workplace.editors.directedit.CmsDirectEditResourceInfo) 092 */ 093 @Override 094 public String startDirectEditDisabled(CmsDirectEditParams params, CmsDirectEditResourceInfo resourceInfo) { 095 096 StringBuffer result = new StringBuffer(256); 097 098 result.append("<span class=\"ocms_txt_dis\">"); 099 result.append(m_messages.key(Messages.GUI_DIRECTEDIT_TEXT_EDIT_0)); 100 result.append("</span>"); 101 102 return result.toString(); 103 } 104 105 /** 106 * @see org.opencms.workplace.editors.directedit.CmsDirectEditDefaultProvider#startDirectEditEnabled(org.opencms.workplace.editors.directedit.CmsDirectEditParams, org.opencms.workplace.editors.directedit.CmsDirectEditResourceInfo) 107 */ 108 @Override 109 public String startDirectEditEnabled(CmsDirectEditParams params, CmsDirectEditResourceInfo resourceInfo) { 110 111 String editId = getNextDirectEditId(); 112 StringBuffer result = new StringBuffer(256); 113 String linkForNew = CmsEncoder.encode(params.getLinkForNew()); 114 115 result.append("<span class=\"ocms_txt_en\">"); 116 if (params.getButtonSelection().isShowEdit()) { 117 result.append("[<a href=\"#\" class=\"ocms_txt\" onclick=\"javascript:submitOcms(\'").append(editId).append( 118 "\', \'").append(CmsDirectEditButtonSelection.VALUE_EDIT).append("\');\">"); 119 result.append(m_messages.key(Messages.GUI_DIRECTEDIT_TEXT_EDIT_0)); 120 result.append("</a>]"); 121 } 122 if (params.getButtonSelection().isShowDelete()) { 123 result.append("\n[<a href=\"#\" class=\"ocms_txt\" onclick=\"javascript:submitOcms(\'").append( 124 editId).append("\', \'").append(CmsDirectEditButtonSelection.VALUE_DELETE).append("\');\">"); 125 result.append(m_messages.key(Messages.GUI_DIRECTEDIT_TEXT_DELETE_0)); 126 result.append("</a>]"); 127 } 128 if (params.getButtonSelection().isShowNew()) { 129 result.append("\n[<a href=\"#\" class=\"ocms_txt\" onclick=\"javascript:submitOcms(\'").append( 130 editId).append("\', \'").append(CmsDirectEditButtonSelection.VALUE_NEW).append("\', \'").append( 131 linkForNew).append("\');\">"); 132 result.append(m_messages.key(Messages.GUI_DIRECTEDIT_TEXT_NEW_0)); 133 result.append("</a>]"); 134 } 135 result.append("</span>"); 136 137 StringBuffer endHtml = new StringBuffer(256); 138 String editLocale = m_cms.getRequestContext().getLocale().toString(); 139 String uri = m_cms.getRequestContext().getUri(); 140 String linkForEdit = getLink(params.getLinkForEdit()); 141 endHtml.append("<form class=\"ocms_nomargin\" name=\"form_").append(editId).append("\" id=\"form_").append( 142 editId).append("\" method=\"post\" action=\"").append(linkForEdit).append("\" target=\"_top\">\n"); 143 endHtml.append("<input type=\"hidden\" name=\"resource\" value=\"").append(params.getResourceName()).append( 144 "\"/>\n"); 145 endHtml.append("<input type=\"hidden\" name=\"directedit\" value=\"true\"/>\n"); 146 endHtml.append("<input type=\"hidden\" name=\"elementlanguage\" value=\"").append(editLocale).append("\"/>\n"); 147 endHtml.append("<input type=\"hidden\" name=\"elementname\" value=\"").append(params.getElement()).append( 148 "\"/>\n"); 149 endHtml.append("<input type=\"hidden\" name=\"backlink\" value=\"").append(uri).append("\"/>\n"); 150 endHtml.append("<input type=\"hidden\" name=\"newlink\"/>\n"); 151 endHtml.append("<input type=\"hidden\" name=\"closelink\"/>\n"); 152 endHtml.append("<input type=\"hidden\" name=\"redirect\" value=\"true\"/>\n"); 153 endHtml.append("<input type=\"hidden\" name=\"editortitle\"/>\n"); 154 endHtml.append("</form>"); 155 m_endHtml = endHtml.toString(); 156 157 return result.toString(); 158 } 159}