aboutsummaryrefslogtreecommitdiffstats
path: root/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexNewModelForm.js
blob: d7e5ccd7b6b532da57b640fe3767279e22615c17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2020-2021 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

import { formUtils_generateDescription, formUtils_generateUUID } from "./ApexFormUtils";
import {apexUtils_removeElement} from "./ApexUtils";
import {pageControl_modelMode} from "./ApexPageControl";
import {ajax_post, ajax_get} from "./ApexAjax";
import {keyInformationTab_reset} from "./ApexKeyInformationTab";

function newModelForm_activate(formParent) {
    apexUtils_removeElement("newModelFormDiv");

    var contentelement = document.createElement("newModelFormDiv");
    var formDiv = document.createElement("div");
    var backgroundDiv = document.createElement("div");
    backgroundDiv.setAttribute("id", "newModelDivBackground");
    backgroundDiv.setAttribute("class", "newModelDivBackground");

    backgroundDiv.appendChild(formDiv);
    contentelement.appendChild(backgroundDiv);
    formParent.appendChild(contentelement);

    formDiv.setAttribute("id", "newModelFormDiv");
    formDiv.setAttribute("class", "newModelFormDiv");

    var headingSpan = document.createElement("span");
    formDiv.appendChild(headingSpan);

    headingSpan.setAttribute("class", "headingSpan");
    headingSpan.innerHTML = "Model Details";

    var form = document.createElement("newModelForm");
    formDiv.appendChild(form);

    form.setAttribute("id", "newModelForm");
    form.setAttribute("class", "form-style-1");
    form.setAttribute("method", "post");

    var ul = document.createElement("ul");
    form.appendChild(ul);

    var nameLI = document.createElement("li");
    form.appendChild(nameLI);

    var nameLabel = document.createElement("label");
    nameLI.appendChild(nameLabel);

    nameLabel.setAttribute("for", "newModelFormNameInput");
    nameLabel.innerHTML = "Name: ";

    var nameLabelSpan = document.createElement("span");
    nameLabel.appendChild(nameLabelSpan);

    nameLabelSpan.setAttribute("class", "required");
    nameLabelSpan.innerHTML = "*";

    var nameInput = document.createElement("input");
    nameLI.appendChild(nameInput);

    nameInput.setAttribute("id", "newModelFormNameInput");
    nameInput.setAttribute("type", "text");
    nameInput.setAttribute("name", "newModelFormameInput");
    nameInput.setAttribute("class", "field ebInput ebInput_width_xLong");
    nameInput.setAttribute("placeholder", "name");

    var versionLI = document.createElement("li");
    form.appendChild(versionLI);

    var versionLabel = document.createElement("label");
    versionLI.appendChild(versionLabel);

    versionLabel.setAttribute("for", "newModelFormVersionInput");
    versionLabel.innerHTML = "Version: ";

    var versionInput = document.createElement("input");
    versionLI.appendChild(versionInput);

    versionInput.setAttribute("id", "newModelFormVersionInput");
    versionInput.setAttribute("type", "text");
    versionInput.setAttribute("name", "newModelFormVersionInput");
    versionInput.setAttribute("class", "field ebInput ebInput_width_xLong");
    versionInput.setAttribute("placeholder", "0.0.1");

    var uuidLI = document.createElement("li");
    form.appendChild(uuidLI);

    var uuidLabel = document.createElement("label");
    uuidLI.appendChild(uuidLabel);

    uuidLabel.setAttribute("for", "newModelFormUuidInput");
    uuidLabel.innerHTML = "UUID: ";

    var uuidInput = document.createElement("input");
    uuidLI.appendChild(uuidInput);

    uuidInput.setAttribute("id", "newModelFormUuidInput");
    uuidInput.setAttribute("type", "text");
    uuidInput.setAttribute("name", "newModelFormUuidInput");
    uuidInput.setAttribute("class", "field-long  ebInput ebInput_width_full");
    uuidInput.setAttribute("placeholder", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");

    var descriptionLI = document.createElement("li");
    form.appendChild(descriptionLI);

    var descriptionLabel = document.createElement("label");
    descriptionLI.appendChild(descriptionLabel);
    descriptionLabel.setAttribute("for", "newModelFormDescriptionTextArea");
    descriptionLabel.innerHTML = "Description: ";

    var descriptionTextArea = document.createElement("textarea");
    descriptionLI.appendChild(descriptionTextArea);

    descriptionTextArea.setAttribute("id", "newModelFormDescriptionTextArea");
    descriptionTextArea.setAttribute("name", "newModelFormDescriptionTextArea");
    descriptionTextArea.setAttribute("class", "field-long field-textarea ebTextArea ebTextArea_width_full");

    var inputLI = document.createElement("li");
    form.appendChild(inputLI);

    var generateUUIDInput = document.createElement("input");
    inputLI.appendChild(generateUUIDInput);

    generateUUIDInput.setAttribute("id", "generateUUID");
    generateUUIDInput.setAttribute("class", "button ebBtn");
    generateUUIDInput.setAttribute("type", "submit");
    generateUUIDInput.setAttribute("value", "Generate UUID");

    generateUUIDInput.onclick = newModelForm_generateUUIDPressed;

    var inputSpan0 = document.createElement("span");
    inputLI.appendChild(inputSpan0);

    inputSpan0.setAttribute("class", "required");
    inputSpan0.innerHTML = " ";

    var generateDescriptionInput = document.createElement("input");
    inputLI.appendChild(generateDescriptionInput);

    generateDescriptionInput.setAttribute("id", "generateDescription");
    generateDescriptionInput.setAttribute("class", "button ebBtn");
    generateDescriptionInput.setAttribute("type", "submit");
    generateDescriptionInput.setAttribute("value", "Generate Description");

    generateDescriptionInput.onclick = newModelForm_generateDescriptionPressed;

    var inputSpan1 = document.createElement("span");
    inputLI.appendChild(inputSpan1);

    inputSpan1.setAttribute("class", "required");
    inputSpan1.innerHTML = " ";

    var cancelInput = document.createElement("input");
    inputLI.appendChild(cancelInput);

    cancelInput.setAttribute("id", "generateDescription");
    cancelInput.setAttribute("class", "button ebBtn");
    cancelInput.setAttribute("type", "submit");
    cancelInput.setAttribute("value", "Cancel");

    cancelInput.onclick = newModelForm_cancelPressed;

    var inputSpan2 = document.createElement("span");
    inputLI.appendChild(inputSpan2);

    inputSpan2.setAttribute("class", "required");
    inputSpan2.innerHTML = " ";

    var submitInput = document.createElement("input");
    inputLI.appendChild(submitInput);

    submitInput.setAttribute("id", "submit");
    submitInput.setAttribute("class", "button ebBtn");
    submitInput.setAttribute("type", "submit");
    submitInput.setAttribute("value", "Submit");

    submitInput.onclick = newModelForm_submitPressed;
}

function newModelForm_generateUUIDPressed() {
    document.getElementById("newModelFormUuidInput").value = formUtils_generateUUID();
}

function newModelForm_generateDescriptionPressed() {
    document.getElementById("newModelFormDescriptionTextArea").value = formUtils_generateDescription(document
            .getElementById("newModelFormNameInput").value, document.getElementById("newModelFormVersionInput").value,
            document.getElementById("newModelFormUuidInput").value);
}

function newModelForm_cancelPressed() {
    apexUtils_removeElement("newModelDivBackground");
}

function newModelForm_submitPressed() {
    var jsonString = JSON.stringify({
        "name" : $('#newModelFormNameInput').val(),
        "version" : $('#newModelFormVersionInput').val(),
        "uuid" : $('#newModelFormUuidInput').val(),
        "description" : $('#newModelFormDescriptionTextArea').val()
    });

    var requestURL = window.restRootURL + "/Model/Create";

    ajax_post(requestURL, jsonString, function(resultData) {
        apexUtils_removeElement("newModelDivBackground");

        requestURL = window.restRootURL + "/Model/GetKey";

        ajax_get(requestURL, function(data) {
            var modelKey = JSON.parse(data.messages.message[0]).apexArtifactKey;
            var modelFileName = modelKey.name + ".json";
            pageControl_modelMode(modelKey.name, modelKey.version, modelFileName);
        });
        keyInformationTab_reset()
    });
}

export {
    newModelForm_activate,
    newModelForm_cancelPressed,
    newModelForm_generateDescriptionPressed,
    newModelForm_generateUUIDPressed,
    newModelForm_submitPressed
}