Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
ed329d10
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ed329d10
编写于
3月 02, 2017
作者:
S
Stephen Connolly
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FIXED JENKINS-42443] Make f:select display spinner during AJAX requests
上级
03c58b9c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
227 addition
and
9 deletion
+227
-9
core/src/main/java/hudson/util/FormFillFailure.java
core/src/main/java/hudson/util/FormFillFailure.java
+202
-0
core/src/main/resources/lib/form/select/select.js
core/src/main/resources/lib/form/select/select.js
+25
-9
未找到文件。
core/src/main/java/hudson/util/FormFillFailure.java
0 → 100644
浏览文件 @
ed329d10
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
hudson.util
;
import
hudson.Functions
;
import
hudson.Util
;
import
java.io.IOException
;
import
java.util.Locale
;
import
javax.annotation.Nonnull
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletResponse
;
import
jenkins.model.Jenkins
;
import
org.kohsuke.stapler.HttpResponse
;
import
org.kohsuke.stapler.Stapler
;
import
org.kohsuke.stapler.StaplerRequest
;
import
org.kohsuke.stapler.StaplerResponse
;
import
static
hudson
.
Util
.
join
;
/**
* Represents the result of the form field fill failure.
*
* <p>
* Use one of the factory methods to create an instance, then throw it from your <tt>doFillXyz</tt>
* method.
*
* @since FIXME
*/
public
abstract
class
FormFillFailure
extends
IOException
implements
HttpResponse
{
/**
* Sends out a string error message that indicates an error.
*
* @param message Human readable message to be sent.
*/
public
static
FormFillFailure
error
(
@Nonnull
String
message
)
{
return
errorWithMarkup
(
Util
.
escape
(
message
));
}
public
static
FormFillFailure
warning
(
@Nonnull
String
message
)
{
return
warningWithMarkup
(
message
==
null
?
null
:
Util
.
escape
(
message
));
}
/**
* Sends out a string error message that indicates an error,
* by formatting it with {@link String#format(String, Object[])}
*/
public
static
FormFillFailure
error
(
String
format
,
Object
...
args
)
{
return
error
(
String
.
format
(
format
,
args
));
}
public
static
FormFillFailure
warning
(
String
format
,
Object
...
args
)
{
return
warning
(
String
.
format
(
format
,
args
));
}
/**
* Sends out a string error message, with optional "show details" link that expands to the full stack trace.
*
* <p>
* Use this with caution, so that anonymous users do not gain too much insights into the state of the system,
* as error stack trace often reveals a lot of information. Consider if a check operation needs to be exposed
* to everyone or just those who have higher access to job/hudson/etc.
*/
public
static
FormFillFailure
error
(
Throwable
e
,
String
message
)
{
return
_error
(
FormValidation
.
Kind
.
ERROR
,
e
,
message
);
}
public
static
FormFillFailure
warning
(
Throwable
e
,
String
message
)
{
return
_error
(
FormValidation
.
Kind
.
WARNING
,
e
,
message
);
}
private
static
FormFillFailure
_error
(
FormValidation
.
Kind
kind
,
Throwable
e
,
String
message
)
{
if
(
e
==
null
)
return
_errorWithMarkup
(
Util
.
escape
(
message
),
kind
);
return
_errorWithMarkup
(
Util
.
escape
(
message
)+
" <a href='#' class='showDetails'>"
+
Messages
.
FormValidation_Error_Details
()
+
"</a><pre style='display:none'>"
+
Util
.
escape
(
Functions
.
printThrowable
(
e
))
+
"</pre>"
,
kind
);
}
public
static
FormFillFailure
error
(
Throwable
e
,
String
format
,
Object
...
args
)
{
return
error
(
e
,
String
.
format
(
format
,
args
));
}
public
static
FormFillFailure
warning
(
Throwable
e
,
String
format
,
Object
...
args
)
{
return
warning
(
e
,
String
.
format
(
format
,
args
));
}
/**
* Sends out an HTML fragment that indicates an error.
*
* <p>
* This method must be used with care to avoid cross-site scripting
* attack.
*
* @param message
* Human readable message to be sent. <tt>error(null)</tt>
* can be used as <tt>ok()</tt>.
*/
public
static
FormFillFailure
errorWithMarkup
(
String
message
)
{
return
_errorWithMarkup
(
message
,
FormValidation
.
Kind
.
ERROR
);
}
public
static
FormFillFailure
warningWithMarkup
(
String
message
)
{
return
_errorWithMarkup
(
message
,
FormValidation
.
Kind
.
WARNING
);
}
private
static
FormFillFailure
_errorWithMarkup
(
@Nonnull
final
String
message
,
final
FormValidation
.
Kind
kind
)
{
return
new
FormFillFailure
(
kind
,
message
)
{
public
String
renderHtml
()
{
StaplerRequest
req
=
Stapler
.
getCurrentRequest
();
if
(
req
==
null
)
{
// being called from some other context
return
message
;
}
// 1x16 spacer needed for IE since it doesn't support min-height
return
"<div class="
+
getKind
().
name
().
toLowerCase
(
Locale
.
ENGLISH
)
+
"><img src='"
+
req
.
getContextPath
()+
Jenkins
.
RESOURCE_PATH
+
"/images/none.gif' height=16 width=1>"
+
message
+
"</div>"
;
}
@Override
public
String
toString
()
{
return
kind
+
": "
+
message
;
}
};
}
/**
* Sends out an arbitrary HTML fragment as the output.
*/
public
static
FormFillFailure
respond
(
FormValidation
.
Kind
kind
,
final
String
html
)
{
return
new
FormFillFailure
(
kind
)
{
public
String
renderHtml
()
{
return
html
;
}
@Override
public
String
toString
()
{
return
getKind
()
+
": "
+
html
;
}
};
}
private
final
FormValidation
.
Kind
kind
;
private
boolean
selectionCleared
;
/**
* Instances should be created via one of the factory methods above.
* @param kind the kind
*/
private
FormFillFailure
(
FormValidation
.
Kind
kind
)
{
this
.
kind
=
kind
;
}
private
FormFillFailure
(
FormValidation
.
Kind
kind
,
String
message
)
{
super
(
message
);
this
.
kind
=
kind
;
}
public
void
generateResponse
(
StaplerRequest
req
,
StaplerResponse
rsp
,
Object
node
)
throws
IOException
,
ServletException
{
rsp
.
setContentType
(
"text/html;charset=UTF-8"
);
rsp
.
setStatus
(
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
);
rsp
.
setHeader
(
"X-Jenkins-Select-Error"
,
selectionCleared
?
"clear"
:
"retain"
);
rsp
.
getWriter
().
print
(
renderHtml
());
}
public
FormValidation
.
Kind
getKind
()
{
return
kind
;
}
public
boolean
isSelectionCleared
()
{
return
selectionCleared
;
}
public
FormFillFailure
withSelectionCleared
()
{
this
.
selectionCleared
=
true
;
return
this
;
}
public
abstract
String
renderHtml
();
}
core/src/main/resources/lib/form/select/select.js
浏览文件 @
ed329d10
...
...
@@ -4,8 +4,13 @@ function updateListBox(listBox,url,config) {
config
=
config
||
{};
config
=
object
(
config
);
var
originalOnSuccess
=
config
.
onSuccess
;
config
.
onSuccess
=
function
(
rsp
)
{
var
l
=
$
(
listBox
);
var
l
=
$
(
listBox
);
var
status
=
findFollowingTR
(
listBox
,
"
validation-error-area
"
).
firstChild
.
nextSibling
;
if
(
status
.
firstChild
&&
status
.
firstChild
.
getAttribute
(
'
data-select-ajax-error
'
))
{
status
.
innerHTML
=
""
;
}
config
.
onSuccess
=
function
(
rsp
)
{
l
.
removeClassName
(
"
select-ajax-pending
"
);
var
currentSelection
=
l
.
value
;
// clear the contents
...
...
@@ -30,13 +35,24 @@ function updateListBox(listBox,url,config) {
if
(
originalOnSuccess
!=
undefined
)
originalOnSuccess
(
rsp
);
},
config
.
onFailure
=
function
(
rsp
)
{
// deleting values can result in the data loss, so let's not do that
// var l = $(listBox);
// l.options[0] = null;
}
};
config
.
onFailure
=
function
(
rsp
)
{
l
.
removeClassName
(
"
select-ajax-pending
"
);
status
.
innerHTML
=
rsp
.
responseText
;
if
(
status
.
firstChild
)
{
status
.
firstChild
.
setAttribute
(
'
data-select-ajax-error
'
,
'
true
'
)
}
Behaviour
.
applySubtree
(
status
);
// deleting values can result in the data loss, so let's not do that unless instructed
var
header
=
rsp
.
getResponseHeader
(
'
X-Jenkins-Select-Error
'
);
if
(
header
&&
"
clear
"
.
toUpperCase
()
===
header
.
toUpperCase
())
{
// clear the contents
while
(
l
.
length
>
0
)
l
.
options
[
0
]
=
null
;
}
};
l
.
addClassName
(
"
select-ajax-pending
"
);
new
Ajax
.
Request
(
url
,
config
);
}
...
...
@@ -82,4 +98,4 @@ Behaviour.specify("SELECT.select", 'select', 1000, function(e) {
}
});
});
});
\ No newline at end of file
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录