blob: 2e97ac427649e197e7582681b4fe536a48cafcd6 [file] [log] [blame]
Shawn Pearce92a1fa82013-07-16 15:01:40 -07001Gerrit Code Review - JavaScript API
2===================================
3
4Gerrit Code Review supports an API for JavaScript plugins to interact
5with the web UI and the server process.
6
7Entry Point
8-----------
9
10JavaScript is loaded using a standard `<script src='...'>` HTML tag.
11Plugins should protect the global namespace by defining their code
12within an anonymous function passed to `Gerrit.install()`. The plugin
13will be passed an object describing its registration with Gerrit:
14
David Pursehouse68153d72013-09-04 10:09:17 +090015[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -070016----
17Gerrit.install(function (self) {
18 // ... plugin JavaScript code here ...
19});
20----
21
22
23[[self]]
24Plugin Instance
25---------------
26
27The plugin instance is passed to the plugin's initialization function
28and provides a number of utility services to plugin authors.
29
David Pursehouse8d0b5202013-08-01 14:13:17 +090030[[self_delete]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -070031self.delete()
32~~~~~~~~~~~~~
33Issues a DELETE REST API request to the Gerrit server.
34
35.Signature
David Pursehouse68153d72013-09-04 10:09:17 +090036[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -070037----
38Gerrit.delete(url, callback)
39----
40
41* url: URL relative to the plugin's URL space. The JavaScript
42 library prefixes the supplied URL with `/plugins/{getPluginName}/`.
43
44* callback: JavaScript function to be invoked with the parsed
45 JSON result of the API call. DELETE methods often return
46 `204 No Content`, which is passed as null.
47
David Pursehouse8d0b5202013-08-01 14:13:17 +090048[[self_get]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -070049self.get()
50~~~~~~~~~~
51Issues a GET REST API request to the Gerrit server.
52
53.Signature
David Pursehouse68153d72013-09-04 10:09:17 +090054[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -070055----
56self.get(url, callback)
57----
58
59* url: URL relative to the plugin's URL space. The JavaScript
60 library prefixes the supplied URL with `/plugins/{getPluginName}/`.
61
62* callback: JavaScript function to be invoked with the parsed JSON
63 result of the API call. If the API returns a string the result is
64 a string, otherwise the result is a JavaScript object or array,
65 as described in the relevant REST API documentation.
66
David Pursehouse8d0b5202013-08-01 14:13:17 +090067[[self_getPluginName]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -070068self.getPluginName()
69~~~~~~~~~~~~~~~~~~~~
70Returns the name this plugin was installed as by the server
71administrator. The plugin name is required to access REST API
72views installed by the plugin, or to access resources.
73
David Pursehouse8d0b5202013-08-01 14:13:17 +090074[[self_post]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -070075self.post()
76~~~~~~~~~~~
77Issues a POST REST API request to the Gerrit server.
78
79.Signature
David Pursehouse68153d72013-09-04 10:09:17 +090080[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -070081----
82self.post(url, input, callback)
83----
84
85* url: URL relative to the plugin's URL space. The JavaScript
86 library prefixes the supplied URL with `/plugins/{getPluginName}/`.
87
88* input: JavaScript object to serialize as the request payload.
89
90* callback: JavaScript function to be invoked with the parsed JSON
91 result of the API call. If the API returns a string the result is
92 a string, otherwise the result is a JavaScript object or array,
93 as described in the relevant REST API documentation.
94
David Pursehouse68153d72013-09-04 10:09:17 +090095[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -070096----
97self.post(
98 '/my-servlet',
99 {start_build: true, platform_type: 'Linux'},
100 function (r) {});
101----
102
David Pursehouse8d0b5202013-08-01 14:13:17 +0900103[[self_put]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700104self.put()
105~~~~~~~~~~
106Issues a PUT REST API request to the Gerrit server.
107
108.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900109[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700110----
111self.put(url, input, callback)
112----
113
114* url: URL relative to the plugin's URL space. The JavaScript
115 library prefixes the supplied URL with `/plugins/{getPluginName}/`.
116
117* input: JavaScript object to serialize as the request payload.
118
119* callback: JavaScript function to be invoked with the parsed JSON
120 result of the API call. If the API returns a string the result is
121 a string, otherwise the result is a JavaScript object or array,
122 as described in the relevant REST API documentation.
123
David Pursehouse68153d72013-09-04 10:09:17 +0900124[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700125----
126self.put(
127 '/builds',
128 {start_build: true, platform_type: 'Linux'},
129 function (r) {});
130----
131
David Pursehouse8d0b5202013-08-01 14:13:17 +0900132[[self_onAction]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700133self.onAction()
134~~~~~~~~~~~~~~~
135Register a JavaScript callback to be invoked when the user clicks
136on a button associated with a server side `UiAction`.
137
138.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900139[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700140----
141Gerrit.onAction(type, view_name, callback);
142----
143
David Ostrovsky9e8b2fb2013-08-30 08:09:53 +0200144* type: `'change'`, `'revision'` or `'project'`, indicating which type
145 of resource the `UiAction` was bound to in the server.
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700146
147* view_name: string appearing in URLs to name the view. This is the
148 second argument of the `get()`, `post()`, `put()`, and `delete()`
149 binding methods in a `RestApiModule`.
150
151* callback: JavaScript function to invoke when the user clicks. The
152 function will be passed a link:#ActionContext[action context].
153
David Pursehouse8d0b5202013-08-01 14:13:17 +0900154[[self_url]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700155self.url()
156~~~~~~~~~~
157Returns a URL within the plugin's URL space. If invoked with no
David Pursehouse8d0b5202013-08-01 14:13:17 +0900158parameter the URL of the plugin is returned. If passed a string
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700159the argument is appended to the plugin URL.
160
David Pursehouse68153d72013-09-04 10:09:17 +0900161[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700162----
163self.url(); // "https://gerrit-review.googlesource.com/plugins/demo/"
164self.url('/static/icon.png'); // "https://gerrit-review.googlesource.com/plugins/demo/static/icon.png"
165----
166
167
168[[ActionContext]]
169Action Context
170--------------
171A new action context is passed to the `onAction` callback function
172each time the associated action button is clicked by the user. A
173context is initialized with sufficient state to issue the associated
174REST API RPC.
175
David Pursehouse8d0b5202013-08-01 14:13:17 +0900176[[context_action]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700177context.action
178~~~~~~~~~~~~~~
David Pursehouse68153d72013-09-04 10:09:17 +0900179An link:rest-api-changes.html#action-info[ActionInfo] object instance
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700180supplied by the server describing the UI button the user used to
181invoke the action.
182
David Pursehouse8d0b5202013-08-01 14:13:17 +0900183[[context_call]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700184context.call()
185~~~~~~~~~~~~~~
186Issues the REST API call associated with the action. The HTTP method
187used comes from `context.action.method`, hiding the JavaScript from
188needing to care.
189
190.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900191[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700192----
193context.call(input, callback)
194----
195
196* input: JavaScript object to serialize as the request payload. This
197 parameter is ignored for GET and DELETE methods.
198
199* callback: JavaScript function to be invoked with the parsed JSON
200 result of the API call. If the API returns a string the result is
201 a string, otherwise the result is a JavaScript object or array,
202 as described in the relevant REST API documentation.
203
David Pursehouse68153d72013-09-04 10:09:17 +0900204[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700205----
206context.call(
207 {message: "..."},
208 function (result) {
209 // ... use result here ...
210 });
211----
212
David Pursehouse8d0b5202013-08-01 14:13:17 +0900213[[context_change]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700214context.change
215~~~~~~~~~~~~~~
216When the action is invoked on a change a
217link:rest-api-changes.html#change-info[ChangeInfo] object instance
218describing the change. Available fields of the ChangeInfo may vary
219based on the options used by the UI when it loaded the change.
220
David Pursehouse8d0b5202013-08-01 14:13:17 +0900221[[context_delete]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700222context.delete()
223~~~~~~~~~~~~~~~~
224Issues a DELETE REST API call to the URL associated with the action.
225
226.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900227[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700228----
229context.delete(callback)
230----
231
232* callback: JavaScript function to be invoked with the parsed
233 JSON result of the API call. DELETE methods often return
234 `204 No Content`, which is passed as null.
235
David Pursehouse68153d72013-09-04 10:09:17 +0900236[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700237----
238context.delete(function () {});
239----
240
David Pursehouse8d0b5202013-08-01 14:13:17 +0900241[[context_get]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700242context.get()
243~~~~~~~~~~~~~
244Issues a GET REST API call to the URL associated with the action.
245
246.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900247[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700248----
249context.get(callback)
250----
251
252* callback: JavaScript function to be invoked with the parsed JSON
253 result of the API call. If the API returns a string the result is
254 a string, otherwise the result is a JavaScript object or array,
255 as described in the relevant REST API documentation.
256
David Pursehouse68153d72013-09-04 10:09:17 +0900257[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700258----
259context.get(function (result) {
260 // ... use result here ...
261});
262----
263
David Pursehouse8d0b5202013-08-01 14:13:17 +0900264[[context_go]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700265context.go()
266~~~~~~~~~~~~
David Pursehouse8d0b5202013-08-01 14:13:17 +0900267Go to a page. Shorthand for link:#Gerrit_go[`Gerrit.go()`].
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700268
David Pursehouse8d0b5202013-08-01 14:13:17 +0900269[[context_hide]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700270context.hide()
271~~~~~~~~~~~~~~
272Hide the currently visible popup displayed by
David Pursehouse8d0b5202013-08-01 14:13:17 +0900273link:#context_popup[`context.popup()`].
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700274
David Pursehouse8d0b5202013-08-01 14:13:17 +0900275[[context_post]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700276context.post()
277~~~~~~~~~~~~~~
278Issues a POST REST API call to the URL associated with the action.
279
280.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900281[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700282----
283context.post(input, callback)
284----
285
286* input: JavaScript object to serialize as the request payload.
287
288* callback: JavaScript function to be invoked with the parsed JSON
289 result of the API call. If the API returns a string the result is
290 a string, otherwise the result is a JavaScript object or array,
291 as described in the relevant REST API documentation.
292
David Pursehouse68153d72013-09-04 10:09:17 +0900293[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700294----
295context.post(
296 {message: "..."},
297 function (result) {
298 // ... use result here ...
299 });
300----
301
David Pursehouse8d0b5202013-08-01 14:13:17 +0900302[[context_popup]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700303context.popup()
304~~~~~~~~~~~~~~~
305
306Displays a small popup near the activation button to gather
307additional input from the user before executing the REST API RPC.
308
309The caller is always responsible for closing the popup with
David Pursehouse8d0b5202013-08-01 14:13:17 +0900310link#context_hide[`context.hide()`]. Gerrit will handle closing a
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700311popup if the user presses `Escape` while keyboard focus is within
312the popup.
313
314.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900315[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700316----
317context.popup(element)
318----
319
320* element: an HTML DOM element to display as the body of the
321 popup. This is typically a `div` element but can be any valid HTML
322 element. CSS can be used to style the element beyond the defaults.
323
324A common usage is to gather more input:
David Pursehouse68153d72013-09-04 10:09:17 +0900325
326[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700327----
328self.onAction('revision', 'start-build', function (c) {
329 var l = c.checkbox();
330 var m = c.checkbox();
331 c.popup(c.div(
332 c.div(c.label(l, 'Linux')),
333 c.div(c.label(m, 'Mac OS X')),
334 c.button('Build', {onclick: function() {
335 c.call(
336 {
337 commit: c.revision.name,
338 linux: l.checked,
339 mac: m.checked,
340 },
341 function() { c.hide() });
342 });
343});
344----
345
David Pursehouse8d0b5202013-08-01 14:13:17 +0900346[[context_put]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700347context.put()
348~~~~~~~~~~~~~
349Issues a PUT REST API call to the URL associated with the action.
350
351.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900352[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700353----
354context.put(input, callback)
355----
356
357* input: JavaScript object to serialize as the request payload.
358
359* callback: JavaScript function to be invoked with the parsed JSON
360 result of the API call. If the API returns a string the result is
361 a string, otherwise the result is a JavaScript object or array,
362 as described in the relevant REST API documentation.
363
David Pursehouse68153d72013-09-04 10:09:17 +0900364[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700365----
366context.put(
367 {message: "..."},
368 function (result) {
369 // ... use result here ...
370 });
371----
372
David Pursehouse8d0b5202013-08-01 14:13:17 +0900373[[context_refresh]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700374context.refresh()
375~~~~~~~~~~~~~~~~~
376Refresh the current display. Shorthand for
David Pursehouse8d0b5202013-08-01 14:13:17 +0900377link:#Gerrit_refresh[`Gerrit.refresh()`].
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700378
David Pursehouse8d0b5202013-08-01 14:13:17 +0900379[[context_revision]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700380context.revision
381~~~~~~~~~~~~~~~~
382When the action is invoked on a specific revision of a change,
383a link:rest-api-changes.html#revision-info[RevisionInfo]
384object instance describing the revision. Available fields of the
385RevisionInfo may vary based on the options used by the UI when it
386loaded the change.
387
David Ostrovsky9e8b2fb2013-08-30 08:09:53 +0200388[[context_project]]
389context.project
390~~~~~~~~~~~~~~~
391When the action is invoked on a specific project,
392the name of the project.
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700393
394Action Context HTML Helpers
395---------------------------
396The link:#ActionContext[action context] includes some HTML helper
397functions to make working with DOM based widgets less painful.
398
399* `br()`: new `<br>` element.
400
401* `button(label, options)`: new `<button>` with the string `label`
402 wrapped inside of a `div`. The optional `options` object may
403 define `onclick` as a function to be invoked upon clicking. This
404 calling pattern avoids circular references between the element
405 and the onclick handler.
406
407* `checkbox()`: new `<input type='checkbox'>` element.
408* `div(...)`: a new `<div>` wrapping the (optional) arguments.
409* `hr()`: new `<hr>` element.
410
411* `label(c, label)`: a new `<label>` element wrapping element `c`
412 and the string `label`. Used to wrap a checkbox with its label,
413 `label(checkbox(), 'Click Me')`.
414
David Ostrovskya1067a32013-08-19 09:09:17 +0200415* `prependLabel(label, c)`: a new `<label>` element wrapping element `c`
416 and the string `label`. Used to wrap an input field with its label,
417 `prependLabel('Greeting message', textfield())`.
418
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700419* `textarea(options)`: new `<textarea>` element. The options
420 object may optionally include `rows` and `cols`. The textarea
421 comes with an onkeypress handler installed to play nicely with
422 Gerrit's keyboard binding system.
423
424* `textfield()`: new `<input type='text'>` element. The text field
425 comes with an onkeypress handler installed to play nicely with
426 Gerrit's keyboard binding system.
427
428* `span(...)`: a new `<span>` wrapping the (optional) arguments.
429
David Ostrovsky7dfc8022013-08-25 23:05:50 +0200430* `msg(label)`: a new label.
431
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700432[[Gerrit]]
433Gerrit
434------
435
436The `Gerrit` object is the only symbol provided into the global
437namespace by Gerrit Code Review. All top-level functions can be
438accessed through this name.
439
David Pursehouse8d0b5202013-08-01 14:13:17 +0900440[[Gerrit_delete]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700441Gerrit.delete()
442~~~~~~~~~~~~~~~
443Issues a DELETE REST API request to the Gerrit server. For plugin
David Pursehouse8d0b5202013-08-01 14:13:17 +0900444private REST API URLs see link:#self_delete[self.delete()].
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700445
446.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900447[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700448----
449Gerrit.delete(url, callback)
450----
451
452* url: URL relative to the Gerrit server. For example to access the
453 link:rest-api-changes.html[changes REST API] use `'/changes/'`.
454
455* callback: JavaScript function to be invoked with the parsed
456 JSON result of the API call. DELETE methods often return
457 `204 No Content`, which is passed as null.
458
David Pursehouse68153d72013-09-04 10:09:17 +0900459[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700460----
461Gerrit.delete(
462 '/changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/topic',
463 function () {});
464----
465
David Pursehouse8d0b5202013-08-01 14:13:17 +0900466[[Gerrit_get]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700467Gerrit.get()
468~~~~~~~~~~~~
469Issues a GET REST API request to the Gerrit server. For plugin
David Pursehouse8d0b5202013-08-01 14:13:17 +0900470private REST API URLs see link:#self_get[self.get()].
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700471
472.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900473[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700474----
475Gerrit.get(url, callback)
476----
477
478* url: URL relative to the Gerrit server. For example to access the
479 link:rest-api-changes.html[changes REST API] use `'/changes/'`.
480
481* callback: JavaScript function to be invoked with the parsed JSON
482 result of the API call. If the API returns a string the result is
483 a string, otherwise the result is a JavaScript object or array,
484 as described in the relevant REST API documentation.
485
David Pursehouse68153d72013-09-04 10:09:17 +0900486[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700487----
488Gerrit.get('/changes/?q=status:open', function (open) {
489 for (var i = 0; i < open.length; i++) {
490 console.log(open.get(i).change_id);
491 }
492});
493----
494
David Pursehouse8d0b5202013-08-01 14:13:17 +0900495[[Gerrit_getPluginName]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700496Gerrit.getPluginName()
497~~~~~~~~~~~~~~~~~~~~~~
498Returns the name this plugin was installed as by the server
499administrator. The plugin name is required to access REST API
500views installed by the plugin, or to access resources.
501
David Pursehouse8d0b5202013-08-01 14:13:17 +0900502Unlike link:#self_getPluginName[`self.getPluginName()`] this method
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700503must guess the name from the JavaScript call stack. Plugins are
504encouraged to use `self.getPluginName()` whenever possible.
505
David Pursehouse8d0b5202013-08-01 14:13:17 +0900506[[Gerrit_go]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700507Gerrit.go()
508~~~~~~~~~~~
509Updates the web UI to display the view identified by the supplied
510URL token. The URL token is the text after `#` in the browser URL.
511
David Pursehouse68153d72013-09-04 10:09:17 +0900512[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700513----
514Gerrit.go('/admin/projects/');
515----
516
517If the URL passed matches `http://...`, `https://...`, or `//...`
518the current browser window will navigate to the non-Gerrit URL.
519The user can return to Gerrit with the back button.
520
David Pursehouse8d0b5202013-08-01 14:13:17 +0900521[[Gerrit_install]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700522Gerrit.install()
523~~~~~~~~~~~~~~~~
524Registers a new plugin by invoking the supplied initialization
525function. The function is passed the link:#self[plugin instance].
526
David Pursehouse68153d72013-09-04 10:09:17 +0900527[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700528----
529Gerrit.install(function (self) {
530 // ... plugin JavaScript code here ...
531});
532----
533
David Pursehouse8d0b5202013-08-01 14:13:17 +0900534[[Gerrit_post]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700535Gerrit.post()
536~~~~~~~~~~~~~
537Issues a POST REST API request to the Gerrit server. For plugin
David Pursehouse8d0b5202013-08-01 14:13:17 +0900538private REST API URLs see link:#self_post[self.post()].
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700539
540.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900541[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700542----
543Gerrit.post(url, input, callback)
544----
545
546* url: URL relative to the Gerrit server. For example to access the
547 link:rest-api-changes.html[changes REST API] use `'/changes/'`.
548
549* input: JavaScript object to serialize as the request payload.
550
551* callback: JavaScript function to be invoked with the parsed JSON
552 result of the API call. If the API returns a string the result is
553 a string, otherwise the result is a JavaScript object or array,
554 as described in the relevant REST API documentation.
555
David Pursehouse68153d72013-09-04 10:09:17 +0900556[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700557----
558Gerrit.post(
559 '/changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/topic',
560 {topic: 'tests', message: 'Classify work as for testing.'},
561 function (r) {});
562----
563
David Pursehouse8d0b5202013-08-01 14:13:17 +0900564[[Gerrit_put]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700565Gerrit.put()
566~~~~~~~~~~~~
567Issues a PUT REST API request to the Gerrit server. For plugin
David Pursehouse8d0b5202013-08-01 14:13:17 +0900568private REST API URLs see link:#self_put[self.put()].
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700569
570.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900571[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700572----
573Gerrit.put(url, input, callback)
574----
575
576* url: URL relative to the Gerrit server. For example to access the
577 link:rest-api-changes.html[changes REST API] use `'/changes/'`.
578
579* input: JavaScript object to serialize as the request payload.
580
581* callback: JavaScript function to be invoked with the parsed JSON
582 result of the API call. If the API returns a string the result is
583 a string, otherwise the result is a JavaScript object or array,
584 as described in the relevant REST API documentation.
585
David Pursehouse68153d72013-09-04 10:09:17 +0900586[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700587----
588Gerrit.put(
589 '/changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/topic',
590 {topic: 'tests', message: 'Classify work as for testing.'},
591 function (r) {});
592----
593
David Pursehouse8d0b5202013-08-01 14:13:17 +0900594[[Gerrit_onAction]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700595Gerrit.onAction()
596~~~~~~~~~~~~~~~~~
597Register a JavaScript callback to be invoked when the user clicks
598on a button associated with a server side `UiAction`.
599
600.Signature
David Pursehouse68153d72013-09-04 10:09:17 +0900601[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700602----
603Gerrit.onAction(type, view_name, callback);
604----
605
606* type: `'change'` or `'revision'`, indicating what sort of resource
607 the `UiAction` was bound to in the server.
608
609* view_name: string appearing in URLs to name the view. This is the
610 second argument of the `get()`, `post()`, `put()`, and `delete()`
611 binding methods in a `RestApiModule`.
612
613* callback: JavaScript function to invoke when the user clicks. The
614 function will be passed a link:#ActionContext[ActionContext].
615
David Pursehouse8d0b5202013-08-01 14:13:17 +0900616[[Gerrit_refresh]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700617Gerrit.refresh()
618~~~~~~~~~~~~~~~~
619Redisplays the current web UI view, refreshing all information.
620
David Pursehouse8d0b5202013-08-01 14:13:17 +0900621[[Gerrit_url]]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700622Gerrit.url()
623~~~~~~~~~~~~
624Returns the URL of the Gerrit Code Review server. If invoked with
625no parameter the URL of the site is returned. If passed a string
626the argument is appended to the site URL.
627
David Pursehouse68153d72013-09-04 10:09:17 +0900628[source,javascript]
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700629----
630Gerrit.url(); // "https://gerrit-review.googlesource.com/"
631Gerrit.url('/123'); // "https://gerrit-review.googlesource.com/123"
632----
633
David Pursehouse8d0b5202013-08-01 14:13:17 +0900634For a plugin specific version see link:#self_url()[`self.url()`].
Shawn Pearce92a1fa82013-07-16 15:01:40 -0700635
636GERRIT
637------
638Part of link:index.html[Gerrit Code Review]