Class: Thredded::PrivateTopicForm
- Inherits:
-
Object
- Object
- Thredded::PrivateTopicForm
- Includes:
- ActiveModel::Model
- Defined in:
- app/forms/thredded/private_topic_form.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#category_ids ⇒ Object
Returns the value of attribute category_ids.
-
#content ⇒ Object
Returns the value of attribute content.
-
#locked ⇒ Object
Returns the value of attribute locked.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#sticky ⇒ Object
Returns the value of attribute sticky.
-
#title ⇒ Object
Returns the value of attribute title.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#user_ids ⇒ Object
Returns the value of attribute user_ids.
- #user_names ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ PrivateTopicForm
constructor
A new instance of PrivateTopicForm.
- #post ⇒ Object
- #preview_path ⇒ Object
- #private_topic ⇒ Object
- #save ⇒ Object
- #submit_path ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ PrivateTopicForm
Returns a new instance of PrivateTopicForm.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/forms/thredded/private_topic_form.rb', line 24 def initialize(params = {}) @params = params @title = params[:title] @category_ids = params[:category_ids] || [] @user_ids = params[:user_ids] || [] @user = params[:user] || fail('user is required') @locked = params[:locked] @sticky = params[:sticky] @content = params[:content] @user_names = params[:user_names] end |
Instance Attribute Details
#category_ids ⇒ Object
Returns the value of attribute category_ids.
11 12 13 |
# File 'app/forms/thredded/private_topic_form.rb', line 11 def category_ids @category_ids end |
#content ⇒ Object
Returns the value of attribute content.
11 12 13 |
# File 'app/forms/thredded/private_topic_form.rb', line 11 def content @content end |
#locked ⇒ Object
Returns the value of attribute locked.
11 12 13 |
# File 'app/forms/thredded/private_topic_form.rb', line 11 def locked @locked end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
19 20 21 |
# File 'app/forms/thredded/private_topic_form.rb', line 19 def params @params end |
#sticky ⇒ Object
Returns the value of attribute sticky.
11 12 13 |
# File 'app/forms/thredded/private_topic_form.rb', line 11 def sticky @sticky end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'app/forms/thredded/private_topic_form.rb', line 11 def title @title end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
19 20 21 |
# File 'app/forms/thredded/private_topic_form.rb', line 19 def user @user end |
#user_ids ⇒ Object
Returns the value of attribute user_ids.
11 12 13 |
# File 'app/forms/thredded/private_topic_form.rb', line 11 def user_ids @user_ids end |
#user_names ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'app/forms/thredded/private_topic_form.rb', line 79 def user_names @user_names ||= Thredded.user_class.where(id: user_ids).pluck(Thredded.user_name_column).map do |name| if name.include?(',') "\"#{name}\"" else name end end.join(', ') end |
Class Method Details
.model_name ⇒ Object
36 37 38 |
# File 'app/forms/thredded/private_topic_form.rb', line 36 def self.model_name Thredded::PrivateTopic.model_name end |
Instance Method Details
#post ⇒ Object
64 65 66 67 68 69 |
# File 'app/forms/thredded/private_topic_form.rb', line 64 def post @post ||= private_topic.posts.build( content: content, user: non_null_user ) end |
#preview_path ⇒ Object
75 76 77 |
# File 'app/forms/thredded/private_topic_form.rb', line 75 def preview_path Thredded::UrlsHelper.preview_new_private_topic_path end |
#private_topic ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'app/forms/thredded/private_topic_form.rb', line 55 def private_topic @private_topic ||= Thredded::PrivateTopic.new( title: title, users: private_users, user: non_null_user, last_user: non_null_user ) end |
#save ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/forms/thredded/private_topic_form.rb', line 40 def save @user_ids ||= [] @user_ids += Thredded.user_class.where(Thredded.user_name_column => parse_names(user_names)).pluck(:id) return false unless valid? ActiveRecord::Base.transaction do new_topic = !private_topic.persisted? private_topic.save! post.save! Thredded::UserPrivateTopicReadState.read_on_first_post!(user, post) if new_topic end true end |
#submit_path ⇒ Object
71 72 73 |
# File 'app/forms/thredded/private_topic_form.rb', line 71 def submit_path Thredded::UrlsHelper.url_for([private_topic, only_path: true]) end |