Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cto
g1
Commits
3ce7c219
Commit
3ce7c219
authored
Mar 14, 2019
by
Tejesh
🖖
Browse files
ENH: link:false in a column should disable the link, fixes
#133
parent
9bcf5d40
Pipeline
#79490
passed with stage
in 2 minutes and 27 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/formhandler.template.html
View file @
3ce7c219
...
...
@@ -144,27 +144,34 @@ Each template receives these variables:
val
,
col_link
%
>
<
%
if
(!
isEdit
&&
'
link
'
in
colinfo
)
var
col_link =
typeof
colinfo.link =
=
'
function
'
?
colinfo.link
({
name:
colinfo.name
,
value:
val
,
format:
disp
,
index:
rowIndex
,
row:
row
,
data:
data
})
:
_.template
(
colinfo.link
)({
name:
colinfo.name
,
value:
val
,
format:
disp
,
index:
rowIndex
,
row:
row
,
data:
data
})
%
>
<
%
if
(
colinfo.template
)
{
%
>
<
%=
typeof
colinfo.template =
=
'
function
'
?
colinfo.template
({
name:
colinfo.name
,
value:
val
,
format:
disp
,
link:
col_link
,
index:
rowIndex
,
row:
row
,
data:
data
})
:
_.template
(
colinfo.template
)(({
name:
colinfo.name
,
value:
val
,
format:
disp
,
link:
col_link
,
index:
rowIndex
,
row:
row
,
data:
data
}))
%
>
<
%
}
else
if
(
col_link
)
{
%
>
<td>
<a
href=
"<%- col_link %>"
target=
"_blank"
>
<
%=
disp
%
>
</a>
</td>
<
%
if
(!
isEdit
&&
colinfo.template
)
{
%
>
<
%=
typeof
colinfo.template =
=
'
function
'
?
colinfo.template
({
name:
colinfo.name
,
value:
val
,
format:
disp
,
link:
col_link
,
index:
rowIndex
,
row:
row
,
data:
data
})
:
_.template
(
colinfo.template
)(({
name:
colinfo.name
,
value:
val
,
format:
disp
,
link:
col_link
,
index:
rowIndex
,
row:
row
,
data:
data
}))
%
>
<
%
}
else
if
(!
isEdit
&&
'
link
'
in
colinfo
)
{
%
>
<
%
col_link =
typeof
colinfo.link =
=
'
function
'
?
colinfo.link
({
name:
colinfo.name
,
value:
val
,
format:
disp
,
index:
rowIndex
,
row:
row
,
data:
data
})
:
(
typeof
colinfo.link =
=
'
string
'
?
_.template
(
colinfo.link
)({
name:
colinfo.name
,
value:
val
,
format:
disp
,
index:
rowIndex
,
row:
row
,
data:
data
})
:
colinfo.link
)
%
>
<
%
if
(col_link =
==
false
)
{
%
>
<td><
%=
disp
%
></td>
<
%
}
else
if
(
col_link
&&
col_link[0] =
=
'?')
{
%
>
<td><a
class=
"urlfilter"
href=
"<%- col_link %>"
><
%=
disp
%
></a></td>
<
%
}
else
{
%
>
<td><a
href=
"<%- col_link %>"
target=
"_blank"
><
%=
disp
%
></a></td>
<
%
}
%
>
<
%
}
else
if
(
isEdit
&&
isEditable
)
{
%
>
<td
data-key=
"<%- colinfo.name %>"
>
<
%=
_.template
(
templates
['
template_editable
'])({
isEditable:
isEditable
,
val:
val
})
%
>
</td>
<
%
}
else
{
%
>
<td>
<a
class=
"urlfilter"
href=
"?<%- encodeURIComponent(colinfo.name) %>=<%- encodeURIComponent(val) %>&_offset="
>
<
%=
disp
%
>
</a>
</td>
<td>
<a
class=
"urlfilter"
href=
"?<%- encodeURIComponent(colinfo.name) %>=<%- encodeURIComponent(val) %>&_offset="
>
<
%=
disp
%
>
</a>
</td>
<
%
}
%
>
<
%
})
%
>
</tr>
...
...
@@ -397,12 +404,12 @@ Each template receives these variables:
colinfo.link
({
row:
row
,
value:
val
,
index:
rowIndex
,
name:
colinfo.name
,
data:
data
,
format:
disp
})
:
_.template
(
colinfo.link
)({
row:
row
,
value:
val
,
index:
rowIndex
,
name:
colinfo.name
,
data:
data
,
format:
disp
})
%
>
<
%
if
(col_link =
==
false
)
{
%
>
<
%=
disp
%
>
<
%
}
else
if
(
col_link
&&
col_link[0] =
=
'?')
{
%
>
<a
class=
"urlfilter"
href=
"<%- col_link %>"
><
%=
disp
%
></a>
<
%
}
else
{
%
>
<a
href=
"<%- col_link %>"
target=
"_blank"
><
%=
disp
%
></a>
<
%
}
%
>
<
%=
disp
%
>
<
%
}
else
if
(
col_link
&&
col_link[0] =
=
'?')
{
%
>
<a
class=
"urlfilter"
href=
"<%- col_link %>"
><
%=
disp
%
></a>
<
%
}
else
{
%
>
<a
href=
"<%- col_link %>"
target=
"_blank"
><
%=
disp
%
></a>
<
%
}
%
>
<
%
}
else
{
%
>
<a
class=
"urlfilter"
href=
"?<%- encodeURIComponent(colinfo.name) %>=<%- encodeURIComponent(val) %>&_offset="
>
<
%=
disp
%
>
...
...
test/test-formhandler-unit.html
View file @
3ce7c219
...
...
@@ -34,6 +34,8 @@
</head>
<body>
<div
class=
"no-link"
data-src=
"/formhandler-data"
></div>
<div
class=
"row_template1"
data-src=
"/formhandler-data"
></div>
<div
class=
"delete_btn"
data-src=
"/formhandler-data"
></div>
<div
class=
"test-star-without-title"
data-src=
"/formhandler-data"
></div>
<div
class=
"test-star-with-title"
data-src=
"/formhandler-data"
></div>
...
...
@@ -43,10 +45,51 @@
<div
class=
"row_template4"
data-src=
"/formhandler-data"
></div>
<div
class=
"row_template3"
data-src=
"/formhandler-data"
></div>
<div
class=
"row_template2"
data-src=
"/formhandler-data"
></div>
<div
class=
"row_template1"
data-src=
"/formhandler-data"
></div>
<script>
tape
(
'
$() test link false renders just td tag, without a tag
'
,
function
(
t
)
{
$
(
'
.no-link
'
).
formhandler
({
columns
:
[
{
name
:
'
*
'
},
{
name
:
'
Continent
'
,
link
:
'
?ID=AND
'
,
},
{
name
:
'
ID
'
,
link
:
false
,
editable
:
false
},
{
name
:
'
Stripes
'
,
editable
:
{
input
:
'
select
'
,
// renders a default select dropdown as
<
select
class
=
"
form-control form-control-sm
"
>
...
<
/select
>
options
:
[
// `options` is mandatory because `input` is "select"
'
Vertical
'
,
'
Horizontal
'
,
'
Diagonal
'
]
}
}
],
pageSize
:
3
,
onhashchange
:
false
,
add
:
true
,
edit
:
true
})
.
on
(
'
load
'
,
function
()
{
t
.
equals
(
$
(
'
div.no-link tr:nth-child(1) > td:nth-child(3)
'
).
text
(),
"
AND
"
)
t
.
equals
(
$
(
'
div.no-link tr:nth-child(2) > td:nth-child(3)
'
).
text
(),
"
ARE
"
)
t
.
ok
(
$
(
'
div.no-link tr:nth-child(1) > td:nth-child(1) a
'
).
hasClass
(
'
urlfilter
'
),
'
has class urlfilter
'
)
t
.
ok
(
$
(
'
div.no-link tr:nth-child(1) > td:nth-child(1) a
'
).
attr
(
'
href
'
),
'
?ID=AND
'
)
t
.
end
()
})
})
tape
(
'
$() test delete action for empty data case and test for edit and add button
'
,
function
(
t
)
{
$
(
'
.delete_btn
'
).
formhandler
({
columns
:
[
...
...
@@ -88,9 +131,9 @@
$
(
'
.add-btn
'
).
click
()
t
.
ok
(
$
(
'
.edit-btn
'
).
prop
(
'
disabled
'
))
// stripes column is dropdown select HTML element and not input textbox
t
.
equals
(
$
(
'
div.
formhandler
tr.new-row td:nth-child(6) select
'
).
length
,
1
)
t
.
equals
(
$
(
'
div.
delete_btn
tr.new-row td:nth-child(6) select
'
).
length
,
1
)
// all other columns must be input textbox and editable, overriding isEditable: false option also
t
.
equals
(
$
(
'
div.
formhandler
tr.new-row td:nth-child(1) input
'
).
length
,
1
)
t
.
equals
(
$
(
'
div.
delete_btn
tr.new-row td:nth-child(1) input
'
).
length
,
1
)
$
(
'
.add-btn
'
).
click
()
// on empty row click, .new-row element does not exist
t
.
equals
(
$
(
'
.new-row
'
,
$
(
'
.delete_btn
'
)).
length
,
0
)
...
...
@@ -148,6 +191,7 @@
t
.
equals
(
$
(
'
body > div.row_template1 > div.position-relative > div.formhandler > div.table > table > tbody > tr:nth-child(
'
+
(
index
+
1
)
+
'
) > td:nth-child(3)
'
).
text
(),
''
+
result
[
index
][
'
c2
'
])
t
.
equals
(
$
(
'
body > div.row_template1 > div.position-relative > div.formhandler > div.table > table > tbody > tr:nth-child(
'
+
(
index
+
1
)
+
'
) > td:nth-child(4)
'
).
text
(),
''
+
result
[
index
][
'
Continent
'
])
}
console
.
log
(
"
$$$$$$$$$$$$$$$$$$$$$$$
"
)
t
.
end
()
});
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment