2 /*******************************************************************************
3 * Copyright (c) 2012-2013 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="used by genericcomponentpage.jsp and by implementations.jsp to create a component instance" pageEncoding="UTF-8"%>
15 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
16 <%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
17 <%@taglib prefix="w" uri="http://www.eclipse.org/winery/repository/functions"%>
19 function createResource(nameOfResource, fields, url, onSuccess) cannot be used as this method is more diverse
22 <%@attribute name="label" required="true" description="The lable to display"%>
24 <%@attribute name="URL" description=""%>
25 <%@attribute name="onSuccess" description=""%>
26 <%@attribute name="type" description="added to dataToSend when doing a POST"%>
27 <%@attribute name="typeSelectorData" type="java.util.Collection" description="All available types when creating a template. We do not support types with names (additional to the id) as the current TOSCA specification does not foresee the usage of both name and id at types"%>
28 <%@attribute name="openinnewwindow" description="if true, the editor for the created component instance is openend in a new window"%>
30 <div class="modal fade" id="addComponentInstanceDiag">
31 <div class="modal-dialog">
32 <div class="modal-content">
33 <div class="modal-header">
34 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
35 <h4 class="modal-title">Add ${label}</h4>
37 <div class="modal-body" style="overflow-y: inherit;">
38 <form id="addComponentInstanceForm" enctype="multipart/form-data">
39 <%-- we send namespace + name to server. There, the ID is generated out of the name --%>
41 <div class="form-group">
42 <label for="nameOfNewCI" class="control-label">Name</label>
43 <input class="form-control" name="name" id="nameOfNewCI" type="text" required="required" />
46 <t:namespaceChooser idOfInput="namespace" allNamespaces="${w:allNamespaces()}"></t:namespaceChooser>
48 <%-- (optional) the type, for instance at an artifact template or node type implementation --%>
50 <%-- Either directly given ... --%>
51 <c:when test="${not empty type}">
52 <%-- then, we just submit it together with the other data --%>
53 <input id="ciType" type="hidden" class="form-control" name="type" value="${type}"/>
55 <%-- ... or a list is given given. --%>
56 <%-- This is somewhat ugly as the UI displays no type dialog if no types are existing, but a template is to be created.
57 We consider that as special case and do not add code to work around that issue.
58 A good solution is to present an error dialog to the user if he hits that case:
59 A hint should be presented to state that the user has to add a type first. --%>
60 <c:when test="${empty type and not empty typeSelectorData}">
61 <div class="form-group">
62 <label for="ciType" class="control-label">Type</label>
63 <%-- similar code to artifacts.jsp.openLink${name}ArtifactDiag().ajax.success --%>
64 <select id="ciType" name="type" class="form-control">
65 <c:forEach var="typeId" items="${typeSelectorData}">
66 <option value="${typeId.QName}">${typeId.xmlId.decoded}</option>
77 <div class="modal-footer">
78 <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
79 <button type="button" class="btn btn-primary" onclick="addComponentInstance();">Add</button>
86 <c:if test="${empty type and not empty typeSelectorData}">
87 $("#ciType").select2();
90 $("#addComponentInstanceDiag").on("shown.bs.modal", function() {
91 $("#nameOfNewCI").focus();
94 function addComponentInstance() {
95 if (highlightRequiredFields()) {
96 vShowError("Please fill in all required fields");
100 var namespace = $("#namespace").val();
101 require(["URIjs/URI"], function(URI) {
102 if (!URI(namespace).is("absolute")) {
103 vShowError("Please enter a valid namespace");
107 var dataToSend = $('#addComponentInstanceForm').serialize();
112 <c:if test="${not empty URL}">"url": "${URL}",</c:if>
114 error: function(jqXHR, textStatus, errorThrown) {
115 vShowAJAXError("Could not add ${label}", jqXHR, errorThrown);
117 success: function(resData, textStatus, jqXHR) {
118 <c:if test="${not empty onSuccess}">
122 //if we want to add the new entry directly in the list, we have to start with following:
123 //var name = $('#nameOfNewCI').val();
124 //var namespace = $('#namespaceOfNewCI').val();
126 //otherwise: directly open edito
127 $('#addComponentInstanceDiag').modal('hide');
128 // open editor for newly created component (assumption: window.location ends with "/")
129 var loc = jqXHR.getResponseHeader('Location');
131 <c:when test="${openinnewwindow}">
132 window.open(loc, "_blank");
135 window.location = loc;
143 function openNewCIdiag() {
144 $('#addComponentInstanceDiag').modal('show');