diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb index 9e3c268..82937f5 100644 --- a/app/controllers/my_profile/tasks_controller.rb +++ b/app/controllers/my_profile/tasks_controller.rb @@ -65,4 +65,11 @@ class TasksController < MyProfileController @ticket = Ticket.find(:first, :conditions => ['(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]]) end + def search_tasks + @filter = params[:filter_type].blank? ? nil : params[:filter_type] + result = Task.to(profile).without_spam.pending.of(@filter).like('data',params[:term]) + + render :json => result.map { |task| {:label => task.data[:name], :value => task.data[:name]} } + end + end diff --git a/app/models/task.rb b/app/models/task.rb index 0620e84..12bd631 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -239,6 +239,8 @@ class Task < ActiveRecord::Base scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} } + #scope :like, lambda { |field, value| {:conditions => ["LOWER(#{field}) LIKE ?", "%#{value}%"]}} + scope :like, ->(field,value) { where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%")} scope :to, lambda { |profile| environment_condition = nil diff --git a/app/views/tasks/index.html.erb b/app/views/tasks/index.html.erb index d5da684..a654728 100644 --- a/app/views/tasks/index.html.erb +++ b/app/views/tasks/index.html.erb @@ -38,11 +38,24 @@