diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 1b08ce315648366b4a4b7403b04f86de707a4bda..b0c4b39a13589fcca6970fe0d9796c6686092897 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -32,6 +32,7 @@ # class Communication::Website::Category < ApplicationRecord include WithGithubFiles + include WithMenuItemTarget include WithSlug include WithTree diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 20f0e94f9a8d48192e6dbbcf5496a463222f4d18..f9b54aa15a581f8474ec10f3701989cc0a4c832a 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -39,15 +39,13 @@ class Communication::Website::Page < ApplicationRecord include Communication::Website::WithMedia include WithGithubFiles + include WithMenuItemTarget include WithSlug include WithTree has_rich_text :text has_one_attached_deletable :featured_image - has_one :imported_page, - class_name: 'Communication::Website::Imported::Page', - dependent: :destroy belongs_to :university belongs_to :website, foreign_key: :communication_website_id @@ -57,13 +55,14 @@ class Communication::Website::Page < ApplicationRecord belongs_to :parent, class_name: 'Communication::Website::Page', optional: true + has_one :imported_page, + class_name: 'Communication::Website::Imported::Page', + dependent: :nullify has_many :children, class_name: 'Communication::Website::Page', foreign_key: :parent_id, dependent: :nullify - has_one :imported_page, - class_name: 'Communication::Website::Imported::Page', - dependent: :nullify + validates :title, presence: true validates :slug, uniqueness: { scope: :communication_website_id } diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index e5e54b9a8d2372f1ad7b33b901ecf8b31757c035..b0fff79419e42318f7eb23aea18754556861bfd8 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -31,6 +31,7 @@ class Communication::Website::Post < ApplicationRecord include Communication::Website::WithMedia include WithGithubFiles + include WithMenuItemTarget include WithSlug has_rich_text :text diff --git a/app/models/concerns/with_menu_item_target.rb b/app/models/concerns/with_menu_item_target.rb new file mode 100644 index 0000000000000000000000000000000000000000..cd5ed55e88515b11fabacc807e047ac7dd23f91a --- /dev/null +++ b/app/models/concerns/with_menu_item_target.rb @@ -0,0 +1,11 @@ +module WithMenuItemTarget + extend ActiveSupport::Concern + + included do + has_many :menu_items, + as: :about, + class_name: 'Communication::Website::Menu::Item', + dependent: :destroy + + end +end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index a743276345c0f1e7306e7e2af80fbe21fde84f0e..6cef3f3d82f4ea5f99cff223d9d990714f9a06a0 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -28,6 +28,7 @@ # class Education::Program < ApplicationRecord include WithGithubFiles + include WithMenuItemTarget include WithTree attr_accessor :skip_websites_categories_callback diff --git a/app/views/admin/communication/website/menus/_form.html.erb b/app/views/admin/communication/website/menus/_form.html.erb index d8e33611a93ff28c4e78edaeefaeb294032766d2..df77eedc360e61da24a9a8bb114c4007564385a5 100644 --- a/app/views/admin/communication/website/menus/_form.html.erb +++ b/app/views/admin/communication/website/menus/_form.html.erb @@ -16,7 +16,11 @@ <h5 class="card-title mb-0"><%= t('metadata') %></h5> </div> <div class="card-body"> - <%= f.input :identifier if can?(:create, menu) %> + <%= f.input :identifier, + input_html: menu.persisted? ? {} : { + class: 'js-slug-input', + data: { source: '#communication_website_menu_title' } + } if can?(:create, menu) %> </div> </div> </div>