Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0] web_multi_attachment_base #1095

Draft
wants to merge 2 commits into
base: 12.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web_multi_attachment_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
"post_init_hook": None,
"uninstall_hook": None,
"auto_install": False,
"installable": False,
"installable": True,
}
28 changes: 14 additions & 14 deletions web_multi_attachment_base/static/src/js/kanban_view.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Copyright 2018 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>
Copyright 2018 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
License MIT (https://opensource.org/licenses/MIT).*/
odoo.define("kanban_view", function(require) {
odoo.define("kanban_view", function (require) {
"use strict";

var core = require("web.core");
Expand All @@ -13,7 +13,7 @@ odoo.define("kanban_view", function(require) {
var FieldMultiFiles = AbstractField.extend({
template: "FieldBinaryFileUploader",
supportedFieldTypes: ["many2many", "one2many"],
init: function() {
init: function () {
this._super.apply(this, arguments);

if (!_.contains(this.supportedFieldTypes, this.field.type)) {
Expand All @@ -27,17 +27,17 @@ odoo.define("kanban_view", function(require) {
this.uploadingFiles = [];
},

destroy: function() {
destroy: function () {
this._super();
$(window).off(this.fileupload_id);
},

_onFileLoaded: function(ev, files, rec) {
_onFileLoaded: function (ev, files, rec) {
var self = this;
this.uploadingFiles = [];

var attachment_ids = this.value.res_ids;
_.each(files, function(file) {
_.each(files, function (file) {
if (file.error) {
self.do_warn(_t("Uploading Error"), file.error);
} else {
Expand All @@ -55,7 +55,7 @@ odoo.define("kanban_view", function(require) {
});

relational_fields.FieldOne2Many.include({
_renderButtons: function() {
_renderButtons: function () {
var self = this;
this._super();
var multy_attach =
Expand Down Expand Up @@ -83,19 +83,19 @@ odoo.define("kanban_view", function(require) {

// Show image attachment button
multy_attach.parent().attr("style", "display: inline-block;");
multy_attach.on("change", function(event) {
self.import_files(event).then(function(res) {
multy_attach.on("change", function (event) {
self.import_files(event).then(function (res) {
mf_widget._onFileLoaded(event, self.updated_files, self);
});
});
}
},

import_files: function(event) {
import_files: function (event) {
var self = this;
this.updated_files = [];

var deferred_cycle = function(files) {
var deferred_cycle = function (files) {
var file = files.shift();
var done = $.Deferred();
var check = typeof file === "object";
Expand All @@ -106,15 +106,15 @@ odoo.define("kanban_view", function(require) {
var reader = new FileReader();
var def = $.Deferred();
// Read in the image file as a data URL.
reader.onloadend = function(theFile) {
reader.onloadend = function (theFile) {
var data = theFile.target.result;
file.image = data.split(",")[1];
file.res_id = self.drop_att.res_id;
def.resolve();
};
reader.readAsDataURL(file);

def.then(function() {
def.then(function () {
var arg = {
name: file.name,
image: file.image,
Expand All @@ -124,10 +124,10 @@ odoo.define("kanban_view", function(require) {
model: self.drop_att.model,
method: "create",
args: [arg],
}).then(function(res) {
}).then(function (res) {
self.updated_files.push(_.extend(file, {id: res}));
if (files.length) {
deferred_cycle(files).then(function() {
deferred_cycle(files).then(function () {
done.resolve();
});
} else {
Expand Down
3 changes: 2 additions & 1 deletion web_multi_attachment_base/static/src/xml/web_kanban.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
class="btn btn-default btn-sm custom-file-upload"
style="display: none;"
>
<i class="fa fa-cloud-upload" /> Select Images
<i class="fa fa-cloud-upload" />
Select Images
<input
id="file-upload"
type="file"
Expand Down