Commit ca9cded4 authored by Kushal Pandya's avatar Kushal Pandya

Fixes as per feedback

parent f16377e7
export { default as ProtectedTagAccessDropdown } from './protected_tag_access_dropdown';
export { default as ProtectedTagCreate } from './protected_tag_create'; export { default as ProtectedTagCreate } from './protected_tag_create';
export { default as ProtectedTagDropdown } from './protected_tag_dropdown';
export { default as ProtectedTagEdit } from './protected_tag_edit';
export { default as ProtectedTagEditList } from './protected_tag_edit_list'; export { default as ProtectedTagEditList } from './protected_tag_edit_list';
...@@ -11,8 +11,8 @@ export default class ProtectedTagAccessDropdown { ...@@ -11,8 +11,8 @@ export default class ProtectedTagAccessDropdown {
selectable: true, selectable: true,
inputId: this.options.$dropdown.data('input-id'), inputId: this.options.$dropdown.data('input-id'),
fieldName: this.options.$dropdown.data('field-name'), fieldName: this.options.$dropdown.data('field-name'),
toggleLabel(item, el) { toggleLabel(item, $el) {
if (el.is('.is-active')) { if ($el.is('.is-active')) {
return item.text; return item.text;
} }
return 'Select'; return 'Select';
......
...@@ -3,7 +3,7 @@ import ProtectedTagDropdown from './protected_tag_dropdown'; ...@@ -3,7 +3,7 @@ import ProtectedTagDropdown from './protected_tag_dropdown';
export default class ProtectedTagCreate { export default class ProtectedTagCreate {
constructor() { constructor() {
this.$form = $('.new_protected_tag'); this.$form = $('.js-new-protected-tag');
this.buildDropdowns(); this.buildDropdowns();
} }
...@@ -34,7 +34,7 @@ export default class ProtectedTagCreate { ...@@ -34,7 +34,7 @@ export default class ProtectedTagCreate {
onSelect() { onSelect() {
// Enable submit button // Enable submit button
const $tagInput = this.$form.find('input[name="protected_tag[name]"]'); const $tagInput = this.$form.find('input[name="protected_tag[name]"]');
const $allowedToCreateInput = this.$form.find('input[name="protected_tag[create_access_levels_attributes][0][access_level]"]'); const $allowedToCreateInput = this.$form.find('#create_access_levels_attributes');
this.$form.find('input[type="submit"]').attr('disabled', !($tagInput.val() && $allowedToCreateInput.length)); this.$form.find('input[type="submit"]').attr('disabled', !($tagInput.val() && $allowedToCreateInput.length));
} }
......
...@@ -50,9 +50,10 @@ export default class ProtectedTagDropdown { ...@@ -50,9 +50,10 @@ export default class ProtectedTagDropdown {
this.$protectedTag.on('click', this.onClickCreateWildcard.bind(this)); this.$protectedTag.on('click', this.onClickCreateWildcard.bind(this));
} }
onClickCreateWildcard() { onClickCreateWildcard(e) {
this.$dropdown.data('glDropdown').remote.execute(); this.$dropdown.data('glDropdown').remote.execute();
this.$dropdown.data('glDropdown').selectRowAtIndex(); this.$dropdown.data('glDropdown').selectRowAtIndex();
e.preventDefault();
} }
getProtectedTags(term, callback) { getProtectedTags(term, callback) {
......
...@@ -6,7 +6,8 @@ import ProtectedTagAccessDropdown from './protected_tag_access_dropdown'; ...@@ -6,7 +6,8 @@ import ProtectedTagAccessDropdown from './protected_tag_access_dropdown';
export default class ProtectedTagEdit { export default class ProtectedTagEdit {
constructor(options) { constructor(options) {
this.$wrap = options.$wrap; this.$wrap = options.$wrap;
this.$allowedToCreateDropdown = this.$wrap.find('.js-allowed-to-create'); this.$allowedToCreateDropdownButton = this.$wrap.find('.js-allowed-to-create');
this.onSelectCallback = this.onSelect.bind(this);
this.buildDropdowns(); this.buildDropdowns();
} }
...@@ -14,19 +15,19 @@ export default class ProtectedTagEdit { ...@@ -14,19 +15,19 @@ export default class ProtectedTagEdit {
buildDropdowns() { buildDropdowns() {
// Allowed to create dropdown // Allowed to create dropdown
this.protectedTagAccessDropdown = new ProtectedTagAccessDropdown({ this.protectedTagAccessDropdown = new ProtectedTagAccessDropdown({
$dropdown: this.$allowedToCreateDropdown, $dropdown: this.$allowedToCreateDropdownButton,
data: gon.create_access_levels, data: gon.create_access_levels,
onSelect: this.onSelect.bind(this), onSelect: this.onSelectCallback,
}); });
} }
onSelect() { onSelect() {
const $allowedToCreateInput = this.$wrap.find(`input[name="${this.$allowedToCreateDropdown.data('fieldName')}"]`); const $allowedToCreateInput = this.$wrap.find(`input[name="${this.$allowedToCreateDropdownButton.data('fieldName')}"]`);
// Do not update if one dropdown has not selected any option // Do not update if one dropdown has not selected any option
if (!$allowedToCreateInput.length) return; if (!$allowedToCreateInput.length) return;
this.$allowedToCreateDropdown.disable(); this.$allowedToCreateDropdownButton.disable();
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
...@@ -36,17 +37,16 @@ export default class ProtectedTagEdit { ...@@ -36,17 +37,16 @@ export default class ProtectedTagEdit {
_method: 'PATCH', _method: 'PATCH',
protected_tag: { protected_tag: {
create_access_levels_attributes: [{ create_access_levels_attributes: [{
id: this.$allowedToCreateDropdown.data('access-level-id'), id: this.$allowedToCreateDropdownButton.data('access-level-id'),
access_level: $allowedToCreateInput.val(), access_level: $allowedToCreateInput.val(),
}], }],
}, },
}, },
error() { error() {
$.scrollTo(0);
new Flash('Failed to update tag!'); new Flash('Failed to update tag!');
}, },
}).always(() => { }).always(() => {
this.$allowedToCreateDropdown.enable(); this.$allowedToCreateDropdownButton.enable();
}); });
} }
} }
/* eslint-disable no-new */
import ProtectedTagEdit from './protected_tag_edit'; import ProtectedTagEdit from './protected_tag_edit';
export default class ProtectedTagEditList { export default class ProtectedTagEditList {
constructor() { constructor() {
this.$wrap = $('.protected-tags-list'); this.$wrap = $('.protected-tags-list');
this.protectedTagList = [];
this.initEditForm(); this.initEditForm();
} }
initEditForm() { initEditForm() {
this.$wrap.find('.js-protected-tag-edit-form').each((i, el) => { this.$wrap.find('.js-protected-tag-edit-form').each((i, el) => {
this.protectedTagList[i] = new ProtectedTagEdit({ new ProtectedTagEdit({
$wrap: $(el), $wrap: $(el),
}); });
}); });
......
...@@ -779,7 +779,8 @@ pre.light-well { ...@@ -779,7 +779,8 @@ pre.light-well {
.protected-tags-list { .protected-tags-list {
.dropdown-menu-toggle { .dropdown-menu-toggle {
width: 300px; width: 100%;
max-width: 300px;
} }
} }
......
= form_for [@project.namespace.becomes(Namespace), @project, @protected_tag], html: { class: 'new_protected_tag' } do |f| = form_for [@project.namespace.becomes(Namespace), @project, @protected_tag], html: { class: 'js-new-protected-tag' } do |f|
.panel.panel-default .panel.panel-default
.panel-heading .panel-heading
%h3.panel-title %h3.panel-title
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment