The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I populate a 'select' box in the config: section of a plugin using args.projects?

Peter Goudman
November 28, 2011

Within the Field+Definintions page.

https://developer.atlassian.com/display/GADGETS/Field+Definitions

It reads,

options:[
{ /* These options are hard-coded but could easily be the results of an AJAX call
(E.g. args.projects) or be calculated at run time
Can anyone tell me how its done, been on this problem for two days now.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

2 votes
Peter Goudman
November 29, 2011

Okay I figured it out. Here is my code to display a prepopulated list box from a dynamic source (JSON) format, it displays the listbox in the config cycle of a JIRA gadget.

/// In gadget.xml config section

config: {
      descriptor: function (args)
      {
          var gadget = this;
          gadgets.window.setTitle("Choose Baseline...");
          
          // A select box that is populated by the AJAX JSON call in the args: section below
          var baselineOne = { 
          		id: "BL1", 
          		userpref: "Testing", 
          		type: "select", 
          		label: "Baseline One", 
          		description: "Select baseline one...", 
          		options:  args.baselines	
          };
          
          return  {
              fields: [
                  
                  baselineOne
              ]
          };
      },
      args: function()
      {		// Call AJAX and return JSON format.  The REST services class returns 
          return [
          {
             key: "baselines",
             ajaxOptions:  "/rest/baseline-gadget/1.0/baselinecomparison/getBaselines.json"
	
          }
	
          ];
      }()
}, // End of config section

// The Java method to return the data follows...

	  @GET
    @AnonymousAllowed
    @Produces({MediaType.APPLICATION_JSON})
    @Path ("/getBaselines")
    public Response getBaselines(@QueryParam ("projectId") String projectIdString){
    	
    	Collection<ABaseline> baselines =
    		new ArrayList<ABaseline>();
 
    	for(int i = 0; i < 10; i++){
    		ABaseline abaseline = 
    			new ABaseline("https://<CONFIDENTIAL DATA REMOVED>" + 
    				(i+1) + "_Baseline", "" + (i+1));
    				
    		baselines.add(abaseline);
    	}
    	
    	return Response.ok(baselines).cacheControl(null).build();
    }

TAGS
AUG Leaders

Atlassian Community Events