/hudson-war/src/main/webapp/scripts/cascading.js

http://github.com/hudson/hudson · JavaScript · 92 lines · 63 code · 6 blank · 23 comment · 9 complexity · f529b0cf207d9adfa062d77cc3b6920a MD5 · raw file

  1. /*
  2. * The MIT License
  3. *
  4. * Copyright (c) 2011, Oracle Corporation, Inc., Nikita Levyankov
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. hudsonRules["A.reset-button"] = function(e) {
  25. e.onclick = function() {
  26. new Ajax.Request(this.getAttribute("resetURL"), {
  27. method : 'get',
  28. onSuccess : function(x) {
  29. location.reload(true);
  30. },
  31. onFailure : function(x) {
  32. }
  33. });
  34. return false;
  35. }
  36. e.tabIndex = 9999; // make help link unnavigable from keyboard
  37. e = null; // avoid memory leak
  38. }
  39. function getJobUrl() {
  40. var url = window.location.href;
  41. return url.substr(0, url.lastIndexOf('/'))
  42. }
  43. function onCascadingProjectUpdated() {
  44. if(isRunAsTest) return;
  45. jQuery('select[name=cascadingProjectName]').change(function() {
  46. var jobUrl = getJobUrl()+'/updateCascadingProject';
  47. var cascadingProject = jQuery(this).val();
  48. new Ajax.Request(jobUrl+'?projectName='+cascadingProject, {
  49. method : 'get',
  50. onSuccess : function(x) {
  51. location.reload(true);
  52. }
  53. });
  54. });
  55. }
  56. function onProjectPropertyChanged() {
  57. if(isRunAsTest) return;
  58. var modify = function() {
  59. var ref = jQuery(this).attr('id');
  60. var cascadingProperty = '';
  61. if (ref != '') {
  62. cascadingProperty = jQuery(this).attr('name');
  63. } else {
  64. var parent = jQuery(this).parents('tr');
  65. while (parent.attr("nameref") == undefined && parent.size() !== 0) {
  66. parent = jQuery(parent).parents('tr');
  67. }
  68. var childRef = parent.attr("nameref");
  69. cascadingProperty = jQuery('#'+childRef).attr('name');
  70. }
  71. if(cascadingProperty !== undefined) {
  72. var jobUrl = getJobUrl()+'/modifyCascadingProperty?propertyName='+cascadingProperty;
  73. new Ajax.Request(jobUrl, {
  74. method : 'get'
  75. });
  76. }
  77. };
  78. jQuery("form[action=configSubmit] input[type=checkbox]").live('click', modify);
  79. jQuery("form[action=configSubmit] input[type!=checkbox]").live('change', modify);
  80. jQuery("form[action=configSubmit] .setting-input").live('change', modify);
  81. jQuery("form[action=configSubmit] button").live('click', modify);
  82. }
  83. jQuery(document).ready(function(){
  84. onCascadingProjectUpdated();
  85. onProjectPropertyChanged();
  86. });