aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKir2011-11-03 19:07:54 +0400
committerKir2011-11-03 19:07:54 +0400
commita9c97ba576f190c18544919af477753c419036cf (patch)
tree48c8a13e862fa249fad50420b077d6f9b1155d4f
parente855fb8574570934cde28cfb190cc3cba31fbec0 (diff)
downloadinboxes-a9c97ba576f190c18544919af477753c419036cf.tar.bz2
REST speakers controller, cganges in locale files
-rw-r--r--app/controllers/discussions_controller.rb11
-rw-r--r--app/controllers/messages_controller.rb2
-rw-r--r--app/controllers/speakers_controller.rb4
-rw-r--r--app/models/discussion.rb12
-rw-r--r--app/views/discussions/show.html.haml2
-rw-r--r--config/locales/en.yml4
-rw-r--r--config/locales/ru.yml14
7 files changed, 22 insertions, 27 deletions
diff --git a/app/controllers/discussions_controller.rb b/app/controllers/discussions_controller.rb
index cf658b6..48f6652 100644
--- a/app/controllers/discussions_controller.rb
+++ b/app/controllers/discussions_controller.rb
@@ -12,7 +12,7 @@ class DiscussionsController < ApplicationController
# GET /discussions/1.json
def show
@discussion = Discussion.includes(:messages, :speakers).find(params[:id])
- redirect_to discussions_url, :notice => t("views.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
+ redirect_to discussions_url, :notice => t("inboxes.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
@discussion.mark_as_read_for(current_user)
end
@@ -36,17 +36,12 @@ class DiscussionsController < ApplicationController
end
if @discussion.save
- redirect_to @discussion, :notice => t("views.discussions.started")
+ redirect_to @discussion, :notice => t("inboxes.discussions.started")
else
render :action => "new"
end
end
- def leave
- @discussion.remove_speaker(current_user)
- redirect_to discussions_url, :notice => t("views.discussions.leaved")
- end
-
private
def load_and_check_discussion_recipient
@@ -64,7 +59,7 @@ class DiscussionsController < ApplicationController
Message.create(:discussion => discussion, :user => current_user, :body => message.body) if message.body
end
# перекидываем на нее
- redirect_to discussion_url(discussion), :notice => t("views.discussions.exists", :user => user[Inboxes::config.user_name])
+ redirect_to discussion_url(discussion), :notice => t("inboxes.discussions.exists", :user => user[Inboxes::config.user_name])
end
end
end
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index a302237..7baf8df 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -2,7 +2,7 @@ class MessagesController < ApplicationController
def create
@discussion = Discussion.find(params[:discussion_id])
- redirect_to root_url, :notice => t("views.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
+ redirect_to root_url, :notice => t("inboxes.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
@message = Message.new(params[:message])
@message.user = current_user
diff --git a/app/controllers/speakers_controller.rb b/app/controllers/speakers_controller.rb
index 17cedb9..db90dbe 100644
--- a/app/controllers/speakers_controller.rb
+++ b/app/controllers/speakers_controller.rb
@@ -13,7 +13,7 @@ class SpeakersController < ApplicationController
def destroy
@speaker = Speaker.find(params[:id])
@speaker.destroy
- flash[:notice] = t("views.speakers.removed")
+ flash[:notice] = @speaker.user == current_user ? t("inboxes.discussions.leaved") : t("inboxes.speakers.removed")
redirect_to @discussion.speakers.any? && @discussion.can_participate?(current_user) ? @discussion : discussions_url
end
@@ -21,6 +21,6 @@ class SpeakersController < ApplicationController
def init_and_check_permissions
@discussion = Discussion.find(params[:discussion_id])
- redirect_to discussions_url, :notice => t("views.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
+ redirect_to discussions_url, :notice => t("inboxes.discussions.can_not_participate") unless @discussion.can_participate?(current_user)
end
end
diff --git a/app/models/discussion.rb b/app/models/discussion.rb
index ad53523..7cab6f0 100644
--- a/app/models/discussion.rb
+++ b/app/models/discussion.rb
@@ -99,16 +99,16 @@ class Discussion < ActiveRecord::Base
# пометить как прочитанная
def mark_as_read_for(user)
- true
- # flag = DiscussionView.find_or_create_by_user_id_and_discussion_id(user.id, self.id)
- # flag.touch
+ # true
+ flag = DiscussionView.find_or_create_by_user_id_and_discussion_id(user.id, self.id)
+ flag.touch
end
-
- private
-
+
def find_speaker_by_user user
Speaker.find_by_discussion_id_and_user_id(self.id, user.id)
end
+
+ private
def check_that_has_at_least_two_users
Rails.logger.info self.recipient_ids
diff --git a/app/views/discussions/show.html.haml b/app/views/discussions/show.html.haml
index 6672c54..e25d0a2 100644
--- a/app/views/discussions/show.html.haml
+++ b/app/views/discussions/show.html.haml
@@ -35,5 +35,5 @@
= render "messages/form"
%p
- = link_to "Выйти из переписки", leave_discussion_path(@discussion), :method => :post unless @discussion.private?
+ = link_to "Leave discussion", discussion_speaker_path(@discussion, @discussion.find_speaker_by_user(current_user)), :method => :delete unless @discussion.private?
= link_to "All discussions", discussions_path \ No newline at end of file
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 34906af..e7013f5 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -3,12 +3,12 @@ en:
attributes:
discussion:
recipient_tokens: "Recipients"
- views:
+ inboxes:
speakers:
added: "Speaker was added to discussion"
removed: "Speaker was removed from discussion"
discussions:
started: "Discussion started"
- leaved: "You leaved discussion"
+ leaved: "You leaved the discussion"
exists: "Discussion between you and %{user} already exists"
can_not_participate: "You are not listed in this discussion" \ No newline at end of file
diff --git a/config/locales/ru.yml b/config/locales/ru.yml
index cc4844e..f0e4f04 100644
--- a/config/locales/ru.yml
+++ b/config/locales/ru.yml
@@ -5,12 +5,12 @@ ru:
recipient_tokens: "Получатели"
message:
body: "Сообщение"
- views:
+ inboxes:
discussions:
- started: "Чат начат."
- leaved: "Вы покинули дискуссию."
- exists: "Дискуссия между вами и %{user} уже существует."
- can_not_participate: "Вы не состоите в этой дискуссии."
+ started: "Чат начат"
+ leaved: "Вы покинули дискуссию"
+ exists: "Дискуссия между вами и %{user} уже существует"
+ can_not_participate: "Вы не состоите в этой дискуссии"
speakers:
- added: "Участник дискуссии добавлен."
- removed: "Участник дискуссии удален." \ No newline at end of file
+ added: "Участник дискуссии добавлен"
+ removed: "Участник дискуссии удален" \ No newline at end of file