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.ade.editprovider.client; 029 030import org.opencms.ade.contenteditor.shared.CmsEditorConstants; 031import org.opencms.gwt.client.CmsCoreProvider; 032import org.opencms.gwt.client.ui.A_CmsDirectEditButtons; 033import org.opencms.gwt.client.ui.CmsCreateModeSelectionDialog; 034import org.opencms.gwt.client.ui.CmsDeleteWarningDialog; 035import org.opencms.gwt.client.ui.CmsPushButton; 036import org.opencms.gwt.client.ui.contenteditor.I_CmsContentEditorHandler; 037import org.opencms.gwt.client.util.CmsDomUtil; 038import org.opencms.gwt.client.util.CmsDomUtil.Method; 039import org.opencms.gwt.client.util.CmsDomUtil.Target; 040import org.opencms.gwt.client.util.CmsPositionBean; 041import org.opencms.util.CmsUUID; 042 043import java.util.HashMap; 044import java.util.Map; 045 046import com.google.common.collect.Maps; 047import com.google.gwt.dom.client.Element; 048import com.google.gwt.dom.client.FormElement; 049import com.google.gwt.dom.client.Style; 050import com.google.gwt.dom.client.Style.Unit; 051import com.google.gwt.user.client.Window; 052import com.google.gwt.user.client.rpc.AsyncCallback; 053 054/** 055 * Direct edit buttons for the Toolbar direct edit provider.<p> 056 * 057 * @since 8.0.0 058 */ 059public class CmsDirectEditButtons extends A_CmsDirectEditButtons implements I_CmsContentEditorHandler { 060 061 /** 062 * Creates a new instance.<p> 063 * 064 * @param editable the editable element 065 * @param parentId the parent id 066 */ 067 public CmsDirectEditButtons(Element editable, String parentId) { 068 069 super(editable, parentId); 070 071 } 072 073 /** 074 * @see org.opencms.gwt.client.ui.contenteditor.I_CmsContentEditorHandler#onClose(java.lang.String, org.opencms.util.CmsUUID, boolean, boolean) 075 */ 076 public void onClose( 077 String sitePath, 078 CmsUUID structureId, 079 boolean isNew, 080 boolean hasChangedSettings, 081 boolean usedPublishDialog) { 082 083 Window.Location.reload(); 084 } 085 086 /** 087 * Sets the position. Make sure the widget is attached to the DOM.<p> 088 * 089 * @param position the absolute position 090 * @param buttonsPosition the corrected position for the buttons 091 * 092 * @param containerElement the parent container element 093 */ 094 public void setPosition(CmsPositionBean position, CmsPositionBean buttonsPosition, Element containerElement) { 095 096 m_position = position; 097 Element parent = CmsDomUtil.getPositioningParent(getElement()); 098 Style style = getElement().getStyle(); 099 style.setRight( 100 parent.getOffsetWidth() 101 - ((buttonsPosition.getLeft() + buttonsPosition.getWidth()) - parent.getAbsoluteLeft()), 102 Unit.PX); 103 int top = buttonsPosition.getTop() - parent.getAbsoluteTop(); 104 if (top < 0) { 105 top = 0; 106 } 107 style.setTop(top, Unit.PX); 108 } 109 110 /** 111 * Delete the editable element from page and VFS.<p> 112 */ 113 protected void deleteElement() { 114 115 //CmsContainerpageController.get().deleteElement(m_editableData.getStructureId(), m_parentResourceId); 116 } 117 118 /** 119 * @see org.opencms.gwt.client.ui.A_CmsDirectEditButtons#getAdditionalButtons() 120 */ 121 @Override 122 protected Map<Integer, CmsPushButton> getAdditionalButtons() { 123 124 Map<Integer, CmsPushButton> result = Maps.newHashMap(); 125 result.put(Integer.valueOf(130), createInfoButton()); 126 return result; 127 } 128 129 /** 130 * @see org.opencms.gwt.client.ui.A_CmsDirectEditButtons#getUploadButtonTitle(java.lang.String) 131 */ 132 @Override 133 protected String getUploadButtonTitle(String uploadFolder) { 134 135 return null; 136 } 137 138 /** 139 * @see org.opencms.gwt.client.ui.A_CmsDirectEditButtons#onClickDelete() 140 */ 141 @Override 142 protected void onClickDelete() { 143 144 CmsDeleteWarningDialog deleteDialog = new CmsDeleteWarningDialog(m_editableData.getSitePath()) { 145 146 @Override 147 protected void onAfterDeletion() { 148 149 Window.Location.reload(); 150 } 151 }; 152 deleteDialog.center(); 153 } 154 155 /** 156 * @see org.opencms.gwt.client.ui.A_CmsDirectEditButtons#onClickEdit() 157 */ 158 @Override 159 protected void onClickEdit() { 160 161 openEditDialog(false, null); 162 removeHighlighting(); 163 } 164 165 /** 166 * @see org.opencms.gwt.client.ui.A_CmsDirectEditButtons#onClickNew(boolean) 167 */ 168 @Override 169 protected void onClickNew(boolean askCreateMode) { 170 171 if (!askCreateMode) { 172 openEditDialog(true, null); 173 removeHighlighting(); 174 } else { 175 176 CmsUUID referenceId = m_editableData.getStructureId(); 177 CmsCreateModeSelectionDialog.showDialog(referenceId, new AsyncCallback<String>() { 178 179 public void onFailure(Throwable caught) { 180 181 // this is never called 182 183 } 184 185 public void onSuccess(String result) { 186 187 openEditDialog(true, result); 188 removeHighlighting(); 189 } 190 }); 191 } 192 } 193 194 /** 195 * Opens the content editor.<p> 196 * 197 * @param isNew <code>true</code> to create and edit a new resource 198 * @param mode the content creation mode 199 */ 200 protected void openEditDialog(boolean isNew, String mode) { 201 202 // create a form to submit a post request to the editor JSP 203 Map<String, String> formValues = new HashMap<String, String>(); 204 if (m_editableData.getSitePath() != null) { 205 formValues.put("resource", m_editableData.getSitePath()); 206 } 207 if (m_editableData.getElementLanguage() != null) { 208 formValues.put("elementlanguage", m_editableData.getElementLanguage()); 209 } 210 if (m_editableData.getElementName() != null) { 211 formValues.put("elementname", m_editableData.getElementName()); 212 } 213 String backlink = CmsCoreProvider.get().getUri(); 214 if (Window.Location.getPath().endsWith(backlink)) { 215 // CmsCoreProvider.get().getUri() is the request context uri from the time the direct edit provider 216 // includes are generated. In case the template has changed the request context uri before that point, 217 // we don't append the request parameters, as they may be inappropriate for the new URI. 218 backlink += Window.Location.getQueryString(); 219 } 220 formValues.put("backlink", backlink); 221 formValues.put("redirect", "true"); 222 formValues.put("directedit", "true"); 223 formValues.put("nofoot", "1"); 224 formValues.put("editcontext", CmsCoreProvider.get().getUri()); 225 String postCreateHandler = m_editableData.getPostCreateHandler(); 226 if (postCreateHandler != null) { 227 formValues.put(CmsEditorConstants.PARAM_POST_CREATE_HANDLER, postCreateHandler); 228 } 229 if (mode != null) { 230 formValues.put(CmsEditorConstants.PARAM_MODE, mode); 231 } 232 233 if (isNew) { 234 formValues.put("newlink", m_editableData.getNewLink()); 235 formValues.put("editortitle", m_editableData.getNewTitle()); 236 } 237 FormElement formElement = CmsDomUtil.generateHiddenForm( 238 CmsCoreProvider.get().link(CmsCoreProvider.get().getContentEditorUrl()), 239 Method.post, 240 Target.TOP, 241 formValues); 242 getMarkerTag().appendChild(formElement); 243 formElement.submit(); 244 } 245}