Class: Thredded::PrivateTopicForm
- Inherits:
-
Object
- Object
- Thredded::PrivateTopicForm
- Includes:
- ActiveModel::Model
- Defined in:
- app/forms/thredded/private_topic_form.rb
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.
-
#private_topic ⇒ Object
Returns the value of attribute private_topic.
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(params = {}) ⇒ PrivateTopicForm
constructor
A new instance of PrivateTopicForm.
- #post ⇒ Object
- #save ⇒ Object
- #users ⇒ Object
- #users_for_select ⇒ Object
- #users_select_html_options ⇒ Object
- #users_selected_options ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ PrivateTopicForm
18 19 20 21 22 23 24 25 26 27 |
# File 'app/forms/thredded/private_topic_form.rb', line 18 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] end |
Instance Attribute Details
#category_ids ⇒ Object
Returns the value of attribute category_ids.
5 6 7 |
# File 'app/forms/thredded/private_topic_form.rb', line 5 def category_ids @category_ids end |
#content ⇒ Object
Returns the value of attribute content.
5 6 7 |
# File 'app/forms/thredded/private_topic_form.rb', line 5 def content @content end |
#locked ⇒ Object
Returns the value of attribute locked.
5 6 7 |
# File 'app/forms/thredded/private_topic_form.rb', line 5 def locked @locked end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
14 15 16 |
# File 'app/forms/thredded/private_topic_form.rb', line 14 def params @params end |
#private_topic ⇒ Object
Returns the value of attribute private_topic.
5 6 7 |
# File 'app/forms/thredded/private_topic_form.rb', line 5 def private_topic @private_topic end |
#sticky ⇒ Object
Returns the value of attribute sticky.
5 6 7 |
# File 'app/forms/thredded/private_topic_form.rb', line 5 def sticky @sticky end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'app/forms/thredded/private_topic_form.rb', line 5 def title @title end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
14 15 16 |
# File 'app/forms/thredded/private_topic_form.rb', line 14 def user @user end |
#user_ids ⇒ Object
Returns the value of attribute user_ids.
5 6 7 |
# File 'app/forms/thredded/private_topic_form.rb', line 5 def user_ids @user_ids end |
Class Method Details
.model_name ⇒ Object
29 30 31 |
# File 'app/forms/thredded/private_topic_form.rb', line 29 def self.model_name Thredded::PrivateTopic.model_name end |
Instance Method Details
#id ⇒ Object
41 42 43 |
# File 'app/forms/thredded/private_topic_form.rb', line 41 def id private_topic.id end |
#post ⇒ Object
63 64 65 66 67 |
# File 'app/forms/thredded/private_topic_form.rb', line 63 def post @post ||= private_topic.posts.build( content: content, user: non_null_user) end |
#save ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'app/forms/thredded/private_topic_form.rb', line 45 def save return false unless valid? ActiveRecord::Base.transaction do private_topic.save! post.save! end true end |
#users ⇒ Object
33 34 35 |
# File 'app/forms/thredded/private_topic_form.rb', line 33 def users @user. end |
#users_for_select ⇒ Object
37 38 39 |
# File 'app/forms/thredded/private_topic_form.rb', line 37 def users_for_select (users - [@user]).map { |user| [user.to_s, user.id] } end |
#users_select_html_options ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'app/forms/thredded/private_topic_form.rb', line 73 def { multiple: true, required: true, 'data-placeholder' => 'select users to participate in this topic', 'data-thredded-users-select' => true } end |
#users_selected_options ⇒ Object
69 70 71 |
# File 'app/forms/thredded/private_topic_form.rb', line 69 def { selected: private_user_ids } end |