Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-base
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 4cac02e9
authored
Aug 31, 2023
by
taufikyu
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
update file upload untuk preview
1 parent
8b26ab2b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
opensipkd/base/views/widgets/file_upload.pt
opensipkd/base/views/widgets/file_upload.pt
View file @
4cac02e
<tal:block tal:define="oid oid|field.oid;
<tal:block tal:define="oid oid|field.oid;
css_class css_class|field.widget.css_class;
css_class css_class|field.widget.css_class;
style style|field.widget.style;">
style style|field.widget.style;
preview_url cstruct.get('preview_url')|cstruct.get('base64')|'';
ext str(cstruct.get('filename').split('.')[-1:][0]).lower()|[];">
${field.start_mapping()}
${field.start_mapping()}
<img tal:define="preview_url cstruct.get('preview_url');
<tal:block tal:condition="preview_url and ext in ['jpg','jpeg','png','bmp','gif']">
filename cstruct.get('filename')"
<img id="preview-${oid}" alt="" src="${structure: preview_url}" style="width:100px;height:auto;"></img>
tal:condition="preview_url" src="${structure: preview_url}"
<br>
></img>
</tal:block>
<tal:block tal:condition="not preview_url or ext not in ['jpg','jpeg','png','bmp','gif']">
<img id="preview-${oid}" alt="" src="" style="width:100px;height:auto;"></img>
<br>
</tal:block>
<a id="label-${oid}" tal:condition="preview_url" class="label label-default" href="${structure: preview_url}"
target="_blank"><i class="fa fa-search"></i> View</a>
<input type="file" name="upload" id="${oid}"
<input type="file" name="upload" id="${oid}"
tal:attributes="style style;
tal:attributes="style style;
accept accept|field.widget.accept;
accept accept|field.widget.accept;
...
@@ -19,5 +27,13 @@
...
@@ -19,5 +27,13 @@
deform.addCallback('${oid}', function (oid) {
deform.addCallback('${oid}', function (oid) {
$('#' + oid).upload();
$('#' + oid).upload();
});
});
document.getElementById('${oid}').addEventListener('change', function () {
var output = document.getElementById('preview-${oid}');
output.src = URL.createObjectURL(this.files[0]);
document.getElementById('label-${oid}').remove();
output.onload = function() {
URL.revokeObjectURL(output.src) // free memory
}
});
</script>
</script>
</tal:block>
</tal:block>
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment