Commit 92a20bd7 authored by Paul Brown's avatar Paul Brown

combine mkdir, edit, rename, and upload templates + separate modal templates

parent 4c0bf96c
...@@ -103,21 +103,41 @@ class FileAdmin(BaseView, ActionsMixin): ...@@ -103,21 +103,41 @@ class FileAdmin(BaseView, ActionsMixin):
File upload template File upload template
""" """
upload_modal_template = 'admin/file/modals/form.html'
"""
File upload template for modal dialog
"""
mkdir_template = 'admin/file/form.html' mkdir_template = 'admin/file/form.html'
""" """
Directory creation (mkdir) template Directory creation (mkdir) template
""" """
rename_template = 'admin/file/rename.html' mkdir_modal_template = 'admin/file/modals/form.html'
"""
Directory creation (mkdir) template for modal dialog
"""
rename_template = 'admin/file/form.html'
""" """
Rename template Rename template
""" """
edit_template = 'admin/file/edit.html' rename_modal_template = 'admin/file/modals/form.html'
"""
Rename template for modal dialog
"""
edit_template = 'admin/file/form.html'
""" """
Edit template Edit template
""" """
edit_modal_template = 'admin/file/modals/form.html'
"""
Edit template for modal dialog
"""
form_base_class = form.BaseForm form_base_class = form.BaseForm
""" """
Base form class. Will be used to create the upload, rename, edit, and delete form. Base form class. Will be used to create the upload, rename, edit, and delete form.
...@@ -660,7 +680,12 @@ class FileAdmin(BaseView, ActionsMixin): ...@@ -660,7 +680,12 @@ class FileAdmin(BaseView, ActionsMixin):
except Exception as ex: except Exception as ex:
flash(gettext('Failed to save file: %(error)s', error=ex), 'error') flash(gettext('Failed to save file: %(error)s', error=ex), 'error')
return self.render(self.upload_template, form=form, if self.upload_modal and request.args.get('modal'):
template = self.upload_modal_template
else:
template = self.upload_template
return self.render(template, form=form,
header_text=gettext('Upload File'), header_text=gettext('Upload File'),
modal=request.args.get('modal')) modal=request.args.get('modal'))
...@@ -721,9 +746,13 @@ class FileAdmin(BaseView, ActionsMixin): ...@@ -721,9 +746,13 @@ class FileAdmin(BaseView, ActionsMixin):
else: else:
helpers.flash_errors(form, message='Failed to create directory: %(error)s') helpers.flash_errors(form, message='Failed to create directory: %(error)s')
return self.render(self.mkdir_template, form=form, dir_url=dir_url, if self.mkdir_modal and request.args.get('modal'):
header_text=gettext('Create Directory'), template = self.mkdir_modal_template
modal=request.args.get('modal')) else:
template = self.mkdir_template
return self.render(template, form=form, dir_url=dir_url,
header_text=gettext('Create Directory'))
@expose('/delete/', methods=('POST',)) @expose('/delete/', methods=('POST',))
def delete(self): def delete(self):
...@@ -817,12 +846,15 @@ class FileAdmin(BaseView, ActionsMixin): ...@@ -817,12 +846,15 @@ class FileAdmin(BaseView, ActionsMixin):
else: else:
helpers.flash_errors(form, message='Failed to rename: %(error)s') helpers.flash_errors(form, message='Failed to rename: %(error)s')
return self.render(self.rename_template, if self.rename_modal and request.args.get('modal'):
form=form, template = self.rename_modal_template
path=op.dirname(path), else:
name=op.basename(path), template = self.rename_template
dir_url=return_url,
modal=request.args.get('modal')) return self.render(template, form=form, path=op.dirname(path),
name=op.basename(path), dir_url=return_url,
header_text=gettext('Rename %(name)s',
name=op.basename(path)))
@expose('/edit/', methods=('GET', 'POST')) @expose('/edit/', methods=('GET', 'POST'))
def edit(self): def edit(self):
...@@ -889,9 +921,17 @@ class FileAdmin(BaseView, ActionsMixin): ...@@ -889,9 +921,17 @@ class FileAdmin(BaseView, ActionsMixin):
else: else:
form.content.data = content form.content.data = content
return self.render(self.edit_template, dir_url=dir_url, path=path, if error:
return redirect(next_url)
if self.edit_modal and request.args.get('modal'):
template = self.edit_modal_template
else:
template = self.edit_template
return self.render(template, dir_url=dir_url, path=path,
form=form, error=error, form=form, error=error,
modal=request.args.get('modal')) header_text=gettext('Editing %(path)s', path=path))
@expose('/action/', methods=('POST',)) @expose('/action/', methods=('POST',))
def action_view(self): def action_view(self):
......
{%- if not modal -%}
{% extends 'admin/master.html' %}
{%- endif -%}
{% import 'admin/lib.html' as lib with context %}
{% macro check_error(error) %}
{% if error %}
<span>{{ _gettext('This file cannot be edited for now.') }}</span>
{% else %}
{{ caller() }}
{% endif %}
{% endmacro %}
{% block body %}
{% call check_error(error) %}
{%- if modal -%}
{# content added to modal-content #}
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
{%- else -%}
{% block header_text -%}
<h3>{{ _gettext('Editing %(path)s', path=path) }}<h3>
{%- endblock %}
{{ lib.render_form(form, dir_url) }}
{%- endif -%}
{% endcall %}
{% endblock %}
{% block tail %}
{%- if modal -%}
<script>
// fill the header of modal dynamically
$('.modal-header h3').html('{{ self.header_text() }}');
// fixes "remote modal shows same content every time"
$('.modal').on('hidden', function() {
$(this).removeData('modal');
});
</script>
{%- endif -%}
{% endblock %}
{%- if not modal -%} {% extends 'admin/master.html' %}
{% extends 'admin/master.html' %}
{%- endif -%}
{% import 'admin/lib.html' as lib with context %} {% import 'admin/lib.html' as lib with context %}
{% block body %} {% block body %}
{%- if modal -%} {% block header %}<h3>{{ header_text }}</h3>{% endblock %}
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }} {{ lib.render_form(form, dir_url) }}
{%- else -%}
<h3>{{ header_text }}</h3>
{{ lib.render_form(form, dir_url) }}
{%- endif -%}
{% endblock %}
{% block tail %}
{%- if modal -%}
<script>
// fill the header of modal dynamically
$('.modal-header h3').html('{{ header_text }}');
// fixes "remote modal shows same content every time"
$('.modal').on('hidden', function() {
$(this).removeData('modal');
});
</script>
{%- endif -%}
{% endblock %} {% endblock %}
{% import 'admin/static.html' as admin_static with context %}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
{# content added to modal-content #}
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
{% endblock %}
{% block tail %}
<script src="{{ admin_static.url(filename='admin/js/bs2_modal.js', v='1.0.0') }}"></script>
<script>
// fill the header of modal dynamically
$('.modal-header h3').html('{% block header %}{{ header_text }}{% endblock %}');
</script>
{% endblock %}
{%- if not modal -%}
{% extends 'admin/master.html' %}
{%- endif -%}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
{%- if modal -%}
{# content added to modal-content #}
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
{%- else -%}
<h3>{% block header_text -%}
{{ _gettext('Rename %(name)s', name=name) }}
{%- endblock %}</h3>
{{ lib.render_form(form, dir_url) }}
{%- endif -%}
{% endblock %}
{% block tail %}
{%- if modal -%}
<script>
// fill the header of modal dynamically
$('.modal-header h3').html('{{ self.header_text() }}');
// fixes "remote modal shows same content every time"
$('.modal').on('hidden', function() {
$(this).removeData('modal');
});
</script>
{%- endif -%}
{% endblock %}
{%- if not modal -%}
{% extends 'admin/master.html' %}
{%- endif -%}
{% import 'admin/lib.html' as lib with context %}
{% macro check_error(error) %}
{% if error %}
<span>{{ _gettext('This file cannot be edited for now.') }}</span>
{% else %}
{{ caller() }}
{% endif %}
{% endmacro %}
{% block body %}
{%- if modal -%}
{# content added to modal-content #}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
{% block header_text %}
<h3>{{ _gettext('Editing %(path)s', path=path) }}</h3>
{% endblock %}
</div>
<div class="modal-body">
{% call check_error(error) %}
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
{% endcall %}
</div>
{%- else -%}
{{ self.header_text() }}
{% call check_error(error) %}
{{ lib.render_form(form, dir_url) }}
{% endcall %}
{%- endif -%}
{% endblock %}
{% block tail %}
{%- if modal -%}
<script>
// fixes "remote modal shows same content every time", avoiding the flicker
$('body').on('hidden.bs.modal', '.modal', function() {
$(this).removeData('bs.modal').find(".modal-content").empty();
});
</script>
{%- endif -%}
{% endblock %}
{%- if not modal -%} {% extends 'admin/master.html' %}
{% extends 'admin/master.html' %}
{%- endif -%}
{% import 'admin/lib.html' as lib with context %} {% import 'admin/lib.html' as lib with context %}
{% block body %} {% block body %}
{%- if modal -%} {% block header %}<h3>{{ header_text }}</h3>{% endblock %}
{# content added to modal-content #} {{ lib.render_form(form, dir_url) }}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h3>{{ header_text }}</h3>
</div>
<div class="modal-body">
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
</div>
{%- else -%}
<h3>{{ header_text }}</h3>
{{ lib.render_form(form, dir_url) }}
{%- endif -%}
{% endblock %}
{% block tail %}
{%- if modal -%}
<script>
// fixes "remote modal shows same content every time", avoiding the flicker
$('body').on('hidden.bs.modal', '.modal', function() {
$(this).removeData('bs.modal').find(".modal-content").empty();
});
</script>
{%- endif -%}
{% endblock %} {% endblock %}
{% import 'admin/static.html' as admin_static with context %}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
{# content added to modal-content #}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
{% block header %}<h3>{{ header_text }}</h3>{% endblock %}
</div>
<div class="modal-body">
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
</div>
{% endblock %}
{% block tail %}
<script src="{{ admin_static.url(filename='admin/js/bs3_modal.js', v='1.0.0') }}"></script>
{% endblock %}
{%- if not modal -%}
{% extends 'admin/master.html' %}
{%- endif -%}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
{%- if modal -%}
{# content added to modal-content #}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
{% block header_text %}
<h3>{{ _gettext('Rename %(name)s', name=name) }}</h3>
{% endblock %}
</div>
<div class="modal-body">
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
</div>
{%- else -%}
<h3>{{ self.header_text() }}</h3>
{{ lib.render_form(form, dir_url) }}
{%- endif -%}
{% endblock %}
{% block tail %}
{%- if modal -%}
<script>
// fixes "remote modal shows same content every time", avoiding the flicker
$('body').on('hidden.bs.modal', '.modal', function() {
$(this).removeData('bs.modal').find(".modal-content").empty();
});
</script>
{%- endif -%}
{% endblock %}
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