mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 13:32:24 +00:00
Add preview feature on description textarea.
This commit is contained in:
1 parent
a9b55e9d54
commit
cfbb2d6e2a
8 files changed
+65
-6
No files matched your search
@@ -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
|
||||
|
||||
@@ -35,7 +35,7 @@ THE SOFTWARE.
|
||||
<table>
|
||||
<f:entry help="${app.markupFormatter.helpUrl}">
|
||||
<f:textarea name="description" value="${it.description}"
|
||||
codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}"/>
|
||||
codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" preview="true"/>
|
||||
</f:entry>
|
||||
</table>
|
||||
<div align="right">
|
||||
|
||||
@@ -34,7 +34,7 @@ THE SOFTWARE.
|
||||
<table>
|
||||
<f:entry help="${app.markupFormatter.helpUrl}">
|
||||
<f:textarea name="description" value="${it.description}"
|
||||
codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}"/>
|
||||
codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" preview="true"/>
|
||||
</f:entry>
|
||||
</table>
|
||||
<f:submit value="${%Submit}" />
|
||||
|
||||
@@ -41,7 +41,7 @@ THE SOFTWARE.
|
||||
</f:entry>
|
||||
</j:if>
|
||||
<f:entry title="${%Description}" help="${app.markupFormatter.helpUrl}">
|
||||
<f:textarea name="description" value="${it.description}" codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}"/>
|
||||
<f:textarea name="description" value="${it.description}" codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" preview="true"/>
|
||||
</f:entry>
|
||||
|
||||
<j:if test="${it.supportsLogRotator()}">
|
||||
|
||||
@@ -33,7 +33,7 @@ THE SOFTWARE.
|
||||
<f:textbox name="displayName" value="${it.hasCustomDisplayName()?it.displayName:''}"/>
|
||||
</f:entry>
|
||||
<f:entry title="${%Description}" help="/help/run-config/description.html">
|
||||
<f:textarea name="description" value="${it.description}" codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}"/>
|
||||
<f:textarea name="description" value="${it.description}" codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" preview="true"/>
|
||||
</f:entry>
|
||||
|
||||
<j:if test="${h.hasPermission(it,it.UPDATE)}">
|
||||
|
||||
@@ -39,7 +39,7 @@ THE SOFTWARE.
|
||||
<f:textbox name="name" value="${it.viewName}" />
|
||||
</f:entry>
|
||||
<f:entry title="${%Description}" help="/help/view-config/description.html">
|
||||
<f:textarea name="description" field="description" codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}"/>
|
||||
<f:textarea name="description" field="description" codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" preview="true"/>
|
||||
</f:entry>
|
||||
<f:entry title="${%Filter build queue}" help="/help/view-config/filter-queue.html">
|
||||
<f:checkbox name="filterQueue" field="filterQueue"/>
|
||||
|
||||
@@ -48,7 +48,7 @@ THE SOFTWARE.
|
||||
</f:advanced>
|
||||
<f:entry title="${%System Message}" help="/help/system-config/systemMessage.html">
|
||||
<f:textarea name="system_message" value="${it.systemMessage}"
|
||||
codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}"/>
|
||||
codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" preview="true"/>
|
||||
</f:entry>
|
||||
|
||||
<!-- global configuration from everyone -->
|
||||
|
||||
@@ -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.
|
||||
</st:attribute>
|
||||
<st:attribute name="preview">
|
||||
If specified, this text area has preview feature.
|
||||
</st:attribute>
|
||||
</st:documentation>
|
||||
|
||||
<f:prepareDatabinding />
|
||||
@@ -80,4 +83,50 @@ THE SOFTWARE.
|
||||
</textarea>
|
||||
<!-- resize handle -->
|
||||
<div class="textarea-handle"/>
|
||||
<j:if test="${attrs['preview']!=null}">
|
||||
<a onclick="previewDescription(this);" href="#">${%Preview}</a>
|
||||
<div class="descriptionPreview" style="text-align:left; background-color: #EEE; padding: 0.5em; display: none;">
|
||||
<a onclick="hidePreview(this);" href="#">${%Hide preview}</a>
|
||||
<hr/>
|
||||
<div><!-- div for preview --></div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
This script can be evaluated in evalInnerHtmlScripts function if used in editableDescription.
|
||||
If evaluated in evalInnerHtmlScripts function:
|
||||
`function functionName(){}`-style declaration becomes a local variable.
|
||||
`var functionName = function(){}`-style declaration becomes a local variable.
|
||||
`functionName = function(){}`-style declaration becomes a global variable.
|
||||
That is why there is no `var`.
|
||||
-->
|
||||
/* var */ previewDescription = function(sender){
|
||||
<!-- Several TEXTAREAs may exist if CodeMirror is enabled. The first one has reference to the CodeMirror object. -->
|
||||
var textarea = sender.parentNode.getElementsByTagName("TEXTAREA")[0];
|
||||
var text = textarea.codemirrorObject ? textarea.codemirrorObject.getValue() : textarea.value;
|
||||
var previewDiv = findNext(sender, function(e){return e.className == "descriptionPreview"});
|
||||
var previewDivBody = previewDiv.getElementsByTagName("DIV")[0];
|
||||
|
||||
new Ajax.Request(rootURL + "/previewDescription", {
|
||||
method: "POST",
|
||||
requestHeaders: "Content-Type: application/x-www-form-urlencoded",
|
||||
parameters: {
|
||||
description: text
|
||||
},
|
||||
onSuccess: function(obj) {
|
||||
$(previewDiv).show();
|
||||
previewDivBody.innerHTML = obj.responseText;
|
||||
},
|
||||
onFailure: function(obj) {
|
||||
$(previewDiv).show();
|
||||
previewDivBody.innerHTML = obj.status + " " + obj.statusText + "<HR/>" + obj.responseText;
|
||||
}
|
||||
});
|
||||
return false;
|
||||
};
|
||||
/* var */ hidePreview = function(sender){
|
||||
var previewDiv = findAncestor(sender, "DIV");
|
||||
$(previewDiv).hide();
|
||||
};
|
||||
</script>
|
||||
</j:if>
|
||||
</j:jelly>
|
||||
Reference in new issue
Block a user