Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
7357d354
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7357d354
编写于
5月 31, 2017
作者:
K
kushalpandya
提交者:
Jarka Kadlecova
6月 01, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update as per review feedback
上级
00cc34cc
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
32 addition
and
27 deletion
+32
-27
app/assets/javascripts/integrations/index.js
app/assets/javascripts/integrations/index.js
+2
-1
app/assets/javascripts/integrations/integration_settings_form.js
...ets/javascripts/integrations/integration_settings_form.js
+30
-26
未找到文件。
app/assets/javascripts/integrations/index.js
浏览文件 @
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
浏览文件 @
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,19 +20,28 @@ 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
)
{
// 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
());
}
}
}
handleServiceToggle
(
e
)
{
this
.
toggleServiceState
(
$
(
e
.
currentTarget
).
is
(
'
:checked
'
));
...
...
@@ -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,11 +85,9 @@ export default class IntegrationSettingsForm {
this
.
$submitBtnLoader
.
removeClass
(
'
hidden
'
);
}
else
{
this
.
$submitBtn
.
enable
();
if
(
!
this
.
$submitBtnLoader
.
hasClass
(
'
hidden
'
))
{
this
.
$submitBtnLoader
.
addClass
(
'
hidden
'
);
}
}
}
/* eslint-disable promise/catch-or-return, no-new */
/**
...
...
@@ -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
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录