pengyuthon
This commit is contained in:
@@ -67,3 +67,8 @@ class preview(http.Controller):
|
||||
# http://view.officeapps.live.com/op/view.aspx?src=https%3A%2F%2Fj2762p6576.vicp.fun%2Fpreview_easy%2Fstatic%2Fdescription%2F123.xlsx
|
||||
# http://view.officeapps.live.com/op/view.aspx?src=https%3A%2F%2Fj2762p6576.vicp.fun%2Fweb%2Fcontent%2Foffice_preview%2F863
|
||||
return werkzeug.wrappers.Response(attach.raw, status=200, headers=headers)
|
||||
|
||||
@http.route('/web/document_module/installed', type='json', method=['POST'], auth='none')
|
||||
def document_module_installed(self):
|
||||
document_module = request.env['ir.module.module'].sudo().search([('name', '=', 'documents')])
|
||||
return {'installed': document_module and document_module.state == 'installed'}
|
||||
|
||||
@@ -36,6 +36,9 @@ export class Many2ManyBinaryField extends Many2ManyTagsField {
|
||||
nameCreateField: { type: String, optional: true },
|
||||
string: { type: String, optional: true },
|
||||
noSearchMore: { type: Boolean, optional: true },
|
||||
showSelectBtn: { type: Boolean, optional: true },
|
||||
previewType: { type: String, optional: true },
|
||||
previewString: { type: String, optional: true },
|
||||
};
|
||||
|
||||
setup() {
|
||||
@@ -106,16 +109,10 @@ export class Many2ManyBinaryField extends Many2ManyTagsField {
|
||||
}
|
||||
|
||||
preview_Obj(id, name) {
|
||||
|
||||
|
||||
var winStr = 'height=600,width=1000,top=' + (screen.height - 600) / 2 + ',left=' + (screen.width - 1000) / 2 + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,location=no';
|
||||
var newWin = window.open('/web/content/preview/'+ id , name, winStr);
|
||||
newWin.focus();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
var winStr = 'height=600,width=1000,top=' + (screen.height - 600) / 2 + ',left=' + (screen.width - 1000) / 2 + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,location=no';
|
||||
var newWin = window.open('/web/content/preview/'+ id , name, winStr);
|
||||
newWin.focus();
|
||||
}
|
||||
|
||||
getExtension(file) {
|
||||
return file.name.replace(/^.*\./, "");
|
||||
@@ -167,6 +164,21 @@ export class Many2ManyBinaryField extends Many2ManyTagsField {
|
||||
title,
|
||||
});
|
||||
}
|
||||
get documentsInstalled() {
|
||||
try {
|
||||
const result = $.ajax({
|
||||
url: "/web/document_module/installed",
|
||||
type: "POST",
|
||||
async: false, // 设置为 false 表示同步请求
|
||||
contentType: "application/json",
|
||||
data: "{}"
|
||||
});
|
||||
return result?.responseJSON?.result?.installed;
|
||||
} catch (error) {
|
||||
console.error('Error fetching document installed status:', error);
|
||||
return false; // 或者其他默认值
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const many2ManyBinaryField = {
|
||||
@@ -186,6 +198,9 @@ export const many2ManyBinaryField = {
|
||||
],
|
||||
extractProps: ({ attrs, options }) => ({
|
||||
acceptedFileExtensions: options.accepted_file_extensions,
|
||||
showSelectBtn: options.show_select_btn === undefined ? true : options.show_select_btn,
|
||||
previewType: options.preview_type,
|
||||
previewString: options.preview_string,
|
||||
className: attrs.class,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
</t>
|
||||
</xpath>
|
||||
<xpath expr="//div[hasclass('oe_add')]" position="inside">
|
||||
<button class="btn btn-secondary o_attach" t-on-click="onExternalBtnClick" data-tooltip="Attach">
|
||||
选择文档
|
||||
<button t-if="documentsInstalled and props.showSelectBtn" class="btn btn-secondary o_attach" t-on-click="onExternalBtnClick" data-tooltip="Attach">
|
||||
<i class="fa fa-folder-open-o"/>
|
||||
选择文件
|
||||
<!-- <Many2XAutocomplete -->
|
||||
<!-- id="props.id" -->
|
||||
<!-- resModel="relation" -->
|
||||
@@ -28,30 +29,37 @@
|
||||
</t>
|
||||
<t t-name="Many2ManyBinaryField.attachment_preview1" owl="1">
|
||||
<t t-set="editable" t-value="!props.readonly"/>
|
||||
<div t-attf-class="o_attachment o_attachment_many2many #{ editable ? 'o_attachment_editable' : '' } #{upload ? 'o_attachment_uploading' : ''}" t-att-title="file.name">
|
||||
<div class="o_attachment_wrap">
|
||||
<t t-set="ext" t-value="getExtension(file)"/>
|
||||
<t t-set="url" t-value="getUrl(file.id)"/>
|
||||
<div class="o_image_box float-start" t-att-data-tooltip="'Preview ' + file.name">
|
||||
|
||||
<span class="o_image o_hover" t-on-click.stop="() => this.preview_Obj(file.id,file.name)" t-att-data-mimetype="file.mimetype" t-att-data-ext="ext" role="img"/>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="caption">
|
||||
<a class="ml4" t-att-data-tooltip="'Download ' + file.name" t-att-href="getUrl(file.id)"><t t-esc='file.name'/></a>
|
||||
</div>
|
||||
<div class="caption small">
|
||||
<a class="ml4 small text-uppercase" t-att-href="getUrl(file.id)"><b><t t-esc='ext'/></b></a>
|
||||
<div t-if="editable" class="progress o_attachment_progress_bar">
|
||||
<div class="progress-bar progress-bar-striped active" style="width: 100%">Uploading</div>
|
||||
<t t-if="props.previewType and props.previewType === 'button'">
|
||||
<button class="btn btn-secondary o_attach" t-on-click.stop="() => this.preview_Obj(file.id,file.name)" data-tooltip="Attach">
|
||||
<i class="fa fa-eye"/>
|
||||
<span t-if="props.previewString" t-out="props.previewString"/>
|
||||
<span t-else="" t-out="'预览文件'"/>
|
||||
</button>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<div t-attf-class="o_attachment o_attachment_many2many #{ editable ? 'o_attachment_editable' : '' } #{upload ? 'o_attachment_uploading' : ''}" t-att-title="file.name">
|
||||
<div class="o_attachment_wrap">
|
||||
<t t-set="ext" t-value="getExtension(file)"/>
|
||||
<t t-set="url" t-value="getUrl(file.id)"/>
|
||||
<div class="o_image_box float-start" t-att-data-tooltip="'Preview ' + file.name">
|
||||
<span class="o_image o_hover" t-on-click.stop="() => this.preview_Obj(file.id,file.name)" t-att-data-mimetype="file.mimetype" t-att-data-ext="ext" role="img"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="o_attachment_uploaded"><i class="text-success fa fa-check" role="img" aria-label="Uploaded" title="Uploaded"/></div>
|
||||
<div t-if="editable" class="o_attachment_delete" t-on-click.stop="() => this.onFileRemove(file.id)"><span class="text-white" role="img" aria-label="Delete" title="Delete">×</span></div>
|
||||
<div class="caption">
|
||||
<a class="ml4" t-att-data-tooltip="'Download ' + file.name" t-att-href="getUrl(file.id)"><t t-esc='file.name'/></a>
|
||||
</div>
|
||||
<div class="caption small">
|
||||
<a class="ml4 small text-uppercase" t-att-href="getUrl(file.id)"><b><t t-esc='ext'/></b></a>
|
||||
<div t-if="editable" class="progress o_attachment_progress_bar">
|
||||
<div class="progress-bar progress-bar-striped active" style="width: 100%">Uploading</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="o_attachment_uploaded"><i class="text-success fa fa-check" role="img" aria-label="Uploaded" title="Uploaded"/></div>
|
||||
<div t-if="editable" class="o_attachment_delete" t-on-click.stop="() => this.onFileRemove(file.id)"><span class="text-white" role="img" aria-label="Delete" title="Delete">×</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
|
||||
Reference in New Issue
Block a user