Skip to content

Commit

Permalink
[FIXED JENKINS-18436]
Browse files Browse the repository at this point in the history
Fire the "jenkins:apply" event from the apply button and listen to that to write back edits to <TEXTAREA>
  • Loading branch information
kohsuke committed Jun 20, 2013
1 parent aff73d4 commit 2ffece9
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion changelog.html
Expand Up @@ -64,7 +64,9 @@
<li class=bug>
Fixed "Comparison method violates its general contract" error in BuildTrigger.execute
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17247">issue 17247</a>)
</ul>
<li class=bug>
Edited description wasn't reflected when pressing the "Apply" button.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-18436">issue 18436</a>) </ul>
</div><!--=TRUNK-END=-->

<!-- these changes are controlled by the release process. DO NOT MODIFY -->
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/resources/lib/form/apply.jelly
Expand Up @@ -28,6 +28,10 @@ THE SOFTWARE.
<s:documentation>
"Apply" button that submits the form but without a page transition.
See hudson.util.FormApply for the server-side code.

When this button is pressed, the FORM element fires the "jenkins:apply" event
that allows interested parties to write back whatever states back into the INPUT
elements.
</s:documentation>
<st:adjunct includes="lib.form.apply.apply"/>
<input type="hidden" name="core:apply" value="" />
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/lib/form/apply/apply.js
Expand Up @@ -54,6 +54,7 @@ Behaviour.specify("INPUT.apply-button", 'apply', 0, function (e) {

f.target = target.id;
f.elements['core:apply'].value = "true";
Event.fire(f,"jenkins:apply"); // give everyone a chance to write back to DOM
try {
buildFormTree(f);
f.submit();
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/resources/lib/form/textarea/textarea.js
Expand Up @@ -13,6 +13,11 @@ Behaviour.specify("TEXTAREA.codemirror", 'textarea', 0, function(e) {
var scroller = codemirror.getScrollerElement();
scroller.setAttribute("style","border:1px solid black;");
scroller.style.height = h+"px";

// the form needs to be populated before the "Apply" button
e.up('form').on("jenkins:apply",function() {

This comment has been minimized.

Copy link
@olivergondza

olivergondza Jun 28, 2013

Member

This breaks https://jenkins.ci.cloudbees.com/job/selenium-tests/167/.
I am getting a javascript error on this line in job configuration page whenever envinject plugin is installed. The behavior-loading div won't disappear so there is no way to configure jobs. This does not seem to relate to any change in the plugin as it affects older versions too.

TypeError: e.up(...).on is not a function @ http://127.0.0.1:8543/adjuncts/64f61af8/lib/form/textarea/textarea.js:18 in firefox and Uncaught TypeError: Property 'on' of object #<HTMLFormElement> is not a function in chrome.

This comment has been minimized.

Copy link
@ssogabe

ssogabe Jun 29, 2013

Member

+1

This comment has been minimized.

Copy link
@Vlatombe

Vlatombe Jun 29, 2013

Member

Can be replaced with YAHOO.util.Event.on(e.up('form'),"jenkins:apply",function() {

This comment has been minimized.

Copy link
@ssogabe

ssogabe Jun 30, 2013

Member

fixed,

e.value = codemirror.getValue()
})
});

Behaviour.specify("DIV.textarea-preview-container", 'textarea', 100, function (e) {
Expand Down
35 changes: 35 additions & 0 deletions test/src/test/groovy/lib/form/ApplyButtonTest.groovy
@@ -0,0 +1,35 @@
package lib.form

import org.junit.Rule
import org.junit.Test
import org.jvnet.hudson.test.Bug
import org.jvnet.hudson.test.JenkinsRule

/**
*
*
* @author Kohsuke Kawaguchi
*/
class ApplyButtonTest {
@Rule public JenkinsRule j = new JenkinsRule();

/**
* Editing code mirror should still gets reflected when you click apply.
*/
@Test @Bug(18436)
public void editDescription() {
def p = j.createFreeStyleProject()
def b = j.assertBuildStatusSuccess(p.scheduleBuild2(0))

def config = j.createWebClient().getPage(b, "configure")
def form = config.getFormByName("config")
// HtmlUnit doesn't have JSON, so we need to emulate one
config.executeJavaScript(getClass().getResource("JSON.js").text)
// it's hard to emulate the keytyping, so we just set the value into codemirror and test if this gets
// reflected back into TEXTAREA
config.executeJavaScript("document.getElementsByTagName('TEXTAREA')[0].codemirrorObject.setLine(0,'foobar')")
j.getButtonByCaption(form,"Apply").click()

assert "foobar"==b.description
}
}
11 changes: 11 additions & 0 deletions test/src/test/resources/lib/form/JSON.js
@@ -0,0 +1,11 @@
// htmlunit doesn't have JSON, so emulate it
if (typeof JSON=="undefined") {
var JSON = {
parse : function (str) {
return String.evalJSON(str);
},
stringify : function (obj) {
return Object.toJSON(obj);
}
};
}

0 comments on commit 2ffece9

Please sign in to comment.