Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-74610

[nutanix-calm] Extract inline script block and event handlers in com/calm/Descriptors/BlueprintLaunch/config.jelly

XMLWordPrintable

      Problems

      == Inline Script Block
      Line: 48
      ----
      <script>
      
      
      	          function projectsChange(id){
                         blueprint = document.getElementById("blueprint-" + id);
                         appProfile = document.getElementById("profile-" + id);
                         runtimeVariables = document.getElementById("runtimeVariables-" + id);
                         blueprintDescription = document.getElementById("blueprintDescription-" + id);
                         blueprint.innerHTML = null;
                         appProfile.innerHTML = null;
                         runtimeVariables.value = null;
                         blueprintDescription.value = null;
                         blueprint.appendChild(document.createElement('option'));
                         appProfile.appendChild(document.createElement('option'));
                    }
      
                    function blueprintChange(id){
                         appProfile = document.getElementById("profile-" + id);
                         runtimeVariables = document.getElementById("runtimeVariables-" + id);
                         blueprintDescription = document.getElementById("blueprintDescription-" + id);
                         blueprintName = document.getElementById("blueprint-" + id).value;
                         blueprintDescription.value = "Fetching blueprint description";
                         appProfile.innerHTML = null;
                         appProfile.appendChild(document.createElement('option'));
                         runtimeVariables.value = null;
                         applicationLaunch.fetchBlueprintDescription(blueprintName, function(obj){
                              desc = obj.responseObject();
                              if(desc.length &gt; 0){
                                  blueprintDescription.value = desc;
                              }
                              else{
                                  blueprintDescription.value = "Description is empty";
                              }
      
                         });
                    }
      
                    function appProfileChange(id){
                         runtimeVariables = document.getElementById("runtimeVariables-" + id);
                         runtimeVariables.value = "Fetching the runtime variables";
                         addRuntimeVariables(id);
                    }
      
      	          function getProjects(id){
                        applicationLaunch.fetchProjects(function(obj)
                           {
                             projectList = obj.responseObject();
                             if(projectList === null){
                                  alert("ERROR occurred while fetching projects. Please check the system logs");
                                  return;
                             }
                             document.getElementById(id).innerHTML=null;
                             var sel = document.getElementById(id);
                             sel.innerHTML = null;
                             var opt = document.createElement('option');
                             opt.innerHTML = "Please select one";
                             opt.value = "Please select one";
                             opt.setAttribute('disabled','disabled');
                             opt.setAttribute('selected','true');
                             sel.appendChild(opt);
                             projectList.forEach(function(key){
                                 var opt = document.createElement('option');
                                 var value = key;
                                 var html = key;
                                 opt.innerHTML = html;
                                 opt.value = key;
                                 sel.appendChild(opt);
                             });
                            });
      
                     }
      
      
                    function getBlueprints(id, editorId){
                        console.log("logging the editorId: "+ editorId);
                        projectName = document.getElementById("project-" + editorId).value;
                        applicationLaunch.fetchBlueprints(projectName, function(obj) {
                            blueprints =  obj.responseObject();
                            if(blueprints === null){
                              alert("ERROR occurred while fetching blueprints");
                              return;
                            }
                            document.getElementById(id).innerHTML=null;
                            var sel = document.getElementById(id);
                            sel.innerHTML = null;
      
                            if(blueprints.length !== 0){
                                var opt = document.createElement('option');
                                opt.innerHTML = "Please select one";
                                opt.value = "Please select one";
                                opt.setAttribute('disabled','disabled');
                                opt.setAttribute('selected','true');
                                sel.appendChild(opt);
                                var i;
                                for(i = 0;i &lt; blueprints.length; i++){
                                  var opt = document.createElement('option');
                                  opt.innerHTML = blueprints[i];
                                  opt.value = blueprints[i];
                                  sel.appendChild(opt);
                                }
                            }
                            else{
                                var opt = document.createElement('option');
                                opt.innerHTML = "No blueprints in this project";
                                opt.value = "No blueprints in this project";
                                opt.setAttribute('disabled','disabled');
                                opt.setAttribute('selected','true');
                                sel.appendChild(opt);
                            }
                         });
                    }
      
                    function getAppProfiles(id, editorId){
                        bpname = document.getElementById("blueprint-" + editorId).value;
                        applicationLaunch.fetchAppProfiles(bpname, function(obj)
                          {
                            applicationProfileList = obj.responseObject();
                            if(applicationProfileList === null){
                                alert("Error occurred while fetching profiles");
                                return;
                            }
      
                            document.getElementById(id).innerHTML=null;
                            var sel = document.getElementById(id);
                            sel.innerHTML = null;
                            var opt = document.createElement('option');
                            opt.innerHTML = "Please select one";
                            opt.value = "Please select one";
                            opt.setAttribute('disabled','disabled');
                            opt.setAttribute('selected','true');
                            sel.appendChild(opt);
                            applicationProfileList.forEach(function(key){
                                var opt = document.createElement('option');
                                var value = key;
                                var html = key;
                                opt.innerHTML = html;
                                opt.value = key;
                                sel.appendChild(opt);
                            });
                          });
      
                    }
                    function addRuntimeVariables(editorId){
                          bpName = document.getElementById("blueprint-" + editorId).value;
                          profileName = document.getElementById("profile-" + editorId).value;
                          applicationLaunch.fetchRuntimeProfileVariables(bpName, profileName, function(obj){
                              runTime = obj.responseObject();
                              if(runTime === null){
                                  alert("ERROR occurred while fetching runtime variables");
                                  return;
                              }
                              var json = JSON.parse(obj.responseObject());
                              var runtimeElement = document.getElementById("runtimeVariables-" + editorId);
                              runtimeElement.value = JSON.stringify(json, undefined,4);
                              console.log("value added");
                          });
                     }
      
          </script>
      ----
      
      == Inline Event Handler
      Line: 23
      ----
      <f:select id="project-${editorId}" onmousedown="getProjects(this.id)" onchange="projectsChange(${editorId})" class="select"/>
      ----
      
      == Inline Event Handler
      Line: 27
      ----
      <f:select id="blueprint-${editorId}" clazz="blueprint" onmousedown="getBlueprints(this.id,${editorId})" onchange="blueprintChange(${editorId})"/>
      ----
      
      == Inline Event Handler
      Line: 34
      ----
      <f:select id="profile-${editorId}" onmousedown="getAppProfiles(this.id, ${editorId})" clazz="appProfile" onchange="appProfileChange(${editorId})"/>
      ----
      

      Solutions

      https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks
      https://www.jenkins.io/doc/developer/security/csp/#inline-event-handlers

            Unassigned Unassigned
            basil Basil Crow
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: