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 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%}
{% for file in results %}
-
@@ -78,5 +72,44 @@
{% 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))