Browse Source
Merge pull request #1028 from tomichal/dev
Refactor ‘open-assets’ editor command to permit arbitrary file types
pull/1076/head
Artur Arseniev
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
24 additions and
4 deletions
-
src/asset_manager/model/AssetImage.js
-
src/asset_manager/view/FileUploader.js
-
src/commands/view/OpenAssets.js
-
src/dom_components/view/ComponentImageView.js
|
|
|
@ -7,5 +7,5 @@ module.exports = Asset.extend({ |
|
|
|
unitDim: 'px', |
|
|
|
height: 0, |
|
|
|
width: 0 |
|
|
|
} |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
@ -5,7 +5,7 @@ module.exports = Backbone.View.extend( |
|
|
|
template: _.template(` |
|
|
|
<form> |
|
|
|
<div id="<%= pfx %>title"><%= title %></div> |
|
|
|
<input type="file" id="<%= uploadId %>" name="file" accept="image/*" <%= disabled ? 'disabled' : '' %> multiple/> |
|
|
|
<input type="file" id="<%= uploadId %>" name="file" accept="*/*" <%= disabled ? 'disabled' : '' %> multiple/> |
|
|
|
<div style="clear:both;"></div> |
|
|
|
</form> |
|
|
|
`),
|
|
|
|
|
|
|
|
@ -1,17 +1,35 @@ |
|
|
|
const $ = Backbone.$; |
|
|
|
|
|
|
|
module.exports = { |
|
|
|
run(editor, sender, opts = {}) { |
|
|
|
const modal = editor.Modal; |
|
|
|
const am = editor.AssetManager; |
|
|
|
const config = am.getConfig(); |
|
|
|
const title = opts.modalTitle || config.modalTitle || ''; |
|
|
|
var types = opts.types; |
|
|
|
var accept = opts.accept; |
|
|
|
|
|
|
|
am.setTarget(opts.target); |
|
|
|
am.onClick(opts.onClick); |
|
|
|
am.onDblClick(opts.onDblClick); |
|
|
|
am.onSelect(opts.onSelect); |
|
|
|
|
|
|
|
if (!this.rendered) { |
|
|
|
am.render(am.getAll().filter(asset => asset.get('type') == 'image')); |
|
|
|
if (!this.rendered || types || accept) { |
|
|
|
var $html; |
|
|
|
var assets; |
|
|
|
|
|
|
|
if (types) { |
|
|
|
assets = am.getAll().filter(asset => { |
|
|
|
return types.indexOf(asset.get('type')) != -1 |
|
|
|
}); |
|
|
|
} else { |
|
|
|
assets = am.getAll(); |
|
|
|
} |
|
|
|
|
|
|
|
$html = $(am.render(assets)); |
|
|
|
|
|
|
|
if (accept) $html.find(`input#${config.stylePrefix}uploadFile`).attr('accept', accept); |
|
|
|
|
|
|
|
this.rendered = 1; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -67,6 +67,8 @@ module.exports = ComponentView.extend({ |
|
|
|
if (editor && this.model.get('editable')) { |
|
|
|
editor.runCommand('open-assets', { |
|
|
|
target: this.model, |
|
|
|
types: ['image'], |
|
|
|
accept: 'image/*', |
|
|
|
onSelect() { |
|
|
|
editor.Modal.close(); |
|
|
|
editor.AssetManager.setTarget(null); |
|
|
|
|