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.gwt.client;
029
030import org.opencms.ade.contenteditor.shared.CmsEditorConstants;
031import org.opencms.gwt.shared.CmsGwtConstants;
032import org.opencms.util.CmsUUID;
033
034import com.google.gwt.core.client.JavaScriptObject;
035
036/**
037 * Javascript overlay object holding data needed to edit a content collector list element.<p>
038 *
039 * @since 8.0.0
040 */
041public final class CmsEditableDataJSO extends JavaScriptObject implements I_CmsEditableData {
042
043    /**
044     * Constructor.<p>
045     */
046    protected CmsEditableDataJSO() {
047
048        // nothing to do
049    }
050
051    /**
052     * Parses the given JSON text and returns the editable data object.<p>
053     *
054     * @param jsonText the JSON text to parse
055     *
056     * @return the data object
057     */
058    public static native CmsEditableDataJSO parseEditableData(String jsonText) /*-{
059        return eval('(' + jsonText + ')');
060    }-*/;
061
062    /**
063     * @see org.opencms.gwt.client.I_CmsEditableData#getContextId()
064     */
065    public String getContextId() {
066
067        return getString(CmsEditorConstants.ATTR_CONTEXT_ID);
068    }
069
070    /**
071     * @see org.opencms.gwt.client.I_CmsEditableData#getEditId()
072     */
073    public native String getEditId() /*-{
074        return this.editId ? this.editId : "";
075    }-*/;
076
077    /**
078     * @see org.opencms.gwt.client.I_CmsEditableData#getElementId()
079     */
080    public String getElementId() {
081
082        return getString(CmsGwtConstants.ATTR_ELEMENT_ID);
083    }
084
085    /**
086     * @see org.opencms.gwt.client.I_CmsEditableData#getElementLanguage()
087     */
088    public native String getElementLanguage() /*-{
089        return this.elementlanguage ? this.elementlanguage : "";
090    }-*/;
091
092    /**
093     * @see org.opencms.gwt.client.I_CmsEditableData#getElementName()
094     */
095    public native String getElementName() /*-{
096        return this.elementname ? this.elementname : "";
097    }-*/;
098
099    /**
100     * Gets the element view.<p>
101     *
102     * @return the element view
103     */
104    public CmsUUID getElementView() {
105
106        String elementViewString = getString(CmsEditorConstants.ATTR_ELEMENT_VIEW);
107        if (elementViewString == null) {
108            return null;
109        }
110        return new CmsUUID(elementViewString);
111    }
112
113    /**
114     * @see org.opencms.gwt.client.I_CmsEditableData#getNewLink()
115     */
116    public native String getNewLink() /*-{
117        return this.newlink ? this.newlink : "";
118    }-*/;
119
120    /**
121     * @see org.opencms.gwt.client.I_CmsEditableData#getNewTitle()
122     */
123    public native String getNewTitle() /*-{
124        return this.newtitle ? this.newtitle : "";
125    }-*/;
126
127    /**
128     * @see org.opencms.gwt.client.I_CmsEditableData#getNoEditReason()
129     */
130    public native String getNoEditReason() /*-{
131
132        if (this.noEditReason)
133            return this.noEditReason;
134        else
135            return null;
136    }-*/;
137
138    /**
139     * @see org.opencms.gwt.client.I_CmsEditableData#getPostCreateHandler()
140     */
141    public String getPostCreateHandler() {
142
143        return getString(CmsEditorConstants.PARAM_POST_CREATE_HANDLER);
144    }
145
146    /**
147     * @see org.opencms.gwt.client.I_CmsEditableData#getSitePath()
148     */
149    public native String getSitePath() /*-{
150        return this.sitePath ? this.sitePath : "";
151    }-*/;
152
153    /**
154     * @see org.opencms.gwt.client.I_CmsEditableData#getStructureId()
155     */
156    public CmsUUID getStructureId() {
157
158        return new CmsUUID(nativeGetStructureId());
159    }
160
161    /**
162     * Returns if the delete button should be present.<p>
163     *
164     * @return <code>true</code> if the delete button should be present
165     */
166    public native boolean hasDelete() /*-{
167        return this.hasDelete;
168    }-*/;
169
170    /**
171     * Returns if the edit button should be present.<p>
172     *
173     * @return <code>true</code> if the edit button should be present
174     */
175    public native boolean hasEdit() /*-{
176        return this.hasEdit;
177    }-*/;
178
179    /**
180     * @see org.opencms.gwt.client.I_CmsEditableData#hasEditHandler()
181     */
182    public native boolean hasEditHandler() /*-{
183
184        return this.hasEditHandler;
185    }-*/;
186
187    /**
188     * Returns if the new button should be present.<p>
189     *
190     * @return <code>true</code> if the new button should be present
191     */
192    public native boolean hasNew() /*-{
193        return this.hasNew;
194    }-*/;
195
196    /**
197     * @see org.opencms.gwt.client.I_CmsEditableData#hasResource()
198     */
199    public native boolean hasResource() /*-{
200        return this.hasResource;
201    }-*/;
202
203    /**
204     * @see org.opencms.gwt.client.I_CmsEditableData#isUnreleasedOrExpired()
205     */
206    public native boolean isUnreleasedOrExpired() /*-{
207        return this.unreleaseOrExpired;
208    }-*/;
209
210    /**
211     * @see org.opencms.gwt.client.I_CmsEditableData#setSitePath(java.lang.String)
212     */
213    public native void setSitePath(String sitePath) /*-{
214
215        this.sitePath = sitePath;
216    }-*/;
217
218    /**
219     * Reads an attribute of the underlying Javascript object as a string.<p>
220     *
221     * @param attribute the name of the attribute
222     *
223     * @return the string contained in the given attribute
224     */
225    private native String getString(String attribute) /*-{
226        return this[attribute];
227    }-*/;
228
229    /**
230     * Returns the structure id as string.<p>
231     *
232     * @return the structure id as string
233     */
234    private native String nativeGetStructureId() /*-{
235        return this.structureId ? this.structureId : "";
236    }-*/;
237
238}