-
Notifications
You must be signed in to change notification settings - Fork 0
/
vici.js
339 lines (325 loc) · 11.6 KB
/
vici.js
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
//CORE COMPONENTS
function createOptionsForCards(coreId){
const mainDetail = document.createElement("details");
const summaryElement = document.createElement('summary');
summaryElement.appendChild(document.createTextNode("Options"));
mainDetail.appendChild(summaryElement);
const moveButton = document.createElement("button");
moveButton.appendChild(document.createTextNode("Move"));
moveButton.name = coreId;
moveButton.setAttribute("onclick", "moveRecord(this.name)");
mainDetail.appendChild(moveButton);
const killButton = document.createElement("button");
killButton.appendChild(document.createTextNode("Delete"));
killButton.name = coreId;
killButton.setAttribute("onclick", "killRecord(this.name)");
mainDetail.appendChild(killButton);
const pullButton = document.createElement("button");
pullButton.appendChild(document.createTextNode("Front"));
pullButton.name = coreId;
pullButton.setAttribute("onclick", "pullRecord(this.name)");
mainDetail.appendChild(pullButton);
const pushButton = document.createElement("button");
pushButton.appendChild(document.createTextNode("Back"));
pushButton.name = coreId;
pushButton.setAttribute("onclick", "pushRecord(this.name)");
mainDetail.appendChild(pushButton);
//GROW SHRINK
const moreButton = document.createElement("button");
moreButton.appendChild(document.createTextNode("Grow"));
moreButton.name = coreId;
moreButton.setAttribute("onclick", "moreRecord(this.name)");
mainDetail.appendChild(moreButton);
const lessButton = document.createElement("button");
lessButton.appendChild(document.createTextNode("Shrink"));
lessButton.name = coreId;
lessButton.setAttribute("onclick", "lessRecord(this.name)");
mainDetail.appendChild(lessButton);
//MOVEMENT BUTTONS
const movUButton = document.createElement("button");
movUButton.appendChild(document.createTextNode("Up"));
movUButton.name = coreId;
movUButton.setAttribute("onclick", "URecord(this.name)");
mainDetail.appendChild(movUButton);
const movDButton = document.createElement("button");
movDButton.appendChild(document.createTextNode("Down"));
movDButton.name = coreId;
movDButton.setAttribute("onclick", "DRecord(this.name)");
mainDetail.appendChild(movDButton);
const movLButton = document.createElement("button");
movLButton.appendChild(document.createTextNode("Left"));
movLButton.name = coreId;
movLButton.setAttribute("onclick", "LRecord(this.name)");
mainDetail.appendChild(movLButton);
const movRButton = document.createElement("button");
movRButton.appendChild(document.createTextNode("Right"));
movRButton.name = coreId;
movRButton.setAttribute("onclick", "RRecord(this.name)");
mainDetail.appendChild(movRButton);
return mainDetail;
}
function coreFormBasics(){
const neededArticle = document.createElement("article");
neededArticle.style = "left:10rem;top:10rem;z-index:1;";
const articleForm = document.createElement("form");
articleForm.style = "width:10rem;height:fit-content;";
const articleFormInput1 = document.createElement("input");
articleFormInput1.type = "text";
articleFormInput1.name = "head";
articleFormInput1.value = "head";
articleForm.appendChild(articleFormInput1);
neededArticle.appendChild(articleForm);
return neededArticle;
}
//REGISTERS
var registeredComponents={
"form-core":{"counter": 1,"component": coreFormBasics()}
};
var heightValue = null;
var widthValue = null;
//EVENTS
/**
* This allows us to confirm the fields we wanted in a given form
* @param {*} event
*/
function createNewForm(event){
console.log("createNewForm");
console.log(event);
//get me the element
var targetSection = document.getElementById("platform-content");
//get the parent element from the registry
if(event in registeredComponents){
countOfElement = registeredComponents[event]["counter"] +1;
registeredComponents[event]["counter"] = countOfElement;
const generatedId = event+"-"+countOfElement;
const neededElement = registeredComponents[event]["component"].cloneNode(true);
neededElement.id = generatedId;
neededElement.appendChild(createOptionsForCards(generatedId));
targetSection.appendChild(neededElement);
}
else {
alert("Unknown form add attempted!");
}
}
/**
* This is the on submit function when adding fields
* @param {*} event
*/
function addFormField(event){
console.log("addFormField");
console.log(event);
let inputField = document.createElement("input");
//the related fields
const typeInput = document.getElementById("formType");
const nameInput = document.getElementById("formName");
const attrInput = document.getElementById("formAttributes");
const classInput = document.getElementById("formClass");
inputField.setAttribute("type", typeInput.value);
inputField.setAttribute("name", nameInput.value);
inputField.setAttribute("class", classInput.value);
if(attrInput.value!=""){
alert("This is a future functionality, we can't cover new types of fields with attr, please reset");
} else {
const bufferTarget = document.getElementById("formCreationBuffer");
bufferTarget.appendChild(inputField);
}
}
/**
* this is the function to clear the added fields
* @param {*} event
*/
function clearFormField(event){
console.log("clearFormField");
console.log(event);
document.getElementById("formCreationBuffer").remove();
const newFormBuffer = document.createElement('form');
newFormBuffer.id = "formCreationBuffer";
const menuFound = document.getElementById("formCreationMenu");
menuFound.appendChild(newFormBuffer);
}
/**
* This saves the given form for use in the main display
* @param {*} event
*/
function addNewForm(event){
console.log("addNewForm");
console.log(event);
const menuFound = document.getElementById("formCreationBuffer");
if(menuFound.children.length>0){
const formClone = menuFound.cloneNode(true);
const neededArticle = document.createElement("article");
neededArticle.style = "left:10rem;top:10rem;z-index:1;";
formClone.style = "width:10rem;height:fit-content;";
neededArticle.appendChild(formClone);
const formOptionName = document.getElementById("formDisplayName").value;
if(formOptionName==""){
alert("Please add name before saving!");
} else {
registeredComponents[formOptionName] = {"counter": 1,"component": neededArticle};
clearFormField(event);
//create my button
const selectionMenu = document.getElementById("formSelectionMenu");
const addButton = document.createElement("button");
addButton.id=formOptionName;
addButton.appendChild(document.createTextNode("Add "+formOptionName));
addButton.setAttribute("onclick", "createNewForm(this.id)");
selectionMenu.appendChild(addButton);
}
}else {
alert("Please add child nodes before aving!");
}
}
/**
* Function to activate move mode, clicking resets the setting
* @param {*} event
*/
function moveRecord(event){
console.log("moveRecord");
console.log(event);
const elementTarget = document.getElementById(event);
if(elementTarget.classList.contains("moving")){
elementTarget.classList.remove("moving");
} else {
elementTarget.classList.add("moving");
}
dragElement(elementTarget);
}
function dragElement(elmnt) {
console.log(elmnt);
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if(elmnt.classList.contains("moving")){
if (document.getElementById(elmnt.id)) {
// if present, the header is where you move the DIV from:
document.getElementById(elmnt.id).onmousedown = dragMouseDown;
} else {
// otherwise, move the DIV from anywhere inside the DIV:
elmnt.onmousedown = dragMouseDown;
}
} else {
closeDragElement();
elmnt.onmousedown=null;
}
function dragMouseDown(e) {
console.log(e);
e = e || window.event;
e.preventDefault();
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}
function elementDrag(e) {
console.log(e);
e = e || window.event;
e.preventDefault();
// set the element's new position:
elmnt.style.top = (e.clientY-(elmnt.clientHeight))+"px";
elmnt.style.left = (e.clientX-(elmnt.clientWidth))+"px";
}
function closeDragElement() {
document.onmouseup = null;
document.onmousemove = null;
}
}
/**
* Function to delete the record
* @param {*} event
*/
function killRecord(event){
console.log("killRecord");
console.log(event);
document.getElementById(event).remove();
}
/**
* Function to bring the record forward
* @param {*} event
*/
function pullRecord(event){
console.log("pullRecord");
console.log(event);
document.getElementById(event).style.zIndex++;
}
/**
* Function to bring the record back
* @param {*} event
*/
function pushRecord(event){
console.log("pushRecord");
console.log(event);
document.getElementById(event).style.zIndex--;
}
/**
* Function to bring the record forward
* @param {*} event
*/
function moreRecord(event){
console.log("pullRecord");
console.log(event);
let widthValue= parseInt(document.getElementById(event).children[0].style.width);
document.getElementById(event).children[0].style.width = (widthValue+1)+"rem";
}
/**
* Function to bring the record back
* @param {*} event
*/
function lessRecord(event){
console.log("pullRecord");
console.log(event);
let widthValue= parseInt(document.getElementById(event).children[0].style.width);
document.getElementById(event).children[0].style.width = (widthValue-1)+"rem";
}
/**
* Function to bring the record forward
* @param {*} event
*/
function URecord(event){
console.log("pullRecord");
console.log(event);
if(document.getElementById(event).classList.contains("moving")){
let widthValue= parseInt(document.getElementById(event).style.top);
document.getElementById(event).style.top = (widthValue-convertRemToPixels(1))+"px";
}
}
/**
* Function to bring the record back
* @param {*} event
*/
function DRecord(event){
console.log("pullRecord");
console.log(event);
if(document.getElementById(event).classList.contains("moving")){
let widthValue= parseInt(document.getElementById(event).style.top);
document.getElementById(event).style.top = (widthValue+convertRemToPixels(1))+"px";
}
}
/**
* Function to bring the record forward
* @param {*} event
*/
function LRecord(event){
console.log("pullRecord");
console.log(event);
if(document.getElementById(event).classList.contains("moving")){
let widthValue= parseInt(document.getElementById(event).style.left);
document.getElementById(event).style.left = (widthValue-convertRemToPixels(1))+"px";
}
}
/**
* Function to bring the record back
* @param {*} event
*/
function RRecord(event){
console.log("pullRecord");
console.log(event);
if(document.getElementById(event).classList.contains("moving")){
let widthValue= parseInt(document.getElementById(event).style.left);
document.getElementById(event).style.left = (widthValue+convertRemToPixels(1))+"px";
}
}
/**
* Helper function to convert to pixels
* @param rem
* @returns
*/
function convertRemToPixels(rem) {
return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
}