diff --git a/app/assets/javascripts/admin/plugins/summernote.js b/app/assets/javascripts/admin/plugins/summernote.js index 51a3263293d0884e177e0a035362b706fc4ebc61..038b6160e95fb8cec6ec566e0dc690c9583ab0e9 100644 --- a/app/assets/javascripts/admin/plugins/summernote.js +++ b/app/assets/javascripts/admin/plugins/summernote.js @@ -2,50 +2,63 @@ $(function () { 'use strict'; + var configs = []; + configs['mini'] = { + toolbar: [ + ['font', ['bold', 'italic']], + ['insert', ['link']], + ['view', ['codeview']] + ] + }; + + configs['default'] = { + popover: { + image: [ + ['remove', ['removeMedia']] + ] + }, + toolbar: [ + ['style', ['style']], + ['font', ['bold', 'italic']], + ['para', ['ul', 'ol']], + ['table', ['table']], + ['insert', ['link', 'picture', 'video']], + ['view', ['codeview']] + ], + styleTags: [ + 'p', + 'blockquote', + 'pre', + 'h2', + 'h3', + 'h4' + ], + followingToolbar: true, + callbacks: { + onImageUpload: function (files) { + var attachmentUpload = new SummernoteAttachmentUpload(this, files[0]); + attachmentUpload.start(); + }, + onMediaDelete: function (_, $editable) { + $.summernote.rails.cleanEmptyAttachments($editable); + }, + onKeyup: function (e) { + var $editable = $(e.currentTarget); + if (e.keyCode === 8) { + $.summernote.rails.cleanEmptyAttachments($editable); + } + } + } + }; + $.extend($.summernote.lang['en-US'].image, { dragImageHere: 'Drag file here', dropImage: 'Drop file' }); $('[data-provider="summernote"]').each(function () { - $(this).summernote({ - popover: { - image: [ - ['remove', ['removeMedia']] - ] - }, - toolbar: [ - ['style', ['style']], - ['font', ['bold', 'italic']], - ['para', ['ul', 'ol']], - ['table', ['table']], - ['insert', ['link', 'picture', 'video']], - ['view', ['codeview']] - ], - styleTags: [ - 'p', - 'blockquote', - 'pre', - 'h2', - 'h3', - 'h4' - ], - followingToolbar: true, - callbacks: { - onImageUpload: function (files) { - var attachmentUpload = new SummernoteAttachmentUpload(this, files[0]); - attachmentUpload.start(); - }, - onMediaDelete: function (_, $editable) { - $.summernote.rails.cleanEmptyAttachments($editable); - }, - onKeyup: function (e) { - var $editable = $(e.currentTarget); - if (e.keyCode === 8) { - $.summernote.rails.cleanEmptyAttachments($editable); - } - } - } - }); + var config = $(this).attr('data-summernote-config'); + config = config || 'default'; + $(this).summernote(configs[config]); }); }); diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index fa9ffcd3bd2594f0ee911d97d1290f4b407b65bc..489f04ea412fbff00ab5c6ac09a88f527fd9ed84 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -120,10 +120,17 @@ class Communication::Website::Page < ApplicationRecord end def slug_unavailable?(slug) - self.class.unscoped - .where(communication_website_id: self.communication_website_id, slug: slug) - .where.not(id: self.id) - .exists? + [ + website.index_for(:communication_posts).path, + website.index_for(:education_programs).path, + website.index_for(:persons).path, + website.index_for(:research_articles).path, + website.index_for(:research_volumes).path + ].include?(slug) || + self.class.unscoped + .where(communication_website_id: self.communication_website_id, slug: slug) + .where.not(id: self.id) + .exists? end def explicit_blob_ids diff --git a/app/models/concerns/with_slug.rb b/app/models/concerns/with_slug.rb index 31de976234557b771e03d8ff6b974febfc7aae82..786e3f176f87233700e20ab138e8485726cecdd7 100644 --- a/app/models/concerns/with_slug.rb +++ b/app/models/concerns/with_slug.rb @@ -2,6 +2,7 @@ module WithSlug extend ActiveSupport::Concern included do + validates :slug, presence: true validate :slug_must_be_unique validates :slug, format: { with: /\A[a-z0-9\-]+\z/, message: I18n.t('slug_error') } diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb index 18e2717aebcda7a9b9bd8f3a5dcf3c5aa3d8fc76..10366cfd8229c1d20e961cf93ba22124f96eefdc 100644 --- a/app/models/research/journal/article.rb +++ b/app/models/research/journal/article.rb @@ -37,6 +37,7 @@ class Research::Journal::Article < ApplicationRecord include WithGit include WithBlobs include WithPosition + include WithSlug has_summernote :text has_one_attached :pdf diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index 1dc8531e61c3d8bfd33541ca3c3116e270cca3c8..30c6db4a0dd9a920a2b18e0a68408bc3d4e5a0b7 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -28,8 +28,9 @@ # class Research::Journal::Volume < ApplicationRecord include WithGit - include WithFeaturedImage include WithBlobs + include WithFeaturedImage + include WithSlug belongs_to :university belongs_to :journal, foreign_key: :research_journal_id diff --git a/app/views/admin/communication/website/index_pages/edit.html.erb b/app/views/admin/communication/website/index_pages/edit.html.erb index 61394a3f3c4c5261c06ed90a8fd3f5470d09c99f..4eaf6be10a3cb0350baaf5e4d1b54303d2f188b5 100644 --- a/app/views/admin/communication/website/index_pages/edit.html.erb +++ b/app/views/admin/communication/website/index_pages/edit.html.erb @@ -22,7 +22,12 @@ input_html: { name: 'communication_website_index_page[breadcrumb_title]' }, hint: t('simple_form.hints.communication_website_index_page.breadcrumb_title') %> <%= f.input :description, input_html: { name: 'communication_website_index_page[description]' } %> - <%= f.input :header_text, as: :summernote, input_html: { name: 'communication_website_index_page[header_text]' } %> + <%= f.input :header_text, + as: :summernote, + input_html: { + name: 'communication_website_index_page[header_text]', + data: { 'summernote-config' => 'mini' } + } %> <%= f.input :text, as: :summernote, input_html: { name: 'communication_website_index_page[text]' } %> </div> </div>