Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1 | = Gerrit Code Review - JavaScript API |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 2 | |
| 3 | Gerrit Code Review supports an API for JavaScript plugins to interact |
| 4 | with the web UI and the server process. |
| 5 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 6 | == Entry Point |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 7 | |
| 8 | JavaScript is loaded using a standard `<script src='...'>` HTML tag. |
| 9 | Plugins should protect the global namespace by defining their code |
| 10 | within an anonymous function passed to `Gerrit.install()`. The plugin |
| 11 | will be passed an object describing its registration with Gerrit: |
| 12 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 13 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 14 | ---- |
| 15 | Gerrit.install(function (self) { |
| 16 | // ... plugin JavaScript code here ... |
| 17 | }); |
| 18 | ---- |
| 19 | |
| 20 | |
| 21 | [[self]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 22 | == Plugin Instance |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 23 | |
| 24 | The plugin instance is passed to the plugin's initialization function |
| 25 | and provides a number of utility services to plugin authors. |
| 26 | |
Edwin Kempin | 2fc17f4 | 2015-07-27 11:51:01 +0200 | [diff] [blame] | 27 | [[self_getServerInfo]] |
| 28 | === self.getServerInfo() |
| 29 | Returns the server's link:rest-api-config.html#server-info[ServerInfo] |
| 30 | data. |
| 31 | |
David Pursehouse | 8d0b520 | 2013-08-01 14:13:17 +0900 | [diff] [blame] | 32 | [[self_getPluginName]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 33 | === self.getPluginName() |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 34 | Returns the name this plugin was installed as by the server |
| 35 | administrator. The plugin name is required to access REST API |
| 36 | views installed by the plugin, or to access resources. |
| 37 | |
Shawn Pearce | db284cd | 2013-11-29 20:48:21 -0800 | [diff] [blame] | 38 | [[self_on]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 39 | === self.on() |
Shawn Pearce | db284cd | 2013-11-29 20:48:21 -0800 | [diff] [blame] | 40 | Register a JavaScript callback to be invoked when events occur within |
| 41 | the web interface. |
| 42 | |
| 43 | .Signature |
| 44 | [source,javascript] |
| 45 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 46 | self.on(event, callback); |
Shawn Pearce | db284cd | 2013-11-29 20:48:21 -0800 | [diff] [blame] | 47 | ---- |
| 48 | |
| 49 | * event: A supported event type. See below for description. |
| 50 | |
| 51 | * callback: JavaScript function to be invoked when event happens. |
| 52 | Arguments may be passed to this function, depending on the event. |
| 53 | |
| 54 | Supported events: |
| 55 | |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 56 | * `history`: Invoked when the view is changed to a new screen within |
| 57 | the Gerrit web application. The token after "#" is passed as the |
Shawn Pearce | a48826e | 2013-11-29 20:38:55 -0800 | [diff] [blame] | 58 | argument to the callback function, for example "/c/42/" while |
| 59 | showing change 42. |
| 60 | |
Shawn Pearce | db284cd | 2013-11-29 20:48:21 -0800 | [diff] [blame] | 61 | * `showchange`: Invoked when a change is made visible. A |
| 62 | link:rest-api-changes.html#change-info[ChangeInfo] and |
| 63 | link:rest-api-changes.html#revision-info[RevisionInfo] |
Wyatt Allen | 95a4d12 | 2018-01-25 14:04:26 -0800 | [diff] [blame] | 64 | are passed as arguments. PolyGerrit provides a third parameter which |
| 65 | is an object with a `mergeable` boolean. |
Shawn Pearce | db284cd | 2013-11-29 20:48:21 -0800 | [diff] [blame] | 66 | |
Shawn Pearce | 7c41899 | 2013-11-29 20:34:28 -0800 | [diff] [blame] | 67 | * `submitchange`: Invoked when the submit button is clicked |
| 68 | on a change. A link:rest-api-changes.html#change-info[ChangeInfo] |
| 69 | and link:rest-api-changes.html#revision-info[RevisionInfo] are |
| 70 | passed as arguments. Similar to a form submit validation, the |
| 71 | function must return true to allow the operation to continue, or |
Wyatt Allen | 7af56a2 | 2018-04-20 15:13:37 +0200 | [diff] [blame] | 72 | false to prevent it. The function may be called multiple times, for |
| 73 | example, if submitting a change shows a confirmation dialog, this |
| 74 | event may be called to validate that the check whether dialog can be |
| 75 | shown, and called again when the submit is confirmed to check whether |
| 76 | the actual submission action can proceed. |
Shawn Pearce | 7c41899 | 2013-11-29 20:34:28 -0800 | [diff] [blame] | 77 | |
Edwin Kempin | daefed0 | 2015-12-22 16:22:44 +0100 | [diff] [blame] | 78 | * `comment`: Invoked when a DOM element that represents a comment is |
| 79 | created. This DOM element is passed as argument. This DOM element |
| 80 | contains nested elements that Gerrit uses to format the comment. The |
| 81 | DOM structure may differ between comment types such as inline |
| 82 | comments, file-level comments and summary comments, and it may change |
| 83 | with new Gerrit versions. |
| 84 | |
Peter Marshall | d1f3642 | 2019-03-11 15:02:56 +0100 | [diff] [blame] | 85 | * `highlightjs-loaded`: Invoked when the highlight.js library has |
| 86 | finished loading. The global `hljs` object (also now accessible via |
| 87 | `window.hljs`) is passed as an argument to the callback function. |
| 88 | This event can be used to register a new language highlighter with |
| 89 | the highlight.js library before syntax highlighting begins. |
| 90 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 91 | [[self_changeActions]] |
| 92 | === self.changeActions() |
| 93 | Returns an instance of ChangeActions API. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 94 | |
| 95 | .Signature |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 96 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 97 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 98 | self.changeActions(); |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 99 | ---- |
| 100 | |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 101 | [[self_screen]] |
| 102 | === self.screen() |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 103 | Register a module to be attached when the user navigates |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 104 | to an extension screen provided by the plugin. Extension screens are |
| 105 | usually linked from the link:dev-plugins.html#top-menu-extensions[top menu]. |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 106 | |
| 107 | .Signature |
| 108 | [source,javascript] |
| 109 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 110 | self.screen(pattern, opt_moduleName); |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 111 | ---- |
| 112 | |
| 113 | * pattern: URL token pattern to identify the screen. Argument can be |
| 114 | either a string (`'index'`) or a RegExp object (`/list\/(.*)/`). |
| 115 | If a RegExp is used the matching groups will be available inside of |
| 116 | the context as `token_match`. |
| 117 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 118 | * opt_moduleName: The module to load when the user navigates to |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 119 | the screen. The function will be passed a link:#ScreenContext[screen context]. |
| 120 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 121 | [[self_settings]] |
| 122 | === self.settings() |
| 123 | Returns the Settings API. |
Edwin Kempin | dcaec6c | 2016-06-03 09:43:10 +0200 | [diff] [blame] | 124 | |
| 125 | .Signature |
| 126 | [source,javascript] |
| 127 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 128 | self.settings(); |
Edwin Kempin | dcaec6c | 2016-06-03 09:43:10 +0200 | [diff] [blame] | 129 | ---- |
| 130 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 131 | [[self_registerCustomComponent]] |
| 132 | === self.registerCustomComponent() |
| 133 | Register a custom component to a specific endpoint. |
Edwin Kempin | 9ef951b | 2016-06-03 13:27:50 +0200 | [diff] [blame] | 134 | |
| 135 | .Signature |
| 136 | [source,javascript] |
| 137 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 138 | self.registerCustomComponent(endpointName, opt_moduleName, opt_options); |
Edwin Kempin | 9ef951b | 2016-06-03 13:27:50 +0200 | [diff] [blame] | 139 | ---- |
| 140 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 141 | * endpointName: The endpoint this plugin should be reigistered to. |
Edwin Kempin | 9ef951b | 2016-06-03 13:27:50 +0200 | [diff] [blame] | 142 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 143 | * opt_moduleName: The module name the custom component will use. |
| 144 | |
| 145 | * opt_options: Options to register this custom component. |
Edwin Kempin | 9ef951b | 2016-06-03 13:27:50 +0200 | [diff] [blame] | 146 | |
David Pursehouse | 8d0b520 | 2013-08-01 14:13:17 +0900 | [diff] [blame] | 147 | [[self_url]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 148 | === self.url() |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 149 | Returns a URL within the plugin's URL space. If invoked with no |
David Pursehouse | 8d0b520 | 2013-08-01 14:13:17 +0900 | [diff] [blame] | 150 | parameter the URL of the plugin is returned. If passed a string |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 151 | the argument is appended to the plugin URL. |
| 152 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 153 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 154 | ---- |
| 155 | self.url(); // "https://gerrit-review.googlesource.com/plugins/demo/" |
| 156 | self.url('/static/icon.png'); // "https://gerrit-review.googlesource.com/plugins/demo/static/icon.png" |
| 157 | ---- |
| 158 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 159 | [[self_restApi]] |
| 160 | === self.restApi() |
| 161 | Returns an instance of the Plugin REST API. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 162 | |
| 163 | .Signature |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 164 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 165 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 166 | self.restApi(prefix_url) |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 167 | ---- |
| 168 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 169 | * prefix_url: Base url for subsequent .get(), .post() etc requests. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 170 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 171 | [[PluginRestAPI]] |
| 172 | == Plugin Rest API |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 173 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 174 | [[plugin_rest_delete]] |
| 175 | === restApi.delete() |
| 176 | Issues a DELETE REST API request to the Gerrit server. |
| 177 | Returns a promise with the response of the request. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 178 | |
| 179 | .Signature |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 180 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 181 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 182 | restApi.delete(url) |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 183 | ---- |
| 184 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 185 | * url: URL relative to the base url. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 186 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 187 | [[plugin_rest_get]] |
| 188 | === restApi.get() |
| 189 | Issues a GET REST API request to the Gerrit server. |
| 190 | Returns a promise with the response of the request. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 191 | |
| 192 | .Signature |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 193 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 194 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 195 | restApi.get(url) |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 196 | ---- |
| 197 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 198 | * url: URL relative to the base url. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 199 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 200 | [[plugin_rest_post]] |
| 201 | === restApi.post() |
| 202 | Issues a POST REST API request to the Gerrit server. |
| 203 | Returns a promise with the response of the request. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 204 | |
| 205 | .Signature |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 206 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 207 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 208 | restApi.post(url, opt_payload, opt_errFn, opt_contentType) |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 209 | ---- |
| 210 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 211 | * url: URL relative to the base url. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 212 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 213 | * opt_payload: JavaScript object to serialize as the request payload. |
| 214 | |
| 215 | * opt_errFn: JavaScript function to be invoked when error occured. |
| 216 | |
| 217 | * opt_contentType: Content-Type to be sent along with the request. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 218 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 219 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 220 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 221 | restApi.post( |
| 222 | '/my-servlet', |
| 223 | {start_build: true, platform_type: 'Linux'}); |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 224 | ---- |
| 225 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 226 | [[plugin_rest_put]] |
| 227 | === restApi.put() |
| 228 | Issues a PUT REST API request to the Gerrit server. |
| 229 | Returns a promise with the response of the request. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 230 | |
| 231 | .Signature |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 232 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 233 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 234 | restApi.put(url, opt_payload, opt_errFn, opt_contentType) |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 235 | ---- |
| 236 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 237 | * url: URL relative to the base url. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 238 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 239 | * opt_payload: JavaScript object to serialize as the request payload. |
| 240 | |
| 241 | * opt_errFn: JavaScript function to be invoked when error occured. |
| 242 | |
| 243 | * opt_contentType: Content-Type to be sent along with the request. |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 244 | |
| 245 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 246 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 247 | restApi.put( |
| 248 | '/builds', |
| 249 | {start_build: true, platform_type: 'Linux'}); |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 250 | ---- |
| 251 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 252 | [[ChangeActions]] |
| 253 | == Change Actions API |
| 254 | A new Change Actions API instance will be created when `changeActions()` |
| 255 | is invoked. |
| 256 | |
| 257 | [[change_actions_add]] |
| 258 | === changeActions.add() |
| 259 | Adds a new action to the change actions section. |
| 260 | Returns the key of the newly added action. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 261 | |
| 262 | .Signature |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 263 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 264 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 265 | changeActions.add(type, label) |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 266 | ---- |
| 267 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 268 | * type: The type of the action, either `change` or `revision`. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 269 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 270 | * label: The label to be used in UI for this action. |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 271 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 272 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 273 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 274 | changeActions.add("change", "test") |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 275 | ---- |
| 276 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 277 | [[change_actions_remove]] |
| 278 | === changeActions.remove() |
| 279 | Removes an action from the change actions section. |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 280 | |
| 281 | .Signature |
| 282 | [source,javascript] |
| 283 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 284 | changeActions.remove(key) |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 285 | ---- |
| 286 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 287 | * key: The key of the action. |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 288 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 289 | [[change_actions_addTapListener]] |
| 290 | === changeActions.addTapListener() |
| 291 | Adds a tap listener to an action that will be invoked when the action |
| 292 | is tapped. |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 293 | |
| 294 | .Signature |
| 295 | [source,javascript] |
| 296 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 297 | changeActions.addTapListener(key, callback) |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 298 | ---- |
| 299 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 300 | * key: The key of the action. |
| 301 | |
| 302 | * callback: JavaScript function to be invoked when action tapped. |
| 303 | |
| 304 | [source,javascript] |
| 305 | ---- |
| 306 | changeActions.addTapListener("__key_for_my_action__", () => { |
| 307 | // do something when my action gets clicked |
| 308 | }) |
| 309 | ---- |
| 310 | |
| 311 | [[change_actions_removeTapListener]] |
| 312 | === changeActions.removeTapListener() |
| 313 | Removes an existing tap listener on an action. |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 314 | |
| 315 | .Signature |
| 316 | [source,javascript] |
| 317 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 318 | changeActions.removeTapListener(key, callback) |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 319 | ---- |
| 320 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 321 | * key: The key of the action. |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 322 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 323 | * callback: JavaScript function to be removed. |
Edwin Kempin | dcaec6c | 2016-06-03 09:43:10 +0200 | [diff] [blame] | 324 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 325 | [[change_actions_setLabel]] |
| 326 | === changeActions.setLabel() |
| 327 | Sets the label for an action. |
Edwin Kempin | dcaec6c | 2016-06-03 09:43:10 +0200 | [diff] [blame] | 328 | |
| 329 | .Signature |
| 330 | [source,javascript] |
| 331 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 332 | changeActions.setLabel(key, label) |
Edwin Kempin | dcaec6c | 2016-06-03 09:43:10 +0200 | [diff] [blame] | 333 | ---- |
| 334 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 335 | * key: The key of the action. |
Edwin Kempin | dcaec6c | 2016-06-03 09:43:10 +0200 | [diff] [blame] | 336 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 337 | * label: The label of the action. |
| 338 | |
| 339 | [[change_actions_setTitle]] |
| 340 | === changeActions.setTitle() |
| 341 | Sets the title for an action. |
Edwin Kempin | dcaec6c | 2016-06-03 09:43:10 +0200 | [diff] [blame] | 342 | |
| 343 | .Signature |
| 344 | [source,javascript] |
| 345 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 346 | changeActions.setTitle(key, title) |
Edwin Kempin | dcaec6c | 2016-06-03 09:43:10 +0200 | [diff] [blame] | 347 | ---- |
| 348 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 349 | * key: The key of the action. |
| 350 | |
| 351 | * title: The title of the action. |
| 352 | |
| 353 | [[change_actions_setIcon]] |
| 354 | === changeActions.setIcon() |
| 355 | Sets an icon for an action. |
Edwin Kempin | dcaec6c | 2016-06-03 09:43:10 +0200 | [diff] [blame] | 356 | |
| 357 | .Signature |
| 358 | [source,javascript] |
| 359 | ---- |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 360 | changeActions.setIcon(key, icon) |
Edwin Kempin | dcaec6c | 2016-06-03 09:43:10 +0200 | [diff] [blame] | 361 | ---- |
| 362 | |
Tao Zhou | 803a381 | 2019-09-26 13:42:05 +0200 | [diff] [blame] | 363 | * key: The key of the action. |
| 364 | |
| 365 | * icon: The name of the icon. |
| 366 | |
| 367 | [[change_actions_setEnabled]] |
| 368 | === changeActions.setEnabled() |
| 369 | Sets an action to enabled or disabled. |
| 370 | |
| 371 | .Signature |
| 372 | [source,javascript] |
| 373 | ---- |
| 374 | changeActions.setEnabled(key, enabled) |
| 375 | ---- |
| 376 | |
| 377 | * key: The key of the action. |
| 378 | |
| 379 | * enabled: The status of the action, true to enable. |
| 380 | |
| 381 | [[change_actions_setActionHidden]] |
| 382 | === changeActions.setActionHidden() |
| 383 | Sets an action to be hidden. |
| 384 | |
| 385 | .Signature |
| 386 | [source,javascript] |
| 387 | ---- |
| 388 | changeActions.setActionHidden(type, key, hidden) |
| 389 | ---- |
| 390 | |
| 391 | * type: The type of the action. |
| 392 | |
| 393 | * key: The key of the action. |
| 394 | |
| 395 | * hidden: True to hide the action, false to show the action. |
| 396 | |
| 397 | [[change_actions_setActionOverflow]] |
| 398 | === changeActions.setActionOverflow() |
| 399 | Sets an action to show in overflow menu. |
| 400 | |
| 401 | .Signature |
| 402 | [source,javascript] |
| 403 | ---- |
| 404 | changeActions.setActionOverflow(type, key, overflow) |
| 405 | ---- |
| 406 | |
| 407 | * type: The type of the action. |
| 408 | |
| 409 | * key: The key of the action. |
| 410 | |
| 411 | * overflow: True to move the action to overflow menu, false to move |
| 412 | the action out of the overflow menu. |
Edwin Kempin | dcaec6c | 2016-06-03 09:43:10 +0200 | [diff] [blame] | 413 | |
Edwin Kempin | 9ef951b | 2016-06-03 13:27:50 +0200 | [diff] [blame] | 414 | [[PanelContext]] |
| 415 | == Panel Context |
| 416 | A new panel context is passed to the `panel` callback function each |
| 417 | time a screen with the given extension point is loaded. |
| 418 | |
| 419 | [[panel_body]] |
| 420 | === panel.body |
| 421 | Empty HTML `<div>` node the plugin should add the panel content to. |
| 422 | The node is already attached to the document. |
| 423 | |
| 424 | [[PanelProperties]] |
| 425 | === Properties |
| 426 | |
| 427 | The extension panel parameters that are described in the |
| 428 | link:dev-plugins.html#panels[plugin development documentation] are |
| 429 | contained in the context as properties. Which properties are available |
| 430 | depends on the extension point. |
| 431 | |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 432 | [[Gerrit]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 433 | == Gerrit |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 434 | |
| 435 | The `Gerrit` object is the only symbol provided into the global |
| 436 | namespace by Gerrit Code Review. All top-level functions can be |
| 437 | accessed through this name. |
| 438 | |
Shawn Pearce | 210b539 | 2013-12-07 22:41:36 -0800 | [diff] [blame] | 439 | [[Gerrit_css]] |
David Pursehouse | b10c266 | 2016-12-06 08:41:33 +0900 | [diff] [blame] | 440 | === Gerrit.css() |
Dmitrii Filippov | 941ee63 | 2019-08-22 15:52:37 +0000 | [diff] [blame] | 441 | [WARNING] |
| 442 | This method is deprecated. It doesn't work with Shadow DOM and |
| 443 | will be removed in the future. Please, use link:pg-plugin-dev.html#plugin-styles[plugin.styles] instead. |
| 444 | |
Shawn Pearce | 210b539 | 2013-12-07 22:41:36 -0800 | [diff] [blame] | 445 | Creates a new unique CSS class and injects it into the document. |
| 446 | The name of the class is returned and can be used by the plugin. |
Shawn Pearce | 210b539 | 2013-12-07 22:41:36 -0800 | [diff] [blame] | 447 | |
| 448 | Classes created with this function should be created once at install |
| 449 | time and reused throughout the plugin. Repeatedly creating the same |
| 450 | class will explode the global stylesheet. |
| 451 | |
| 452 | .Signature |
| 453 | [source,javascript] |
| 454 | ---- |
| 455 | Gerrit.install(function(self)) { |
| 456 | var style = { |
| 457 | name: Gerrit.css('background: #fff; color: #000;'), |
| 458 | }; |
| 459 | }); |
| 460 | ---- |
| 461 | |
David Pursehouse | 8d0b520 | 2013-08-01 14:13:17 +0900 | [diff] [blame] | 462 | [[Gerrit_install]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 463 | === Gerrit.install() |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 464 | Registers a new plugin by invoking the supplied initialization |
| 465 | function. The function is passed the link:#self[plugin instance]. |
| 466 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 467 | [source,javascript] |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 468 | ---- |
| 469 | Gerrit.install(function (self) { |
| 470 | // ... plugin JavaScript code here ... |
| 471 | }); |
| 472 | ---- |
| 473 | |
Shawn Pearce | 92a1fa8 | 2013-07-16 15:01:40 -0700 | [diff] [blame] | 474 | GERRIT |
| 475 | ------ |
| 476 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 477 | |
| 478 | SEARCHBOX |
| 479 | --------- |