Commit 23fcc9dd563adc61579b1cb262091f8a37d428dc
Committed by
Victor Costa
1 parent
9984b8c2
Exists in
staging
and in
4 other branches
Added field 'Text filter' autocomplete on Tasks list, to better filter data
Showing
4 changed files
with
27 additions
and
1 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
@@ -65,4 +65,11 @@ class TasksController < MyProfileController | @@ -65,4 +65,11 @@ class TasksController < MyProfileController | ||
65 | @ticket = Ticket.find(:first, :conditions => ['(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]]) | 65 | @ticket = Ticket.find(:first, :conditions => ['(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]]) |
66 | end | 66 | end |
67 | 67 | ||
68 | + def search_tasks | ||
69 | + @filter = params[:filter_type].blank? ? nil : params[:filter_type] | ||
70 | + result = Task.to(profile).without_spam.pending.of(@filter).like('data',params[:term]) | ||
71 | + | ||
72 | + render :json => result.map { |task| {:label => task.data[:name], :value => task.data[:name]} } | ||
73 | + end | ||
74 | + | ||
68 | end | 75 | end |
app/models/task.rb
@@ -239,6 +239,8 @@ class Task < ActiveRecord::Base | @@ -239,6 +239,8 @@ class Task < ActiveRecord::Base | ||
239 | scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } | 239 | scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } |
240 | scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } | 240 | scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } |
241 | scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} } | 241 | scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} } |
242 | + #scope :like, lambda { |field, value| {:conditions => ["LOWER(#{field}) LIKE ?", "%#{value}%"]}} | ||
243 | + scope :like, ->(field,value) { where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%")} | ||
242 | 244 | ||
243 | scope :to, lambda { |profile| | 245 | scope :to, lambda { |profile| |
244 | environment_condition = nil | 246 | environment_condition = nil |
app/views/tasks/index.html.erb
@@ -38,11 +38,24 @@ | @@ -38,11 +38,24 @@ | ||
38 | 38 | ||
39 | <ul class='task-list'> | 39 | <ul class='task-list'> |
40 | <p> | 40 | <p> |
41 | - <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :onchange => "document.location.href = '?filter_type='+this.value") %> | 41 | + <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, {:onchange => "document.location.href = '?filter_type='+this.value", :id => 'filter-type'}) %> |
42 | + </p> | ||
43 | + <p> | ||
44 | + <%= labelled_text_field(_("Text filter")+': ', :text_filter, nil, {:id => 'text-filter-autocomplete'}) %> | ||
45 | + <script type="text/javascript"> | ||
46 | + jQuery('#text-filter-autocomplete').autocomplete({ | ||
47 | + source:<%= "'/myprofile/#{profile.identifier}/tasks/search_tasks'" %>+'?filter_type='+jQuery('#filter-type').val(), | ||
48 | + minLength:3, | ||
49 | + select:function(event,ui){ | ||
50 | + document.location.href += '&term='+ui.item.value | ||
51 | + } | ||
52 | + }); | ||
53 | + </script> | ||
42 | </p> | 54 | </p> |
43 | <p> | 55 | <p> |
44 | <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "up-set-all-tasks-to") %> | 56 | <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "up-set-all-tasks-to") %> |
45 | </p> | 57 | </p> |
58 | + | ||
46 | <% @tasks.each do |task| %> | 59 | <% @tasks.each do |task| %> |
47 | <%= render :partial => 'task', :locals => { :task => task } %> | 60 | <%= render :partial => 'task', :locals => { :task => task } %> |
48 | <% end %> | 61 | <% end %> |
public/stylesheets/application.css
@@ -6746,6 +6746,10 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img { | @@ -6746,6 +6746,10 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img { | ||
6746 | 6746 | ||
6747 | /* AutoComplete*/ | 6747 | /* AutoComplete*/ |
6748 | .formfield input.ui-autocomplete-loading { background: url('/images/loading-small.gif') right center no-repeat, url("../images/input-bg.gif") no-repeat left top; } | 6748 | .formfield input.ui-autocomplete-loading { background: url('/images/loading-small.gif') right center no-repeat, url("../images/input-bg.gif") no-repeat left top; } |
6749 | +.ui-autocomplete-loading{ | ||
6750 | + background: url('/images/loading-small.gif') right center no-repeat | ||
6751 | +} | ||
6752 | + | ||
6749 | 6753 | ||
6750 | .ui-autocomplete-category { | 6754 | .ui-autocomplete-category { |
6751 | font-weight: bold; | 6755 | font-weight: bold; |