diff --git a/core/src/main/resources/lib/hudson/project/configurable.jelly b/core/src/main/resources/lib/hudson/project/configurable.jelly index 9bc320fd9266..44bac9b2b9bf 100644 --- a/core/src/main/resources/lib/hudson/project/configurable.jelly +++ b/core/src/main/resources/lib/hudson/project/configurable.jelly @@ -24,20 +24,10 @@ THE SOFTWARE. --> - + - - - + + diff --git a/core/src/main/resources/lib/hudson/project/configurable/configurable.js b/core/src/main/resources/lib/hudson/project/configurable/configurable.js new file mode 100644 index 000000000000..a96e64219502 --- /dev/null +++ b/core/src/main/resources/lib/hudson/project/configurable/configurable.js @@ -0,0 +1,17 @@ +(function () { + /* The JS formatting rules enforced in this repo can result in function declarations incompatible with HTMLUnit. + As a workaround, split function definition and assignment. */ + function foo(el, ev) { + let parameterized = el.dataset.parameterized; + let success = el.dataset.buildSuccess; + if (parameterized === "false") { + fetch(el.href, { + method: "post", + headers: crumb.wrap({}), + }); + hoverNotification(success, ev.target.parentNode); + ev.preventDefault(); + } + } + window.lib_hudson_project_configurable_build_now_callback = foo; +})(); diff --git a/core/src/main/resources/lib/layout/task.jelly b/core/src/main/resources/lib/layout/task.jelly index ec17b8e92a53..0d75a2b0b32d 100644 --- a/core/src/main/resources/lib/layout/task.jelly +++ b/core/src/main/resources/lib/layout/task.jelly @@ -77,6 +77,18 @@ THE SOFTWARE. (onclick supersedes this except in the context menu.) (since 1.512) + + Onclick inline JS handler. Deprecated, specify data-callback attribute instead. + + + Name of a global function to call when clicked. + It will be called with an element (currently 'a') as first argument, and the event as second argument. + You can specify further data-* attributes to customize behavior, those will be defined on the element passed as first argument. + See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset for more information about these attributes. + Has no effect if you specify the 'requiresConfirmation' attribute. + Has no effect on menu items showing in context menus, only 'href', 'post', and 'requiresConfirmation' attributes substantially change behavior there. + Set 'contextMenu' to 'false' to remove this task from those menus. + If set, displays the value as a small badge on the right side of the sidepanel item. (since 2.401) @@ -161,19 +173,6 @@ THE SOFTWARE. ${taskTags!=null and attrs.contextMenu!='false' ? taskTags.add(href, iconSrc, iconXml, title, post == 'true', requiresConfirmation == 'true', null, confirmationMessage ?: null) : null} - - - - @@ -191,7 +190,14 @@ THE SOFTWARE. - + + @@ -201,7 +207,8 @@ THE SOFTWARE. ${attrs.badge.text} - + + diff --git a/core/src/main/resources/lib/layout/task/task.js b/core/src/main/resources/lib/layout/task/task.js new file mode 100644 index 000000000000..5d6fd6fd008c --- /dev/null +++ b/core/src/main/resources/lib/layout/task/task.js @@ -0,0 +1,28 @@ +Behaviour.specify("a.task-link-no-confirm", "task-link", 0, function (el) { + if (el.onclick !== null) { + return; + } + + let post = el.dataset.taskPost; + let callback = el.dataset.callback; + let success = el.dataset.taskSuccess; + let href = el.href; + + if (callback !== undefined) { + el.onclick = function (ev) { + window[callback](el, ev); + }; + return; + } + + if (post === "true") { + el.onclick = function (ev) { + fetch(href, { + method: "post", + headers: crumb.wrap({}), + }); + hoverNotification(success, el.parentNode); + ev.preventDefault(); + }; + } +});