From 0867342fc91fa1f203e6cbb4a18a574e6d942646 Mon Sep 17 00:00:00 2001 From: Siddharth Bhalgami Date: Wed, 3 Jul 2019 11:11:04 +0800 Subject: [PATCH] [11.0][MIG] web_widget_image_webcam: code migration --- web_widget_image_webcam/README.rst | 2 +- web_widget_image_webcam/__init__.py | 4 ++ web_widget_image_webcam/__manifest__.py | 7 ++-- web_widget_image_webcam/models/__init__.py | 4 ++ .../models/ir_config_parameter.py | 14 +++++++ .../src/css/web_widget_image_webcam.css | 2 +- .../static/src/js/webcam_widget.js | 37 +++++++++++-------- .../src/xml/web_widget_image_webcam.xml | 2 +- web_widget_image_webcam/views/assets.xml | 2 +- 9 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 web_widget_image_webcam/models/__init__.py create mode 100644 web_widget_image_webcam/models/ir_config_parameter.py diff --git a/web_widget_image_webcam/README.rst b/web_widget_image_webcam/README.rst index f893fef7..3790845c 100644 --- a/web_widget_image_webcam/README.rst +++ b/web_widget_image_webcam/README.rst @@ -39,7 +39,7 @@ Credits Contributors ------------ -* Siddharth Bhalgami +* Siddharth Bhalgami * Kaushal Prajapati Maintainer diff --git a/web_widget_image_webcam/__init__.py b/web_widget_image_webcam/__init__.py index e69de29b..26ecd8a9 100644 --- a/web_widget_image_webcam/__init__.py +++ b/web_widget_image_webcam/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2019 Siddharth Bhalgami +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from . import models diff --git a/web_widget_image_webcam/__manifest__.py b/web_widget_image_webcam/__manifest__.py index 240415d1..31093c54 100644 --- a/web_widget_image_webcam/__manifest__.py +++ b/web_widget_image_webcam/__manifest__.py @@ -1,12 +1,11 @@ -# -*- coding: utf-8 -*- -# Copyright 2016 Siddharth Bhalgami +# Copyright 2016 Siddharth Bhalgami # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). { "name": "Web Widget - Image WebCam", "summary": "Allows to take image with WebCam", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "category": "web", - "website": "https://www.techreceptives.com", + "website": "https://github.com/OCA/web", "author": "Tech Receptives, " "Odoo Community Association (OCA), " "Kaushal Prajapati", diff --git a/web_widget_image_webcam/models/__init__.py b/web_widget_image_webcam/models/__init__.py new file mode 100644 index 00000000..7f5514dd --- /dev/null +++ b/web_widget_image_webcam/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2019 Siddharth Bhalgami +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from . import ir_config_parameter diff --git a/web_widget_image_webcam/models/ir_config_parameter.py b/web_widget_image_webcam/models/ir_config_parameter.py new file mode 100644 index 00000000..5f2be0ee --- /dev/null +++ b/web_widget_image_webcam/models/ir_config_parameter.py @@ -0,0 +1,14 @@ +# Copyright 2019 Siddharth Bhalgami +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo.models import api, Model + + +class IrConfigParameter(Model): + _inherit = "ir.config_parameter" + + @api.model + def get_webcam_flash_fallback_mode_config(self): + return self.sudo().get_param( + 'web_widget_image_webcam.flash_fallback_mode', + default=False) diff --git a/web_widget_image_webcam/static/src/css/web_widget_image_webcam.css b/web_widget_image_webcam/static/src/css/web_widget_image_webcam.css index 5f4ce0be..d631fe18 100644 --- a/web_widget_image_webcam/static/src/css/web_widget_image_webcam.css +++ b/web_widget_image_webcam/static/src/css/web_widget_image_webcam.css @@ -1,5 +1,5 @@ /* - Copyright 2016 Siddharth Bhalgami + Copyright 2016 Siddharth Bhalgami License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */ .o_form_view.o_form_editable .o_form_field_image .o_form_image_controls diff --git a/web_widget_image_webcam/static/src/js/webcam_widget.js b/web_widget_image_webcam/static/src/js/webcam_widget.js index db35c343..0cea5383 100644 --- a/web_widget_image_webcam/static/src/js/webcam_widget.js +++ b/web_widget_image_webcam/static/src/js/webcam_widget.js @@ -1,20 +1,21 @@ /* - Copyright 2016 Siddharth Bhalgami + Copyright 2016 Siddharth Bhalgami License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */ odoo.define('web_widget_image_webcam.webcam_widget', function(require) { "use strict"; var core = require('web.core'); - var Model = require('web.Model'); + var rpc = require('web.rpc'); var Dialog = require('web.Dialog'); + var FieldBinaryImage = require('web.basic_fields').FieldBinaryImage; var _t = core._t; var QWeb = core.qweb; - core.form_widget_registry.get("image").include({ + FieldBinaryImage.include({ - render_value: function () { + _render: function () { this._super(); var self = this, @@ -35,10 +36,10 @@ odoo.define('web_widget_image_webcam.webcam_widget', function(require) { swfURL: '/web_widget_image_webcam/static/src/js/webcam.swf', }); - self.$el.find('.o_form_binary_file_web_cam').removeClass('col-md-offset-5'); - - new Model('ir.config_parameter').call('get_param', ['web_widget_image_webcam.flash_fallback_mode', false]). - then(function(default_flash_fallback_mode) { + rpc.query({ + model: 'ir.config_parameter', + method: 'get_webcam_flash_fallback_mode_config', + }).then(function(default_flash_fallback_mode) { if (default_flash_fallback_mode == 1) { Webcam.set({ /* @@ -52,7 +53,7 @@ odoo.define('web_widget_image_webcam.webcam_widget', function(require) { self.$el.find('.o_form_binary_file_web_cam').off().on('click', function(){ // Init Webcam - new Dialog(self, { + var dialog = new Dialog(self, { size: 'large', dialogClass: 'o_act_window', title: _t("WebCam Booth"), @@ -66,8 +67,10 @@ odoo.define('web_widget_image_webcam.webcam_widget', function(require) { // Display Snap besides Live WebCam Preview WebCamDialog.find("#webcam_result").html(''); }); - // Remove "disabled" attr from "Save & Close" button - $('.save_close_btn').removeAttr('disabled'); + if (Webcam.live) { + // Remove "disabled" attr from "Save & Close" button + $('.save_close_btn').removeAttr('disabled'); + } } }, { @@ -100,13 +103,15 @@ odoo.define('web_widget_image_webcam.webcam_widget', function(require) { ] }).open(); - Webcam.attach('#live_webcam'); + dialog.opened().then(function() { + Webcam.attach('#live_webcam'); - // At time of Init "Save & Close" button is disabled - $('.save_close_btn').attr('disabled', 'disabled'); + // At time of Init "Save & Close" button is disabled + $('.save_close_btn').attr('disabled', 'disabled'); - // Placeholder Image in the div "webcam_result" - WebCamDialog.find("#webcam_result").html(''); + // Placeholder Image in the div "webcam_result" + WebCamDialog.find("#webcam_result").html(''); + }); }); }, }); diff --git a/web_widget_image_webcam/static/src/xml/web_widget_image_webcam.xml b/web_widget_image_webcam/static/src/xml/web_widget_image_webcam.xml index 7360a471..df50df2e 100644 --- a/web_widget_image_webcam/static/src/xml/web_widget_image_webcam.xml +++ b/web_widget_image_webcam/static/src/xml/web_widget_image_webcam.xml @@ -1,5 +1,5 @@ -