diff --git a/app/assets/javascripts/admin/document_publishing.js b/app/assets/javascripts/admin/document_publishing.js new file mode 100644 index 00000000000..f2ef80ed5dc --- /dev/null +++ b/app/assets/javascripts/admin/document_publishing.js @@ -0,0 +1,30 @@ +(function ($) { + var _enableChangeNoteHighlighting = function() { + var form = $(this); + var changeNoteLabels = form.find("label[for=document_change_note]"); + var changeNoteTextareas = form.find("textarea#document_change_note"); + var changeNoteElements = changeNoteLabels.add(changeNoteTextareas); + + if ((changeNoteLabels.length > 0) && (changeNoteTextareas.length > 0)) { + var buttonValue = form.find("input[type=submit]")[0].value; + var publishButtonLink = $("").text(buttonValue).addClass("button").attr("href", "#document_publishing"); + + publishButtonLink.click(function() { + publishButtonLink.hide(); + $(changeNoteElements).wrap($("
")); + form.show(); + }); + + form.hide(); + form.before(publishButtonLink); + }; + } + + $.fn.extend({ + enableChangeNoteHighlighting: _enableChangeNoteHighlighting + }); +})(jQuery); + +jQuery(function($) { + $("#document_publishing").enableChangeNoteHighlighting(); +}) \ No newline at end of file diff --git a/app/helpers/admin/document_actions_helper.rb b/app/helpers/admin/document_actions_helper.rb index 53b47266641..16dcca16afb 100644 --- a/app/helpers/admin/document_actions_helper.rb +++ b/app/helpers/admin/document_actions_helper.rb @@ -21,7 +21,7 @@ def publish_document_form(document, options = {}) button_title = "Publish #{document.title}" confirm = publish_document_alerts(document, options[:force]) capture do - form_for [:admin, document], {as: :document, url: url, method: :post} do |form| + form_for [:admin, document], {as: :document, url: url, method: :post, html: {id: "document_publishing"}} do |form| concat(form.hidden_field :lock_version) concat(form.text_area :change_note, rows: 4) if document.change_note_required? concat(form.submit button_text, title: button_title, confirm: confirm) diff --git a/test/javascripts/document_publishing_test.js b/test/javascripts/document_publishing_test.js new file mode 100644 index 00000000000..da04d541f14 --- /dev/null +++ b/test/javascripts/document_publishing_test.js @@ -0,0 +1,72 @@ +module("No change note label or field present", { + setup: function() { + this.publishingForm = $("
"); + + $("#qunit-fixture").append(this.publishingForm); + this.publishingForm.enableChangeNoteHighlighting(); + } +}); + +test("should not hide form", function() { + ok($(this.publishingForm).is(":visible")); +}); + +module("Change note label and field present with publish button", { + setup: function() { + this.publishingForm = $(""); + this.changeNoteLabel = $("