BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
115d4a41
Commit
115d4a41
authored
Apr 06, 2017
by
Kushal Pandya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert to pure ES6 class
parent
678672b0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
146 deletions
+132
-146
protected_tag_access_dropdown.js
...vascripts/protected_tags/protected_tag_access_dropdown.js
+24
-27
protected_tag_create.js
...assets/javascripts/protected_tags/protected_tag_create.js
+41
-45
protected_tag_dropdown.js
...sets/javascripts/protected_tags/protected_tag_dropdown.js
+4
-8
protected_tag_edit.js
app/assets/javascripts/protected_tags/protected_tag_edit.js
+49
-51
protected_tag_edit_list.js
...ets/javascripts/protected_tags/protected_tag_edit_list.js
+14
-15
No files found.
app/assets/javascripts/protected_tags/protected_tag_access_dropdown.js
View file @
115d4a41
/* eslint-disable arrow-parens, no-param-reassign, object-shorthand, no-else-return, comma-dangle, max-len */
export
default
class
ProtectedTagAccessDropdown
{
constructor
(
options
)
{
this
.
options
=
options
;
this
.
initDropdown
();
}
(
global
=>
{
initDropdown
()
{
global
.
gl
=
global
.
gl
||
{};
const
{
onSelect
}
=
this
.
options
;
this
.
options
.
$dropdown
.
glDropdown
({
gl
.
ProtectedTagAccessDropdown
=
class
{
data
:
this
.
options
.
data
,
constructor
(
options
)
{
selectable
:
true
,
const
{
$dropdown
,
data
,
onSelect
}
=
options
;
inputId
:
this
.
options
.
$dropdown
.
data
(
'input-id'
),
fieldName
:
this
.
options
.
$dropdown
.
data
(
'field-name'
),
$dropdown
.
glDropdown
({
toggleLabel
(
item
,
el
)
{
data
:
data
,
if
(
el
.
is
(
'.is-active'
))
{
selectable
:
true
,
return
item
.
text
;
inputId
:
$dropdown
.
data
(
'input-id'
),
fieldName
:
$dropdown
.
data
(
'field-name'
),
toggleLabel
(
item
,
el
)
{
if
(
el
.
is
(
'.is-active'
))
{
return
item
.
text
;
}
else
{
return
'Select'
;
}
},
clicked
(
item
,
$el
,
e
)
{
e
.
preventDefault
();
onSelect
();
}
}
});
return
'Select'
;
}
},
};
clicked
(
item
,
$el
,
e
)
{
})(
window
);
e
.
preventDefault
();
onSelect
();
},
});
}
}
app/assets/javascripts/protected_tags/protected_tag_create.js
View file @
115d4a41
/* eslint-disable no-new, arrow-parens, no-param-reassign, comma-dangle, max-len */
import
ProtectedTagAccessDropdown
from
'./protected_tag_access_dropdown'
;
/* global ProtectedTagDropdown */
import
ProtectedTagDropdown
from
'./protected_tag_dropdown'
;
(
global
=>
{
export
default
class
ProtectedTagCreate
{
global
.
gl
=
global
.
gl
||
{};
constructor
()
{
this
.
$form
=
$
(
'.new_protected_tag'
);
gl
.
ProtectedTagCreate
=
class
{
this
.
buildDropdowns
();
constructor
()
{
}
this
.
$wrap
=
this
.
$form
=
$
(
'.new_protected_tag'
);
this
.
buildDropdowns
();
buildDropdowns
()
{
}
const
$allowedToCreateDropdown
=
this
.
$form
.
find
(
'.js-allowed-to-create'
);
buildDropdowns
()
{
// Cache callback
const
$allowedToCreateDropdown
=
this
.
$wrap
.
find
(
'.js-allowed-to-create'
);
this
.
onSelectCallback
=
this
.
onSelect
.
bind
(
this
);
// Cache callback
// Allowed to Create dropdown
this
.
onSelectCallback
=
this
.
onSelect
.
bind
(
this
);
this
.
protectedTagAccessDropdown
=
new
ProtectedTagAccessDropdown
({
$dropdown
:
$allowedToCreateDropdown
,
// Allowed to Create dropdown
data
:
gon
.
create_access_levels
,
new
gl
.
ProtectedTagAccessDropdown
({
onSelect
:
this
.
onSelectCallback
,
$dropdown
:
$allowedToCreateDropdown
,
});
data
:
gon
.
create_access_levels
,
onSelect
:
this
.
onSelectCallback
// Select default
});
$allowedToCreateDropdown
.
data
(
'glDropdown'
).
selectRowAtIndex
(
0
);
// Select default
// Protected tag dropdown
$allowedToCreateDropdown
.
data
(
'glDropdown'
).
selectRowAtIndex
(
0
);
this
.
protectedTagDropdown
=
new
ProtectedTagDropdown
({
$dropdown
:
this
.
$form
.
find
(
'.js-protected-tag-select'
),
// Protected tag dropdown
onSelect
:
this
.
onSelectCallback
,
new
ProtectedTagDropdown
({
});
$dropdown
:
this
.
$wrap
.
find
(
'.js-protected-tag-select'
),
}
onSelect
:
this
.
onSelectCallback
});
// This will run after clicked callback
}
onSelect
()
{
// Enable submit button
// This will run after clicked callback
const
$tagInput
=
this
.
$form
.
find
(
'input[name="protected_tag[name]"]'
);
onSelect
()
{
const
$allowedToCreateInput
=
this
.
$form
.
find
(
'input[name="protected_tag[create_access_levels_attributes][0][access_level]"]'
);
// Enable submit button
const
$tagInput
=
this
.
$wrap
.
find
(
'input[name="protected_tag[name]"]'
);
this
.
$form
.
find
(
'input[type="submit"]'
).
attr
(
'disabled'
,
!
(
$tagInput
.
val
()
&&
$allowedToCreateInput
.
length
));
const
$allowedToCreateInput
=
this
.
$wrap
.
find
(
'input[name="protected_tag[create_access_levels_attributes][0][access_level]"]'
);
}
}
this
.
$form
.
find
(
'input[type="submit"]'
).
attr
(
'disabled'
,
!
(
$tagInput
.
val
()
&&
$allowedToCreateInput
.
length
));
}
};
})(
window
);
app/assets/javascripts/protected_tags/protected_tag_dropdown.js
View file @
115d4a41
/* eslint-disable comma-dangle, no-unused-vars */
export
default
class
ProtectedTagDropdown
{
class
ProtectedTagDropdown
{
constructor
(
options
)
{
constructor
(
options
)
{
this
.
onSelect
=
options
.
onSelect
;
this
.
onSelect
=
options
.
onSelect
;
this
.
$dropdown
=
options
.
$dropdown
;
this
.
$dropdown
=
options
.
$dropdown
;
...
@@ -21,7 +19,7 @@ class ProtectedTagDropdown {
...
@@ -21,7 +19,7 @@ class ProtectedTagDropdown {
filterable
:
true
,
filterable
:
true
,
remote
:
false
,
remote
:
false
,
search
:
{
search
:
{
fields
:
[
'title'
]
fields
:
[
'title'
]
,
},
},
selectable
:
true
,
selectable
:
true
,
toggleLabel
(
selected
)
{
toggleLabel
(
selected
)
{
...
@@ -38,7 +36,7 @@ class ProtectedTagDropdown {
...
@@ -38,7 +36,7 @@ class ProtectedTagDropdown {
clicked
:
(
item
,
$el
,
e
)
=>
{
clicked
:
(
item
,
$el
,
e
)
=>
{
e
.
preventDefault
();
e
.
preventDefault
();
this
.
onSelect
();
this
.
onSelect
();
}
}
,
});
});
}
}
...
@@ -63,7 +61,7 @@ class ProtectedTagDropdown {
...
@@ -63,7 +61,7 @@ class ProtectedTagDropdown {
this
.
selectedTag
=
{
this
.
selectedTag
=
{
title
:
tagName
,
title
:
tagName
,
id
:
tagName
,
id
:
tagName
,
text
:
tagName
text
:
tagName
,
};
};
if
(
tagName
)
{
if
(
tagName
)
{
...
@@ -75,5 +73,3 @@ class ProtectedTagDropdown {
...
@@ -75,5 +73,3 @@ class ProtectedTagDropdown {
this
.
$dropdownFooter
.
toggleClass
(
'hidden'
,
!
tagName
);
this
.
$dropdownFooter
.
toggleClass
(
'hidden'
,
!
tagName
);
}
}
}
}
window
.
ProtectedTagDropdown
=
ProtectedTagDropdown
;
app/assets/javascripts/protected_tags/protected_tag_edit.js
View file @
115d4a41
/* eslint-disable no-new
, arrow-parens, no-param-reassign, comma-dangle, max-len
*/
/* eslint-disable no-new */
/* global Flash */
/* global Flash */
(
global
=>
{
import
ProtectedTagAccessDropdown
from
'./protected_tag_access_dropdown'
;
global
.
gl
=
global
.
gl
||
{};
export
default
class
ProtectedTagEdit
{
gl
.
ProtectedTagEdit
=
class
{
constructor
(
options
)
{
constructor
(
options
)
{
this
.
$wrap
=
options
.
$wrap
;
this
.
$wrap
=
options
.
$wrap
;
this
.
$allowedToCreateDropdown
=
this
.
$wrap
.
find
(
'.js-allowed-to-create'
);
this
.
$allowedToCreateDropdown
=
this
.
$wrap
.
find
(
'.js-allowed-to-create'
);
this
.
buildDropdowns
();
this
.
buildDropdowns
();
}
}
buildDropdowns
()
{
buildDropdowns
()
{
// Allowed to create dropdown
// Allowed to create dropdown
this
.
protectedTagAccessDropdown
=
new
ProtectedTagAccessDropdown
({
new
gl
.
ProtectedTagAccessDropdown
({
$dropdown
:
this
.
$allowedToCreateDropdown
,
$dropdown
:
this
.
$allowedToCreateDropdown
,
data
:
gon
.
create_access_levels
,
data
:
gon
.
create_access_levels
,
onSelect
:
this
.
onSelect
.
bind
(
this
),
onSelect
:
this
.
onSelect
.
bind
(
this
)
});
});
}
}
onSelect
()
{
onSelect
()
{
const
$allowedToCreateInput
=
this
.
$wrap
.
find
(
`input[name="
${
this
.
$allowedToCreateDropdown
.
data
(
'fieldName'
)}
"]`
);
const
$allowedToCreateInput
=
this
.
$wrap
.
find
(
`input[name="
${
this
.
$allowedToCreateDropdown
.
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
.
$allowedToCreateDropdown
.
disable
();
$
.
ajax
({
$
.
ajax
({
type
:
'POST'
,
type
:
'POST'
,
url
:
this
.
$wrap
.
data
(
'url'
),
url
:
this
.
$wrap
.
data
(
'url'
),
dataType
:
'json'
,
dataType
:
'json'
,
data
:
{
data
:
{
_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
.
$allowedToCreateDropdown
.
data
(
'access-level-id'
),
access_level
:
$allowedToCreateInput
.
val
(),
access_level
:
$allowedToCreateInput
.
val
()
}],
}]
}
},
},
error
()
{
},
$
.
scrollTo
(
0
);
error
()
{
new
Flash
(
'Failed to update tag!'
);
$
.
scrollTo
(
0
);
}
new
Flash
(
'Failed to update tag!'
);
}
).
always
(()
=>
{
}
,
this
.
$allowedToCreateDropdown
.
enable
();
}).
always
(()
=>
{
}
);
this
.
$allowedToCreateDropdown
.
enable
(
);
}
}
);
}
;
}
}
)(
window
);
}
app/assets/javascripts/protected_tags/protected_tag_edit_list.js
View file @
115d4a41
/* eslint-disable arrow-parens, no-param-reassign, no-new, comma-dangle */
import
ProtectedTagEdit
from
'./protected_tag_edit'
;
(
global
=>
{
export
default
class
ProtectedTagEditList
{
global
.
gl
=
global
.
gl
||
{};
constructor
()
{
this
.
$wrap
=
$
(
'.protected-tags-list'
);
this
.
protectedTagList
=
[];
this
.
initEditForm
();
}
gl
.
ProtectedTagEditList
=
class
{
initEditForm
()
{
constructor
()
{
this
.
$wrap
.
find
(
'.js-protected-tag-edit-form'
).
each
((
i
,
el
)
=>
{
this
.
$wrap
=
$
(
'.protected-tags-list'
);
this
.
protectedTagList
[
i
]
=
new
ProtectedTagEdit
({
$wrap
:
$
(
el
),
// Build edit forms
this
.
$wrap
.
find
(
'.js-protected-tag-edit-form'
).
each
((
i
,
el
)
=>
{
new
gl
.
ProtectedTagEdit
({
$wrap
:
$
(
el
)
});
});
});
}
}
);
}
;
}
}
)(
window
);
}
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