Skip to content
Snippets Groups Projects
Commit 1b1732be authored by qmo-odoo's avatar qmo-odoo Committed by jem-odoo
Browse files

[IMP] website_slides: new modal to upload a document

With new slide type, it was required to change the
upload modaL. Now, the use select first the type
of document he wants to upload, then the correct
form appears. When filled, user can sumbit it to
be redirect to the slide he just create.

Task-1938643
parent 0f22f952
No related branches found
No related tags found
No related merge requests found
......@@ -275,8 +275,8 @@ class WebsiteSlides(http.Controller):
return {'error': 'join_done'}
return success
@http.route(['/slides/dialog_preview'], type='json', auth='user', methods=['POST'], website=True)
def dialog_preview(self, **data):
@http.route(['/slides/prepare_preview'], type='json', auth='user', methods=['POST'], website=True)
def prepare_preview(self, **data):
Slide = request.env['slide.slide']
document_type, document_id = Slide._find_document_data_from_url(data['url'])
preview = {}
......@@ -297,13 +297,14 @@ class WebsiteSlides(http.Controller):
def create_slide(self, *args, **post):
# check the size only when we upload a file.
if post.get('datas'):
file_size = len(post['datas']) * 3 / 4 # base64
file_size = len(post['datas']) * 3 / 4 # base64
if (file_size / 1024.0 / 1024.0) > 25:
return {'error': _('File is too big. File size cannot exceed 25MB')}
values = dict((fname, post[fname]) for fname in [
'name', 'url', 'tag_ids', 'slide_type', 'channel_id',
'mime_type', 'datas', 'description', 'image', 'index_content', 'website_published'] if post.get(fname))
if post.get('category_id'):
if post['category_id'][0] == 0:
values['category_id'] = request.env['slide.category'].create({
......@@ -335,7 +336,11 @@ class WebsiteSlides(http.Controller):
except Exception as e:
_logger.error(e)
return {'error': _('Internal server error, please try again later or contact administrator.\nHere is the error message: %s') % e}
return {'url': "/slides/slide/%s" % (slide.id)}
redirect_url = "/slides/slide/%s" % (slide.id)
if slide.slide_type == 'webpage':
redirect_url += "?enable_editor=1"
return {'url': redirect_url}
@http.route(['/slides/channel/tag/search_read'], type='json', auth='user', methods=['POST'], website=True)
def slide_channel_tag_search_read(self, fields, domain):
......
This diff is collapsed.
......@@ -172,3 +172,9 @@ div.embed-responsive {
.oe_show_footer {
z-index: $MAX-Z-INDEX; // Looks terrible but seems necessary due to fullscreen & canvas in PDFSlidesViewer
}
// Upload Modal
.o_wslides_select_type {
cursor: pointer;
}
\ No newline at end of file
<templates id="template" xml:space="preserve">
<t t-name="website.slide.upload">
<div role="dialog" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<header class="modal-header">
<h3 class="modal-title">Upload Presentation</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">×</button>
</header>
<div class="oe_slides_upload_loading text-center" style="display:none" aria-hidden="true" role="status">
<h4><i class='fa fa-spinner fa-spin'></i> Uploading presentation... </h4>
</div>
<main class="modal-body">
<form class="clearfix">
<div class="form-group row">
<div class="col-md-4">
<div class="img-thumbnail">
<div class="o_slide_preview">
<img src="/website_slides/static/src/img/document.png" id="slide-image" title="Content Preview" alt="Content Preview" class="img-fluid"/>
</div>
</div>
</div>
<div class="col-md-8">
<ul class="list-group">
<li class="list-group-item active">
<h5 class="list-group-item-heading">
<label for="upload" class="col-form-label">PDF or Image File</label>
</h5>
<input id="upload" name="file" class="form-control" accept="image/*,application/pdf" type="file"/>
</li>
<li class="list-group-item">
<h5 class="list-group-item-heading">
<label for="url" class="col-form-label">Youtube or Google Doc URL</label>
</h5>
<input id="url" name="url" class="form-control" placeholder="Youtube Video URL"/>
</li>
</ul>
</div>
</div>
<div class="form-group row">
<label for="name" class="col-form-label col-md-2">Title</label>
<div class="col-md-10">
<input id="name" placeholder="Title" class="form-control" required="required"/>
</div>
</div>
<div class="form-group row">
<label for="tag_ids" class="col-form-label col-md-2">Tags</label>
<div class="controls col-md-10">
<input id="tag_ids" type="hidden"/>
</div>
</div>
<div class="form-group row">
<label for="category_id" class="col-form-label col-md-2">Category</label>
<div class="controls col-md-10">
<input id="category_id" type="hidden"/>
</div>
</div>
<div class="form-group row">
<label for="description" class="col-form-label col-md-2">Description</label>
<div class="controls col-md-10">
<textarea id="description" rows="4" placeholder="Description" class="form-control"></textarea>
</div>
</div>
<canvas id="data_canvas" style="display: none;"></canvas>
</form>
</main>
<footer class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Discard</button>
<button type="button" data-loading-text="Loading..." t-if="widget.canUpload &amp;&amp; widget.canPublish" class="btn btn-primary save">Save as Draft</button>
<button type="button" data-loading-text="Loading..." t-if="widget.canUpload &amp;&amp; ! widget.canPublish" class="btn btn-primary save">Submit</button>
<button type="button" data-loading-text="Loading..." t-if="widget.canUpload &amp;&amp; widget.canPublish" data-published="true" class="btn btn-primary save">Publish</button>
</footer>
</div>
</div>
</div>
</t>
<t t-name="website.slide.create">
<form>
<div class="form-group row">
<label class="col-form-label col-md-3" for="slide_channel_id">Channel</label>
<div class="col-md-9">
<select class="form-control" id="slide_channel_id" required="">
<t t-foreach="channels" t-as="channel">
<option t-att-value="channel.website_url"><t t-esc="channel.name"/></option>
</t>
</select>
</div>
</div>
</form>
</t>
</templates>
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="website.slide.upload.modal">
<div>
<div class="o_w_slide_upload_modal_container">
<t t-call="website.slide.upload.modal.select"/>
</div>
</div>
</t>
<!--
Slide Type Selection template
-->
<t t-name="website.slide.upload.modal.select">
<div class="d-flex flex-wrap justify-content-between align-items-stretch text-primary p-1 mt-4">
<t t-foreach="widget.slide_type_data" t-as="slide_type">
<t t-set="type_data" t-value="widget.slide_type_data[slide_type]"/>
<div class="content-type d-flex flex-column align-items-center p-1 mb-4 o_wslides_select_type" t-att-data-slide-type="slide_type">
<i t-attf-class="fa #{type_data['icon']} mb-2" style="font-size:4rem;"></i>
<t t-esc="type_data['label']"/>
</div>
</t>
</div>
</t>
<!--
Uploading template
-->
<t t-name="website.slide.upload.modal.uploading">
<div class="oe_slides_upload_loading text-center" aria-hidden="true" role="status">
<div class="fa-3x">
<i class="fas fa-spinner fa-pulse"></i>
</div>
<h4>Uploading document ...</h4>
</div>
</t>
<!--
Slide Type common form part template
-->
<t t-name="website.slide.upload.modal.common">
<div class="form-group row">
<label for="name" class="col-form-label col-md-2">Title</label>
<div class="col-md-10">
<input id="name" name="name" placeholder="Title" class="form-control" required="required"/>
</div>
</div>
<div class="form-group row">
<label for="category_id" class="col-form-label col-md-2">Category</label>
<div class="controls col-md-10">
<input class="form-control" id="category_id"/>
</div>
</div>
<div class="form-group row">
<label for="tag_ids" class="col-form-label col-md-2">Tags</label>
<div class="controls col-md-10">
<input id="tag_ids" name="tag_ids" type="hidden"/>
</div>
</div>
</t>
<!--
Slide Type templates
-->
<t t-name="website.slide.upload.modal.presentation">
<div>
<form class="clearfix">
<div class="form-group row">
<div class="col-md-4">
<div class="img-thumbnail">
<div class="o_slide_preview">
<img src="/website_slides/static/src/img/document.png" id="slide-image" title="Content Preview" alt="Content Preview" class="img-fluid"/>
</div>
</div>
</div>
<div class="col-md-8">
<ul class="list-group">
<li class="list-group-item">
<h5 class="list-group-item-heading">
<label for="upload" class="col-form-label">PDF or Image File</label>
</h5>
<input id="upload" name="file" class="form-control" accept="image/*,application/pdf" type="file" required="required"/>
<input id="index_content" name="index_content" type="hidden"/>
</li>
</ul>
</div>
</div>
<canvas id="data_canvas" class="d-none"></canvas>
<t t-call="website.slide.upload.modal.common"/>
</form>
</div>
</t>
<t t-name="website.slide.upload.modal.webpage">
<div>
<form class="clearfix">
<t t-call="website.slide.upload.modal.common"/>
</form>
</div>
</t>
<t t-name="website.slide.upload.modal.video">
<div>
<form class="clearfix">
<div class="form-group row">
<div class="col-md-4">
<div class="img-thumbnail">
<div class="o_slide_preview">
<img src="/website_slides/static/src/img/document.png" id="slide-image" title="Content Preview" alt="Content Preview" class="img-fluid"/>
</div>
</div>
</div>
<div class="col-md-8">
<ul class="list-group">
<li class="list-group-item">
<h5 class="list-group-item-heading">
<label for="url" class="col-form-label">Youtube Link</label>
</h5>
<input id="url" name="url" class="form-control" placeholder="Youtube Video URL" required="required"/>
</li>
</ul>
</div>
</div>
<canvas id="data_canvas" class="d-none"></canvas>
<t t-call="website.slide.upload.modal.common"/>
</form>
</div>
</t>
</templates>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment