İçereği Atla
Menü
Bu soru işaretlendi

Hey there!


I'm trying to develop a module in Odoo 17.

I want to make a snippet for a website page that will allow me to upload .mp4 videos inside the module structure and then play it on page with open-source player.


__manifest.py__ partial code:

    'data': [

        'security/ir.model.access.csv',

        'views/templates.xml',

    ],

    'assets': {

        'web.assets_wysiwyg': [

            'my_module/static/src/js/snippet_options.js',

        ],

    },

    'installable': True,

    'application': True,

templates.xml partial code of a button in snippet options where i'm trying to upload video:

<odoo>

...

    <template id="video_upload_option" inherit_id="website.snippet_options">

        <xpath expr="." position="inside">

            <div class="o_we_option" data-selector=".s_video" data-js="VideoUpload">

                <we-row string="Upload .mp4">

                    <input type="file" id="video_upload" accept="video/mp4"/>

                </we-row>

            </div>

        </xpath>

    </template>

</odoo>

snippet_options.js to receive a video:

/** @odoo-module */


console.log('snippet_options.js loaded');


import options from 'website.snippet_options';


options.registry.VideoUpload = options.Class.extend({

    start: function () {

        console.log('VideoUpload class initialized');

        var self = this;


        // Знаходимо елемент <input type="file">

        var fileInput = this.$target.find('#video_upload');

        if (fileInput.length === 0) {

            console.error('File input not found');

            return;

        }

       

        fileInput.on('change', function (ev) {

            console.log('File input change event triggered');

            self.onUpload(ev);

        });


        return this._super.apply(this, arguments);

    },


    onUpload: function (ev) {

        var self = this;

        var file = ev.target.files[0];

        if (file && file.type === 'video/mp4') {

            console.log('File selected:', file.name);


            var formData = new FormData();

            formData.append('file', file);


            console.log('Sending file to server...');


            // Відправляємо файл на сервер

            $.ajax({

                url: 'my_upload_url',

                type: 'POST',

                data: formData,

                processData: false,

                contentType: false,

                success: function (response) {

                    console.log('File uploaded successfully:', response);

                    var videoUrl = JSON.parse(response).path;

                    self.$target.find('video source').attr('src', videoUrl);

                    self.$target.find('video')[0].load();

                },

                error: function (error) {

                    console.error('Error uploading video:', error);

                }

            });

        } else {

            console.error('Invalid file type. Please upload a .mp4 file.');

        }

    }

});


Module installs and running with no errors. I can drag my snippet to the page, i can go to it's options. The main problem is that a button is visible but nothing happens when i'm choosing a file.

Also there are no messages in dev console so I'm suggesting that JS is not even loading.


Any help will be really nice.


Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Mar 23
2072
5
Oca 22
11568
3
Mar 15
4405
1
Eki 23
1765
0
Ağu 23
2153