Class: Muck::ActivitiesController

Inherits:
ApplicationController
  • Object
show all
Includes:
ApplicationHelper, MuckActivityHelper
Defined in:
app/controllers/muck/activities_controller.rb

Instance Method Summary collapse

Methods included from MuckActivityHelper

#activity_comment_link, #activity_comments, #activity_feed_for, #activity_filter, #all_activities_url, #current_status, #delete_activity, #get_activities, #has_comments_css, #is_current_filter?, #no_filter?, #status_update

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/muck/activities_controller.rb', line 22

def create
  @activity = @parent.activities.build(params[:activity])
  @activity.source = @parent
  @activity.content.gsub!(@parent.display_name, '')
  @parent.save!

  @activity_html = get_activity_html(@activity)
  if @activity.template == 'status_update'
    @status_html = get_status_html(@parent)
  else
    @status_html = ''
  end
  respond_to do |format|
    format.js do
      render :update do |page|
        page.insert_html :top, 'activity-feed-content', @activity_html
        page.replace_html 'current-status', @status_html if @status_html
        page.visual_effect :highlight, "#{@activity.dom_id}".to_sym
        page << 'jQuery("#status_update").val(\'\');'
        page << "jQuery('#status-update-field').removeClass('status-update-lit');"
        page << "jQuery('#status-update-field').addClass('status-update-dim');" 
        page << 'jQuery("#status-update-field").show();'
        page << 'jQuery("#submit_status").show();'
        page << 'jQuery("#progress-bar").hide();'
        page << 'setup_submit_delete();'
        page << 'apply_comment_methods();'
      end
    end
    format.html do
      redirect_back_or_default(@parent)
    end
    format.json do
      render :json => { :success => true,
                        :is_status_update => @activity.is_status_update,
                        :html => @activity_html,
                        :status_html => @status_html,
                        :message => t("muck.activities.created") }
    end
  end

rescue ActiveRecord::RecordInvalid => ex

  if @activity
    errors = @activity.errors.full_messages.to_sentence
  else
    errors = ex
  end
  message = t('muck.activities.update_error', :errors => errors)
  respond_to do |format|
    format.html do
      flash[:error] = message
      redirect_back_or_default(@parent)
    end
    format.js do
      render :update do |page|
        page_alert(page, message)
      end
    end
  end

end

#destroyObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/controllers/muck/activities_controller.rb', line 84

def destroy
  @activities_object = @activity.source
  @activity.destroy
  respond_to do |format|
    format.html do
      flash[:notice] = t("muck.activities.item_removed")
      redirect_back_or_default(@activities_object)
    end
    format.js do
      if @activity.is_status_update
        @new_status = get_status_html(@activities_object)
        render(:update) do |page|
          page << "jQuery('##{@activity.dom_id}').fadeOut();"
          page.replace_html 'current-status', @new_status if @new_status
        end
      end
    end
    format.json do
      @new_status = get_status_html(@activities_object)
      render :json => { :success => true,
                        :is_status_update => @activity.is_status_update,
                        :html => @new_status,
                        :message => t("muck.activities.item_removed") }
    end
  end

rescue => ex
  respond_to do |format|
    format.html do
      flash[:notice] = t("muck.activities.item_could_not_be_removed")
      redirect_back_or_default(current_user)
    end
    format.js do
      render(:update){ |page| page_alert(page, t("muck.activities.item_could_not_be_removed")) }
    end
    format.json { render :json => { :success => false, :message => t("muck.activities.item_could_not_be_removed") } }
  end
end

#indexObject



11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/muck/activities_controller.rb', line 11

def index
  if @parent.can_view?(current_user)
    @activities = get_activities(@parent)
    respond_to do |format|
      format.js do
        render :partial => "activities/cached_activities", :locals => {:activities => @activities}
      end
    end
  end
end