summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/protected_tags
diff options
context:
space:
mode:
authorKushal Pandya <kushal@gitlab.com>2017-04-03 11:40:21 +0530
committerKushal Pandya <kushal@gitlab.com>2017-04-03 11:40:21 +0530
commit85e1fa8e21c73746bb6f6270a658453a230bb9a2 (patch)
treed1217e6e66d8d7b09bc4703901be775e932212f0 /app/assets/javascripts/protected_tags
parent553cf9ea54ccb0736a8b44e2f3d047d0860aa71e (diff)
downloadgitlab-ce-85e1fa8e21c73746bb6f6270a658453a230bb9a2.tar.gz
ProtectedTagEdit class for edit protected tags
Diffstat (limited to 'app/assets/javascripts/protected_tags')
-rw-r--r--app/assets/javascripts/protected_tags/protected_tag_edit.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/app/assets/javascripts/protected_tags/protected_tag_edit.js b/app/assets/javascripts/protected_tags/protected_tag_edit.js
new file mode 100644
index 00000000000..b93e903621e
--- /dev/null
+++ b/app/assets/javascripts/protected_tags/protected_tag_edit.js
@@ -0,0 +1,54 @@
+/* eslint-disable no-new, arrow-parens, no-param-reassign, comma-dangle, max-len */
+/* global Flash */
+
+(global => {
+ global.gl = global.gl || {};
+
+ gl.ProtectedTagEdit = class {
+ constructor(options) {
+ this.$wrap = options.$wrap;
+ this.$allowedToPushDropdown = this.$wrap.find('.js-allowed-to-push');
+
+ this.buildDropdowns();
+ }
+
+ buildDropdowns() {
+ // Allowed to push dropdown
+ new gl.ProtectedTagAccessDropdown({
+ $dropdown: this.$allowedToPushDropdown,
+ data: gon.push_access_levels,
+ onSelect: this.onSelect.bind(this)
+ });
+ }
+
+ onSelect() {
+ const $allowedToPushInput = this.$wrap.find(`input[name="${this.$allowedToPushDropdown.data('fieldName')}"]`);
+
+ // Do not update if one dropdown has not selected any option
+ if (!$allowedToPushInput.length) return;
+
+ this.$allowedToPushDropdown.disable();
+
+ $.ajax({
+ type: 'POST',
+ url: this.$wrap.data('url'),
+ dataType: 'json',
+ data: {
+ _method: 'PATCH',
+ protected_tag: {
+ push_access_levels_attributes: [{
+ id: this.$allowedToPushDropdown.data('access-level-id'),
+ access_level: $allowedToPushInput.val()
+ }]
+ }
+ },
+ error() {
+ $.scrollTo(0);
+ new Flash('Failed to update tag!');
+ }
+ }).always(() => {
+ this.$allowedToPushDropdown.enable();
+ });
+ }
+ };
+})(window);