From cfbb2d6e2a980b0222a3c860ce6dfb60c8a13b87 Mon Sep 17 00:00:00 2001 From: OHTAKE Tomohiro Date: Tue, 13 Sep 2011 15:21:55 +0900 Subject: [PATCH] Add preview feature on description textarea. --- core/src/main/java/hudson/model/AllView.java | 10 ++++ .../AbstractModelObject/descriptionForm.jelly | 2 +- .../AbstractModelObject/editDescription.jelly | 2 +- .../hudson/model/Job/configure.jelly | 2 +- .../hudson/model/Run/configure.jelly | 2 +- .../hudson/model/View/configure.jelly | 2 +- .../jenkins/model/Jenkins/configure.jelly | 2 +- .../main/resources/lib/form/textarea.jelly | 49 +++++++++++++++++++ 8 files changed, 65 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/hudson/model/AllView.java b/core/src/main/java/hudson/model/AllView.java index 5d9b235769..81861f6241 100644 --- a/core/src/main/java/hudson/model/AllView.java +++ b/core/src/main/java/hudson/model/AllView.java @@ -90,6 +90,16 @@ public class AllView extends View { rsp.sendRedirect("."); } + /** + * Generate HTML for preview, using markup formatter. + * Can be called from other views. + */ + public void doPreviewDescription( StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { + String desc = req.getParameter("description"); + rsp.setContentType("text/html; charset=UTF-8"); // UTF-8 required by XHR + Jenkins.getInstance().getMarkupFormatter().translate(desc, rsp.getWriter()); + } + @Override public String getPostConstructLandingPage() { return ""; // there's no configuration page diff --git a/core/src/main/resources/hudson/model/AbstractModelObject/descriptionForm.jelly b/core/src/main/resources/hudson/model/AbstractModelObject/descriptionForm.jelly index 9a27babe2b..a7b5fa01ab 100644 --- a/core/src/main/resources/hudson/model/AbstractModelObject/descriptionForm.jelly +++ b/core/src/main/resources/hudson/model/AbstractModelObject/descriptionForm.jelly @@ -35,7 +35,7 @@ THE SOFTWARE. + codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" preview="true"/>
diff --git a/core/src/main/resources/hudson/model/AbstractModelObject/editDescription.jelly b/core/src/main/resources/hudson/model/AbstractModelObject/editDescription.jelly index a450bc6bc2..6536fa693e 100644 --- a/core/src/main/resources/hudson/model/AbstractModelObject/editDescription.jelly +++ b/core/src/main/resources/hudson/model/AbstractModelObject/editDescription.jelly @@ -34,7 +34,7 @@ THE SOFTWARE. + codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" preview="true"/>
diff --git a/core/src/main/resources/hudson/model/Job/configure.jelly b/core/src/main/resources/hudson/model/Job/configure.jelly index 3000b57320..4f4e300e3d 100644 --- a/core/src/main/resources/hudson/model/Job/configure.jelly +++ b/core/src/main/resources/hudson/model/Job/configure.jelly @@ -41,7 +41,7 @@ THE SOFTWARE. - + diff --git a/core/src/main/resources/hudson/model/Run/configure.jelly b/core/src/main/resources/hudson/model/Run/configure.jelly index c71262878d..04ee7bb0fc 100644 --- a/core/src/main/resources/hudson/model/Run/configure.jelly +++ b/core/src/main/resources/hudson/model/Run/configure.jelly @@ -33,7 +33,7 @@ THE SOFTWARE. - + diff --git a/core/src/main/resources/hudson/model/View/configure.jelly b/core/src/main/resources/hudson/model/View/configure.jelly index 5253f0272a..53beaa7438 100644 --- a/core/src/main/resources/hudson/model/View/configure.jelly +++ b/core/src/main/resources/hudson/model/View/configure.jelly @@ -39,7 +39,7 @@ THE SOFTWARE. - + diff --git a/core/src/main/resources/jenkins/model/Jenkins/configure.jelly b/core/src/main/resources/jenkins/model/Jenkins/configure.jelly index c4ba3f6a35..49e699c354 100644 --- a/core/src/main/resources/jenkins/model/Jenkins/configure.jelly +++ b/core/src/main/resources/jenkins/model/Jenkins/configure.jelly @@ -48,7 +48,7 @@ THE SOFTWARE. + codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" preview="true"/> diff --git a/core/src/main/resources/lib/form/textarea.jelly b/core/src/main/resources/lib/form/textarea.jelly index 0a940dfd54..d910c3fad7 100644 --- a/core/src/main/resources/lib/form/textarea.jelly +++ b/core/src/main/resources/lib/form/textarea.jelly @@ -60,6 +60,9 @@ THE SOFTWARE. Specifies additional key/value pairs in the JSON format (except the start and end bracket) to be passed as CodeMirror option object. + + If specified, this text area has preview feature. + @@ -80,4 +83,50 @@ THE SOFTWARE.
+ + ${%Preview} + + +