diff --git a/Netdisco/lib/Netdisco.pm b/Netdisco/lib/Netdisco.pm index af5c498a..df775a0b 100644 --- a/Netdisco/lib/Netdisco.pm +++ b/Netdisco/lib/Netdisco.pm @@ -43,6 +43,14 @@ get '/search' => sub { params->{'vendor'} = 'checked'; } + # list of tabs + var('tabs' => [ + { id => 'device', label => 'Device' }, + { id => 'node', label => 'Node' }, + { id => 'vlan', label => 'VLAN' }, + { id => 'port', label => 'Port' }, + ]); + template 'search'; }; diff --git a/Netdisco/views/inc/js/search.js b/Netdisco/views/inc/js/search.js new file mode 100644 index 00000000..03e519fd --- /dev/null +++ b/Netdisco/views/inc/js/search.js @@ -0,0 +1,67 @@ + $(document).ready(function() { + // parameterised for the active tab - submits search form and injects + // HTML response into the tab pane, or an error/empty-results message + function do_search (event, tab) { + var form = '#' + tab + '_form'; + var target = '#' + tab + '_pane'; + + // stop form from submitting normally + event.preventDefault(); + + // get the form params + var query = $(form).serialize(); + + // in case of slow data load, let the user know + $(target).html( + '

Waiting for results...

' + ); + + // submit the query and put results into the tab pane + $(target).load( '/ajax/content/search/' + tab + '?' + query, + function(response, status, xhr) { + if (status !== "success") { + $(target).html( + '
' + + '

Search failed! Please contact your site administrator.

' + ); + return; + } + if (response === "") { + $(target).html( + '

No matching records.

' + ); + return; + } + } + ); + } + + // search hook for each tab + [% FOREACH tab IN vars.tabs %] + $('[% "#${tab.id}_form" %]').submit(function(event){ do_search(event, '[% tab.id %]'); }); + [% END %] + + // on page load, load the content for the active tab + [% IF params.tab %] + $('#[% params.tab %]_form').trigger("submit"); + [% END %] + + // on tab change, hide previous tab's search form and show new tab's + // search form. also trigger to load the content for the newly active tab. + $('#search_results').bind('change', function(e) { + var to = $(e.target).attr('href').replace(/^#/,"").replace(/_pane$/,""); + var from = $(e.relatedTarget).attr('href').replace(/^#/,"").replace(/_pane$/,""); + + $('#' + from + '_search').toggleClass('active'); + $('#' + to + '_search').toggleClass('active'); + + $('#' + to + '_form').trigger("submit"); + }); + + // fix green background on search checkboxes + // https://github.com/twitter/bootstrap/issues/742 + syncCheckBox = function() { + $(this).parents('.add-on').toggleClass('active', $(this).is(':checked')); + }; + $('.add-on :checkbox').each(syncCheckBox).click(syncCheckBox); + }); diff --git a/Netdisco/views/inc/search/device.tt b/Netdisco/views/inc/search/device.tt new file mode 100644 index 00000000..1b70da49 --- /dev/null +++ b/Netdisco/views/inc/search/device.tt @@ -0,0 +1,12 @@ + diff --git a/Netdisco/views/inc/search/node.tt b/Netdisco/views/inc/search/node.tt new file mode 100644 index 00000000..149b762e --- /dev/null +++ b/Netdisco/views/inc/search/node.tt @@ -0,0 +1,36 @@ + diff --git a/Netdisco/views/inc/search/port.tt b/Netdisco/views/inc/search/port.tt new file mode 100644 index 00000000..0a828721 --- /dev/null +++ b/Netdisco/views/inc/search/port.tt @@ -0,0 +1,11 @@ + diff --git a/Netdisco/views/inc/search/vlan.tt b/Netdisco/views/inc/search/vlan.tt new file mode 100644 index 00000000..30e70115 --- /dev/null +++ b/Netdisco/views/inc/search/vlan.tt @@ -0,0 +1,11 @@ + diff --git a/Netdisco/views/search.tt b/Netdisco/views/search.tt index 12cf6336..a5d1628a 100644 --- a/Netdisco/views/search.tt +++ b/Netdisco/views/search.tt @@ -2,156 +2,27 @@
-
-

Waiting for results...

-
-
-

Waiting for results...

-
-
-

Waiting for results...

-
-
-

Waiting for results...

-
+ [% FOREACH tab IN vars.tabs %] +
+ [% END %]
- diff --git a/README b/README deleted file mode 100644 index e69de29b..00000000