Fix the first page of the search, by avoiding to look within category and subcategory fields
|
@ -0,0 +1 @@
|
|||
Voir ici pour l'autocomplétion proprement http://j-mad.com/blog/2011/08/20/django-autocomplete-and-all-your-requests-will-be-complete-but-be-careful-with-the-horn/
|
|
@ -15,13 +15,10 @@ import cards.forms
|
|||
def index(request):
|
||||
from django.db.models import Count
|
||||
|
||||
nbr_of_cards = Card.objects.count()
|
||||
|
||||
tags_list = Tag.objects.annotate(occurence=Count('tags'))
|
||||
|
||||
#tag_max = max(tags_list, key=occurence)
|
||||
#tag_min = max(tags_list, key=occurence)
|
||||
|
||||
#print '################' + str(tag_max) + ' ' + str(tag_min)
|
||||
|
||||
cards_list = Card.objects.order_by('-created_at')[:25]
|
||||
|
||||
context = { 'tags_list' : tags_list,'cards_list' : cards_list}
|
||||
|
@ -65,7 +62,7 @@ def query(request):
|
|||
q = Q()
|
||||
|
||||
for term in terms.split(' '):
|
||||
q.add((Q(label__icontains=term) | Q(subcategory__label__icontains=term) | Q(subcategory__category__label__icontains=term) | Q(country__label__icontains=term) ), q.AND)
|
||||
q.add((Q(label__icontains=term) | Q(country__label__icontains=term) ), q.AND)
|
||||
|
||||
cards_list = Card.objects.filter(q)
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
Copyright (c) 2010 John Resig, http://jquery.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,468 @@
|
|||
/*
|
||||
* jQuery UI CSS Framework 1.8.11
|
||||
*
|
||||
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
* http://jquery.org/license
|
||||
*
|
||||
* http://docs.jquery.com/UI/Theming/API
|
||||
*/
|
||||
|
||||
/* Layout helpers
|
||||
----------------------------------*/
|
||||
.ui-helper-hidden { display: none; }
|
||||
.ui-helper-hidden-accessible { position: absolute !important; clip: rect(1px,1px,1px,1px); clip: rect(1px,1px,1px,1px); }
|
||||
.ui-helper-reset { margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.3; text-decoration: none; font-size: 100%; list-style: none; }
|
||||
.ui-helper-clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
|
||||
.ui-helper-clearfix { display: inline-block; }
|
||||
/* required comment for clearfix to work in Opera \*/
|
||||
* html .ui-helper-clearfix { height:1%; }
|
||||
.ui-helper-clearfix { display:block; }
|
||||
/* end clearfix */
|
||||
.ui-helper-zfix { width: 100%; height: 100%; top: 0; left: 0; position: absolute; opacity: 0; filter:Alpha(Opacity=0); }
|
||||
|
||||
|
||||
/* Interaction Cues
|
||||
----------------------------------*/
|
||||
.ui-state-disabled { cursor: default !important; }
|
||||
|
||||
|
||||
/* Icons
|
||||
----------------------------------*/
|
||||
|
||||
/* states and images */
|
||||
.ui-icon { display: block; text-indent: -99999px; overflow: hidden; background-repeat: no-repeat; }
|
||||
|
||||
|
||||
/* Misc visuals
|
||||
----------------------------------*/
|
||||
|
||||
/* Overlays */
|
||||
.ui-widget-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
|
||||
|
||||
|
||||
/*
|
||||
* jQuery UI CSS Framework 1.8.11
|
||||
*
|
||||
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
* http://jquery.org/license
|
||||
*
|
||||
* http://docs.jquery.com/UI/Theming/API
|
||||
*
|
||||
* To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Trebuchet%20MS,%20Tahoma,%20Verdana,%20Arial,%20sans-serif&fwDefault=bold&fsDefault=1.1em&cornerRadius=4px&bgColorHeader=f6a828&bgTextureHeader=12_gloss_wave.png&bgImgOpacityHeader=35&borderColorHeader=e78f08&fcHeader=ffffff&iconColorHeader=ffffff&bgColorContent=eeeeee&bgTextureContent=03_highlight_soft.png&bgImgOpacityContent=100&borderColorContent=dddddd&fcContent=333333&iconColorContent=222222&bgColorDefault=f6f6f6&bgTextureDefault=02_glass.png&bgImgOpacityDefault=100&borderColorDefault=cccccc&fcDefault=1c94c4&iconColorDefault=ef8c08&bgColorHover=fdf5ce&bgTextureHover=02_glass.png&bgImgOpacityHover=100&borderColorHover=fbcb09&fcHover=c77405&iconColorHover=ef8c08&bgColorActive=ffffff&bgTextureActive=02_glass.png&bgImgOpacityActive=65&borderColorActive=fbd850&fcActive=eb8f00&iconColorActive=ef8c08&bgColorHighlight=ffe45c&bgTextureHighlight=03_highlight_soft.png&bgImgOpacityHighlight=75&borderColorHighlight=fed22f&fcHighlight=363636&iconColorHighlight=228ef1&bgColorError=b81900&bgTextureError=08_diagonals_thick.png&bgImgOpacityError=18&borderColorError=cd0a0a&fcError=ffffff&iconColorError=ffd27a&bgColorOverlay=666666&bgTextureOverlay=08_diagonals_thick.png&bgImgOpacityOverlay=20&opacityOverlay=50&bgColorShadow=000000&bgTextureShadow=01_flat.png&bgImgOpacityShadow=10&opacityShadow=20&thicknessShadow=5px&offsetTopShadow=-5px&offsetLeftShadow=-5px&cornerRadiusShadow=5px
|
||||
*/
|
||||
|
||||
|
||||
/* Component containers
|
||||
----------------------------------*/
|
||||
.ui-widget { font-family: "Lucida Grande",Verdana,Arial,sans-serif; font-size: 11px; }
|
||||
.ui-widget .ui-widget { font-size: 1em; }
|
||||
.ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1em; }
|
||||
.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee url(../img/ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x; color: #333333; }
|
||||
.ui-widget-content a { color: #333333; }
|
||||
.ui-widget-header { border: 1px solid #7CA0C7; background: #81aad7 url(../img/default-bg.gif) 50% 50% repeat-x; color: #ffffff; font-weight: bold; }
|
||||
.ui-widget-header a { color: #ffffff; }
|
||||
|
||||
/* Interaction states
|
||||
----------------------------------*/
|
||||
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 url(../img/ui-bg_glass_100_f6f6f6_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #1c94c4; }
|
||||
.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #1c94c4; text-decoration: none; }
|
||||
.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce url(../img/ui-bg_glass_100_fdf5ce_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #c77405; }
|
||||
.ui-state-hover a, .ui-state-hover a:hover { color: #c77405; text-decoration: none; }
|
||||
.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff url(../img/ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #eb8f00; }
|
||||
.ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #eb8f00; text-decoration: none; }
|
||||
.ui-widget :active { outline: none; }
|
||||
|
||||
/* Interaction Cues
|
||||
----------------------------------*/
|
||||
.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c url(../img/ui-bg_highlight-soft_75_ffe45c_1x100.png) 50% top repeat-x; color: #363636; }
|
||||
.ui-state-highlight a, .ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a { color: #363636; }
|
||||
.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 url(../img/ui-bg_diagonals-thick_18_b81900_40x40.png) 50% 50% repeat; color: #ffffff; }
|
||||
.ui-state-error a, .ui-widget-content .ui-state-error a, .ui-widget-header .ui-state-error a { color: #ffffff; }
|
||||
.ui-state-error-text, .ui-widget-content .ui-state-error-text, .ui-widget-header .ui-state-error-text { color: #ffffff; }
|
||||
.ui-priority-primary, .ui-widget-content .ui-priority-primary, .ui-widget-header .ui-priority-primary { font-weight: bold; }
|
||||
.ui-priority-secondary, .ui-widget-content .ui-priority-secondary, .ui-widget-header .ui-priority-secondary { opacity: .7; filter:Alpha(Opacity=70); font-weight: normal; }
|
||||
.ui-state-disabled, .ui-widget-content .ui-state-disabled, .ui-widget-header .ui-state-disabled { opacity: .35; filter:Alpha(Opacity=35); background-image: none; }
|
||||
|
||||
/* Icons
|
||||
----------------------------------*/
|
||||
|
||||
/* states and images */
|
||||
.ui-icon { width: 16px; height: 16px; background-image: url(../img/ui-icons_222222_256x240.png); }
|
||||
.ui-widget-content .ui-icon {background-image: url(../img/ui-icons_222222_256x240.png); }
|
||||
.ui-widget-header .ui-icon {background-image: url(../img/ui-icons_ffffff_256x240.png); }
|
||||
.ui-state-default .ui-icon { background-image: url(../img/ui-icons_ef8c08_256x240.png); }
|
||||
.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(../img/ui-icons_ef8c08_256x240.png); }
|
||||
.ui-state-active .ui-icon {background-image: url(../img/ui-icons_ef8c08_256x240.png); }
|
||||
.ui-state-highlight .ui-icon {background-image: url(../img/ui-icons_228ef1_256x240.png); }
|
||||
.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(../img/ui-icons_ffd27a_256x240.png); }
|
||||
|
||||
/* positioning */
|
||||
.ui-icon-carat-1-n { background-position: 0 0; }
|
||||
.ui-icon-carat-1-ne { background-position: -16px 0; }
|
||||
.ui-icon-carat-1-e { background-position: -32px 0; }
|
||||
.ui-icon-carat-1-se { background-position: -48px 0; }
|
||||
.ui-icon-carat-1-s { background-position: -64px 0; }
|
||||
.ui-icon-carat-1-sw { background-position: -80px 0; }
|
||||
.ui-icon-carat-1-w { background-position: -96px 0; }
|
||||
.ui-icon-carat-1-nw { background-position: -112px 0; }
|
||||
.ui-icon-carat-2-n-s { background-position: -128px 0; }
|
||||
.ui-icon-carat-2-e-w { background-position: -144px 0; }
|
||||
.ui-icon-triangle-1-n { background-position: 0 -16px; }
|
||||
.ui-icon-triangle-1-ne { background-position: -16px -16px; }
|
||||
.ui-icon-triangle-1-e { background-position: -32px -16px; }
|
||||
.ui-icon-triangle-1-se { background-position: -48px -16px; }
|
||||
.ui-icon-triangle-1-s { background-position: -64px -16px; }
|
||||
.ui-icon-triangle-1-sw { background-position: -80px -16px; }
|
||||
.ui-icon-triangle-1-w { background-position: -96px -16px; }
|
||||
.ui-icon-triangle-1-nw { background-position: -112px -16px; }
|
||||
.ui-icon-triangle-2-n-s { background-position: -128px -16px; }
|
||||
.ui-icon-triangle-2-e-w { background-position: -144px -16px; }
|
||||
.ui-icon-arrow-1-n { background-position: 0 -32px; }
|
||||
.ui-icon-arrow-1-ne { background-position: -16px -32px; }
|
||||
.ui-icon-arrow-1-e { background-position: -32px -32px; }
|
||||
.ui-icon-arrow-1-se { background-position: -48px -32px; }
|
||||
.ui-icon-arrow-1-s { background-position: -64px -32px; }
|
||||
.ui-icon-arrow-1-sw { background-position: -80px -32px; }
|
||||
.ui-icon-arrow-1-w { background-position: -96px -32px; }
|
||||
.ui-icon-arrow-1-nw { background-position: -112px -32px; }
|
||||
.ui-icon-arrow-2-n-s { background-position: -128px -32px; }
|
||||
.ui-icon-arrow-2-ne-sw { background-position: -144px -32px; }
|
||||
.ui-icon-arrow-2-e-w { background-position: -160px -32px; }
|
||||
.ui-icon-arrow-2-se-nw { background-position: -176px -32px; }
|
||||
.ui-icon-arrowstop-1-n { background-position: -192px -32px; }
|
||||
.ui-icon-arrowstop-1-e { background-position: -208px -32px; }
|
||||
.ui-icon-arrowstop-1-s { background-position: -224px -32px; }
|
||||
.ui-icon-arrowstop-1-w { background-position: -240px -32px; }
|
||||
.ui-icon-arrowthick-1-n { background-position: 0 -48px; }
|
||||
.ui-icon-arrowthick-1-ne { background-position: -16px -48px; }
|
||||
.ui-icon-arrowthick-1-e { background-position: -32px -48px; }
|
||||
.ui-icon-arrowthick-1-se { background-position: -48px -48px; }
|
||||
.ui-icon-arrowthick-1-s { background-position: -64px -48px; }
|
||||
.ui-icon-arrowthick-1-sw { background-position: -80px -48px; }
|
||||
.ui-icon-arrowthick-1-w { background-position: -96px -48px; }
|
||||
.ui-icon-arrowthick-1-nw { background-position: -112px -48px; }
|
||||
.ui-icon-arrowthick-2-n-s { background-position: -128px -48px; }
|
||||
.ui-icon-arrowthick-2-ne-sw { background-position: -144px -48px; }
|
||||
.ui-icon-arrowthick-2-e-w { background-position: -160px -48px; }
|
||||
.ui-icon-arrowthick-2-se-nw { background-position: -176px -48px; }
|
||||
.ui-icon-arrowthickstop-1-n { background-position: -192px -48px; }
|
||||
.ui-icon-arrowthickstop-1-e { background-position: -208px -48px; }
|
||||
.ui-icon-arrowthickstop-1-s { background-position: -224px -48px; }
|
||||
.ui-icon-arrowthickstop-1-w { background-position: -240px -48px; }
|
||||
.ui-icon-arrowreturnthick-1-w { background-position: 0 -64px; }
|
||||
.ui-icon-arrowreturnthick-1-n { background-position: -16px -64px; }
|
||||
.ui-icon-arrowreturnthick-1-e { background-position: -32px -64px; }
|
||||
.ui-icon-arrowreturnthick-1-s { background-position: -48px -64px; }
|
||||
.ui-icon-arrowreturn-1-w { background-position: -64px -64px; }
|
||||
.ui-icon-arrowreturn-1-n { background-position: -80px -64px; }
|
||||
.ui-icon-arrowreturn-1-e { background-position: -96px -64px; }
|
||||
.ui-icon-arrowreturn-1-s { background-position: -112px -64px; }
|
||||
.ui-icon-arrowrefresh-1-w { background-position: -128px -64px; }
|
||||
.ui-icon-arrowrefresh-1-n { background-position: -144px -64px; }
|
||||
.ui-icon-arrowrefresh-1-e { background-position: -160px -64px; }
|
||||
.ui-icon-arrowrefresh-1-s { background-position: -176px -64px; }
|
||||
.ui-icon-arrow-4 { background-position: 0 -80px; }
|
||||
.ui-icon-arrow-4-diag { background-position: -16px -80px; }
|
||||
.ui-icon-extlink { background-position: -32px -80px; }
|
||||
.ui-icon-newwin { background-position: -48px -80px; }
|
||||
.ui-icon-refresh { background-position: -64px -80px; }
|
||||
.ui-icon-shuffle { background-position: -80px -80px; }
|
||||
.ui-icon-transfer-e-w { background-position: -96px -80px; }
|
||||
.ui-icon-transferthick-e-w { background-position: -112px -80px; }
|
||||
.ui-icon-folder-collapsed { background-position: 0 -96px; }
|
||||
.ui-icon-folder-open { background-position: -16px -96px; }
|
||||
.ui-icon-document { background-position: -32px -96px; }
|
||||
.ui-icon-document-b { background-position: -48px -96px; }
|
||||
.ui-icon-note { background-position: -64px -96px; }
|
||||
.ui-icon-mail-closed { background-position: -80px -96px; }
|
||||
.ui-icon-mail-open { background-position: -96px -96px; }
|
||||
.ui-icon-suitcase { background-position: -112px -96px; }
|
||||
.ui-icon-comment { background-position: -128px -96px; }
|
||||
.ui-icon-person { background-position: -144px -96px; }
|
||||
.ui-icon-print { background-position: -160px -96px; }
|
||||
.ui-icon-trash { background-position: -176px -96px; }
|
||||
.ui-icon-locked { background-position: -192px -96px; }
|
||||
.ui-icon-unlocked { background-position: -208px -96px; }
|
||||
.ui-icon-bookmark { background-position: -224px -96px; }
|
||||
.ui-icon-tag { background-position: -240px -96px; }
|
||||
.ui-icon-home { background-position: 0 -112px; }
|
||||
.ui-icon-flag { background-position: -16px -112px; }
|
||||
.ui-icon-calendar { background-position: -32px -112px; }
|
||||
.ui-icon-cart { background-position: -48px -112px; }
|
||||
.ui-icon-pencil { background-position: -64px -112px; }
|
||||
.ui-icon-clock { background-position: -80px -112px; }
|
||||
.ui-icon-disk { background-position: -96px -112px; }
|
||||
.ui-icon-calculator { background-position: -112px -112px; }
|
||||
.ui-icon-zoomin { background-position: -128px -112px; }
|
||||
.ui-icon-zoomout { background-position: -144px -112px; }
|
||||
.ui-icon-search { background-position: -160px -112px; }
|
||||
.ui-icon-wrench { background-position: -176px -112px; }
|
||||
.ui-icon-gear { background-position: -192px -112px; }
|
||||
.ui-icon-heart { background-position: -208px -112px; }
|
||||
.ui-icon-star { background-position: -224px -112px; }
|
||||
.ui-icon-link { background-position: -240px -112px; }
|
||||
.ui-icon-cancel { background-position: 0 -128px; }
|
||||
.ui-icon-plus { background-position: -16px -128px; }
|
||||
.ui-icon-plusthick { background-position: -32px -128px; }
|
||||
.ui-icon-minus { background-position: -48px -128px; }
|
||||
.ui-icon-minusthick { background-position: -64px -128px; }
|
||||
.ui-icon-close { background-position: -80px -128px; }
|
||||
.ui-icon-closethick { background-position: -96px -128px; }
|
||||
.ui-icon-key { background-position: -112px -128px; }
|
||||
.ui-icon-lightbulb { background-position: -128px -128px; }
|
||||
.ui-icon-scissors { background-position: -144px -128px; }
|
||||
.ui-icon-clipboard { background-position: -160px -128px; }
|
||||
.ui-icon-copy { background-position: -176px -128px; }
|
||||
.ui-icon-contact { background-position: -192px -128px; }
|
||||
.ui-icon-image { background-position: -208px -128px; }
|
||||
.ui-icon-video { background-position: -224px -128px; }
|
||||
.ui-icon-script { background-position: -240px -128px; }
|
||||
.ui-icon-alert { background-position: 0 -144px; }
|
||||
.ui-icon-info { background-position: -16px -144px; }
|
||||
.ui-icon-notice { background-position: -32px -144px; }
|
||||
.ui-icon-help { background-position: -48px -144px; }
|
||||
.ui-icon-check { background-position: -64px -144px; }
|
||||
.ui-icon-bullet { background-position: -80px -144px; }
|
||||
.ui-icon-radio-off { background-position: -96px -144px; }
|
||||
.ui-icon-radio-on { background-position: -112px -144px; }
|
||||
.ui-icon-pin-w { background-position: -128px -144px; }
|
||||
.ui-icon-pin-s { background-position: -144px -144px; }
|
||||
.ui-icon-play { background-position: 0 -160px; }
|
||||
.ui-icon-pause { background-position: -16px -160px; }
|
||||
.ui-icon-seek-next { background-position: -32px -160px; }
|
||||
.ui-icon-seek-prev { background-position: -48px -160px; }
|
||||
.ui-icon-seek-end { background-position: -64px -160px; }
|
||||
.ui-icon-seek-start { background-position: -80px -160px; }
|
||||
/* ui-icon-seek-first is deprecated, use ui-icon-seek-start instead */
|
||||
.ui-icon-seek-first { background-position: -80px -160px; }
|
||||
.ui-icon-stop { background-position: -96px -160px; }
|
||||
.ui-icon-eject { background-position: -112px -160px; }
|
||||
.ui-icon-volume-off { background-position: -128px -160px; }
|
||||
.ui-icon-volume-on { background-position: -144px -160px; }
|
||||
.ui-icon-power { background-position: 0 -176px; }
|
||||
.ui-icon-signal-diag { background-position: -16px -176px; }
|
||||
.ui-icon-signal { background-position: -32px -176px; }
|
||||
.ui-icon-battery-0 { background-position: -48px -176px; }
|
||||
.ui-icon-battery-1 { background-position: -64px -176px; }
|
||||
.ui-icon-battery-2 { background-position: -80px -176px; }
|
||||
.ui-icon-battery-3 { background-position: -96px -176px; }
|
||||
.ui-icon-circle-plus { background-position: 0 -192px; }
|
||||
.ui-icon-circle-minus { background-position: -16px -192px; }
|
||||
.ui-icon-circle-close { background-position: -32px -192px; }
|
||||
.ui-icon-circle-triangle-e { background-position: -48px -192px; }
|
||||
.ui-icon-circle-triangle-s { background-position: -64px -192px; }
|
||||
.ui-icon-circle-triangle-w { background-position: -80px -192px; }
|
||||
.ui-icon-circle-triangle-n { background-position: -96px -192px; }
|
||||
.ui-icon-circle-arrow-e { background-position: -112px -192px; }
|
||||
.ui-icon-circle-arrow-s { background-position: -128px -192px; }
|
||||
.ui-icon-circle-arrow-w { background-position: -144px -192px; }
|
||||
.ui-icon-circle-arrow-n { background-position: -160px -192px; }
|
||||
.ui-icon-circle-zoomin { background-position: -176px -192px; }
|
||||
.ui-icon-circle-zoomout { background-position: -192px -192px; }
|
||||
.ui-icon-circle-check { background-position: -208px -192px; }
|
||||
.ui-icon-circlesmall-plus { background-position: 0 -208px; }
|
||||
.ui-icon-circlesmall-minus { background-position: -16px -208px; }
|
||||
.ui-icon-circlesmall-close { background-position: -32px -208px; }
|
||||
.ui-icon-squaresmall-plus { background-position: -48px -208px; }
|
||||
.ui-icon-squaresmall-minus { background-position: -64px -208px; }
|
||||
.ui-icon-squaresmall-close { background-position: -80px -208px; }
|
||||
.ui-icon-grip-dotted-vertical { background-position: 0 -224px; }
|
||||
.ui-icon-grip-dotted-horizontal { background-position: -16px -224px; }
|
||||
.ui-icon-grip-solid-vertical { background-position: -32px -224px; }
|
||||
.ui-icon-grip-solid-horizontal { background-position: -48px -224px; }
|
||||
.ui-icon-gripsmall-diagonal-se { background-position: -64px -224px; }
|
||||
.ui-icon-grip-diagonal-se { background-position: -80px -224px; }
|
||||
|
||||
|
||||
/* Misc visuals
|
||||
----------------------------------*/
|
||||
|
||||
/* Corner radius */
|
||||
.ui-corner-tl { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; border-top-left-radius: 4px; }
|
||||
.ui-corner-tr { -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; border-top-right-radius: 4px; }
|
||||
.ui-corner-bl { -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; border-bottom-left-radius: 4px; }
|
||||
.ui-corner-br { -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; border-bottom-right-radius: 4px; }
|
||||
.ui-corner-top { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; border-top-left-radius: 4px; -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; border-top-right-radius: 4px; }
|
||||
.ui-corner-bottom { -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; border-bottom-left-radius: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; border-bottom-right-radius: 4px; }
|
||||
.ui-corner-right { -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; border-top-right-radius: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; border-bottom-right-radius: 4px; }
|
||||
.ui-corner-left { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; border-top-left-radius: 4px; -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; border-bottom-left-radius: 4px; }
|
||||
.ui-corner-all { -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px; }
|
||||
|
||||
/* Overlays */
|
||||
.ui-widget-overlay { background: #666666 url(../img/ui-bg_diagonals-thick_20_666666_40x40.png) 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); }
|
||||
.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 url(../img/ui-bg_flat_10_000000_40x100.png) 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }/*
|
||||
* jQuery UI Autocomplete 1.8.11
|
||||
*
|
||||
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
* http://jquery.org/license
|
||||
*
|
||||
* http://docs.jquery.com/UI/Autocomplete#theming
|
||||
*/
|
||||
.ui-autocomplete { position: absolute; cursor: default; }
|
||||
|
||||
/* workarounds */
|
||||
* html .ui-autocomplete { width:1px; } /* without this, the menu expands to 100% in IE6 */
|
||||
|
||||
/*
|
||||
* jQuery UI Menu 1.8.11
|
||||
*
|
||||
* Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
* http://jquery.org/license
|
||||
*
|
||||
* http://docs.jquery.com/UI/Menu#theming
|
||||
*/
|
||||
.ui-menu {
|
||||
list-style:none;
|
||||
padding: 2px;
|
||||
margin: 0;
|
||||
display:block;
|
||||
float: left;
|
||||
}
|
||||
.ui-menu .ui-menu {
|
||||
margin-top: -3px;
|
||||
}
|
||||
.ui-menu .ui-menu-item {
|
||||
margin:0;
|
||||
padding: 0;
|
||||
zoom: 1;
|
||||
float: left;
|
||||
clear: left;
|
||||
width: 100%;
|
||||
}
|
||||
.ui-menu .ui-menu-item a {
|
||||
text-decoration:none;
|
||||
display:block;
|
||||
padding:.2em .4em;
|
||||
line-height:1.5;
|
||||
zoom:1;
|
||||
}
|
||||
.ui-menu .ui-menu-item a.ui-state-hover,
|
||||
.ui-menu .ui-menu-item a.ui-state-active {
|
||||
font-weight: normal;
|
||||
margin: -1px;
|
||||
}
|
||||
|
||||
/*
|
||||
* jQuery UI Progressbar 1.8.18
|
||||
*
|
||||
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
* http://jquery.org/license
|
||||
*
|
||||
* http://docs.jquery.com/UI/Progressbar#theming
|
||||
*/
|
||||
.ui-progressbar { height:1em; text-align: left; overflow: hidden; }
|
||||
.ui-progressbar .ui-progressbar-value {margin: -1px; height:100%; }
|
||||
.ui-progressbar.ui-progressbar-ani .ui-progressbar-value { background-image: url(../img/pbar-ani-blue.gif); }
|
||||
|
||||
/* django-autocomplpete customizations */
|
||||
form ul.ui-autocomplete {
|
||||
margin-left: 0;
|
||||
padding: 0;
|
||||
/* add scrolling */
|
||||
max-height: 125px;
|
||||
overflow: auto;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
/* drop shadow */
|
||||
-moz-box-shadow: 0px 5px 10px #999999;
|
||||
-webkit-box-shadow: 0px 5px 10px #999999;
|
||||
box-shadow: 0px 5px 10px #999999;
|
||||
background: #FFFFFF;
|
||||
border: 1px solid #CCCCCC;
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
ul.ui-autocomplete > div {
|
||||
display: table;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
ul.ui-autocomplete div .ui-menu-item {
|
||||
float: none;
|
||||
display: table-row;
|
||||
}
|
||||
|
||||
ul.ui-autocomplete div .ui-menu-item a {
|
||||
display: table-cell;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.ui-autocomplete .ui-corner-all,
|
||||
.ui-autocomplete {
|
||||
-moz-border-radius: 0;
|
||||
-webkit-border-radius: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.ui-autocomplete li {
|
||||
list-style-type: none;
|
||||
font-family: "Lucida Grande","DejaVu Sans","Bitstream Vera Sans",Verdana,Arial,sans-serif;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.ui-autocomplete .ui-menu-item a.ui-state-hover {
|
||||
font-weight: normal;
|
||||
border: 0;
|
||||
background: #ffdf4e;
|
||||
color: #333333;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ui-autocomplete-values .ui-autocomplete-value a {
|
||||
float: right;
|
||||
}
|
||||
|
||||
/* Adding spinner on query */
|
||||
.ui-autocomplete-loading {
|
||||
background: #FFFFFF url(../img/process-working.gif) right center no-repeat;
|
||||
}
|
||||
|
||||
/* M2M */
|
||||
table.ui-autocomplete-values tr {
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
||||
table.ui-autocomplete-values tbody {
|
||||
display: table;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.ui-autocomplete-values td {
|
||||
padding: 0.2em 0.4em;
|
||||
line-height: 1.5;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
table.ui-autocomplete-values td:last-child {
|
||||
width: 1px;
|
||||
}
|
||||
|
||||
.ui-autocomplete-values {
|
||||
border: 1px solid #CCCCCC;
|
||||
background-color: #EEEEEE;
|
||||
width: 270px;
|
||||
min-height: 18px;
|
||||
max-height: 200px;
|
||||
overflow: auto;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
padding: 0;
|
||||
margin-left: 106px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.ui-autocomplete-values .ui-autocomplete-value a {
|
||||
color: #CC0000;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Zebra */
|
||||
.ui-autocomplete a.ui-menu-item-alternate,
|
||||
table.ui-autocomplete-values tr.ui-menu-item-alternate {
|
||||
background-color: #EDF3FE; /* alternate item bgcolor */
|
||||
}
|
After Width: | Height: | Size: 844 B |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 260 B |
After Width: | Height: | Size: 251 B |
After Width: | Height: | Size: 178 B |
After Width: | Height: | Size: 104 B |
After Width: | Height: | Size: 125 B |
After Width: | Height: | Size: 105 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 90 B |
After Width: | Height: | Size: 129 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
|
@ -0,0 +1,100 @@
|
|||
function bassistance_autocomplete(name, ac_url, force_selection) {
|
||||
$(document).ready(function () {
|
||||
var input = $('#id_' + name);
|
||||
var hidden_input = $('#id_hidden_' + name);
|
||||
input.autocomplete(ac_url, {
|
||||
limit: 10,
|
||||
matchSubset: false,
|
||||
dataType: 'json',
|
||||
parse: function(data) {
|
||||
var parsed = [];
|
||||
for (var i in data) {
|
||||
row = {
|
||||
data: data[i][1]+'|'+data[i][0],
|
||||
value: data[i][0],
|
||||
result: data[i][1]
|
||||
};
|
||||
parsed[parsed.length] = row;
|
||||
}
|
||||
return parsed;
|
||||
},
|
||||
formatItem: function(data, i, total) {
|
||||
return data.split('|')[0];
|
||||
}
|
||||
});
|
||||
input.result(function(event, data, formatted) {
|
||||
hidden_input.val(data.split('|')[1]);
|
||||
});
|
||||
form = $("form:first");
|
||||
form.submit(function() {
|
||||
if (hidden_input.val() != input.val() && !force_selection) {
|
||||
hidden_input.val(input.val());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function jquery_autocomplete(name, ac_url, force_selection) {
|
||||
|
||||
this.name = name;
|
||||
this.ac_url = ac_url;
|
||||
this.force_selection = force_selection;
|
||||
|
||||
this.source = function (request, response) {
|
||||
function success(data) {
|
||||
var parsed = [];
|
||||
for (var i in data) {
|
||||
parsed[parsed.length] = {
|
||||
id: data[i][0],
|
||||
value: data[i][1],
|
||||
label: data[i][1],
|
||||
};
|
||||
}
|
||||
response(parsed);
|
||||
};
|
||||
$.ajax({
|
||||
url: this.ac_url,
|
||||
dataType: "json",
|
||||
data: {q: request.term},
|
||||
success: success
|
||||
});
|
||||
};
|
||||
|
||||
this.select = function (event, ui) {
|
||||
// set the hidden input field.
|
||||
this.last_item = ui.item;
|
||||
this.hidden_input.val(ui.item.id);
|
||||
};
|
||||
|
||||
this.close = function (event, ui) {
|
||||
alert(ui.toSource());
|
||||
};
|
||||
|
||||
this.setup = function () {
|
||||
this.input = $("#id_" + this.name);
|
||||
this.hidden_input = $("#id_hidden_" + this.name);
|
||||
this.last_item = {};
|
||||
this.input.autocomplete({
|
||||
// minLength: 2,
|
||||
source: jQuery.proxy(this.source, this),
|
||||
select: jQuery.proxy(this.select, this),
|
||||
});
|
||||
this.input.closest("form").submit(jQuery.proxy(function () {
|
||||
if ((!this.input.val()) || (this.hidden_input.val() != this.input.val()
|
||||
&& !this.force_selection)) {
|
||||
this.hidden_input.val(this.input.val());
|
||||
}
|
||||
}, this));
|
||||
if (this.force_selection) {
|
||||
this.input.focusout(jQuery.proxy(function (event) {
|
||||
if (this.input.val() != this.last_item.value)
|
||||
this.input.val("");
|
||||
}, this));
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(jQuery.proxy(this.setup, this));
|
||||
};
|
||||
|
||||
autocomplete = jquery_autocomplete;
|
|
@ -0,0 +1,495 @@
|
|||
(function( window, undefined ) {
|
||||
|
||||
var $ = window.jQuery || window.django.jQuery,
|
||||
django = window.django || {};
|
||||
|
||||
$.widget( "ui.djangoautocomplete", {
|
||||
options: {
|
||||
source: "../autocomplete/$name/",
|
||||
multiple: false,
|
||||
force_selection: true,
|
||||
delimiterList: true,
|
||||
highlight: true,
|
||||
zebra: true,
|
||||
autoFocus: true,
|
||||
delimiter: "",
|
||||
minLength: 1,
|
||||
cache: true,
|
||||
renderItem: function( ul, item) {
|
||||
var content = $( "<li></li>" );
|
||||
$.each(item.label.split('\t'), function(i, v) {
|
||||
content.append($('<a></a>').append(v));
|
||||
});
|
||||
return content
|
||||
.data( "item.autocomplete", item )
|
||||
.appendTo( ul );
|
||||
}
|
||||
|
||||
},
|
||||
_create: function() {
|
||||
var self = this;
|
||||
this.hidden_input = this.element.prev( "input[type=hidden]" );
|
||||
this.name = this.hidden_input.attr( "name" );
|
||||
var queryCache = {};
|
||||
var lastXhr;
|
||||
var accents = {
|
||||
"àåáâäãåą": "a",
|
||||
"èéêëę": "e",
|
||||
"ìíîïı": "i",
|
||||
"òóôõöøő": "o",
|
||||
"ùúûü": "u",
|
||||
"çćč": "c",
|
||||
"żźž": "z",
|
||||
"śşš": "s",
|
||||
"ñń": "n",
|
||||
"ýŸ": "y",
|
||||
"ł": "l",
|
||||
"đ": "d",
|
||||
"ğ": "g",
|
||||
};
|
||||
function convertEntities(val) {
|
||||
return $('<div/>').html(val).html().replace(' ', ' ');
|
||||
}
|
||||
function stripAccents(term) {
|
||||
term = convertEntities(term).toLowerCase();
|
||||
$.each(accents, function(accent) {
|
||||
term = term.replace(new RegExp("[" + accent + "]", "g"), accents[accent])
|
||||
});
|
||||
return term;
|
||||
}
|
||||
var multiField = this.options.delimiter && !self.options.multiple && !self.options.force_selection;
|
||||
if (multiField) {
|
||||
if (self.options.delimiterList) {
|
||||
var delimiterList = true;
|
||||
multiField = false;
|
||||
} else {
|
||||
var deliRegex = new RegExp('(?:' + self.options.delimiter.replace(' ', '(?: | )') + ")+\\s*")
|
||||
var trimRegex = new RegExp('(?:' + self.options.delimiter.replace(' ', '(?: | )') + ")*\\s*$")
|
||||
function split(val){
|
||||
val = val.replace(trimRegex, "");
|
||||
return val.split(deliRegex);
|
||||
}
|
||||
var terms = split(this.element.val());
|
||||
var termsSelect = terms;
|
||||
function extractCurrent(term){
|
||||
var new_terms = split(term);
|
||||
for (idx = 0; idx < new_terms.length; idx++) {
|
||||
if (terms[idx] !== new_terms[idx]) {
|
||||
return new_terms[idx];
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// Don't navigate away from the field on tab when selecting an item
|
||||
this.element.bind("keydown", function(event){
|
||||
if (event.keyCode === $.ui.keyCode.TAB &&
|
||||
$(this).data("autocomplete").menu.active) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
this.element.autocomplete({
|
||||
appendTo: this.element.parent(),
|
||||
// Add SelectFirst, need jquery.ui >= 1.8.11
|
||||
autoFocus: this.options.autoFocus,
|
||||
minLength: this.options.minLength,
|
||||
source: function(request, response) {
|
||||
var term = request.term;
|
||||
if (multiField) {
|
||||
term = extractCurrent(request.term);
|
||||
terms = split(self.element.val());
|
||||
if (terms.length === 1) {
|
||||
terms = [];
|
||||
}
|
||||
}
|
||||
if ( self.options.cache && term in queryCache ) {
|
||||
response( queryCache[ term ] );
|
||||
return;
|
||||
}
|
||||
lastXhr = $.getJSON( this.options.sourceURL,
|
||||
{term: term},
|
||||
function( data, status, xhr ) {
|
||||
if ( xhr === lastXhr ) {
|
||||
if (self.options.highlight) {
|
||||
$.each(data, function(idx, result){
|
||||
if (term) {
|
||||
var label = stripAccents(result.label);
|
||||
var stripTerm = stripAccents(term);
|
||||
var parts = label.split(new RegExp("(?!<[^<>]*)(" +
|
||||
$.ui.autocomplete.escapeRegex(stripTerm) +
|
||||
")(?![^<>]*>)", "gi"));
|
||||
if (parts.length > 1) {
|
||||
label = [];
|
||||
var pos = 0;
|
||||
for (var i=0; i<parts.length; i++) {
|
||||
var part = parts[i];
|
||||
if (part === stripTerm) {
|
||||
label.push("<strong>" + result.label.substring(pos, pos + part.length) + "</strong>");
|
||||
} else {
|
||||
label.push(result.label.substring(pos, pos + part.length));
|
||||
}
|
||||
pos += part.length;
|
||||
}
|
||||
result.label = label.join("");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
queryCache[ term ] = data;
|
||||
response( data );
|
||||
}
|
||||
});
|
||||
},
|
||||
// Add Zebra
|
||||
open: function( event, ui ) {
|
||||
if (self.options.zebra) {
|
||||
$(this).autocomplete("widget").find("ui-menu-item-alternate")
|
||||
.removeClass("ui-menu-item-alternate").end()
|
||||
.find("li.ui-menu-item:odd a").addClass("ui-menu-item-alternate");
|
||||
}
|
||||
},
|
||||
search: function() {
|
||||
// Custom minLength that support multiple terms
|
||||
if (multiField) {
|
||||
termsSelect = terms;
|
||||
var term = extractCurrent( this.value );
|
||||
if ( term.length < self.options.minLength ) {
|
||||
terms = split(this.value);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
focus: function() {
|
||||
// prevent value inserted on focus
|
||||
if (multiField) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
select: function( event, ui ) {
|
||||
self.lastSelected = ui.item;
|
||||
if ( delimiterList ) {
|
||||
if ( $.inArray( ui.item.value, self.values ) < 0 ) {
|
||||
self._buildValueRow(ui.item.value, ui.item.value);
|
||||
}
|
||||
return false;
|
||||
} else if (self.options.multiple) {
|
||||
if ($.inArray(ui.item.id, self.values) < 0) {
|
||||
self._buildValueRow(ui.item.id, ui.item.value);
|
||||
}
|
||||
return false;
|
||||
} else if (multiField) {
|
||||
var new_terms = split( this.value );
|
||||
var selectionStart = 0;
|
||||
var deliLength = self.options.delimiter.length;
|
||||
for (idx=0; idx<new_terms.length; idx++) {
|
||||
if (termsSelect[idx] !== new_terms[idx]) {
|
||||
// add the selected item
|
||||
if (new_terms.length > termsSelect.length) {
|
||||
termsSelect.splice(idx, 0, ui.item.value);
|
||||
} else {
|
||||
termsSelect[idx] = ui.item.value;
|
||||
}
|
||||
// add placeholder to get the delimiter-and-space at the end
|
||||
if (termsSelect.length === idx + 1) {
|
||||
termsSelect.push( "" );
|
||||
} else {
|
||||
deliLength = 0;
|
||||
}
|
||||
terms = termsSelect;
|
||||
this.value = termsSelect.join( self.options.delimiter );
|
||||
selectionStart += ui.item.value.length + deliLength;
|
||||
this.setSelectionRange(selectionStart, selectionStart);
|
||||
break;
|
||||
}
|
||||
selectionStart += new_terms[idx].length + deliLength;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}).data( "autocomplete" )._renderItem = this.options.renderItem;
|
||||
// Override _resizeMenu to always set it to the size of the input box
|
||||
this.element.data( "autocomplete" )._resizeMenu = function() {
|
||||
var ul = this.menu.element;
|
||||
ul.wrapInner('<div></div>');
|
||||
ul.outerWidth( this.element.outerWidth() );
|
||||
}
|
||||
// Override menu move function to support the <div> around the <li>s.
|
||||
this.element.data( "autocomplete" ).menu.move = function(direction, edge, event) {
|
||||
if (!this.active) {
|
||||
this.activate(event, this.element.find(edge));
|
||||
return;
|
||||
}
|
||||
var next = this.active[direction + "All"](".ui-menu-item").eq(0);
|
||||
if (next.length) {
|
||||
this.activate(event, next);
|
||||
} else {
|
||||
this.activate(event, this.element.find(edge));
|
||||
}
|
||||
}
|
||||
this._initSource();
|
||||
if ( delimiterList ) {
|
||||
this._initDelimiterList();
|
||||
} else if (this.options.multiple) {
|
||||
this._initManyToMany();
|
||||
} else {
|
||||
this.lastSelected = {
|
||||
id: this.hidden_input.val(),
|
||||
value: this.element.val()
|
||||
};
|
||||
}
|
||||
if (this.options.force_selection) {
|
||||
this.element.focusout(function() {
|
||||
if ( self.element.val() != self.lastSelected.value ) {
|
||||
self.element.val( "" );
|
||||
}
|
||||
});
|
||||
}
|
||||
this.element.closest( "form" ).submit(function() {
|
||||
if (delimiterList) {
|
||||
self.hidden_input.val(self.values.join(self.options.delimiter));
|
||||
} else if ( self.options.multiple ) {
|
||||
self.hidden_input.val( self.values.join(",") );
|
||||
} else if ( self.options.force_selection ) {
|
||||
self.hidden_input.val( self.element.val() ? self.lastSelected.id : "" );
|
||||
} else {
|
||||
self.element.val(self.element.val().replace(trimRegex, ""));
|
||||
self.hidden_input.val( self.element.val() );
|
||||
}
|
||||
});
|
||||
if (self.options.multiple || self.options.force_selection) {
|
||||
var hidden_value = self.hidden_input.val();
|
||||
var lookupXhr;
|
||||
var intervalID;
|
||||
|
||||
function lookup(query){
|
||||
if (self.options.multiple) {
|
||||
query = query.split(',').pop();
|
||||
}
|
||||
lookupXhr = $.getJSON(self.options.source, {
|
||||
lookup: query
|
||||
}, function(data, status, xhr){
|
||||
if (xhr === lookupXhr) {
|
||||
if (self.options.multiple) {
|
||||
self._buildValueRow(query, data);
|
||||
} else {
|
||||
self.element.val(data);
|
||||
self.lastSelected.value = data;
|
||||
self.lastSelected.id = query;
|
||||
}
|
||||
hidden_value = self.hidden_input.val();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function check(){
|
||||
check_value = self.hidden_input.val();
|
||||
if (check_value && check_value != hidden_value) {
|
||||
clearInterval(intervalID);
|
||||
lookup(check_value);
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
self.element.nextAll( "a.related-lookup, a.add-another" )
|
||||
.click(function() {
|
||||
intervalID = window.setInterval(check, 200);
|
||||
})
|
||||
.blur(function() {
|
||||
clearInterval(intervalID);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
this.element.autocomplete( "destroy" );
|
||||
if ( this.options.multiple || (this.options.delimiter && this.options.delimiterList) ) {
|
||||
this.values_ul.remove();
|
||||
}
|
||||
$.Widget.prototype.destroy.call( this );
|
||||
},
|
||||
|
||||
_setOption: function( key, value ) {
|
||||
$.Widget.prototype._setOption.apply( this, arguments );
|
||||
if ( key === "source" ) {
|
||||
this._initSource();
|
||||
}
|
||||
},
|
||||
|
||||
_initSource: function() {
|
||||
var source = typeof this.options.source === "string" ?
|
||||
this.options.source.replace( "$name", this.hidden_input.attr("name") ) :
|
||||
this.options.source;
|
||||
this.element.autocomplete( "option", "sourceURL", source );
|
||||
},
|
||||
|
||||
_addZebra: function(elem) {
|
||||
elem.find(".ui-menu-item-alternate")
|
||||
.removeClass("ui-menu-item-alternate").end()
|
||||
.find(".ui-autocomplete-value:odd").addClass("ui-menu-item-alternate");
|
||||
},
|
||||
|
||||
_buildValueRow: function(id, value, oneRow) {
|
||||
var self = this;
|
||||
$('<tr></tr>')
|
||||
.addClass("ui-autocomplete-value")
|
||||
.data("value.autocomplete", id)
|
||||
.append('<td>' + value.replace('\t', '</td><td>') + '</td><td><a href="#">x</a></td>')
|
||||
.appendTo(self.values_ul);
|
||||
if (oneRow !== false) {
|
||||
self._addZebra(self.values_ul);
|
||||
self.values.push(id);
|
||||
}
|
||||
},
|
||||
|
||||
_addRemoveOnClick: function() {
|
||||
var self = this;
|
||||
$( ".ui-autocomplete-value a", this.values_ul[0] ).live( "click", function() {
|
||||
var span = $(this).closest('tr');
|
||||
var id = span.data( "value.autocomplete" );
|
||||
$.each( self.values, function (i, v) {
|
||||
if (v === id) {
|
||||
self.values.splice(i, 1);
|
||||
}
|
||||
});
|
||||
span.remove();
|
||||
self._addZebra(self.values_ul);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
|
||||
_initManyToMany: function() {
|
||||
var self = this;
|
||||
this.element.bind( "autocompleteclose", function( event, ui ) {
|
||||
self.element.val( "" );
|
||||
});
|
||||
this.values = [];
|
||||
if ( this.hidden_input.val() !== "" ) {
|
||||
$.each(this.hidden_input.val().split( "," ), function(i, id) {
|
||||
self.values.push( parseInt(id, 10) );
|
||||
});
|
||||
}
|
||||
this.values_ul = this.element.nextAll( "table.ui-autocomplete-values" );
|
||||
this.lastSelected = { id: null, value: null };
|
||||
if ( this.values.length && this.values_ul[0] ) {
|
||||
this.values_ul.find('tr').each(function(i) {
|
||||
$(this)
|
||||
.addClass( "ui-autocomplete-value" )
|
||||
.data( "value.autocomplete", self.values[i] )
|
||||
.append( '<td><a href="#">x</a></td>' );
|
||||
});
|
||||
} else {
|
||||
this.values_ul = $( "<table></table>" ).appendTo( this.element.parent() );
|
||||
}
|
||||
// On DOM ready, move list to the end
|
||||
$(function() {
|
||||
self.values_ul.appendTo( self.element.parent() );
|
||||
});
|
||||
this.values_ul.addClass( "ui-autocomplete-values" );
|
||||
this._addZebra(this.values_ul);
|
||||
this._addRemoveOnClick();
|
||||
},
|
||||
|
||||
_initDelimiterList: function() {
|
||||
var self = this;
|
||||
this.autocomplete = this.element.data('autocomplete');
|
||||
this.element.val( "" );
|
||||
this.values = [];
|
||||
if ( this.hidden_input.val() !== "" ) {
|
||||
$.each(this.hidden_input.val().split( this.options.delimiter ), function(i, value) {
|
||||
self.values.push( $.trim(value) );
|
||||
});
|
||||
}
|
||||
this.lastSelected = { id: null, value: null };
|
||||
this.values_ul = $( '<table class="ui-autocomplete-values"></table>' ).appendTo( this.element.parent() );
|
||||
if ( this.values.length ) {
|
||||
$(this.values).each(function(index, value) {
|
||||
this._buildValueRow(value, value, false);
|
||||
})
|
||||
}
|
||||
// On DOM ready, move list to the end
|
||||
$(function() {
|
||||
self.values_ul.appendTo( self.element.parent() );
|
||||
});
|
||||
this._addZebra(this.values_ul);
|
||||
if (this.options.autoFocus) {
|
||||
this.element.bind( "autocompleteclose", function( event, ui ) {
|
||||
self.element.val( "" );
|
||||
});
|
||||
} else {
|
||||
// Add the typed text on enter
|
||||
var delimiter = this.options.delimiter;
|
||||
// Support both normal spaces and non-breaking spaces
|
||||
// if there's spaces in the delimiter
|
||||
if (delimiter.indexOf(' ') !== -1) {
|
||||
delimiter = new RegExp(delimiter.replace(' ', '(?: | )'));
|
||||
}
|
||||
this.element.bind("keydown", function(event){
|
||||
if (event.keyCode === $.ui.keyCode.ENTER &&
|
||||
!self.autocomplete.menu.active) {
|
||||
event.stopImmediatePropagation();
|
||||
var values = $(this).val().split(delimiter);
|
||||
$(this).val("");
|
||||
self.autocomplete.close();
|
||||
$.each(values, function(index, value) {
|
||||
if ( $.inArray( value, self.values ) < 0 ) {
|
||||
$('<tr></tr>')
|
||||
.addClass( "ui-autocomplete-value" )
|
||||
.data( "value.autocomplete", value )
|
||||
.append('<td>' + value + '</td><td><a href="#">x</a><td>')
|
||||
.appendTo( self.values_ul );
|
||||
self._addZebra(self.values_ul);
|
||||
self.values.push( value );
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
this._addRemoveOnClick();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
django.autocomplete = function (id, options) {
|
||||
return $(id).djangoautocomplete(options);
|
||||
};
|
||||
|
||||
window.django = django;
|
||||
|
||||
// Activate autocomplete on dynamically added row in inlines in admin.
|
||||
$(window).load(function() {
|
||||
// Get all the inlines
|
||||
$('.inline-group').each(function() {
|
||||
var inlineGroup = $(this);
|
||||
var acWidgets = [];
|
||||
// For each inlines check for autocomplete input in the empty form
|
||||
inlineGroup.find('.empty-form .ui-autocomplete-input').each(function() {
|
||||
var ac = $(this);
|
||||
// Copy the script tag and restore the pre-autocomplete state
|
||||
var script = ac.nextAll('script');
|
||||
acWidgets.push(script);
|
||||
script.remove();
|
||||
ac.nextAll('ul.ui-autocomplete').remove();
|
||||
ac.before($('<input id="' + ac.attr('id') + '" type="text" />'));
|
||||
ac.remove();
|
||||
});
|
||||
if (acWidgets.length > 0) {
|
||||
inlineGroup.find('.add-row a').attr('href', '#').click(function() {
|
||||
// Find the current id #
|
||||
var num = $('#id_' + inlineGroup.attr('id').replace(/group$/, 'TOTAL_FORMS')).val() - 1;
|
||||
$.each(acWidgets, function() {
|
||||
// Clone the script tag, add the id # and append the tag
|
||||
var widget = $(this).clone();
|
||||
widget.text(widget.text().replace('__prefix__', num));
|
||||
inlineGroup.append(widget);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
})(window);
|
|
@ -0,0 +1,54 @@
|
|||
function yui_autocomplete(name, ac_url, force_selection) {
|
||||
|
||||
this.name = name;
|
||||
this.ac_url = ac_url;
|
||||
this.force_selection = force_selection;
|
||||
|
||||
this.setup = function () {
|
||||
var datasource = new YAHOO.util.XHRDataSource(ac_url);
|
||||
datasource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
|
||||
datasource.responseSchema = {
|
||||
resultsList: "result",
|
||||
fields: ["label", "id"]
|
||||
};
|
||||
|
||||
datasource.doBeforeParseData = function (request, original, callback) {
|
||||
var parsed = {"result": []};
|
||||
for (var i in original)
|
||||
parsed.result.push({"id": original[i][0], "label": original[i][1]});
|
||||
return parsed;
|
||||
};
|
||||
datasource.resultTypeList = false;
|
||||
|
||||
var input = document.getElementById("id_"+name);
|
||||
var container = document.createElement("div");
|
||||
YAHOO.util.Dom.insertAfter(container, input);
|
||||
if (!YAHOO.util.Dom.hasClass(document.body, "yui-skin-sam"))
|
||||
YAHOO.util.Dom.addClass(document.body, "yui-skin-sam");
|
||||
|
||||
var autocomplete = new YAHOO.widget.AutoComplete(input, container, datasource);
|
||||
autocomplete.resultTypeList = false;
|
||||
autocomplete.queryDelay = .5;
|
||||
autocomplete.forceSelection = force_selection;
|
||||
autocomplete.generateRequest = function(sQuery) {
|
||||
return "?q="+sQuery;
|
||||
};
|
||||
|
||||
var hidden = document.getElementById("id_hidden_"+name);
|
||||
this.selected_item = {label: input.value, id: hidden.value};
|
||||
autocomplete.itemSelectEvent.subscribe(function (type, args) {
|
||||
this.selected_item = args[2];
|
||||
hidden.value = this.selected_item.id;
|
||||
});
|
||||
form = document.getElementsByTagName("form")[0];
|
||||
YAHOO.util.Event.addListener(form, "submit", function (event, form) {
|
||||
if ((!input.value) || (this.selected_item.label != input.value && !force_selection))
|
||||
hidden.value = input.value;
|
||||
});
|
||||
this.datasource = datasource;
|
||||
this.autocomplete = autocomplete;
|
||||
};
|
||||
YAHOO.util.Event.onDOMReady(this.setup, null, this);
|
||||
};
|
||||
|
||||
autocomplete = yui_autocomplete;
|
|
@ -9,7 +9,7 @@
|
|||
<div class="well">
|
||||
<ul style="list-style-type: none;">
|
||||
{% for tag in tags_list %}
|
||||
<li style="display: inline;"><a href="{% url list-by-tag tag.id %}">{{ tag.label }} ({{ tag.occurence }})</li>
|
||||
<li style="display: inline;"><a href="{% url list-by-tag tag.id %}"><span style="font-size: {{ tag.occurence }} / {{ total }}">{{ tag.label }} ({{ tag.occurence }})</span></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
|