diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-04-12 19:19:54 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-04-12 19:19:54 +0200 |
commit | 9bf6fb03580a6a277502ca68738f84af7675445f (patch) | |
tree | c1fba513ad10b3758a49cdbfd2989fb44012f031 | |
parent | 210c91c1cb05f74c574f4fd28e23e5f1622afaa2 (diff) | |
download | Ishtar-9bf6fb03580a6a277502ca68738f84af7675445f.tar.bz2 Ishtar-9bf6fb03580a6a277502ca68738f84af7675445f.zip |
Add a rollback button (closes #349)
-rw-r--r-- | ishtar/furnitures/urls.py | 6 | ||||
-rw-r--r-- | ishtar/furnitures/views.py | 16 | ||||
-rw-r--r-- | ishtar/templates/sheet.html | 2 | ||||
-rw-r--r-- | ishtar/templates/sheet_file.html | 5 | ||||
-rw-r--r-- | static/js/ishtar.js | 15 |
5 files changed, 39 insertions, 5 deletions
diff --git a/ishtar/furnitures/urls.py b/ishtar/furnitures/urls.py index 5a155b5b5..e7e9ff85a 100644 --- a/ishtar/furnitures/urls.py +++ b/ishtar/furnitures/urls.py @@ -96,7 +96,7 @@ actions = r"|".join(actions) urlpatterns += patterns('ishtar.furnitures.views', url(BASE_URL + r'(?P<action_slug>' + actions + r')/$', 'action', name='action'), - url(BASE_URL + r'autocomplete-persone/([0-9_]+)?$', 'autocomplete_person', + url(BASE_URL + r'autocomplete-person/([0-9_]+)?$', 'autocomplete_person', name='autocomplete-person'), url(BASE_URL + r'autocomplete-town/$', 'autocomplete_town', name='autocomplete-town'), @@ -113,10 +113,14 @@ urlpatterns += patterns('ishtar.furnitures.views', name='show-file'), url(BASE_URL + r'show-historized-file/(?P<pk>.+)?/(?P<date>.+)?$', 'show_file', name='show-historized-file'), + url(BASE_URL + r'revert-file/(?P<pk>.+)/(?P<date>.+)$', + 'revert_file', name='revert-file'), url(BASE_URL + r'autocomplete-operation/$', 'autocomplete_operation', name='autocomplete-operation'), url(BASE_URL + r'get-operation/(?P<type>.+)?$', 'get_operation', name='get-operation'), + url(BASE_URL + r'revert-operation/(?P<pk>.+)/(?P<date>.+)$', + 'revert_operation', name='revert-operation'), url(BASE_URL + r'show-operation/(?P<pk>.+)?/(?P<type>.+)?$', 'show_operation', name='show-operation'), diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py index 8dea8cb2f..107d9f3ea 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -289,7 +289,7 @@ def show_item(model, name): datetime.datetime.now().strftime('%M%s')) if date: try: - date = datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S.%f') + date = datetime.datetime.strptime(date, '%Y-%m-%dT%H:%M:%S.%f') item = item.get_previous(date=date) assert item != None except (ValueError, AssertionError): @@ -369,8 +369,21 @@ def show_item(model, name): return HttpResponse(content, content_type="application/xhtml") return func +def revert_item(model): + def func(request, pk, date, **dct): + try: + item = model.objects.get(pk=pk) + date = datetime.datetime.strptime(date, '%Y-%m-%dT%H:%M:%S.%f') + item.rollback(date) + except (ObjectDoesNotExist, ValueError, HistoryError): + return HttpResponse(None, mimetype='text/plain') + return HttpResponse("True", mimetype='text/plain') + return func + + get_file = get_item(models.File, 'get_file', 'file') show_file = show_item(models.File, 'file') +revert_file = revert_item(models.File) def autocomplete_operation(request, non_closed=True): if not request.user.has_perm('furnitures.view_operation', models.Operation)\ @@ -399,6 +412,7 @@ def autocomplete_operation(request, non_closed=True): get_operation = get_item(models.Operation, 'get_operation', 'operation') show_operation = show_item(models.Operation, 'operation') +revert_operation = revert_item(models.Operation) get_administrativeactfile = get_item(models.AdministrativeAct, 'get_administrativeactfile', 'administrativeactfile', diff --git a/ishtar/templates/sheet.html b/ishtar/templates/sheet.html index e2d1cc6c0..5608a684f 100644 --- a/ishtar/templates/sheet.html +++ b/ishtar/templates/sheet.html @@ -17,7 +17,7 @@ <script type="text/javascript">var last_window='{{window_id}}';</script> <div class="head"> <a href='#' onclick='$("#{{window_id}}").hide("slow")'>{% trans "Close" %}</a> - -<a href='#' onclick='$("#window > div").hide("slow");$("#window").html("")'> +<a href='#' onclick='closeAllWindows();'> {% trans "Close all windows" %} </a></div>{% endblock %} <div class="body"> diff --git a/ishtar/templates/sheet_file.html b/ishtar/templates/sheet_file.html index bf74490d5..1ba043239 100644 --- a/ishtar/templates/sheet_file.html +++ b/ishtar/templates/sheet_file.html @@ -4,11 +4,12 @@ {% if previous or next %} <div class='tool'> {%if previous%} -<a href="#" onclick='load_window("{% url show-historized-file item.pk previous %}");$("#{{window_id}}").hide();return false;'>{%trans "Previous version"%} ({{previous}})</a> +<a href="#" onclick='load_window("{% url show-historized-file item.pk previous|date:"c"%}");$("#{{window_id}}").hide();return false;'>{%trans "Previous version"%} ({{previous}})</a> {% endif %} {% if previous and next %} - {% endif %} {%if next%} -<a href="#" onclick='load_window("{% url show-historized-file item.pk next %}");$("#{{window_id}}").hide();return false;'>{%trans "Next version"%} ({{next}})</a> +<a href="#" onclick='if(confirm("{%trans "Are you sure to rollback to this version?"%}")){load_url("{% url revert-file item.pk item.history_date|date:"c"%}");closeAllWindows();load_window("{% url show-file item.pk None %}");}'>Rollback</a> - +<a href="#" onclick='load_window("{% url show-historized-file item.pk next|date:"c" %}");$("#{{window_id}}").hide();return false;'>{%trans "Next version"%} ({{next}})</a> {% endif %} </div> {% endif %} diff --git a/static/js/ishtar.js b/static/js/ishtar.js index f345cf030..534670cba 100644 --- a/static/js/ishtar.js +++ b/static/js/ishtar.js @@ -60,6 +60,16 @@ function load_window(url, speed){ }); } +function load_url(url){ + $.ajax({ + url: url, + cache: false, + success:function(html){}, + error:function(XMLHttpRequest, textStatus, errorThrows){ + } + }); +} + function open_window(url){ var newwindow = window.open(url, 'Ishtar', 'height=400,width=550,scrollbars=yes'); @@ -83,3 +93,8 @@ function multiRemoveItem(selItems, name, idx){ } jQuery("#selected_"+name+"_"+idx).remove(); } + +function closeAllWindows(){ + jQuery("#window > div").hide("slow"); + jQuery("#window").html(""); +} |