提交 b9c18a7b 编写于 作者: J Jesse Glick

[FIXED JENKINS-16844] MenuItem.post allows context menu items like Build Now...

[FIXED JENKINS-16844] MenuItem.post allows context menu items like Build Now to send a POST request.
Currently just shows a hover notification; TBD if there are use cases for displaying the response.
上级 09c7cf6a
......@@ -58,7 +58,9 @@ Upcoming changes</a>
<li class=bug>
Fixed: Human readable file size method returns ",00" for files with byte length 0
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16630">issue 16630</a>)
<li class=bug>
“Build” from job context menu produced a confusing warning page.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16844">issue 16844</a>)
</ul>
</div><!--=TRUNK-END=-->
......
......@@ -95,6 +95,16 @@ public interface ModelObjectWithContextMenu extends ModelObject {
return this;
}
/** @since 1.504 */
public ContextMenu add(String url, String icon, String text, boolean post) {
if (text != null && icon != null && url != null) {
MenuItem item = new MenuItem(url,icon,text);
item.post = post;
items.add(item);
}
return this;
}
/**
* Default implementation of the context menu generation.
*
......@@ -167,6 +177,12 @@ public interface ModelObjectWithContextMenu extends ModelObject {
@Exported
public String icon;
/**
* True to make a POST request rather than GET.
* @since 1.504
*/
@Exported public boolean post;
/**
* If this is a submenu, definition of subitems.
*/
......
......@@ -46,7 +46,7 @@ THE SOFTWARE.
<j:if test="${it.configurable}">
<j:if test="${it.buildable}">
<l:task icon="images/24x24/clock.png" href="${url}/build?delay=0sec" title="${it.buildNowText}"
onclick="${it.parameterized?null:'return build(this)'}" permission="${it.BUILD}" />
onclick="${it.parameterized?null:'return build(this)'}" post="true" permission="${it.BUILD}"/>
<script>
function build(a) {
new Ajax.Request(a.href);
......
......@@ -66,6 +66,13 @@ var breadcrumbs = (function() {
return a+'/'+b+qs;
}
function postRequest(action, event, url) {
new Ajax.Request(url);
if (event.length == 1 && event[0].target != null) {
hoverNotification('Done.', event[0].target);
}
}
/**
* Called when the mouse cursor comes into the context menu hot spot.
*
......@@ -111,6 +118,10 @@ var breadcrumbs = (function() {
e.text = makeMenuHtml(e.icon, e.displayName);
if (e.subMenu!=null)
e.subMenu = {id:"submenu"+(iota++), itemdata:e.subMenu.items.each(fillMenuItem)};
if (e.post) {
e.onclick = {fn: postRequest, obj: e.url};
delete e.url;
}
}
a.each(fillMenuItem);
......
......@@ -56,6 +56,11 @@ THE SOFTWARE.
This is useful for showing links to restricted pages, as showing
them to unprivileged users don't make sense.
</st:attribute>
<st:attribute name="post" type="boolean">
If true, send a POST rather than a GET request.
(onclick supersedes this except in the context menu.)
(since 1.504)
</st:attribute>
</st:documentation>
<!--
......@@ -98,14 +103,24 @@ THE SOFTWARE.
<j:otherwise>
<div class="task">
<j:set var="icon" value="${rootURL}${icon.startsWith('images/') || icon.startsWith('plugin/') ? h.resourcePath : ''}/${icon}"/>
${taskTags!=null and attrs.contextMenu!='false' ? taskTags.add(href,icon,title) : null}
${taskTags!=null and attrs.contextMenu!='false' ? taskTags.add(href, icon, title, post == 'true') : null}
<j:if test="${attrs.onclick == null &amp;&amp; post}">
<script>
function postRequest(a) {
new Ajax.Request(a.href);
hoverNotification('${%Done.}', a.parentNode);
return false;
}
</script>
</j:if>
<a href="${href}" onclick="${attrs.onclick}">
<a href="${href}" onclick="${attrs.onclick ?: (post ? 'postRequest(this)' : null)}">
<img width="24" height="24" style="margin: 2px;" alt="" src="${icon}"/>
</a>
<st:nbsp />
<a href="${href}" onclick="${attrs.onclick}">
<a href="${href}" onclick="${attrs.onclick ?: (post ? 'postRequest(this)' : null)}">
<j:choose>
<j:when test="${match}">
<b>${title}</b>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册