当光标位于按钮上时显示一条消息(并禁用单击)



JavaScript

$(function(){
$('.select-another-button').each(function(){
$(this).bind('click', function(e){
$('#message').show()
setTimeout(function(){ $('#message').hide() }, 300000);
e.preventDefault();
fileBrowser(this);
return false;
});
});
});

.HTML

<a href="#"
title="{% trans "Send email - rejected file(s)" %}"
class="btn btn-icon select-another-button"
data-url="{% url "messaging:send" request_id=object.pk %}">
<i class="material-icons">assignment_late</i>
<div class='alert alert-success' id='message'>
The message was sent to the client. Please wait 5 minutes before sending the message again.
</div>
</a>

姜戈

app_name = 'messaging'
urlpatterns = [
...
url(r'^send/(?P<request_id>[0-9]+)/$',
send, name='send'),
]

@staff_member_required
@csrf_exempt
def send(request, request_id=None):
req= Request.objects.get(pk=request_id)
request_folders = req.folder.all_files.all()
context = []
for doc in request_folders:
if doc.meta.state == u'rejected':
context.append(doc)
if context:
ctx = {'request': req}
EmailFromTemplate('document-refusal', extra_context=ctx)
.send_to(req.customer.user)
return HttpResponse('')

此代码的目的是创建一个按钮,该按钮将在特定条件下发送电子邮件。我的弱点可能是HTML和jS部分。用户单击该按钮后,我希望延迟五分钟,然后才能再次发送消息。因此,一旦使用按钮,我必须停用该按钮五分钟并显示消息:">消息已发送给客户端。请等待 5 分钟,然后再次发送消息。当光标在按钮上时。我怎样才能修改JS部分,以便它可以做我想做的事?


更新

<div class="title-actions">
{% if not object.is_readonly %}
{# TODO: apply perms #}
<a href="#"
id="id_select_request_document"
title="{% trans "Select file(s)" %}"
class="btn btn-icon select-button"
data-turbolinks="false"
data-save-label="{% trans "Ok" %}"
data-close-label="{% trans "Cancel" %}"
data-copy-to="{{ folder.pk }}"
data-reload="true"
data-url="{% url "documents:ajax-select" folder_id=object.customer.folder.pk %}">
<i class="material-icons">folder</i>
</a>
{# TODO: apply perms #}
{# if permissions.has_add_children_permission and not folder.is_root #}
<a href="#"
id="id_upload_request_document"
title="{% trans "Upload file(s)" %}"
class="btn btn-icon upload-button"
data-turbolinks="false"
data-url="{% url "documents:ajax-upload" folder_id=folder.pk %}"
data-complete-post="{% url "requests:validate-requirements" pk=object.pk %}"
data-max-uploader-connections="1">
<i class="material-icons">cloud_upload</i>
</a>
<div class="wrapper">
<div id="overlay"></div>
<a href="#"
title="{% trans "Send email - rejected file(s)" %}"
class="btn btn-icon select-another-button"
data-url="{% url "messaging:send" request_id=object.pk %}">
<i class="material-icons">assignment_late</i>
<div class='alert alert-success' id='send-message' style="display: none;">
<p>
The message was sent to the client. Please wait 5 minutes <br> before sending the message again.
</p>
</div>
</a>
</div>
{% endif %}
{% if request.user.is_superuser %}
<a href="{{ folder.get_admin_directory_listing_url_path }}" class="btn-icon"><i class="material-icons">settings</i></a>
{% endif %}
</div>

在修改之前,我得到了正确的显示,但现在我的显示错误。

我不知道它是否好,但我把以下块放在我的.html文件的顶部。

<script type="text/css">
.wrapper{
position: relative;
display: inline-block;
}
#overlay{
display: none;
position: absolute;       
top: 0;
left: 0;
opacity: .1;
background-color: blue;
height: 100%;
width: 100%;
}

.CSS

.title-actions {
float: right;
height: 50px;
margin-top: 13px; }
.title-actions a {
transition: background 0.3s ease; }
.title-actions a.btn {
padding: 2px 14px;
line-height: 26px;
max-height: 28px;
position: relative;
top: -1px;
margin-left: 8px; }
.title-actions a:hover {
background: #4382b5; }
.title-actions span {
color: #444;
background: #e6e6e6;
padding: 6px 10px;
border-radius: 3px;
float: none;
position: relative;
margin-left: 6px; }
.title-actions .btn {
padding: 2px 14px;
line-height: 26px;
max-height: 28px;
position: relative;
top: -1px;
margin-left: 8px; }
.title-actions .btn-icon {
background: transparent;
position: relative;
color: #3e5366;
text-align: center;
display: inline-block;
padding: 0 !important;
transition: color 0.3s ease;
box-shadow: none !important;
margin-top: -16px;
margin-left: 6px; }
.title-actions .btn-icon i {
font-size: 35px;
line-height: 20px;
position: relative;
top: 12px; }
.title-actions .btn-icon:hover {
color: #4382b5;
background: transparent; }
.title-actions .badge .material-icons {
font-size: 1.2em;
line-height: 0;
position: relative;
top: 4px; }

您需要对代码进行大量更改。假设您只有 1 个带有id="message"的元素。

从你的 JQuery 代码开始。

$(function(){
$('.select-another-button').each(function(){
$(this).bind('click', function(e) {
$(this).attr('disabled','true'); //disables the button
$('#overlay').show(); //after disabling show the overlay for hover
setTimeout(function(){ 
$(this).attr('disabled','false'); //enables after 5mins
$('#overlay').hide(); //hide the overlay
}, 300000);
e.preventDefault();
fileBrowser(this);
return false;
});
});
});
$("#overlay").hover(function(){
$('#message').show();
},function(){
$('#message').hide();
});

由于禁用的按钮不能有hover事件,因此您需要在按钮上放置透明覆盖并在其悬停时显示#message

.HTML

<div class="wrapper">
<div id="overlay"></div>
<a href="#"
title="{% trans "Send email - rejected file(s)" %}"
class="btn btn-icon select-another-button"
data-url="{% url "messaging:send" request_id=object.pk %}">
<i class="material-icons">assignment_late</i>
<div class='alert alert-success' id='message' style="display: none;">
The message was sent to the client. Please wait 5 minutes before sending the message again.
</div>
</a>
</div>

当然,CSS会更改以确保overlay正确放置在稍后将被禁用的按钮上。

.wrapper{
position: relative;
display: inline-block;
}
#overlay{
display: none;
position: absolute;       
top: 0;
left: 0;
opacity: .1;
height: 100%;
width: 100%;
}

$(function(){
$('.select-another-button').each(function(){
$(this).bind('click', function(e) {
$(this).attr('disabled','true');
$('#overlay').show();
setTimeout(function(){ 
$(this).attr('disabled','false');
$('#overlay').hide();
}, 300000);
e.preventDefault();
fileBrowser(this);
return false;
});
});
});
$("#overlay").hover(function(){
$('#message').show();
},function(){
$('#message').hide();
});
.wrapper{
position: relative;
display: inline-block;
}
#overlay{
display: none;
position: absolute;       
top: 0;
left: 0;
opacity: .1;
height: 100%;
width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<div id="overlay"></div> 
<a href="#"
title="{% trans "Send email - rejected file(s)" %}"
class="btn btn-icon select-another-button"
data-url="{% url "messaging:send" request_id=object.pk %}">
<i class="material-icons">assignment_late</i>
<div class='alert alert-success' id='message' style="display: none;">
The message was sent to the client. Please wait 5 minutes before sending the message again.
</div>
</a>
</div>

相关内容

最新更新