Commit 3ce7c219 authored by Tejesh's avatar 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
...@@ -144,27 +144,34 @@ Each template receives these variables: ...@@ -144,27 +144,34 @@ Each template receives these variables:
val, val,
col_link 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 (!isEdit && colinfo.template) { %>
<% if (colinfo.template) { %> <%= typeof colinfo.template == 'function' ?
<%= 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})) %> colinfo.template({name: colinfo.name, value: val, format: disp, link: col_link, index: rowIndex, row: row, data: data}) :
<% } else if (col_link) { %> _.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) { %>
<td> <% col_link = typeof colinfo.link == 'function' ?
<a href="<%- col_link %>" target="_blank"> colinfo.link({name: colinfo.name, value: val, format: disp, index: rowIndex, row: row, data: data}) :
<%= disp %> (typeof colinfo.link == 'string' ?
</a> _.template(colinfo.link)({name: colinfo.name, value: val, format: disp, index: rowIndex, row: row, data: data})
</td> : 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) { %> <% } else if (isEdit && isEditable) { %>
<td data-key="<%- colinfo.name %>"> <td data-key="<%- colinfo.name %>">
<%= _.template(templates['template_editable'])({isEditable: isEditable, val: val}) %> <%= _.template(templates['template_editable'])({isEditable: isEditable, val: val}) %>
</td> </td>
<% } else { %> <% } else { %>
<td> <td>
<a class="urlfilter" href="?<%- encodeURIComponent(colinfo.name) %>=<%- encodeURIComponent(val) %>&amp;_offset="> <a class="urlfilter" href="?<%- encodeURIComponent(colinfo.name) %>=<%- encodeURIComponent(val) %>&amp;_offset=">
<%= disp %> <%= disp %>
</a> </a>
</td> </td>
<% } %> <% } %>
<% }) %> <% }) %>
</tr> </tr>
...@@ -397,12 +404,12 @@ Each template receives these variables: ...@@ -397,12 +404,12 @@ Each template receives these variables:
colinfo.link({row: row, value: val, index: rowIndex, name: colinfo.name, data: data, format: disp}) : 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}) %> _.template(colinfo.link)({row: row, value: val, index: rowIndex, name: colinfo.name, data: data, format: disp}) %>
<% if (col_link === false) { %> <% if (col_link === false) { %>
<%= disp %> <%= disp %>
<% } else if (col_link && col_link[0] == '?') { %> <% } else if (col_link && col_link[0] == '?') { %>
<a class="urlfilter" href="<%- col_link %>"><%= disp %></a> <a class="urlfilter" href="<%- col_link %>"><%= disp %></a>
<% } else { %> <% } else { %>
<a href="<%- col_link %>" target="_blank"><%= disp %></a> <a href="<%- col_link %>" target="_blank"><%= disp %></a>
<% } %> <% } %>
<% } else { %> <% } else { %>
<a class="urlfilter" href="?<%- encodeURIComponent(colinfo.name) %>=<%- encodeURIComponent(val) %>&amp;_offset="> <a class="urlfilter" href="?<%- encodeURIComponent(colinfo.name) %>=<%- encodeURIComponent(val) %>&amp;_offset=">
<%= disp %> <%= disp %>
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
</head> </head>
<body> <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="delete_btn" data-src="/formhandler-data"></div>
<div class="test-star-without-title" 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> <div class="test-star-with-title" data-src="/formhandler-data"></div>
...@@ -43,10 +45,51 @@ ...@@ -43,10 +45,51 @@
<div class="row_template4" data-src="/formhandler-data"></div> <div class="row_template4" data-src="/formhandler-data"></div>
<div class="row_template3" 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_template2" data-src="/formhandler-data"></div>
<div class="row_template1" data-src="/formhandler-data"></div>
<script> <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) { tape('$() test delete action for empty data case and test for edit and add button', function(t) {
$('.delete_btn').formhandler({ $('.delete_btn').formhandler({
columns: [ columns: [
...@@ -88,9 +131,9 @@ ...@@ -88,9 +131,9 @@
$('.add-btn').click() $('.add-btn').click()
t.ok($('.edit-btn').prop('disabled')) t.ok($('.edit-btn').prop('disabled'))
// stripes column is dropdown select HTML element and not input textbox // 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 // 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() $('.add-btn').click()
// on empty row click, .new-row element does not exist // on empty row click, .new-row element does not exist
t.equals($('.new-row', $('.delete_btn')).length, 0) t.equals($('.new-row', $('.delete_btn')).length, 0)
...@@ -148,6 +191,7 @@ ...@@ -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(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']) 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() t.end()
}); });
}) })
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment