app/controllers/searches_controller.rb in artfully_ose-1.2.0 vs app/controllers/searches_controller.rb in artfully_ose-1.3.0.pre1

- old
+ new

@@ -1,15 +1,14 @@ class SearchesController < ApplicationController before_filter :load_discount_codes + before_filter :set_campaigns_and_appeals, :only => [:new, :show] before_filter :load_tags, :only => [:new, :show] def new authorize! :view, Search @search = Search.new(params[:search]) - @membership_types = current_user.current_organization.membership_types.all - @pass_types = current_user.current_organization.pass_types.all prepare_form end def create authorize! :create, Search @@ -21,33 +20,65 @@ def show @search = Search.find(params[:id]) authorize! :view, @search @segment = Segment.new - @membership_types = current_user.current_organization.membership_types.all - @pass_types = current_user.current_organization.pass_types.all session[:return_to] ||= request.referer # Record the current page, in case creating a list segment fails. prepare_form prepare_people respond_to do |format| format.html { @people = @people.paginate(:page => params[:page], :per_page => (params[:per_page] || 20)) } - format.csv { render :csv => Person.where(:id => @people.collect(&:id)).includes(:phones, :address, :tags).order('lower(people.last_name)'), :filename => "#{@search.id}-#{DateTime.now.strftime("%m-%d-%y")}" } + format.csv do + job_monitor = JobMonitor.enqueue(current_organization, + SearchExportJob.new(current_organization.id, @search.id), + {:return_url => search_url(@search)}) + redirect_to monitor_path(job_monitor) + end end end def tag @search = Search.find(params[:id]) - authorize! :tag, Segment + authorize! :manage, Search @search.tag(params[:name]) flash[:notice] = "We're tagging all the people and we'll be done shortly. Refresh this page in a minute or two." redirect_to @search end + def subscribe + @search = Search.find(params[:id]) + authorize! :subscribe, Search + job = MailchimpSyncJob.new(@search.organization.kits.mailchimp, { + :type => "subscribe_search", + :search_id => @search.id, + :list_id => params[:list_id], + }) + Delayed::Job.enqueue(job, :queue => "mailchimp") + flash[:notice] = "We're subscribing new people now and we'll be done shortly." + redirect_to @search + end + + def add_group + @search = Search.find(params[:id]) + authorize! :subscribe, Search + job = MailchimpSyncJob.new(@search.organization.kits.mailchimp, { + :type => "add_group_search", + :search_id => @search.id, + :grouping => params[:grouping], + }) + Delayed::Job.enqueue(job, :queue => "mailchimp") + flash[:notice] = "We're adding new people now and we'll be done shortly." + redirect_to @search + end + private def prepare_form + @membership_types = MembershipType.in_play(current_user.current_organization) + @pass_types = current_user.current_organization.pass_types.all @event_options = Event.options_for_select_by_organization(@current_user.current_organization) @event_options.unshift(["Any Event", Search::ANY_EVENT]) + @campaigns = current_user.current_organization.campaigns.active end def prepare_people @people = @search.people end