Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Resize client upload web/static/src /js/fields/relational_fields.js (Odoo 11)

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
3550 Vues
Avatar
Edwin valdez

Hi, modifying the web base file web/static/src /js/fields/relational_fields.js
I am resizing the images on the client side using the many2many_binary widget managed to modify it but it has problems since when it selected 10 images for example it only shows me 8 images that were uploaded to the analysis in the console it shows me that 10 images were loaded but it shows less I think it is not possible to climb due to lack of time I hope you can help me thanks.

_onFileChanged: function (ev) {
var self = this;
var files = ev.target.files;
var attachment_ids = this.value.res_ids;


// Don't create an attachment if the upload window is cancelled.
if(files.length === 0)
return;

var dataurl=null;
var filesnew=[];
var filesname=[];
var finaliza=false;
var conteo=0;
_.each(files, function (file) {

var record = _.find(self.value.data, function (attachment) {
return attachment.data.name === file.name;
});
if (record) {
var metadata = self.metadata[record.id];
if (!metadata || metadata.allowUnlink) {
// there is a existing attachment with the same name so we
// replace it
attachment_ids = _.without(attachment_ids, record.res_id);
self._rpc({
model: 'ir.attachment',
method: 'unlink',
args: [record.res_id],
});
}
}
if (file.type.match('image.*')) {
var MAX_WIDTH = 800;
var MAX_HEIGHT = 600;
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(e) {
var img = new Image();

img.src = e.target.result;
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
img.onload = function(){
var height = img.height;
var width = img.width;
ctx.drawImage(img, 0, 0);

if (width > MAX_WIDTH || height> MAX_HEIGHT ) {
if (width > MAX_WIDTH) {
var scaleFactor = MAX_WIDTH / width;
width = MAX_WIDTH;
height = height * scaleFactor;

} else if (height > MAX_HEIGHT) {
var scaleFactor = MAX_HEIGHT / height;
height = MAX_HEIGHT;
width = width * scaleFactor;

}
canvas.width = width;
canvas.height = height;
ctx.drawImage(img, 0, 0, width, height);


}
dataurl = canvas.toDataURL(file.type);
console.log("cantidad archivos");
console.log(files.length);
file.src = dataurl;
filesnew.push(dataurl);
filesname.push(file.name);

conteo++;

if(files.length == conteo){
finaliza=true;

}


};//fin onload image
};//fin onload reader
} else { //onload image type
conteo++;
}
self.uploadingFiles.push(file);
});
this._setValue({
operation: 'REPLACE_WITH',
ids: attachment_ids,
});


var thiss=this;
var interv = setInterval(function(){
console.log(finaliza);
console.log("SET INTERVAL");
if(finaliza){
console.log(files.length);
for(var i=0;i<filesnew.length;i++){
console.log(filesnew.src);
console.log("llama a upload");
uploadFile(filesnew[i],thiss.fileupload_id,thiss.model,filesname[i]);
}
finaliza=false;
console.log("FINALIZA");
thiss.$('.oe_fileupload').hide();
ev.target.value = "";
clearInterval(interv);
}
},3000);

function uploadFile (imagen,fileupload_id,model,name) {
console.log("ENTRA A UPLOAD");
var nombreIframe=fileupload_id;
fetch(imagen).then(res => res.blob()).then(blob => {

var xhr = new XMLHttpRequest();
xhr.open('POST', '/web/binary/upload_attachment', true);

// define new form
var formData = new FormData();
formData.append('ufile', blob,name);
formData.append('csrf_token', core.csrf_token);
formData.append('callback',nombreIframe);
formData.append('model',model);
formData.append('id','0');
// action after uploading happens
xhr.onload = function(e) {
console.log("File uploading completed! ");

var regex = new RegExp("\"", "g");
var textojavascript=(xhr.responseText.toString().replace(regex,"'").replace("<script language='javascript' type='text/javascript'>",'').replace('</script>',''));
var html = '<html><head></head><body></body></html>';


var eScript = document.createElement("script");
var script = document.createTextNode(textojavascript);
eScript.appendChild(script);

var eHead = document.createElement("head");
eHead.appendChild(eScript);


var iframe=document.getElementById(nombreIframe);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(html);
iframe.contentWindow.document.close();
//document.body.appendChild(iframe);

//document.getElementById("oe_fileupload_temp43").contentWindow.document.write(eHead);
var doc = iframe.contentWindow.document.head;
doc.append(eHead);
//document.getElementById("oe_fileupload_temp43")=eIframe;
};
// do the uploading
xhr.send(formData);
xhr.onreadystatechange = (e) => {

}
});
}



0
Avatar
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now