Commit 5778c5bf authored by Romain Loth's avatar Romain Loth

[fix] projects and corpora views: add some waiting images to all delete/update actions (bug-33)

parent 7ffe20ea
...@@ -200,8 +200,34 @@ function getRessources(){ ...@@ -200,8 +200,34 @@ function getRessources(){
//// POST TO API //// POST TO API
//// PUT AND PATCH TO API //// PUT AND PATCH TO API
function deleteOne(url){ function deleteOne(url, thatButton){
// we just show wait image before ajax
var $thatButton = $(thatButton)
var alreadyWaiting = $thatButton.has($('.wait-img-active')).length
if (! alreadyWaiting) {
var previousButtonContent = $thatButton.html()
var availableWidth = $thatButton.width()
var $myWaitImg = $('#wait-img').clone()
$myWaitImg.attr("id", null)
.attr("class","wait-img-active pull-right")
.width(availableWidth)
.css("display", "block") ;
$thatButton.append($myWaitImg)
}
else {
// uncomment if user should stop clicking ;)
// $thatButton.addClass("btn-danger")
// uncomment to prevent a 2nd ajax
return false
}
// now the real ajax
$.ajax({ $.ajax({
url: '/api'+url, url: '/api'+url,
type: 'delete', type: 'delete',
...@@ -306,7 +332,7 @@ $(document).on('change', 'input[type=checkbox]', function() { ...@@ -306,7 +332,7 @@ $(document).on('change', 'input[type=checkbox]', function() {
$(document).on("click","#delete", function(){ $(document).on("click","#delete", function(){
var selected = selectedUrls(); var selected = selectedUrls();
selected.forEach(function(url) { selected.forEach(function(url) {
deleteOne(url); deleteOne(url, this);
}); });
//window.location.reload(); //window.location.reload();
}); });
...@@ -336,7 +362,7 @@ $(document).on("click","#recalculate", function(){ ...@@ -336,7 +362,7 @@ $(document).on("click","#recalculate", function(){
// UNIQUE DELETION // UNIQUE DELETION
$(document).on("click", ".delete", function() { $(document).on("click", ".delete", function() {
var url = $( this ).data("url"); var url = $( this ).data("url");
deleteOne(url); deleteOne(url, this);
//window.location.reload(); //window.location.reload();
}); });
......
...@@ -18,6 +18,11 @@ ...@@ -18,6 +18,11 @@
.ui-autocomplete .ui-menu-item { .ui-autocomplete .ui-menu-item {
font-size:x-small; font-size:x-small;
} }
/* for wait gif in buttons */
.wait-img-active {
margin-left: .5em;
}
</style> </style>
{% endblock %} {% endblock %}
...@@ -97,6 +102,7 @@ ...@@ -97,6 +102,7 @@
<!--here loading projectlist from GET /projects--> <!--here loading projectlist from GET /projects-->
</div> </div>
<img id="wait-img" width="90%" style="display:none" src="{% static "img/ajax-loader.gif"%}"></img>
</div> </div>
...@@ -116,10 +122,10 @@ ...@@ -116,10 +122,10 @@
<!-- DELETE PROJECT --> <!-- DELETE PROJECT -->
<button type="button" class="btn btn-default delete pull-right" data-url="{url}" > <button type="button" class="btn btn-default delete pull-right" data-url="{url}" >
<span class="glyphicon glyphicon-trash pull-right" aria-hidden="true"></span> <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
</button> </button>
<!-- EDIT PROJECT-->
<!-- EDIT PROJECT-->
<button class="btn btn-default edit pull-right" data-id="{id}" data-url="{url}" data-toggle="collapse"> <button class="btn btn-default edit pull-right" data-id="{id}" data-url="{url}" data-toggle="collapse">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</button> </button>
......
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
margin-top: .3em; margin-top: .3em;
color: grey ; color: grey ;
} }
ul.inside-popover {
padding: .5em ;
list-style-type: none ;
}
</style> </style>
{% endblock %} {% endblock %}
...@@ -111,9 +116,9 @@ ...@@ -111,9 +116,9 @@
<button type="button" class="btn btn-default {% if not state.complete %}hidden{% endif %}" data-container="body" data-toggle="popover" data-placement="bottom" data-trigger="focus" <button type="button" class="btn btn-default {% if not state.complete %}hidden{% endif %}" data-container="body" data-toggle="popover" data-placement="bottom" data-trigger="focus"
data-content=" data-content="
<ul> <ul class=&quot;inside-popover&quot;>
<li <li
onclick=&quot;updateCorpus({{corpus.id}})&quot;> onclick=&quot;updateCorpus(event, {{corpus.id}})&quot;>
<a href='#'>Recalculate ngram metrics</a> <br/> (can take a little while) <a href='#'>Recalculate ngram metrics</a> <br/> (can take a little while)
</li> </li>
</ul> </ul>
...@@ -125,19 +130,9 @@ ...@@ -125,19 +130,9 @@
<!-- TODO: delete non seulement si state.complete mais aussi si state.error --> <!-- TODO: delete non seulement si state.complete mais aussi si state.error -->
<button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="bottom" <button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="bottom"
data-content=" data-content="
<ul> <ul id=&quot;{{corpus.id}}_trash_msg&quot; class=&quot;inside-popover&quot;>
<li <li
onclick=&quot; onclick=&quot;deleteCorpus(event, {{corpus.id}})&quot;>
trashedIds[{{corpus.id}}] = true ;
garganrest.nodes.delete(
{{corpus.id}},
function(){
$('#corpus_'+{{corpus.id}}).remove()
delete trashedIds[{{corpus.id}}]
}
);
$(this).parent().parent().remove();
&quot;>
<a href='#'>Delete this</a> <a href='#'>Delete this</a>
</li> </li>
</ul> </ul>
...@@ -798,7 +793,36 @@ ...@@ -798,7 +793,36 @@
}); });
} }
function updateCorpus(corpusId) { function deleteCorpus(e, corpusId) {
// prevents scroll back to top of page
e.preventDefault()
// register pending operation
trashedIds[corpusId] = true ;
// visual loader wheel
var statusDiv = document.getElementById("corpus_"+corpusId+"_status")
statusDiv.innerHTML = '<img width="10%" src="{% static "img/ajax-loader.gif"%}"></img>'
var trashMsgDiv = document.getElementById(corpusId+"_trash_msg")
trashMsgDiv.innerHTML = '<h5>Deleting corpus, please wait</h5>'
// REST and callback
garganrest.nodes.delete(
corpusId,
function(){
$('#corpus_'+corpusId).remove()
delete trashedIds[corpusId]
// remove any popover too
$('.popover').remove();
}
);
}
function updateCorpus(e, corpusId) {
// prevents scroll back to top of page
e.preventDefault()
// show 'waiting' // show 'waiting'
var statusDiv = document.getElementById("corpus_"+corpusId+"_status") var statusDiv = document.getElementById("corpus_"+corpusId+"_status")
var previousStatus = statusDiv.innerHTML var previousStatus = statusDiv.innerHTML
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment