Browse Source

Merge 746100a761 into d736ee4460

pull/964/merge
Siddharth Bhalgami 5 years ago
committed by GitHub
parent
commit
9473c8c193
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 58
      web_widget_image_webcam/README.rst
  2. 4
      web_widget_image_webcam/__init__.py
  3. 23
      web_widget_image_webcam/__manifest__.py
  4. 4
      web_widget_image_webcam/models/__init__.py
  5. 14
      web_widget_image_webcam/models/ir_config_parameter.py
  6. BIN
      web_widget_image_webcam/static/description/icon.png
  7. 28
      web_widget_image_webcam/static/src/css/web_widget_image_webcam.css
  8. BIN
      web_widget_image_webcam/static/src/img/webcam_placeholder.png
  9. 1052
      web_widget_image_webcam/static/src/js/webcam.js
  10. BIN
      web_widget_image_webcam/static/src/js/webcam.swf
  11. 127
      web_widget_image_webcam/static/src/js/webcam_widget.js
  12. 28
      web_widget_image_webcam/static/src/xml/web_widget_image_webcam.xml
  13. 15
      web_widget_image_webcam/views/assets.xml

58
web_widget_image_webcam/README.rst

@ -0,0 +1,58 @@
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
=========================
Web Widget - Image WebCam
=========================
This module extends the functionality of the image widget and allows to take snapshots with WebCam.
Configuration
=============
By default, the module works with all `major browsers
<https://github.com/jhuckaby/webcamjs#browser-support>`_.
An important note for **Chrome 47+** users - this module only works with websites delivered over SSL / HTTPS.
Visit this for `more info
<https://github.com/jhuckaby/webcamjs#important-note-for-chrome-47>`_.
But, If you still want this module to work with websites without SSL / HTTPS.
Here is the steps to do it easily (Always run in Adobe Flash fallback mode, but it is not desirable).
Set the configuration parameter ``web_widget_image_webcam.flash_fallback_mode`` to ``1``
Its done! Now this module also work with websites without SSL / HTTPS.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/web/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Contributors
------------
* Siddharth Bhalgami <siddharth.bhalgami@gmail.com>
* Kaushal Prajapati <kbprajapati@live.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

4
web_widget_image_webcam/__init__.py

@ -0,0 +1,4 @@
# Copyright 2019 Siddharth Bhalgami <siddharth.bhalgami@gmail.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import models

23
web_widget_image_webcam/__manifest__.py

@ -0,0 +1,23 @@
# Copyright 2016 Siddharth Bhalgami <siddharth.bhalgami@gmail.com>
# 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": "11.0.1.0.0",
"category": "web",
"website": "https://github.com/OCA/web",
"author": "Tech Receptives, "
"Odoo Community Association (OCA), "
"Kaushal Prajapati",
"license": "LGPL-3",
"data": [
"views/assets.xml",
],
"depends": [
"web",
],
"qweb": [
"static/src/xml/web_widget_image_webcam.xml",
],
"installable": True,
}

4
web_widget_image_webcam/models/__init__.py

@ -0,0 +1,4 @@
# Copyright 2019 Siddharth Bhalgami <siddharth.bhalgami@gmail.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import ir_config_parameter

14
web_widget_image_webcam/models/ir_config_parameter.py

@ -0,0 +1,14 @@
# Copyright 2019 Siddharth Bhalgami <siddharth.bhalgami@gmail.com>
# 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)

BIN
web_widget_image_webcam/static/description/icon.png

After

Width: 105  |  Height: 104  |  Size: 15 KiB

28
web_widget_image_webcam/static/src/css/web_widget_image_webcam.css

@ -0,0 +1,28 @@
/*
Copyright 2016 Siddharth Bhalgami <siddharth.bhalgami@gmail.com>
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 {
color: inherit;
}
.o_form_view .o_form_field_image .o_form_image_controls > .fa{
margin:3px;
}
.live_webcam_outer_div, .webcam_result_outer_div {
padding-left: 20px;
}
#webcam_result img {
max-width: 320px;
max-height: 240px;
}
#live_webcam {
width: 320px;
height: 240px;
}
.direction_icon {
text-align: center;
}

BIN
web_widget_image_webcam/static/src/img/webcam_placeholder.png

After

Width: 320  |  Height: 240  |  Size: 7.1 KiB

1052
web_widget_image_webcam/static/src/js/webcam.js
File diff suppressed because it is too large
View File

BIN
web_widget_image_webcam/static/src/js/webcam.swf

127
web_widget_image_webcam/static/src/js/webcam_widget.js

@ -0,0 +1,127 @@
/*
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) {
"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 _t = core._t;
var QWeb = core.qweb;
FieldBinaryImage.include({
_render: function () {
this._super();
var self = this,
WebCamDialog = $(QWeb.render("WebCamDialog")),
img_data;
// ::webcamjs:: < https://github.com/jhuckaby/webcamjs >
// Webcam: Set Custom Parameters
Webcam.set({
width: 320,
height: 240,
dest_width: 320,
dest_height: 240,
image_format: 'jpeg',
jpeg_quality: 90,
force_flash: false,
fps: 45,
swfURL: '/web_widget_image_webcam/static/src/js/webcam.swf',
});
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({
/*
:: Important Note about Chrome 47+ :: < https://github.com/jhuckaby/webcamjs#important-note-for-chrome-47 >
Setting "force_flash" to "true" will always run in Adobe Flash fallback mode on Chrome, but it is not desirable.
*/
force_flash: true,
});
}
});
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
-> http://stackoverflow.com/questions/6793575/estimating-the-size-of-binary-data-encoded-as-a-b64-string-in-python
-> https://en.wikipedia.org/wiki/Base64
[ The ratio of output bytes to input bytes is 4:3 (33% overhead).
Specifically, given an input of n bytes, the output will be "4[n/3]" bytes long in base64,
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) // 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();
dialog.opened().then(function() {
Webcam.attach('#live_webcam');
// 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"/>');
});
});
},
});
Dialog.include({
destroy: function () {
// Shut Down the Live Camera Preview | Reset the System
Webcam.reset();
this._super.apply(this, arguments);
},
});
});

28
web_widget_image_webcam/static/src/xml/web_widget_image_webcam.xml

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2016 Siddharth Bhalgami <siddharth.bhalgami@gmail.com>
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"/>
</t>
</t>
<div t-name="WebCamDialog" id="WebCamModal">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="col-md-5 live_webcam_outer_div">
<div id="live_webcam"/>
</div>
<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>
</div>
</div>
</div>
</div>
</template>

15
web_widget_image_webcam/views/assets.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 Siddharth Bhalgami <siddharth.bhalgami@gmail.com>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo>
<template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr=".">
<script type="text/javascript"
src="/web_widget_image_webcam/static/src/js/webcam.js"/>
<link rel="stylesheet"
href="/web_widget_image_webcam/static/src/css/web_widget_image_webcam.css"/>
<script type="text/javascript"
src="/web_widget_image_webcam/static/src/js/webcam_widget.js"/>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save