From bf3e63a75b8fbc9d613ec3fd6289a178731692e4 Mon Sep 17 00:00:00 2001 From: Reed Loden Date: Mon, 5 Jul 2010 02:42:01 -0500 Subject: [PATCH] Bug 455810 - Add autocomplete support to the keywords field * Special thanks to Guy Pyrzak for the original patch [r=mkanat a=mkanat] --- Bugzilla/Constants.pm | 2 ++ Bugzilla/Field.pm | 4 +-- Bugzilla/Template.pm | 3 ++ js/field.js | 34 ++++++++++++++++-- skins/standard/IE-fixes.css | 10 ++++-- skins/standard/global.css | 20 +++++++++-- .../en/default/bug/create/create.html.tmpl | 11 +++--- template/en/default/bug/edit.html.tmpl | 9 +++-- template/en/default/bug/field.html.tmpl | 27 ++++++++++---- .../en/default/list/edit-multiple.html.tmpl | 25 +++++++------ template/en/default/search/field.html.tmpl | 35 ++++++++++++++++--- .../default/search/search-advanced.html.tmpl | 2 +- 12 files changed, 140 insertions(+), 42 deletions(-) diff --git a/Bugzilla/Constants.pm b/Bugzilla/Constants.pm index d11736af10..a003ce7398 100644 --- a/Bugzilla/Constants.pm +++ b/Bugzilla/Constants.pm @@ -128,6 +128,7 @@ use File::Basename; FIELD_TYPE_DATETIME FIELD_TYPE_BUG_ID FIELD_TYPE_BUG_URLS + FIELD_TYPE_KEYWORDS EMPTY_DATETIME_REGEX @@ -395,6 +396,7 @@ use constant FIELD_TYPE_TEXTAREA => 4; use constant FIELD_TYPE_DATETIME => 5; use constant FIELD_TYPE_BUG_ID => 6; use constant FIELD_TYPE_BUG_URLS => 7; +use constant FIELD_TYPE_KEYWORDS => 8; use constant EMPTY_DATETIME_REGEX => qr/^[0\-:\sA-Za-z]+$/; diff --git a/Bugzilla/Field.pm b/Bugzilla/Field.pm index 9ab5c49b9e..15b4947627 100644 --- a/Bugzilla/Field.pm +++ b/Bugzilla/Field.pm @@ -182,7 +182,7 @@ use constant DEFAULT_FIELDS => ( {name => 'status_whiteboard', desc => 'Status Whiteboard', in_new_bugmail => 1, buglist => 1}, {name => 'keywords', desc => 'Keywords', in_new_bugmail => 1, - buglist => 1}, + type => FIELD_TYPE_KEYWORDS, buglist => 1}, {name => 'resolution', desc => 'Resolution', type => FIELD_TYPE_SINGLE_SELECT, buglist => 1}, {name => 'bug_severity', desc => 'Severity', in_new_bugmail => 1, @@ -322,7 +322,7 @@ sub _check_type { my $saved_type = $type; # The constant here should be updated every time a new, # higher field type is added. - (detaint_natural($type) && $type <= FIELD_TYPE_BUG_URLS) + (detaint_natural($type) && $type <= FIELD_TYPE_KEYWORDS) || ThrowCodeError('invalid_customfield_type', { type => $saved_type }); my $custom = blessed($invocant) ? $invocant->custom : $params->{custom}; diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index a317bb7c70..71ade2f016 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -765,6 +765,9 @@ sub create { # Whether or not keywords are enabled, in this Bugzilla. 'use_keywords' => sub { return Bugzilla::Keyword->any_exist; }, + # All the keywords. + 'all_keywords' => sub { return Bugzilla::Keyword->get_all(); }, + 'feature_enabled' => sub { return Bugzilla->feature(@_); }, # field_descs can be somewhat slow to generate, so we generate diff --git a/js/field.js b/js/field.js index 39b272f920..20485bcc8c 100644 --- a/js/field.js +++ b/js/field.js @@ -16,6 +16,7 @@ * * Contributor(s): Max Kanat-Alexander * Guy Pyrzak + * Reed Loden */ /* This library assumes that the needed YUI libraries have been loaded @@ -621,8 +622,8 @@ YAHOO.bugzilla.userAutocomplete = { userAutoComp.autoHighlight = false; // this is a throttle to determine the delay of the query from typing // set this higher to cause fewer calls to the server - userAutoComp.queryDelay = 0.05 - userAutoComp.useIFrame = true + userAutoComp.queryDelay = 0.05; + userAutoComp.useIFrame = true; userAutoComp.resultTypeList = false; if( multiple == true ){ userAutoComp.delimChar = [","," "]; @@ -631,3 +632,32 @@ YAHOO.bugzilla.userAutocomplete = { } }; +YAHOO.bugzilla.keywordAutocomplete = { + dataSource : null, + init_ds : function(){ + this.dataSource = new YAHOO.util.LocalDataSource( YAHOO.bugzilla.keyword_array ); + }, + init : function( field, container ) { + if( this.dataSource == null ){ + this.init_ds(); + } + var keywordAutoComp = new YAHOO.widget.AutoComplete(field, container, this.dataSource); + keywordAutoComp.maxResultsDisplayed = YAHOO.bugzilla.keyword_array.length; + keywordAutoComp.minQueryLength = 0; + keywordAutoComp.useIFrame = true; + keywordAutoComp.delimChar = [","," "]; + keywordAutoComp.resultTypeList = false; + keywordAutoComp.queryDelay = 0; + /* Causes all the possibilities in the keyword to appear when a user + * focuses on the textbox + */ + keywordAutoComp.textboxFocusEvent.subscribe( function(){ + var sInputValue = YAHOO.util.Dom.get('keywords').value; + if( sInputValue.length === 0 ){ + this.sendQuery(sInputValue); + this.collapseContainer(); + this.expandContainer(); + } + }); + } +}; diff --git a/skins/standard/IE-fixes.css b/skins/standard/IE-fixes.css index 1b6b9929f8..fc22253985 100644 --- a/skins/standard/IE-fixes.css +++ b/skins/standard/IE-fixes.css @@ -47,6 +47,10 @@ form#Create #comp_desc { #bug_id_container, .search_field_grid, .search_email_fields, ul.bug_changes li { - zoom: 1; - display: inline; -} \ No newline at end of file + zoom: 1; + display: inline; +} + +#keyword_container .yui-ac-content { + _height: 30em; /* ie6 */ +} diff --git a/skins/standard/global.css b/skins/standard/global.css index 5cc71ef533..f0809c33a3 100644 --- a/skins/standard/global.css +++ b/skins/standard/global.css @@ -527,7 +527,21 @@ input.required, select.required, span.required_explanation { background-image: url(global/down.png); } -/* custom styles for inline instances of autocomplete input fields*/ +/* custom styles for inline instances of autocomplete input fields */ .yui-skin-sam .yui-ac-input { position:static !important; - vertical-align:middle !important;} -.yui-skin-sam .yui-ac-container { left:0px !important;} + vertical-align:middle !important; + width:auto !important; } +.yui-skin-sam .yui-ac-container { left:0px !important; } +.yui-skin-sam .yui-ac { display: inline-block; } + +#keyword_container { + padding-bottom: 2em; + padding-top: .2em; +} + +#keyword_container .yui-ac-content { + max-height: 19em; + overflow: auto; + overflow-x: hidden; + margin-left: -1px; +} diff --git a/template/en/default/bug/create/create.html.tmpl b/template/en/default/bug/create/create.html.tmpl index 0733de02a0..fdac893c07 100644 --- a/template/en/default/bug/create/create.html.tmpl +++ b/template/en/default/bug/create/create.html.tmpl @@ -630,14 +630,11 @@ TUI_hide_default('expert_fields'); [% IF user.in_group('editbugs', product.id) %] [% IF use_keywords %] - [% INCLUDE "bug/field-label.html.tmpl" - field = bug_fields.keywords editable = 1 - desc_url = "describekeywords.cgi" + [% INCLUDE bug/field.html.tmpl + bug = default, field = bug_fields.keywords, editable = 1, + value = keywords, desc_url = "describekeywords.cgi", + value_span = 2 %] - - (optional) - [% END %] diff --git a/template/en/default/bug/edit.html.tmpl b/template/en/default/bug/edit.html.tmpl index 0ef3cba8f4..5520e76996 100644 --- a/template/en/default/bug/edit.html.tmpl +++ b/template/en/default/bug/edit.html.tmpl @@ -591,8 +591,13 @@ : - [% PROCESS input inputname => "keywords" size => 40 colspan => 2 - value => bug.keywords.join(', ') %] + + [% INCLUDE bug/field.html.tmpl + bug = bug, field = bug_fields.keywords, value = bug.keywords + editable = bug.check_can_change_field("keywords", 0, 1), + no_tds = 1 + %] + [% END %] [% END %] diff --git a/template/en/default/bug/field.html.tmpl b/template/en/default/bug/field.html.tmpl index 97d38661c2..2417ce39b2 100644 --- a/template/en/default/bug/field.html.tmpl +++ b/template/en/default/bug/field.html.tmpl @@ -18,6 +18,8 @@ # Contributor(s): Myk Melez # Max Kanat-Alexander # Elliotte Martin + # Guy Pyrzak + # Reed Loden #%] [%# INTERFACE: @@ -165,22 +167,35 @@ [% FOREACH url = value %]
  • [% url FILTER html %] - [% IF editable %] - - [% END %] +
  • [% END %] [% '' IF value.size %] - [% IF editable && Param('use_see_also') %] + [% IF Param('use_see_also') %]
    [% END %] + [% CASE constants.FIELD_TYPE_KEYWORDS %] +
    + +
    +
    + [% END %] [% ELSIF field.type == constants.FIELD_TYPE_TEXTAREA %]
    [% value FILTER wrap_comment(60) diff --git a/template/en/default/list/edit-multiple.html.tmpl b/template/en/default/list/edit-multiple.html.tmpl index 619afe8ddd..87eb0c7d45 100644 --- a/template/en/default/list/edit-multiple.html.tmpl +++ b/template/en/default/list/edit-multiple.html.tmpl @@ -19,6 +19,7 @@ # Max Kanat-Alexander # Frédéric Buclin # Guy Pyrzak + # Reed Loden #%] [% PROCESS global/variables.none.tmpl %] @@ -173,7 +174,7 @@ id => "assigned_to" name => "assigned_to" value => dontchange - size => 32 + size => 40 %] @@ -188,7 +189,7 @@ id => "qa_contact" name => "qa_contact" value => dontchange - size => 32 + size => 40 %] @@ -200,7 +201,7 @@ - + + [% INCLUDE bug/field.html.tmpl + field = bug_fields.keywords, editable = 1, value = keywords + no_tds = 1 + %] + + + [% CASE constants.FIELD_TYPE_KEYWORDS %] + [% INCLUDE "bug/field-label.html.tmpl" + field = field + tag_name = "span" + editable = 1 + %] + [% INCLUDE "search/type-select.html.tmpl" + name = field.name _ "_type", + types = types, + selected = type_selected + %] +
    + +
    +
    + [% CASE constants.FIELD_TYPE_DATETIME %] [% INCLUDE "bug/field-label.html.tmpl" field = field @@ -113,5 +139,4 @@ [% END %]
    - [% END %] - \ No newline at end of file + [% END %] diff --git a/template/en/default/search/search-advanced.html.tmpl b/template/en/default/search/search-advanced.html.tmpl index 1e0cc9251d..fa9819c35c 100644 --- a/template/en/default/search/search-advanced.html.tmpl +++ b/template/en/default/search/search-advanced.html.tmpl @@ -38,7 +38,7 @@ var queryform = "queryform" title = "Search for $terms.bugs" onload = "doOnSelectProduct(0); enableHelp();" javascript = js_data - yui = [ 'calendar' ] + yui = [ 'autocomplete', 'calendar' ] javascript_urls = [ "js/productform.js", "js/util.js", "js/help.js" , "js/TUI.js", "js/field.js"] style_urls = [ "skins/standard/help.css" , "skins/standard/search_form.css" ] -- 2.47.2