diff options
Diffstat (limited to 'app/assets/javascripts/deprecated_jquery_dropdown/gl_dropdown_remote.js')
-rw-r--r-- | app/assets/javascripts/deprecated_jquery_dropdown/gl_dropdown_remote.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/app/assets/javascripts/deprecated_jquery_dropdown/gl_dropdown_remote.js b/app/assets/javascripts/deprecated_jquery_dropdown/gl_dropdown_remote.js new file mode 100644 index 00000000000..1f6a2e1f646 --- /dev/null +++ b/app/assets/javascripts/deprecated_jquery_dropdown/gl_dropdown_remote.js @@ -0,0 +1,42 @@ +/* eslint-disable consistent-return */ + +import axios from '../lib/utils/axios_utils'; + +export class GitLabDropdownRemote { + constructor(dataEndpoint, options) { + this.dataEndpoint = dataEndpoint; + this.options = options; + } + + execute() { + if (typeof this.dataEndpoint === 'string') { + return this.fetchData(); + } else if (typeof this.dataEndpoint === 'function') { + if (this.options.beforeSend) { + this.options.beforeSend(); + } + return this.dataEndpoint('', data => { + // Fetch the data by calling the data function + if (this.options.success) { + this.options.success(data); + } + if (this.options.beforeSend) { + return this.options.beforeSend(); + } + }); + } + } + + fetchData() { + if (this.options.beforeSend) { + this.options.beforeSend(); + } + + // Fetch the data through ajax if the data is a string + return axios.get(this.dataEndpoint).then(({ data }) => { + if (this.options.success) { + return this.options.success(data); + } + }); + } +} |