提交 737a7dfe 编写于 作者: K Kohsuke Kawaguchi

Merge branch 'pull-243'

......@@ -70,6 +70,9 @@ Upcoming changes</a>
<li class=rfe>
Managed windows slaves can be now run as a specific user account
(<a href="https://github.com/jenkinsci/jenkins/pull/289">pull #289</a>)
<li class=rfe>
Description field now has the preview button to test it inline.
(<a href="https://github.com/jenkinsci/jenkins/pull/243">pull #243</a>)
<li class=rfe>
Maven mojo records can be now sorted
</ul>
......
......@@ -25,7 +25,14 @@ package hudson.markup;
import hudson.ExtensionPoint;
import hudson.model.AbstractDescribableImpl;
import hudson.util.HttpResponses;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
......@@ -91,4 +98,14 @@ public abstract class MarkupFormatter extends AbstractDescribableImpl<MarkupForm
public MarkupFormatterDescriptor getDescriptor() {
return (MarkupFormatterDescriptor)super.getDescriptor();
}
/**
* Generate HTML for preview, using markup formatter.
* Can be called from other views.
*/
public HttpResponse doPreviewDescription(@QueryParameter String text) throws IOException {
StringWriter w = new StringWriter();
translate(text, w);
return HttpResponses.html(w.toString());
}
}
......@@ -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}" previewEndpoint="/markupFormatter/previewDescription"/>
</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}" previewEndpoint="/markupFormatter/previewDescription"/>
</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}" previewEndpoint="/markupFormatter/previewDescription"/>
</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}" previewEndpoint="/markupFormatter/previewDescription"/>
</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}" previewEndpoint="/markupFormatter/previewDescription"/>
</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}" previewEndpoint="/markupFormatter/previewDescription"/>
</f:entry>
<!-- global configuration from everyone -->
......
......@@ -60,6 +60,10 @@ 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="previewEndpoint">
If specified, this text area has preview feature.
The previewEndpoint is used to obtain formatted html.
</st:attribute>
</st:documentation>
<f:prepareDatabinding />
......@@ -80,4 +84,14 @@ THE SOFTWARE.
</textarea>
<!-- resize handle -->
<div class="textarea-handle"/>
<j:if test="${attrs.previewEndpoint!=null}">
<div class="textarea-preview-container">
<a href="#" class="textarea-show-preview" previewEndpoint="${attrs.previewEndpoint}">${%Preview}</a>
<st:nbsp/>
<a href="#" class="textarea-hide-preview">${%Hide preview}</a>
<div class="textarea-preview">
<!-- div for preview -->
</div>
</div>
</j:if>
</j:jelly>
......@@ -1003,3 +1003,13 @@ table.progress-bar.red td.progress-bar-done {
.tag7 { font-size: 1.70em; }
.tag8 { font-size: 1.80em; }
.tag9 { font-size: 1.90em; }
/* ========================= textarea.jelly ================== */
.textarea-preview-container {
text-align:left;
}
.textarea-preview {
background-color: #F0F0F0;
padding: 0.5em;
}
......@@ -1194,6 +1194,45 @@ var hudsonRules = {
".button-with-dropdown" : function (e) {
new YAHOO.widget.Button(e, { type: "menu", menu: e.nextSibling });
},
"DIV.textarea-preview-container" : function (e) {
var previewDiv = findElementsBySelector(e,".textarea-preview")[0];
var showPreview = findElementsBySelector(e,".textarea-show-preview")[0];
var hidePreview = findElementsBySelector(e,".textarea-hide-preview")[0];
$(hidePreview).hide();
$(previewDiv).hide();
showPreview.onclick = function() {
// Several TEXTAREAs may exist if CodeMirror is enabled. The first one has reference to the CodeMirror object.
var textarea = e.parentNode.getElementsByTagName("TEXTAREA")[0];
var text = textarea.codemirrorObject ? textarea.codemirrorObject.getValue() : textarea.value;
var render = function(txt) {
$(hidePreview).show();
$(previewDiv).show();
previewDiv.innerHTML = txt;
};
new Ajax.Request(rootURL + showPreview.getAttribute("previewEndpoint"), {
method: "POST",
requestHeaders: "Content-Type: application/x-www-form-urlencoded",
parameters: {
text: text
},
onSuccess: function(obj) {
render(obj.responseText)
},
onFailure: function(obj) {
render(obj.status + " " + obj.statusText + "<HR/>" + obj.responseText)
}
});
return false;
}
hidePreview.onclick = function() {
$(hidePreview).hide();
$(previewDiv).hide();
};
}
};
......@@ -2357,4 +2396,3 @@ function createComboBox(idOrField,valueFunction) {
Ajax.Request.prototype.dispatchException = function(e) {
throw e;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册