The tags are suggested based on the entries the user makes.

Cambios para hacer commit:
	modificado:    app/assets/javascripts/tag_autocomplete.js.coffee
	modificado:    app/assets/stylesheets/autocomplete_overrides.scss
	nuevo archivo: app/controllers/tags_controller.rb
	modificado:    app/models/abilities/common.rb
	modificado:    app/views/debates/_form.html.erb
	modificado:    app/views/proposals/_form.html.erb
	modificado:    config/initializers/acts_as_taggable_on.rb
	modificado:    config/routes.rb
	modificado:    spec/lib/acts_as_taggable_on_spec.rb
This commit is contained in:
iagirre
2017-09-21 18:21:45 +02:00
parent 049967649e
commit 4db2584f87
9 changed files with 86 additions and 47 deletions

View File

@@ -7,13 +7,18 @@ App.TagAutocomplete =
return (App.TagAutocomplete.split( term ).pop())
init_autocomplete: ->
$('.js-tag-list').autocomplete
$('.tag-autocomplete').autocomplete
source: (request, response) ->
response( $.ui.autocomplete.filter(["Arbol", "Becerro", "Caracol"], App.TagAutocomplete.extractLast( request.term ) ) );
$.ajax
url: $('.tag-autocomplete').data('js-url'),
data: {search: App.TagAutocomplete.extractLast( request.term )},
type: 'GET',
dataType: 'json'
success: ( data ) ->
response( data );
minLength: 0,
search: ->
console.log(this.value);
console.log(App.TagAutocomplete.extractLast( this.value ));
App.TagAutocomplete.extractLast( this.value );
focus: ->
return false;

View File

@@ -4,7 +4,6 @@
/* Autocomplete
----------------------------------*/
.ui-autocomplete { position: absolute; cursor: default; }
.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
/* workarounds */
* html .ui-autocomplete { width:1px; } /* without this, the menu expands to 100% in IE6 */
@@ -13,29 +12,23 @@
----------------------------------*/
.ui-menu {
list-style:none;
padding: 0px 5px;
margin: 0;
padding: $line-height / 4 $line-height / 3;
display:block;
/*width:227px;*/
background: white;
border: 1px solid $border;
}
.ui-menu .ui-menu {
margin-top: -3px;
}
.ui-menu .ui-menu-item {
margin:0;
padding: 0;
width: 200px;
}
.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 {
margin: -1px;
font-size: $small-font-size;
.ui-menu-item {
.ui-menu-item-wrapper {
padding: $line-height / 4 $line-height / 3;
position: relative;
}
.ui-state-hover, .ui-state-active {
background: #ececec;
border-radius: rem-calc(6);
}
}
}

View File

@@ -0,0 +1,11 @@
class TagsController < ApplicationController
load_and_authorize_resource class: ActsAsTaggableOn::Tag
respond_to :json
def suggest
@tags = ActsAsTaggableOn::Tag.search(params[:search]).map(&:name)
respond_with @tags
end
end

View File

@@ -24,6 +24,7 @@ module Abilities
can :suggest, Debate
can :suggest, Proposal
can :suggest, ActsAsTaggableOn::Tag
can [:flag, :unflag], Comment
cannot [:flag, :unflag], Comment, user_id: user.id

View File

@@ -23,7 +23,8 @@
label: false,
placeholder: t("debates.form.tags_placeholder"),
aria: {describedby: "tag-list-help-text"},
data: {js_url: tags_search_path}%>
data: {js_url: suggest_tags_path},
class: 'tag-autocomplete'%>
</div>
<div class="small-12 column">
<% if @debate.new_record? %>

View File

@@ -70,8 +70,9 @@
<%= f.text_field :tag_list, value: @proposal.tag_list.to_s,
label: false,
placeholder: t("proposals.form.tags_placeholder"),
class: 'js-tag-list',
aria: {describedby: "tag-list-help-text"} %>
class: 'js-tag-list tag-autocomplete',
aria: {describedby: "tag-list-help-text"},
data: {js_url: suggest_tags_path} %>
</div>
<% if current_user.unverified? %>