## -*- coding: utf-8 -*-
##
## CDDL HEADER START
##
## The contents of this file are subject to the terms of the
## Common Development and Distribution License (the "License").
## You may not use this file except in compliance with the License.
##
## You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
## or http://www.opensolaris.org/os/licensing.
## See the License for the specific language governing permissions
## and limitations under the License.
##
## When distributing Covered Code, include this CDDL HEADER in each
## file and include the License file at usr/src/OPENSOLARIS.LICENSE.
## If applicable, add the following below this CDDL HEADER, with the
## fields enclosed by brackets "[]" replaced with your own identifying
## information: Portions Copyright [yyyy] [name of copyright owner]
##
## CDDL HEADER END
##
## Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
## Use is subject to license terms.
##
<%!
        import urllib

        fmri_ops = {
            'info': "Info",
            'manifest': "Manifest"
        }
%>\
<%inherit file="layout.shtml"/>\
<%page args="g_vars"/>\
<%
        catalog = g_vars["catalog"]
        request = g_vars["request"]
%>\
<%def name="page_title(g_vars)"><%
        return "Package Search"
%></%def>\
<div id="yui-main">
% if not catalog.search_available:
        <div class="yui-b">
                <p>Search functionality is not available at this time.</p>
        </div>
% else:
<%
        token_val = request.params.get("token", "")
        searched = False
        if len(token_val):
                searched = True
%>\
        <div class="yui-b">
                <form action="search.shtml">
                        <p>
                                <input id="search-field" type="text" size="30"
                                    maxlength="512" name="token"
                                    value="${token_val | h}"/>
                                <input id="submit-search" type="submit"
                                    name="action" value="Search"/>
                        </p>
%       if not searched:
                        <p>Search Tips:</p>
                        <ul class="tips">
                                <li>All searches are case-insensitive.</li>
                                <li>To find packages that contain a specific
file, start your search criteria with a '/':<br/>
<kbd>/usr/bin/vim</kbd></li>
                                <li>To find packages based on a partial match,
use the wildcard characters '*' or '?':<br/>
<kbd>*.xhtm?</kbd></li>
                                <li>To find packages based on specific
matching characters use '[' and ']':<br/>
<kbd>/usr/bin/[ca]t</kbd></li>
                        </ul>
%       endif
                </form>
        </div>
        <div class="yui-b results">
<%
        rclass = None
        results = None
        result_count = 0
        max_results = 100
        if searched:
                results = catalog.search(token_val)
%>\
%       if searched and results:
%               for v, return_type, vals in results:
<%
                                pfmri = vals
%>
			        ## Only print row for first result.  Can't do this
			        ## before now since results is a generator.
%                               if rclass is None:
                <table summary="A list of packages from the repository catalog
 that matched the specified search criteria.">
                        <tr class="first">
                                <th>Package</th>
                        </tr>
%                               endif
<%
                                result_count += 1
                                if rclass is None or rclass == ' class="odd"':
                                        rclass = ""
                                else:
                                        rclass = ' class="odd"'

                                phref = self.shared.rpath(g_vars, "info/0/%s" % (
                                    urllib.quote(pfmri, ""))) 
%>\
                        <tr${rclass} >
                                <td><a href="${phref}">${pfmri}</a></td>
                        </tr>
%                               if result_count > max_results:
                        <tr class="last">
                                <td>More than ${max_results}
record(s) matched your query; the rest will not be shown.  Please refine your
query and try again.</td>
<%
                                        break
%>
                        </tr>
%                               endif
%               else:
%                       if result_count > 0:
                                <tr class="last">
                                        <td>${result_count} record(s) found</td>
                                </tr>
%                               endif
                </table>
%               endfor
%       endif
%       if searched and rclass is None:
                <p>Your search - <b>${token_val | h}</b> - did not match any packages.</p>
                <p>Suggestions:</p>
                <ul>
                        <li>Ensure that all words are spelled correctly.</li>
                        <li>Try different keywords.</li>
                        <li>Try more general keywords.</li>
                </ul>
%       endif
        </div>
% endif
</div>
