Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Luciano Barletta
/
mini-web
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit f873b0cc
authored
2019-11-26 13:38:03 +0000
by
Luciano Barletta
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
all done
1 parent
4c298a5b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
24 deletions
Luciano/static/Scripts/construct.js
Luciano/templates/generate.html
Luciano/static/Scripts/construct.js
View file @
f873b0c
...
...
@@ -12,6 +12,16 @@ var getAncestorByAttribute = (elem,attr,val) => {
return
elem
;
}
var
getDescendantByAttribute
=
(
elem
,
attr
,
val
)
=>
{
if
(
elem
.
getAttribute
(
attr
)
==
val
)
return
elem
;
Array
.
from
(
elem
.
children
).
reduce
(
(
a
,
b
)
=>
{
let
x
=
getDescendantByAttribute
(
a
,
attr
,
val
);
let
y
=
getDescendantByAttribute
(
b
,
attr
,
val
);
return
x
==
null
?
x
:
y
;
});
return
null
;
}
/**
* Armado de formulario
*/
...
...
@@ -20,7 +30,7 @@ function removeTab(button){
tabs
.
removeChild
(
getAncestorByAttribute
(
button
,
'name'
,
'Tab'
)
)
if
(
tabs
.
childElementCount
>
0
){
if
(
tabs
.
childElementCount
==
0
){
document
.
getElementById
(
"ContinuarText"
).
style
.
display
=
'none'
;
document
.
getElementById
(
"ContinuarButton"
).
style
.
display
=
'none'
;
}
...
...
@@ -32,9 +42,9 @@ function addField(b,n){
newfield
.
innerHTML
=
document
.
getElementById
(
"fieldTemplate"
).
innerHTML
;
accessNumber
(
newfield
).
setAttribute
(
"value"
,
n
);
// swap
let
tab
=
b
.
parentElement
;
tab
.
appendChild
(
newfield
);
tab
.
appendChild
(
b
);
let
container
=
b
.
parentElement
;
container
.
appendChild
(
newfield
);
container
.
appendChild
(
b
);
}
function
addTab
(
t
,
n
){
...
...
@@ -79,18 +89,21 @@ function generate(tabs){
}
function
sortChildren
(
container
,
number
){
fixparse
let
fixinput
=
a
=>
number
(
a
).
nodeName
==
"INPUT"
&&
number
(
a
).
type
==
"number"
?
parseInt
(
number
(
a
).
value
)
:
Infinity
;
Array
.
from
(
container
.
children
).
sort
(
(
a
,
b
)
=>
number
(
a
).
value
<
number
(
b
).
value
?
-
1
:
number
(
a
).
value
>
number
(
b
).
value
?
1
:
0
(
a
,
b
)
=>
fixinput
(
a
)
<
fixinput
(
b
)
?
-
1
:
fixinput
(
a
)
>
fixinput
(
b
)
?
1
:
0
).
forEach
(
c
=>
tabs
.
appendChild
(
c
)
c
=>
container
.
appendChild
(
c
)
)
}
function
maxChild
(
container
,
number
){
if
(
container
.
childElementCount
==
0
)
return
1
;
let
fixinput
=
a
=>
number
(
a
).
nodeName
==
"INPUT"
&&
number
(
a
).
type
==
"number"
?
parseInt
(
number
(
a
).
value
)
:
0
;
if
(
container
.
childElementCount
==
0
)
return
0
;
let
max
=
Array
.
from
(
container
.
children
).
reduce
(
(
a
,
b
)
=>
number
(
a
).
value
>
number
(
b
).
value
?
a
:
b
(
a
,
b
)
=>
fixinput
(
a
)
>
fixinput
(
b
)
?
a
:
b
)
return
parseInt
(
number
(
max
).
value
)
==
NaN
?
1
:
parseInt
(
number
(
max
).
value
)
+
1
;
return
fixinput
(
max
)
;
}
\ No newline at end of file
Luciano/templates/generate.html
View file @
f873b0c
...
...
@@ -19,10 +19,7 @@
<div
id=
"tabs"
></div>
<div
style=
"text-align: center;"
>
<button
class=
"NewTabButton"
onclick=
"addTab(
document.getElementById('tabs'),
maxChild(document.getElementById('tabs'),accessNumber)
)"
>
onclick=
"let t = document.getElementById('tabs'); addTab(t, maxChild(t, accessNumber) + 1)"
>
+
</button>
</div>
...
...
@@ -33,7 +30,8 @@
<!-- templates -->
<template
id=
"tabTemplate"
>
<div
class=
"TabCards"
>
<input
type=
"number"
class=
"TabNumber"
onchange=
"sortChildren(document.getElementById('tabs'),accessNumber)"
>
<input
type=
"number"
class=
"TabNumber"
onchange=
"sortChildren(getAncestorByAttribute(this,'name','Tab').parentElement, accessNumber)"
>
<input
class=
"TabTitle"
placeholder=
"Titulo del Tab"
type=
"text"
>
<button
class=
"RemoveTabButton"
onclick=
"removeTab(this)"
>
X
...
...
@@ -41,10 +39,7 @@
<br>
<div
style=
"text-align: center;"
>
<button
class=
"NewInputButton"
onclick=
"addField(
this,
maxChild(getAncestorByAttribute(this,'name','Tab'),accessNumber)
)"
>
onclick=
"addField(this, maxChild(this.parentElement,accessNumber) + 1)"
>
+
</button>
</div>
...
...
@@ -55,10 +50,7 @@
<div
class=
"InputContainer"
>
<input
type=
"number"
class=
"InputNumber"
onchange=
"sortChildren(
getAncestorByAttribute(this,'name','Tab'),
accessNumber
)"
>
onchange=
"sortChildren(getAncestorByAttribute(this,'name','Field').parentElement, accessNumber)"
>
<input
type=
"text"
id=
"Titulo"
class=
"Input"
placeholder=
"Título"
>
<select
name=
"input"
class=
"Input"
>
...
...
@@ -74,7 +66,7 @@
</select>
Obligatorio :
<input
type=
"checkbox"
>
<button
class=
"RemoveInputButton"
onclick=
"
getAncestorByAttribute(this,'name','Tab').removeChild(getAncestorByAttribute(this,'name','Field')
)"
>
onclick=
"
let f = getAncestorByAttribute(this,'name','Field'); f.parentElement.removeChild(f
)"
>
-
</button>
</div>
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment