Commit 66874b8d authored by Serge S. Koval's avatar Serge S. Koval

Merge pull request #1046 from pawl/move_file_admin_templates

File-admin - combine mkdir, rename, edit, and upload templates
parents 4c0bf96c 92a20bd7
......@@ -103,21 +103,41 @@ class FileAdmin(BaseView, ActionsMixin):
File upload template
"""
upload_modal_template = 'admin/file/modals/form.html'
"""
File upload template for modal dialog
"""
mkdir_template = 'admin/file/form.html'
"""
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
"""
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_modal_template = 'admin/file/modals/form.html'
"""
Edit template for modal dialog
"""
form_base_class = form.BaseForm
"""
Base form class. Will be used to create the upload, rename, edit, and delete form.
......@@ -660,7 +680,12 @@ class FileAdmin(BaseView, ActionsMixin):
except Exception as ex:
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'),
modal=request.args.get('modal'))
......@@ -721,9 +746,13 @@ class FileAdmin(BaseView, ActionsMixin):
else:
helpers.flash_errors(form, message='Failed to create directory: %(error)s')
return self.render(self.mkdir_template, form=form, dir_url=dir_url,
header_text=gettext('Create Directory'),
modal=request.args.get('modal'))
if self.mkdir_modal and request.args.get('modal'):
template = self.mkdir_modal_template
else:
template = self.mkdir_template
return self.render(template, form=form, dir_url=dir_url,
header_text=gettext('Create Directory'))
@expose('/delete/', methods=('POST',))
def delete(self):
......@@ -817,12 +846,15 @@ class FileAdmin(BaseView, ActionsMixin):
else:
helpers.flash_errors(form, message='Failed to rename: %(error)s')
return self.render(self.rename_template,
form=form,
path=op.dirname(path),
name=op.basename(path),
dir_url=return_url,
modal=request.args.get('modal'))
if self.rename_modal and request.args.get('modal'):
template = self.rename_modal_template
else:
template = self.rename_template
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'))
def edit(self):
......@@ -889,9 +921,17 @@ class FileAdmin(BaseView, ActionsMixin):
else:
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,
modal=request.args.get('modal'))
header_text=gettext('Editing %(path)s', path=path))
@expose('/action/', methods=('POST',))
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' %}
{%- endif -%}
{% extends 'admin/master.html' %}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
{%- if modal -%}
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
{%- 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 -%}
{% block header %}<h3>{{ header_text }}</h3>{% endblock %}
{{ lib.render_form(form, dir_url) }}
{% 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' %}
{%- endif -%}
{% extends 'admin/master.html' %}
{% 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>
<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 -%}
{% block header %}<h3>{{ header_text }}</h3>{% endblock %}
{{ lib.render_form(form, dir_url) }}
{% 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