PageRenderTime 22ms CodeModel.GetById 1ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/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
25hudsonRules["A.reset-button"] = function(e) {
26    e.onclick = function() {
27        new Ajax.Request(this.getAttribute("resetURL"), {
28                method : 'get',
29                onSuccess : function(x) {
30                    location.reload(true);
31                },
32                onFailure : function(x) {
33
34                }
35            });
36        return false;
37    }
38    e.tabIndex = 9999; // make help link unnavigable from keyboard
39    e = null; // avoid memory leak
40}
41
42function getJobUrl() {
43    var url = window.location.href;
44    return url.substr(0, url.lastIndexOf('/'))
45}
46
47function onCascadingProjectUpdated() {
48    if(isRunAsTest) return;
49    jQuery('select[name=cascadingProjectName]').change(function() {
50        var jobUrl = getJobUrl()+'/updateCascadingProject';
51        var cascadingProject = jQuery(this).val();
52        new Ajax.Request(jobUrl+'?projectName='+cascadingProject, {
53            method : 'get',
54            onSuccess : function(x) {
55                location.reload(true);
56            }
57        });
58    });
59}
60
61function onProjectPropertyChanged() {
62    if(isRunAsTest) return;
63    var modify = function() {
64        var ref = jQuery(this).attr('id');
65        var cascadingProperty = '';
66        if (ref != '') {
67            cascadingProperty = jQuery(this).attr('name');
68        } else {
69            var parent = jQuery(this).parents('tr');
70            while (parent.attr("nameref") == undefined && parent.size() !== 0) {
71                parent = jQuery(parent).parents('tr');
72            }
73            var childRef = parent.attr("nameref");
74            cascadingProperty = jQuery('#'+childRef).attr('name');
75        }
76        if(cascadingProperty !== undefined) {
77            var jobUrl = getJobUrl()+'/modifyCascadingProperty?propertyName='+cascadingProperty;
78            new Ajax.Request(jobUrl, {
79                method : 'get'
80            });
81        }
82    };
83    jQuery("form[action=configSubmit] input[type=checkbox]").live('click', modify);
84    jQuery("form[action=configSubmit] input[type!=checkbox]").live('change', modify);    
85    jQuery("form[action=configSubmit] .setting-input").live('change', modify);
86    jQuery("form[action=configSubmit] button").live('click', modify);
87}
88
89jQuery(document).ready(function(){
90    onCascadingProjectUpdated();
91    onProjectPropertyChanged();
92});