import { isString } from 'underscore';
import PropertyView from './PropertyView';
export default class PropertyFileView extends PropertyView {
events() {
return {
...PropertyView.prototype.events(),
'click [data-clear-asset]': 'clear',
'click [data-open-assets]': 'openAssetManager',
};
}
templateInput() {
const { pfx, em } = this;
const icons = this.em?.getConfig().icons;
const iconClose = icons?.close;
return `
`;
}
__setValueInput(value: string) {
const { model, el } = this;
const valueDef = model.getDefaultValue();
const prvBoxEl = el.querySelector('[data-preview-box]') as HTMLElement;
const prvEl = el.querySelector('[data-preview]') as HTMLElement;
prvBoxEl.style.display = !value || value === valueDef ? 'none' : '';
prvEl.style.backgroundImage = value || model.getDefaultValue();
}
openAssetManager() {
const am = this.em?.Assets;
am?.open({
select: (asset, complete) => {
const url = isString(asset) ? asset : asset.get('src');
this.model.upValue(url, { partial: !complete });
complete && am.close();
},
types: ['image'],
accept: 'image/*',
});
}
}