Skip to content
This repository was archived by the owner on May 3, 2020. It is now read-only.

Commit fe9c493

Browse files
authored
Merge pull request #409 from MaxNad/fix402
Fixed the other search forms (related to #402)
2 parents 6fc5c03 + 46d3810 commit fe9c493

File tree

4 files changed

+35
-38
lines changed

4 files changed

+35
-38
lines changed

public/js/helpers.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
//used to confirm deletion
1+
// Used to search in tables
2+
// credit to http://www.redotheweb.com/2013/05/15/client-side-full-text-search-in-css.html for this
3+
function initSearch() {
4+
var searchBox = document.getElementById('search');
5+
var searchStyle = document.getElementById('search_style');
6+
7+
if (searchBox && searchStyle) {
8+
// If the page loads with a value already present in the tables,
9+
// lets run the search right away
10+
if (searchBox.value) {
11+
searchStyle.innerHTML = ".searchable:not([data-index*=\"" + searchBox.value.toLowerCase().replace(/</g, '&lt;').replace(/>/g, '&rt;').replace(/"/g, '&quot;') + "\"]) { display: none; }";
12+
}
13+
14+
searchBox.addEventListener('input', function() {
15+
if (!this.value) {
16+
searchStyle.innerHTML = "";
17+
return;
18+
}
19+
searchStyle.innerHTML = ".searchable:not([data-index*=\"" + this.value.toLowerCase().replace(/</g, '&lt;').replace(/>/g, '&rt;').replace(/"/g, '&quot;') + "\"]) { display: none; }";
20+
});
21+
}
22+
}
23+
24+
$(document).ready(function(){
25+
initSearch();
26+
});
27+
28+
// Used to confirm deletion
229
function confirmDelete(evt) {
330
if (!confirm('Are you sure you want to permanently delete the selected element(s) ?')) {
431
evt.preventDefault();

views/findings_add.haml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@
1414
%input.form-control#search{ :type => "text", :placeholder => "Finding Name Search" }
1515
%style#search_style
1616
%span.input-group-btn
17-
%script{ :type => "text/javascript" }
18-
// credit to http://www.redotheweb.com/2013/05/15/client-side-full-text-search-in-css.html for this
19-
var searchStyle = document.getElementById('search_style');
20-
document.getElementById('search').addEventListener('input', function() {
21-
if (!this.value) {
22-
searchStyle.innerHTML = "";
23-
return;
24-
}
25-
searchStyle.innerHTML = ".searchable:not([data-index*=\"" + this.value.toLowerCase().replace(/</g, '&rt;').replace(/>/g, '&lt;').replace(/"/g, '&quot;') + "\"]) { display: none; }";
26-
});
2717
%form.form-inline{ :method => "post", :action => "/report/#{@report.id}/findings_add" }
2818
.table
2919
%table{ :style => "width: 90%" }
@@ -45,7 +35,7 @@
4535
- @findings.each do |finding|
4636
- if finding.type == type
4737
%tr
48-
%td.searchable{ :style => "width: 80%", :"data-index" => "#{finding.title.downcase.gsub(' ','')}" }
38+
%td.searchable{ :style => "width: 80%", :"data-index" => "#{finding.title.downcase}" }
4939
- if @autoadd
5040
- if @autoadd_findings.include?(finding.id.to_s) and not @dup_findings.include?(finding.id)
5141
%input{ :id => "finding_#{finding.id}", :type => "checkbox", :name => "finding[]", :value => "#{finding.id}", :checked => "" }
@@ -69,7 +59,7 @@
6959
.label.label-default #{ip}
7060
- iplist = @autoadd_hosts[x].join(",")
7161
%input{ :type => "hidden", :name => "finding#{finding.id.to_s}", :value => "#{iplist}" }
72-
%td.searchable{ :style => "width: 20%", :"data-index" => "#{finding.title.downcase.gsub(' ','')}" }
62+
%td.searchable{ :style => "width: 20%", :"data-index" => "#{finding.title.downcase}" }
7363
- if @master
7464
%a.btn.btn-warning{ :href => "/master/findings/#{finding.id}/edit" }
7565
%i.icon-pencil.icon-white{ :title => "Edit" }

views/findings_list.haml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@
3333
%br
3434
%style#search_style
3535
%span.input-group-btn
36-
%script{ :type=>"text/javascript" }
37-
// credit to http://www.redotheweb.com/2013/05/15/client-side-full-text-search-in-css.html for this
38-
var searchStyle = document.getElementById('search_style');
39-
document.getElementById('search').addEventListener('input', function() {
40-
if (!this.value) {
41-
searchStyle.innerHTML = "";
42-
return;
43-
}
44-
searchStyle.innerHTML = ".searchable:not([data-index*=\"" + this.value.toLowerCase().replace(/</g, '&lt;').replace(/>/g, '&rt;').replace(/"/g, '&quot;') + "\"]) { display: none; }";
45-
});
4636
&nbsp;
4737
- settings.finding_types.each do |type|
4838
%tr

views/reports_list.haml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@
77
%input.form-control#search{ :type => "text", :placeholder => "Report Name Search" }
88
%style#search_style
99
%span.input-group-btn
10-
%script{ :type=>"text/javascript" }
11-
// credit to http://www.redotheweb.com/2013/05/15/client-side-full-text-search-in-css.html for this
12-
var searchStyle = document.getElementById('search_style');
13-
document.getElementById('search').addEventListener('input', function() {
14-
if (!this.value) {
15-
searchStyle.innerHTML = "";
16-
return;
17-
}
18-
searchStyle.innerHTML = ".searchable:not([data-index*=\"" + this.value.toLowerCase().replace(/</g, '&lt;').replace(/>/g, '&rt;').replace(/"/g, '&quot;') + "\"]) { display: none; }";
19-
});
2010
%br
2111
%br
2212
%a.btn.btn-danger#deletemultiple{ :href => "/report/remove/" }
@@ -36,15 +26,15 @@
3626
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Actions
3727
- @reports.each do |report|
3828
%tr
39-
%td.searchable{ :"data-index" => "#{report.report_name.downcase.gsub(' ','')}" }
29+
%td.searchable{ :"data-index" => "#{report.report_name.downcase}" }
4030
%input.checkbox{ :type => "checkbox", :name => "#{report.id}" }
41-
%td.searchable{ :style => "width: 70%", :"data-index" => "#{report.report_name.downcase.gsub(' ','')}" }
31+
%td.searchable{ :style => "width: 70%", :"data-index" => "#{report.report_name.downcase}" }
4232
#{report.report_name}
43-
%td.searchable{ :style => "width: 10%", :"data-index" => "#{report.report_name.downcase.gsub(' ','')}" }
33+
%td.searchable{ :style => "width: 10%", :"data-index" => "#{report.report_name.downcase}" }
4434
#{report.full_company_name}
45-
%td.searchable{ :style => "width: 10%", :"data-index" => "#{report.report_name.downcase.gsub(' ','')}" }
35+
%td.searchable{ :style => "width: 10%", :"data-index" => "#{report.report_name.downcase}" }
4636
#{report.owner}
47-
%td.searchable{ :style => "width: 20%", :"data-index" => "#{report.report_name.downcase.gsub(' ','')}" }
37+
%td.searchable{ :style => "width: 20%", :"data-index" => "#{report.report_name.downcase}" }
4838
- if @master
4939
%a.btn.btn-warning{ :href => "/master/reports/#{finding.id}" }
5040
%i.icon-pencil.icon-white{ :title => "Edit" }

0 commit comments

Comments
 (0)