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
7357d354
Commit
7357d354
authored
May 31, 2017
by
kushalpandya
Committed by
Jarka Kadlecova
Jun 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update as per review feedback
parent
00cc34cc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
27 deletions
+32
-27
index.js
app/assets/javascripts/integrations/index.js
+2
-1
integration_settings_form.js
...ets/javascripts/integrations/integration_settings_form.js
+30
-26
No files found.
app/assets/javascripts/integrations/index.js
View file @
7357d354
...
...
@@ -2,5 +2,6 @@
import
IntegrationSettingsForm
from
'./integration_settings_form'
;
$
(()
=>
{
new
IntegrationSettingsForm
(
'.js-integration-settings-form'
);
const
integrationSettingsForm
=
new
IntegrationSettingsForm
(
'.js-integration-settings-form'
);
integrationSettingsForm
.
init
();
});
app/assets/javascripts/integrations/integration_settings_form.js
View file @
7357d354
...
...
@@ -5,20 +5,14 @@ export default class IntegrationSettingsForm {
this
.
$form
=
$
(
formSelector
);
// Form Metadata
this
.
endPoint
=
this
.
$form
.
attr
(
'action'
);
this
.
canTestService
=
this
.
$form
.
data
(
'can-test'
);
this
.
testEndPoint
=
this
.
$form
.
data
(
'test-url'
);
// Form Child Elements
this
.
$serviceToggle
=
this
.
$form
.
find
(
'#service_active'
);
this
.
$submitBtn
=
this
.
$form
.
find
(
'button[type="submit"]'
);
this
.
$submitBtnLoader
=
this
.
$submitBtn
.
find
(
'.js-btn-spinner'
);
this
.
$submitBtnLabel
=
this
.
$submitBtn
.
find
(
'.js-btn-label'
);
// Class Member methods
this
.
handleServiceToggle
=
this
.
handleServiceToggle
.
bind
(
this
);
this
.
handleSettingsSave
=
this
.
handleSettingsSave
.
bind
(
this
);
this
.
init
();
}
init
()
{
...
...
@@ -26,17 +20,26 @@ export default class IntegrationSettingsForm {
this
.
toggleServiceState
(
this
.
$serviceToggle
.
is
(
':checked'
));
// Bind Event Listeners
this
.
$serviceToggle
.
on
(
'change'
,
this
.
handleServiceToggle
);
this
.
$submitBtn
.
on
(
'click'
,
this
.
handleSettingsSave
);
this
.
$serviceToggle
.
on
(
'change'
,
e
=>
this
.
handleServiceToggle
(
e
)
);
this
.
$submitBtn
.
on
(
'click'
,
e
=>
this
.
handleSettingsSave
(
e
)
);
}
handleSettingsSave
(
e
)
{
if
(
this
.
$serviceToggle
.
is
(
':checked'
))
{
if
(
this
.
$form
.
get
(
0
).
checkValidity
()
&&
this
.
canTestService
)
{
e
.
preventDefault
();
this
.
testSettings
(
this
.
$form
.
serialize
());
}
// Check if Service is marked active, as if not marked active,
// We can skip testing it and directly go ahead to allow form to
// be submitted
if
(
!
this
.
$serviceToggle
.
is
(
':checked'
))
{
return
;
}
// Service was marked active so now we check;
// 1) If form contents are valid
// 2) If this service can be tested
// If both conditions are true, we override form submission
// and test the service using provided configuration.
if
(
this
.
$form
.
get
(
0
).
checkValidity
()
&&
this
.
canTestService
)
{
e
.
preventDefault
();
this
.
testSettings
(
this
.
$form
.
serialize
());
}
}
...
...
@@ -48,7 +51,7 @@ export default class IntegrationSettingsForm {
* Change Form's validation enforcement based on service status (active/inactive)
*/
toggleServiceState
(
serviceActive
)
{
this
.
toggleSubmitBtnLabel
(
serviceActive
,
this
.
canTestService
);
this
.
toggleSubmitBtnLabel
(
serviceActive
);
if
(
serviceActive
)
{
this
.
$form
.
removeAttr
(
'novalidate'
);
}
else
if
(
!
this
.
$form
.
attr
(
'novalidate'
))
{
...
...
@@ -59,11 +62,14 @@ export default class IntegrationSettingsForm {
/**
* Toggle Submit button label based on Integration status and ability to test service
*/
toggleSubmitBtnLabel
(
serviceActive
,
canTestService
)
{
this
.
$submitBtnLabel
.
text
(
serviceActive
&&
canTestService
?
'Test settings and save changes'
:
'Save changes'
);
toggleSubmitBtnLabel
(
serviceActive
)
{
let
btnLabel
=
'Save changes'
;
if
(
serviceActive
&&
this
.
canTestService
)
{
btnLabel
=
'Test settings and save changes'
;
}
this
.
$submitBtnLabel
.
text
(
btnLabel
);
}
/**
...
...
@@ -79,9 +85,7 @@ export default class IntegrationSettingsForm {
this
.
$submitBtnLoader
.
removeClass
(
'hidden'
);
}
else
{
this
.
$submitBtn
.
enable
();
if
(
!
this
.
$submitBtnLoader
.
hasClass
(
'hidden'
))
{
this
.
$submitBtnLoader
.
addClass
(
'hidden'
);
}
this
.
$submitBtnLoader
.
addClass
(
'hidden'
);
}
}
...
...
@@ -93,12 +97,12 @@ export default class IntegrationSettingsForm {
this
.
toggleSubmitBtnState
(
true
);
$
.
ajax
({
type
:
'PUT'
,
url
:
`
${
this
.
endPoint
}
/test`
,
url
:
this
.
testEndPoint
,
data
:
formData
,
})
.
done
((
res
)
=>
{
if
(
res
.
error
)
{
new
Flash
(
`
${
res
.
message
}
`
,
null
,
null
,
{
new
Flash
(
res
.
message
,
null
,
null
,
{
title
:
'Save anyway'
,
clickHandler
:
(
e
)
=>
{
e
.
preventDefault
();
...
...
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