summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2019-05-18 12:28:51 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2019-05-20 15:40:55 (GMT)
commit19011ae0d30d5fbc0f8e8b58ec74f27182ae164e (patch)
treebbcfa88fcaff08e114a01d59758074432361dba8
parent07562beebd2769ea5f91756bb75522bef6869631 (diff)
downloadcombo-19011ae0d30d5fbc0f8e8b58ec74f27182ae164e.zip
combo-19011ae0d30d5fbc0f8e8b58ec74f27182ae164e.tar.gz
combo-19011ae0d30d5fbc0f8e8b58ec74f27182ae164e.tar.bz2
manager: keep cell open after edit actions (#33103)
-rw-r--r--combo/apps/gallery/views.py6
-rw-r--r--combo/manager/static/js/combo.manager.js7
-rw-r--r--combo/manager/templates/combo/page_view.html2
-rw-r--r--combo/manager/views.py5
-rw-r--r--tests/test_manager.py10
5 files changed, 18 insertions, 12 deletions
diff --git a/combo/apps/gallery/views.py b/combo/apps/gallery/views.py
index 76ca351..06a1776 100644
--- a/combo/apps/gallery/views.py
+++ b/combo/apps/gallery/views.py
@@ -37,7 +37,8 @@ class ImageAddView(CreateView):
return super(ImageAddView, self).form_valid(form)
def get_success_url(self):
- return reverse('combo-manager-page-view', kwargs={'pk': self.object.gallery.page.id})
+ return reverse('combo-manager-page-view',
+ kwargs={'pk': self.object.gallery.page.id}) + '#cell-' + self.object.gallery.get_reference()
image_add = ImageAddView.as_view()
@@ -48,7 +49,8 @@ class ImageEditView(UpdateView):
form_class = ImageEditForm
def get_success_url(self):
- return reverse('combo-manager-page-view', kwargs={'pk': self.object.gallery.page.id})
+ return reverse('combo-manager-page-view',
+ kwargs={'pk': self.object.gallery.page.id}) + '#cell-' + self.object.gallery.get_reference()
image_edit = ImageEditView.as_view()
diff --git a/combo/manager/static/js/combo.manager.js b/combo/manager/static/js/combo.manager.js
index cdaaeb9..f074e8d 100644
--- a/combo/manager/static/js/combo.manager.js
+++ b/combo/manager/static/js/combo.manager.js
@@ -269,9 +269,12 @@ $(function() {
});
$('div.cell').each(function(i, x) {
- $(this).attr('id', 'div-cell-'+i);
compute_max_height($(this));
- $(this).addClass('untoggled');
+ if (window.location.hash == '#' + $(this).attr('id')) {
+ $(this).addClass('toggled');
+ } else {
+ $(this).addClass('untoggled');
+ }
});
$('#assets-browser table tr').on('hover mouseenter', function() {
var $img = $(this).find('img');
diff --git a/combo/manager/templates/combo/page_view.html b/combo/manager/templates/combo/page_view.html
index 7f430eb..ec3585f 100644
--- a/combo/manager/templates/combo/page_view.html
+++ b/combo/manager/templates/combo/page_view.html
@@ -95,7 +95,7 @@
<h2>{{ placeholder.name }}</h2>
<div class="cell-list">
{% for cell in placeholder.cells %}
- <div class="cell {{cell.class_name}}" data-cell-reference="{{ cell.get_reference }}">
+ <div id="cell-{{cell.get_reference}}" class="cell {{cell.class_name}}" data-cell-reference="{{ cell.get_reference }}">
<h3><span class="handle">⣿</span>
<span class="group1">
{{ cell.get_label }}
diff --git a/combo/manager/views.py b/combo/manager/views.py
index cca2a79..04dfae4 100644
--- a/combo/manager/views.py
+++ b/combo/manager/views.py
@@ -346,7 +346,7 @@ class PageAddCellView(RedirectView):
cell.order = 1
cell.save()
PageSnapshot.take(cell.page, request=self.request, comment=_('added cell "%s"') % cell)
- return reverse('combo-manager-page-view', kwargs={'pk': page_pk})
+ return reverse('combo-manager-page-view', kwargs={'pk': page_pk}) + '#cell-' + cell.get_reference()
page_add_cell = PageAddCellView.as_view()
@@ -375,7 +375,8 @@ class PageEditCellView(UpdateView):
return self.object.get_default_form_class()
def get_success_url(self):
- return reverse('combo-manager-page-view', kwargs={'pk': self.kwargs.get('page_pk')})
+ return reverse('combo-manager-page-view', kwargs={'pk': self.kwargs.get('page_pk')}
+ ) + '#cell-' + self.object.get_reference()
def form_valid(self, form):
if self.request.is_ajax():
diff --git a/tests/test_manager.py b/tests/test_manager.py
index 8392f42..8aafd61 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -342,18 +342,18 @@ def test_add_edit_cell(app, admin_user):
resp = app.get('/manage/pages/%s/' % page.id)
# click on first option link, this should add a text cell
resp = app.get(resp.html.find('option').get('data-add-url'))
- assert resp.location.endswith('/manage/pages/1/')
cells = CellBase.get_cells(page_id=page.id)
assert len(cells) == 1
assert isinstance(cells[0], TextCell)
+ assert resp.location.endswith('/manage/pages/1/#cell-%s' % cells[0].get_reference())
resp = app.get('/manage/pages/%s/' % page.id)
assert ('data-cell-reference="%s"' % cells[0].get_reference()) in resp.text
resp.forms[0]['c%s-text' % cells[0].get_reference()].value = 'Hello world'
resp = resp.forms[0].submit()
assert resp.status_int == 302
- assert resp.location.endswith('/manage/pages/1/')
+ assert resp.location.endswith('/manage/pages/1/#cell-%s' % cells[0].get_reference())
resp = app.get('/manage/pages/%s/' % page.id)
assert resp.forms[0]['c%s-text' % cells[0].get_reference()].value == 'Hello world'
@@ -557,11 +557,11 @@ def test_edit_text_cell(app, admin_user):
resp = app.get('/manage/pages/%s/' % page.id)
data_add_url = [x for x in resp.html.find_all('option') if x.text == 'Text'][0].get('data-add-url')
resp = app.get(data_add_url)
- assert resp.location.endswith('/manage/pages/%s/' % page.id)
cells = CellBase.get_cells(page_id=page.id)
assert len(cells) == 1
assert isinstance(cells[0], TextCell)
+ assert resp.location.endswith('/manage/pages/%s/#cell-%s' % (page.id, cells[0].get_reference()))
resp = app.get('/manage/pages/%s/' % page.id)
resp.form['cdata_textcell-%s-text' % cells[0].id].value = 'Hello : World'
@@ -594,12 +594,12 @@ def test_edit_config_json_cell(app, admin_user):
assert 'Foobar' in options
data_add_url = [x for x in resp.html.find_all('option') if x.text == 'Foobar'][0].get('data-add-url')
resp = app.get(data_add_url)
- assert resp.location.endswith('/manage/pages/%s/' % page.id)
cells = CellBase.get_cells(page_id=page.id)
assert len(cells) == 1
assert isinstance(cells[0], ConfigJsonCell)
assert cells[0].key == 'test-config-json-cell'
+ assert resp.location.endswith('/manage/pages/%s/#cell-%s' % (page.id, cells[0].get_reference()))
resp = app.get('/manage/pages/%s/' % page.id)
assert ('data-cell-reference="%s"' % cells[0].get_reference()) in resp.text
@@ -641,7 +641,7 @@ def test_edit_config_json_cell(app, admin_user):
resp.form['c%s-test3' % cells[0].get_reference()].value = 'Hello again'
resp = resp.form.submit()
assert resp.status_int == 302
- assert resp.location.endswith('/manage/pages/%s/' % page.id)
+ assert resp.location.endswith('/manage/pages/%s/#cell-%s' % (page.id, cells[0].get_reference()))
resp = app.get('/manage/pages/%s/' % page.id)
assert resp.form['c%s-test' % cells[0].get_reference()].value == 'Hello world'