Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
fb8dffb3
Commit
fb8dffb3
authored
Aug 18, 2016
by
Alfredo Sumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete access level when unselecting it from dropdown
parent
65de9b33
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
7 deletions
+29
-7
app/assets/javascripts/protected_branch_access_dropdown.js.es6
...ssets/javascripts/protected_branch_access_dropdown.js.es6
+3
-3
app/assets/javascripts/protected_branch_edit.js.es6
app/assets/javascripts/protected_branch_edit.js.es6
+26
-4
No files found.
app/assets/javascripts/protected_branch_access_dropdown.js.es6
View file @
fb8dffb3
...
@@ -3,9 +3,10 @@
...
@@ -3,9 +3,10 @@
gl.ProtectedBranchAccessDropdown = class {
gl.ProtectedBranchAccessDropdown = class {
constructor(options) {
constructor(options) {
const { $dropdown, onSelect, onHide } = options;
const { $dropdown, onSelect, onHide
, accessLevel
} = options;
const self = this;
const self = this;
this.accessLevel = accessLevel;
this.$dropdown = $dropdown;
this.$dropdown = $dropdown;
this.$wrap = this.$dropdown.parents().eq(1); // TODO: Find a better way to get the wrap element
this.$wrap = this.$dropdown.parents().eq(1); // TODO: Find a better way to get the wrap element
this.usersPath = '/autocomplete/users.json';
this.usersPath = '/autocomplete/users.json';
...
@@ -16,7 +17,6 @@
...
@@ -16,7 +17,6 @@
selectable: true,
selectable: true,
filterable: true,
filterable: true,
filterRemote: true,
filterRemote: true,
inputId: $dropdown.data('input-id'),
data: this.getData.bind(this),
data: this.getData.bind(this),
multiSelect: $dropdown.hasClass('js-multiselect'),
multiSelect: $dropdown.hasClass('js-multiselect'),
renderRow: this.renderRow.bind(this),
renderRow: this.renderRow.bind(this),
...
@@ -39,7 +39,7 @@
...
@@ -39,7 +39,7 @@
self.inputCount++;
self.inputCount++;
if (onSelect) {
if (onSelect) {
onSelect(item, $el);
onSelect(item, $el
, self
);
}
}
}
}
});
});
...
...
app/assets/javascripts/protected_branch_edit.js.es6
View file @
fb8dffb3
...
@@ -27,13 +27,14 @@
...
@@ -27,13 +27,14 @@
// Save initial state with existing dropdowns
// Save initial state with existing dropdowns
this.state = {};
this.state = {};
for (let ACCESS_LEVEL in ACCESS_LEVELS) {
for (let ACCESS_LEVEL in ACCESS_LEVELS) {
this.state[`${ACCESS_LEVELS[ACCESS_LEVEL]}_attributes`] = this.getAccessLevelData(ACCESS_LEVEL);
this.state[`${ACCESS_LEVELS[ACCESS_LEVEL]}_attributes`] = this.getAccessLevelData
FromInputs
(ACCESS_LEVEL);
}
}
}
}
buildDropdowns() {
buildDropdowns() {
// Allowed to merge dropdown
// Allowed to merge dropdown
new gl.allowedToMergeDropdown({
new gl.allowedToMergeDropdown({
accessLevel: ACCESS_LEVELS.MERGE,
$dropdown: this.$allowedToMergeDropdown,
$dropdown: this.$allowedToMergeDropdown,
onSelect: this.onSelectOption.bind(this),
onSelect: this.onSelectOption.bind(this),
onHide: this.onDropdownHide.bind(this),
onHide: this.onDropdownHide.bind(this),
...
@@ -41,14 +42,28 @@
...
@@ -41,14 +42,28 @@
// Allowed to push dropdown
// Allowed to push dropdown
new gl.allowedToPushDropdown({
new gl.allowedToPushDropdown({
accessLevel: ACCESS_LEVELS.PUSH,
$dropdown: this.$allowedToPushDropdown,
$dropdown: this.$allowedToPushDropdown,
onSelect: this.onSelectOption.bind(this),
onSelect: this.onSelectOption.bind(this),
onHide: this.onDropdownHide.bind(this)
onHide: this.onDropdownHide.bind(this)
});
});
}
}
onSelectOption(item, $el) {
onSelectOption(item, $el
, dropdownInstance
) {
this.hasChanges = true;
this.hasChanges = true;
let itemToDestroy;
let accessLevelState = this.state[`${dropdownInstance.accessLevel}_attributes`];
// If we are unselecting an option
if (!$el.is('.is-active')) {
if (item.type === LEVEL_TYPES.USER) {
itemToDestroy = _.findWhere(accessLevelState, { user_id: item.id });
} else if (item.type === LEVEL_TYPES.ROLE) {
itemToDestroy = _.findWhere(accessLevelState, { access_level: item.id });
}
itemToDestroy['_destroy'] = 1;
}
}
}
onDropdownHide() {
onDropdownHide() {
...
@@ -116,7 +131,7 @@
...
@@ -116,7 +131,7 @@
// State takes precedence
// State takes precedence
let accessLevel = ACCESS_LEVELS[accessLevelKey];
let accessLevel = ACCESS_LEVELS[accessLevelKey];
let accessLevelData = [];
let accessLevelData = [];
let dataFromInputs = this.getAccessLevelData(accessLevelKey);
let dataFromInputs = this.getAccessLevelData
FromInputs
(accessLevelKey);
for (let i = 0; i < dataFromInputs.length; i++) {
for (let i = 0; i < dataFromInputs.length; i++) {
let inState;
let inState;
...
@@ -146,10 +161,17 @@
...
@@ -146,10 +161,17 @@
}
}
}
}
// Items to be deleted
this.state[`${accessLevel}_attributes`].forEach((item) => {
if (item._destroy) {
accessLevelData.push(item);
}
});
return accessLevelData;
return accessLevelData;
}
}
getAccessLevelData(accessLevelKey) {
getAccessLevelData
FromInputs
(accessLevelKey) {
let accessLevels = [];
let accessLevels = [];
let accessLevel = ACCESS_LEVELS[accessLevelKey];
let accessLevel = ACCESS_LEVELS[accessLevelKey];
this.$wraps[accessLevel]
this.$wraps[accessLevel]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment