2 /*******************************************************************************
3 * Copyright (c) 2013-2014 University of Stuttgart.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * and the Apache License 2.0 which both accompany this distribution,
7 * and are available at http://www.eclipse.org/legal/epl-v10.html
8 * and http://www.apache.org/licenses/LICENSE-2.0
11 * Oliver Kopp - initial API and implementation and/or initial documentation
12 *******************************************************************************/
14 <%@tag description="Wrapper for an orion editing area" pageEncoding="UTF-8"%>
16 <%@attribute name="areaid" required="true" description="The id of the editing area."%>
17 <%@attribute name="withoutsavebutton" required="false"%>
18 <%@attribute name="initialtext" required="false" description="The value to put in the editor. Can be also passed as body of this tag"%>
19 <%@attribute name="url" required="false"%>
20 <%@attribute name="hidden" required="false" description="if not empty, the form is hidden"%>
21 <%@attribute name="method" required="false" description="the method to use. Defaults to PUT"%>
23 <%-- QUICK HACK to change the method from POST to PUT after saving an empty documentation the first time --%>
24 <%@attribute name="reloadAfterSuccess" required="false" description="Trigger a page reload after success (if true)"%>
26 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
27 <%@taglib prefix="wc" uri="http://www.eclipse.org/winery/functions" %>
30 <div id="${areaid}" class="orionxmleditordiv" <c:if test="{$not empty hidden}">style="display: none;"</c:if>><pre>${wc:escapeHtml4(initialtext)}<jsp:doBody/></pre></div>
31 <c:if test="${empty withoutsavebutton}">
32 <button class="btn btn-primary" type="button" onclick="window.winery.orionareas['${areaid}'].save(this);" data-loading-text="Saving...">Save</button>
37 if (window.winery === undefined) {
40 if (window.winery.orionareas === undefined) {
41 window.winery.orionareas = {};
43 require(["orioneditor"], function(edit) {
45 id: "${areaid}", // used for URL update
46 reloadAfterSuccess : "${reloadAfterSuccess}",
48 contentType: "application/xml",
50 // todo: we can set the initial text by the parameter "contents"
53 contentType: "text/xml"
55 fixEditorHeight: function() {
57 // orion puts "height:0px" -> we remove that
58 $("#${areaid}").removeAttr("style");
59 // due to the CSS style, the height is 300px
60 // "just" adapt the editor to that size
63 save: function(button) {
64 var btn = $(button); // also works if button is undefined
65 btn.button("loading");
67 var options = this.ajaxOptions;
68 options.data = this.editor.getText();
70 // ensure that "config" variable is initialized within the ajax call
72 // the following code does not use "this" anymore as the "this" in the function references to the jqXHR instead of config
73 $.ajax(options).done(function( data, textStatus, jqXHR ) {
74 if (data !== undefined) {
75 // data contains the new id
76 url = url.replace(config.id, data);
78 config.ajaxOptions.url = url;
80 if (config.reloadAfterSuccess) {
83 vShowSuccess("sucessfully saved");
86 }).fail(function(jqXHR, textStatus, errorThrown) {
87 vShowAJAXError("Could not add update XML", jqXHR, errorThrown);
93 // now, editor is defined
94 // we cannot "fix" the appearance as the editor height determination does not work on hidden fields
96 // url is an optional parameter to the .tag
98 config.ajaxOptions.url = "${url}";
100 // method is an optional parameter to the .tag
101 if ("${method}" == "") {
102 config.ajaxOptions.type = "PUT";
104 config.ajaxOptions.type = "${method}";
107 // store the config in global variable
108 window.winery.orionareas["${areaid}"] = config;