diff --git a/media/css/seahub.css b/media/css/seahub.css index 59ee95ec17..54262896d1 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -90,6 +90,7 @@ button { } input[type=radio] { height:auto; + border:0;/*for ie*/ } input::-webkit-outer-spin-button, input::-webkit-inner-spin-button {/*for input type="number" in chrome: to hide up/download arrow*/ @@ -2222,13 +2223,13 @@ textarea:-moz-placeholder {/* for FF */ } /* search */ -.search-form { +.search-form, +#search-form .input_and_submit { padding-left:5px; height:24px; border:1px solid #ddd; border-radius:3px; background:#fff; - /*overflow:hidden;for some chromium*/ position:relative; } #top-search-form { @@ -2250,25 +2251,46 @@ textarea:-moz-placeholder {/* for FF */ cursor:pointer; line-height:24px; } -.search-scales { +#advanced-search-form { position:absolute; - padding:2px 0; + width:500px; + padding:18px; + height:auto; font-weight:normal; - background:#fff; + box-shadow:0 0 10px #ddd; + z-index:100;/* for pages with jquery tabs*/ +} +#advanced-search-form .search-input { + width:98%; + padding:0 3px; border:1px solid #ddd; border-radius:3px; - box-shadow:0 0 10px #ddd; +} +#advanced-search-form .submit { + margin-bottom:0; +} +.search-scales { + margin-top:8px; } .search-scales .item { - padding:2px 6px; + width:48%; } -.search-scales .item-hover { - color:#fff; - background:#666; - cursor:pointer; +.search-repos { + border-bottom:1px dotted #ddd; + margin-bottom:3px; } -.search-scales [class^="icon-"] { - margin-right:5px; +.custom-ftype-options { + font-size:13px; + padding:2px 0; + background:#fafafa; +} +.custom-ftype-options .checkbox-label { + display:inline-block; + margin:0 10px 0 0; +} +.custom-ftype-options .fileext-input { + padding:0 3px; + width:70%; } .search-form .search-submit { width:30px; @@ -2279,17 +2301,26 @@ textarea:-moz-placeholder {/* for FF */ color:#aaa; } #search-form { + padding:7px 5px; + height:auto; + background:#f7f7f8; + border:0; + border-radius:2px; +} +#search-form .input_and_submit { + display:inline-block; width:426px; *width:430px; } +#search-form .advanced-search { + color:#666; + font-size:16px; + cursor:pointer; + margin-left:4px; +} #search-form .search-input { width:392px; } -#search-form-container { - padding:7px 5px; - background:#f7f7f8; - border-radius:2px; -} #search-results { padding-top:15px; } diff --git a/media/js/base.js b/media/js/base.js index 8d1eb1a643..214d9ec773 100644 --- a/media/js/base.js +++ b/media/js/base.js @@ -362,3 +362,15 @@ function disable(btn) { function enable(btn) { btn.removeAttr('disabled').removeClass('btn-disabled'); } + +// for browsers don't support array.indexOf +if (!Array.indexOf) { + Array.prototype.indexOf = function(obj){ + for(var i = 0; i < this.length; i++){ + if(this[i] == obj){ + return i; + } + } + return -1; + } +} diff --git a/seahub/templates/base.html b/seahub/templates/base.html index 1c2ab43d3a..c34e9318f7 100644 --- a/seahub/templates/base.html +++ b/seahub/templates/base.html @@ -71,24 +71,61 @@ {% if enable_file_search and request.user.is_authenticated %}
- - {% if search_repo_id %} - + + + {% else %} + {% endif %} - -
+ {# ftype value should be the same with utils/file_types.py #} + + + + + + + + + +
+ +

{% trans "Please select at least 1 file type or input at least 1 file extension" %}

+ + + {% endif %} @@ -204,40 +241,41 @@ $(document).ready(function(){ }); {% if enable_file_search %} -$('#top-search-form .icon-caret-down').click(function() { - var form = $(this).parent(); - form.find('.search-scales').css({'right':form.find('.search-submit').outerWidth(true), 'top':form.outerHeight()}).toggleClass('hide'); +// search-form: top-search-form, advanced-search-form, search-form in search result page +$('.search-form').submit(function() { + if (!$.trim($(this).find('.search-input').val())) { + return false; + } }); -$('.search-scales li').hover( - function() { - $(this).addClass('item-hover'); - }, - function() { - $(this).removeClass('item-hover'); +$('#top-search-form .icon-caret-down').click(function() { + var form = $(this).parent(), + q = form.find('[name="q"]').val(), + advanced_form = $('#advanced-search-form'); + $('#header-inner').css({'position':'relative'}); + advanced_form.css({'right': 0, 'top':form.outerHeight(true)}).toggleClass('hide'); + if (!advanced_form.hasClass('hide') && q) { + advanced_form.find('.search-input').val(q); } -).click(function() { - $(this).parent().find('span').attr('class', 'icon-'); - $(this).children('span').attr('class', 'icon-ok'); - if (!pseudo_support) { - $(this).parent().find('span').html(''); - setCon($(this).children('span'), 'icon-', fa_icons); - } - $('#top-search-form [name="scale"]').val($(this).data('value')); - $(this).parent().addClass('hide'); - var search_input = $('#top-search-form .search-input'); - if ($.trim(search_input.val())) { - $('#top-search-form').submit(); - } else { - search_input.attr('placeholder', $(this).text().replace(/^&#x\w+;$/,'')); // replace(...) to rm icon text for some browsers - if (!('placeholder' in document.createElement('input'))) { // for browsers which don't natively support 'placeholder' attr - search_input.attr('value', search_input.attr('placeholder')); - } +}); +$('.search-filetypes .item:first-child').click(function() { + $(this).parents('.search-form').find('.custom-ftype-options').addClass('hide'); +}); +$('.search-filetypes .item:last-child').click(function() { + $(this).parents('.search-form').find('.custom-ftype-options').removeClass('hide'); +}); +$('#advanced-search-form').submit(function() { + if ($('#custom-search-ftypes').attr('checked') && + $('.custom-ftype-options .checkbox-checked').length == 0 && + !$.trim($('.custom-ftype-options .fileext-input').val())) { + $(this).find('.error').removeClass('hide'); + return false; } }); $(document).click(function(e) { var target = e.target || event.srcElement; - if (!$('.search-scales, #top-search-form .icon-caret-down').is(target) && !($('.search-scales').find('*').is(target))) { - $('.search-scales').addClass('hide'); + var popup = $('#advanced-search-form'); + if (!popup.is(target) && !popup.find('*').is(target) && !$('#top-search-form .icon-caret-down').is(target)) { + popup.addClass('hide'); } }); {% endif %} @@ -282,7 +320,9 @@ $(document).click(function(e) { {'name':'star', 'con':'f005'}, {'name':'star-empty', 'con':'f006'}, {'name':'caret-down', 'con':'f0d7'}, - {'name':'ok', 'con':'f00c'} + {'name':'ok', 'con':'f00c'}, + {'name':'double-angle-up', 'con':'f102'}, + {'name':'double-angle-down', 'con':'f103'} ]; function setCon(icon, icon_class_prefix, icon_list) { for (var i = 0, len = icon_list.length; i < len; i++) { diff --git a/seahub/templates/search_results.html b/seahub/templates/search_results.html index 22a33a1c4f..01a1879240 100644 --- a/seahub/templates/search_results.html +++ b/seahub/templates/search_results.html @@ -4,26 +4,20 @@ {% load url from future %} {% block right_panel %} -
-
+ +
- -
+
+ +
+ {% if not error %} {% if not results %} -

{% trans 'No result found' %} - {% if repo %} - {% trans 'in repo' %} {{ repo.name }} - {% endif %} -

+

{% trans 'No result found' %}

{% else %} -

{% blocktrans count counter=total %}{{ total }} result{% plural %}{{ total }} results{% endblocktrans%} - {% if repo %} - {% trans 'found in repo' %} {{ repo.name }} - {% endif %} -

+

{% blocktrans count counter=total %}{{ total }} result{% plural %}{{ total }} results{% endblocktrans%}

{% endif %} {% endif %} +{% endif %} {% endblock %} +{% block extra_script %} + +{% endblock %} diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index 9e9b4f5857..1cff73f5cf 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -53,7 +53,7 @@ EMPTY_SHA1 = '0000000000000000000000000000000000000000' MAX_INT = 2147483647 PREVIEW_FILEEXT = { - TEXT: ('ac', 'am', 'bat', 'c', 'cc', 'cmake', 'cpp', 'cs', 'css', 'diff', 'el', 'h', 'html', 'htm', 'java', 'js', 'json', 'less', 'make', 'org', 'php', 'pl', 'properties', 'py', 'rb', 'scala', 'script', 'sh', 'sql', 'txt', 'text', 'tex', 'vi', 'vim', 'xhtml', 'xml', 'log', 'csv', 'groovy', 'rst', 'patch', ), + TEXT: ('ac', 'am', 'bat', 'c', 'cc', 'cmake', 'cpp', 'cs', 'css', 'diff', 'el', 'h', 'html', 'htm', 'java', 'js', 'json', 'less', 'make', 'org', 'php', 'pl', 'properties', 'py', 'rb', 'scala', 'script', 'sh', 'sql', 'txt', 'text', 'tex', 'vi', 'vim', 'xhtml', 'xml', 'log', 'csv', 'groovy', 'rst', 'patch'), IMAGE: ('gif', 'jpeg', 'jpg', 'png', 'ico'), DOCUMENT: ('doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx'), SVG: ('svg',), diff --git a/seahub/views/search.py b/seahub/views/search.py index 9170774a80..4eee919e9d 100644 --- a/seahub/views/search.py +++ b/seahub/views/search.py @@ -3,27 +3,41 @@ from django.template import RequestContext from seaserv import get_repo from seahub.auth.decorators import login_required +from seahub.utils import PREVIEW_FILEEXT from seahub.utils.search import search_file_by_name, search_repo_file_by_name - -def parse_suffixes(suffixes): - if not suffixes: - return None - - l = [] - for suffix in suffixes.split(','): - suffix = suffix.strip() - if suffix: - l.append(suffix) - - print l - - return l - @login_required def search(request): - keyword = request.GET['q'] - suffixes = parse_suffixes(request.GET.get('suffixes', None)) + template = 'search_results.html' + error = False + + keyword = request.GET.get('q', None) + if not keyword: + return render_to_response(template, { + 'error': True, + }, context_instance=RequestContext(request)) + + # advanced search + search_repo = request.GET.get('search_repo', None) # val: 'all' or 'search_repo_id' + search_ftypes = request.GET.get('search_ftypes', None) # val: 'all' or 'custom' + custom_ftypes = request.GET.getlist('ftype') # types like 'Image', 'Video'... same in utils/file_types.py + input_fileexts = request.GET.get('input_fexts', '') # file extension input by the user + + suffixes = None + if search_ftypes == 'custom': + suffixes = [] + if len(custom_ftypes) > 0: + for ftp in custom_ftypes: + if PREVIEW_FILEEXT.has_key(ftp): + for ext in PREVIEW_FILEEXT[ftp]: + suffixes.append(ext) + + if input_fileexts: + input_fexts = input_fileexts.split(',') + for i_ext in input_fexts: + i_ext = i_ext.strip() + if i_ext: + suffixes.append(i_ext) current_page = int(request.GET.get('page', '1')) per_page= int(request.GET.get('per_page', '25')) @@ -31,10 +45,9 @@ def search(request): start = (current_page - 1) * per_page size = per_page - scale = request.GET.get('scale', None) - repo_id = request.GET.get('search_repo_id', None) repo = None - if scale == 'current' and repo_id: + if search_repo and search_repo != 'all': + repo_id = search_repo repo = get_repo(repo_id) if repo: results, total = search_repo_file_by_name(request, repo, keyword, suffixes, start, size) @@ -48,7 +61,7 @@ def search(request): else: has_more = False - return render_to_response('search_results.html', { + return render_to_response(template, { 'repo': repo, 'keyword': keyword, 'results': results, @@ -58,4 +71,9 @@ def search(request): 'prev_page': current_page - 1, 'next_page': current_page + 1, 'per_page': per_page, + 'search_repo': search_repo, + 'search_ftypes': search_ftypes, + 'custom_ftypes': custom_ftypes, + 'input_fileexts': input_fileexts, + 'error': error, }, context_instance=RequestContext(request))