2 /*******************************************************************************
3 * Copyright (c) 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 *******************************************************************************/
15 <%@tag pageEncoding="UTF-8"%>
17 <%@attribute name="label" description="Requirement|Capability" required="true" %>
18 <%@attribute name="requirementsOrCapabilities" description="requirements|capabilities" required="true" %>
19 <%@attribute name="reqOrCap" description="requirement|capability" required="true" %>
21 <%@taglib prefix="b" tagdir="/WEB-INF/tags/servicetemplates/boundarydefinitions"%>
23 <b:browseForX XShort="${reqOrCap}" XLong="${label}" />
25 <div class="modal fade" id="${reqOrCap}Diag">
26 <div class="modal-dialog">
27 <div class="modal-content">
28 <div class="modal-header">
29 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
30 <h4 class="modal-title"><span id="addOrUpdate${reqOrCap}Span"></span> ${label}</h4>
32 <div class="modal-body">
35 <div class="form-group">
36 <label for="${reqOrCap}Name">Name</label>
38 <input name="${reqOrCap}Name" id="${reqOrCap}Name" class="form-control" type="text">
41 <div class="form-group">
42 <label for="${reqOrCap}RefDiv">${label}</label>
43 <div id="${reqOrCap}RefDiv" class="row">
44 <div class="col-xs-10">
45 <input id="X${reqOrCap}Ref" class="form-control" type="text"> <%-- The input id is prefixed with "X" as "requirementRef" alone does not work --%>
47 <div class="col-xs-2">
48 <button type="button" class="btn btn-default btn-sm" onclick="browseFor${reqOrCap}($('#XReqRef'));">Browse</button>
56 <div class="modal-footer">
57 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
58 <button id="add${reqOrCap}" type="button" class="btn btn-primary" onclick="addorUpdate${reqOrCap}(false);">Add</button>
59 <button id="delete${reqOrCap}" type="button" class="btn btn-danger" onclick="delete${reqOrCap}t();">Delete</button>
60 <button id="update${reqOrCap}" type="button" class="btn btn-primary" onclick="addorUpdate${reqOrCap}(true);">Update</button>
69 * Triggered by the browse button at requirements. In the dialog Add/Change Requirement
71 function browseFor${reqOrCap}(field) {
72 $("#${reqOrCap}ReferenceField").val($("#X${reqOrCap}Ref").val());
73 $("#browseFor${reqOrCap}Diag").modal("show");
77 * Called by click on "Set" button at the browseForReqDiag
79 function set${reqOrCap}Ref() {
80 $("#X${reqOrCap}Ref").val($("#${reqOrCap}ReferenceField").val());
81 $("#browseFor${reqOrCap}Diag").modal("hide");
85 * Called from the modal after the user clicks "Add" or "Delete"
87 function addorUpdate${reqOrCap}(update) {
89 name: $("#${reqOrCap}Name").val(),
90 ref: $("#X${reqOrCap}Ref").val()
94 url: "boundarydefinitions/${requirementsOrCapabilities}/",
97 }).fail(function(jqXHR, textStatus, errorThrown) {
98 vShowAJAXError("Could not add ${label}", jqXHR, errorThrown);
99 }).done(function(id) {
100 // data is the new id
101 var tableRow = [id, data.name, data.ref];
102 ${requirementsOrCapabilities}TableInfo.table.fnAddData(tableRow);
105 // update is implemented as delete + recreate
106 // after successfull creation, we can delete
107 deleteOnServerAndInTable(${requirementsOrCapabilities}TableInfo, '${label}', 'boundarydefinitions/${requirementsOrCapabilities}/', undefined, undefined, undefined, true);
108 // TODO: we should hook into onSuccess/onError, but currently these are not exposed from deleteResource to deleteOnServerAndInTable
109 vShowSuccess("Successfully updated ${label}.");
111 vShowSuccess("Successfully added ${label}.");
115 $('#${reqOrCap}Diag').modal('hide');
119 function deleteRequirement() {
120 $('#${reqOrCap}Diag').modal('hide');
121 $("#delete${reqOrCap}").click();
125 * Called from the buttons in the table if the user clicks "Add" or "Edit"
127 function open${reqOrCap}Editor(update) {
129 if (${requirementsOrCapabilities}TableInfo.selectedRow) {
130 require(["winery-support"], function(ws) {
131 if (ws.isEmptyTable(${requirementsOrCapabilities}TableInfo)) {
132 vShowError("No ${requirementsOrCapabilities} available");
136 var data = ${requirementsOrCapabilities}TableInfo.table.fnGetData(${requirementsOrCapabilities}TableInfo.table.selectedRow);
137 // we don't require the id as deleteOnServerAndInTable automatically deletes the selectedRow
138 $("#${reqOrCap}Name").val(data[0][1]);
139 $("#X${reqOrCap}Ref").val(data[0][2]);
141 $("#add${reqOrCap}").hide();
142 $("#update${reqOrCap}").show();
143 $("#delete${reqOrCap}").show();
145 $("#addOrUpdate${reqOrCap}Span").text("Change");
146 $('#${reqOrCap}Diag').modal('show');
149 vShowError("No ${label} selected");
152 // create a new req/cap
153 $("#add${reqOrCap}").show();
154 $("#update${reqOrCap}").hide();
155 $("#delete${reqOrCap}").hide();
156 $("#addOrUpdate${reqOrCap}Span").text("Add");
157 $('#${reqOrCap}Diag').modal('show');