mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[MIG] Migrated web_widget_image_webcam module from v12 to v13.
This commit is contained in:
committed by
Sylvain LE GAL
parent
9e072f5ddf
commit
4829683f09
@@ -3,17 +3,20 @@
|
||||
Copyright 2019-Today: Druidoo (<https://www.druidoo.io>)
|
||||
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
|
||||
.o_form_binary_file_web_cam {
|
||||
.o_form_view.o_form_editable
|
||||
.o_form_field_image
|
||||
.o_form_image_controls
|
||||
.o_form_binary_file_web_cam {
|
||||
color: inherit;
|
||||
}
|
||||
.o_field_widget.o_field_image .o_form_image_controls > .fa {
|
||||
margin: 3px;
|
||||
}
|
||||
.o_form_view .o_form_field_image .o_form_image_controls > .fa{
|
||||
.o_form_view .o_form_field_image .o_form_image_controls > .fa {
|
||||
margin: 3px;
|
||||
}
|
||||
.live_webcam_outer_div, .webcam_result_outer_div {
|
||||
.live_webcam_outer_div,
|
||||
.webcam_result_outer_div {
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,25 +2,24 @@
|
||||
Copyright 2016 Siddharth Bhalgami <siddharth.bhalgami@gmail.com>
|
||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
|
||||
*/
|
||||
odoo.define('web_widget_image_webcam.webcam_widget', function(require) {
|
||||
odoo.define("web_widget_image_webcam.webcam_widget", function(require) {
|
||||
"use strict";
|
||||
|
||||
var core = require('web.core');
|
||||
var rpc = require('web.rpc');
|
||||
var Dialog = require('web.Dialog');
|
||||
var FieldBinaryImage = require('web.basic_fields').FieldBinaryImage;
|
||||
var core = require("web.core");
|
||||
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;
|
||||
|
||||
FieldBinaryImage.include({
|
||||
|
||||
_render: function () {
|
||||
_render: function() {
|
||||
this._super();
|
||||
|
||||
var self = this,
|
||||
WebCamDialog = $(QWeb.render("WebCamDialog")),
|
||||
img_data;
|
||||
img_data = false;
|
||||
|
||||
// ::webcamjs:: < https://github.com/jhuckaby/webcamjs >
|
||||
// Webcam: Set Custom Parameters
|
||||
@@ -29,16 +28,16 @@ odoo.define('web_widget_image_webcam.webcam_widget', function(require) {
|
||||
height: 240,
|
||||
dest_width: 320,
|
||||
dest_height: 240,
|
||||
image_format: 'jpeg',
|
||||
image_format: "jpeg",
|
||||
jpeg_quality: 90,
|
||||
force_flash: false,
|
||||
fps: 45,
|
||||
swfURL: '/web_widget_image_webcam/static/src/js/webcam.swf',
|
||||
swfURL: "/web_widget_image_webcam/static/src/js/webcam.swf",
|
||||
});
|
||||
|
||||
rpc.query({
|
||||
model: 'ir.config_parameter',
|
||||
method: 'get_webcam_flash_fallback_mode_config',
|
||||
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({
|
||||
@@ -51,34 +50,42 @@ 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
|
||||
var dialog = new Dialog(self, {
|
||||
size: 'large',
|
||||
dialogClass: 'o_act_window',
|
||||
title: _t("WebCam Booth"),
|
||||
$content: WebCamDialog,
|
||||
buttons: [
|
||||
{
|
||||
text: _t("Take Snapshot"), classes: 'btn-primary take_snap_btn',
|
||||
click: function () {
|
||||
Webcam.snap( function(data) {
|
||||
img_data = data;
|
||||
// Display Snap besides Live WebCam Preview
|
||||
WebCamDialog.find("#webcam_result").html('<img src="'+img_data+'"/>');
|
||||
});
|
||||
if (Webcam.live) {
|
||||
// Remove "disabled" attr from "Save & Close" button
|
||||
$('.save_close_btn').removeAttr('disabled');
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
text: _t("Save & Close"), classes: 'btn-primary save_close_btn', close: true,
|
||||
click: function () {
|
||||
var img_data_base64 = img_data.split(',')[1];
|
||||
self.$el
|
||||
.find(".o_form_binary_file_web_cam")
|
||||
.off()
|
||||
.on("click", function() {
|
||||
// Init Webcam
|
||||
var dialog = new Dialog(self, {
|
||||
size: "large",
|
||||
dialogClass: "o_act_window",
|
||||
title: _t("WebCam Booth"),
|
||||
$content: WebCamDialog,
|
||||
buttons: [
|
||||
{
|
||||
text: _t("Take Snapshot"),
|
||||
classes: "btn-primary take_snap_btn",
|
||||
click: function() {
|
||||
Webcam.snap(function(data) {
|
||||
img_data = data;
|
||||
// Display Snap besides Live WebCam Preview
|
||||
WebCamDialog.find("#webcam_result").html(
|
||||
'<img src="' + img_data + '"/>'
|
||||
);
|
||||
});
|
||||
if (Webcam.live) {
|
||||
// Remove "disabled" attr from "Save & Close" button
|
||||
$(".save_close_btn").removeAttr("disabled");
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
text: _t("Save & Close"),
|
||||
classes: "btn-primary save_close_btn",
|
||||
close: true,
|
||||
click: function() {
|
||||
var img_data_base64 = img_data.split(",")[1];
|
||||
|
||||
/*
|
||||
/*
|
||||
Size in base64 is approx 33% overhead the original data size.
|
||||
|
||||
Source: -> http://stackoverflow.com/questions/11402329/base64-encoded-image-size
|
||||
@@ -90,38 +97,48 @@ odoo.define('web_widget_image_webcam.webcam_widget', function(require) {
|
||||
including padding characters. ]
|
||||
*/
|
||||
|
||||
// From the above info, we doing the opposite stuff to find the approx size of Image in bytes.
|
||||
var approx_img_size = 3 * (img_data_base64.length / 4) - (img_data_base64.match(/=+$/g) || []).length; // like... "3[n/4]"
|
||||
// From the above info, we doing the opposite stuff to find the approx size of Image in bytes.
|
||||
var approx_img_size =
|
||||
3 * (img_data_base64.length / 4) -
|
||||
(img_data_base64.match(/[=]+$/g) || []).length;
|
||||
// Like... "3[n/4]"
|
||||
|
||||
// Upload image in Binary Field
|
||||
self.on_file_uploaded(approx_img_size, "web-cam-preview.jpeg", "image/jpeg", img_data_base64);
|
||||
}
|
||||
},
|
||||
{
|
||||
text: _t("Close"), close: true
|
||||
}
|
||||
]
|
||||
}).open();
|
||||
// Upload image in Binary Field
|
||||
self.on_file_uploaded(
|
||||
approx_img_size,
|
||||
"web-cam-preview.jpeg",
|
||||
"image/jpeg",
|
||||
img_data_base64
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
text: _t("Close"),
|
||||
close: true,
|
||||
},
|
||||
],
|
||||
}).open();
|
||||
|
||||
dialog.opened().then(function() {
|
||||
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('<img src="/web_widget_image_webcam/static/src/img/webcam_placeholder.png"/>');
|
||||
// Placeholder Image in the div "webcam_result"
|
||||
WebCamDialog.find("#webcam_result").html(
|
||||
'<img src="/web_widget_image_webcam/static/src/img/webcam_placeholder.png"/>'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Dialog.include({
|
||||
destroy: function () {
|
||||
destroy: function() {
|
||||
// Shut Down the Live Camera Preview | Reset the System
|
||||
Webcam.reset();
|
||||
this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!-- Copyright 2016 Siddharth Bhalgami <siddharth.bhalgami@gmail.com>
|
||||
Copyright 2019-Today: Druidoo (<https://www.druidoo.io>)
|
||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
|
||||
<template id="template" xml:space="preserve">
|
||||
|
||||
<t t-extend="FieldBinaryImage">
|
||||
<t t-jquery=".o_select_file_button" t-operation="after">
|
||||
<span class="fa fa-eye o_form_binary_file_web_cam" title="WebCam"/>
|
||||
<span class="fa fa-eye o_form_binary_file_web_cam" title="WebCam" />
|
||||
</t>
|
||||
</t>
|
||||
|
||||
<div t-name="WebCamDialog" id="WebCamModal">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-5 live_webcam_outer_div">
|
||||
<div id="live_webcam"/>
|
||||
<div id="live_webcam" />
|
||||
</div>
|
||||
<div class="col-md-2 mt64 direction_icon fa fa-angle-right fa-8x"/>
|
||||
<div class="col-md-2 mt64 direction_icon fa fa-angle-right fa-8x" />
|
||||
<div class="col-md-5 webcam_result_outer_div">
|
||||
<div id="webcam_result"/>
|
||||
<div id="webcam_result" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user