Skip to content
Permalink
Browse files

[ADD] mrp: added a new file for 'slide_viewer' widget

with this commit, we have added a new widget 'slide_viewer' to show google embedded slide view

Task ID: 1909010
  • Loading branch information...
jpr-odoo committed Feb 19, 2019
1 parent 6ec4e53 commit e862813007f983bf063bc8e3cb67855de6de1ec3
Showing with 77 additions and 0 deletions.
  1. +76 −0 addons/mrp/static/src/js/mrp_slide.js
  2. +1 −0 addons/mrp/views/mrp_templates.xml
@@ -0,0 +1,76 @@
odoo.define('mrp.mrp_slide', function (require) {
"use strict";

var field_registry = require('web.field_registry');
var FieldChar = require('web.basic_fields').FieldChar;


var SlideViewer = FieldChar.extend({

/**
* force to set src for iframe when its value has changed
*
* @override
*/
reset: function () {
var self = this;
return $.when(this._super.apply(this, arguments)).then(function () {
var $iframe = self.$el.find('iframe.o_slideview_iframe');
if ($iframe.length) {
self._getEmbedURL(self.value);
if (self.src && $iframe.attr('src') !== self.src) {
$iframe.removeClass('o_hidden');
} else {
$iframe.addClass('o_hidden');
}
$iframe.attr('src', self.src);
}
});
},

//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------

/**
*
* @private
*/
_getEmbedURL: function (value) {
var src = false;
if (value) {
var googleRegExp = /(^https:\/\/docs.google.com).*(\/d\/e\/|\/d\/)([A-Za-z0-9-_]+)/;
var google = value.match(googleRegExp);
if (google && google[3]) {
src = 'https://docs.google.com/presentation' + google[2] + google[3] + '/preview';
}
}
this.src = src || value || this.value;
},

/**
* append iframe for embed view
*
* @override
* @private
*/
_render: function () {
this._super.apply(this, arguments);
this._getEmbedURL(this.value);
this.mode === 'readonly' ? this.$el.hide() : this.$el.show();
this.setElement(this.$el.wrap('<div class="o_slide_viewer"/>').parent());
this.$el.append($('<iframe>', {
src: this.src || 'about:blank',
class: this.src ? 'o_slideview_iframe' : 'o_slideview_iframe o_hidden',
width: '100%',
height: '30rem',
css: {
border: '0',
},
allowfullscreen: true,
}));
},
});
field_registry.add('slide_viewer', SlideViewer);
return SlideViewer;
});
@@ -4,6 +4,7 @@
<xpath expr="." position="inside">
<script type="text/javascript" src="/mrp/static/src/js/mrp.js"></script>
<script type="text/javascript" src="/mrp/static/src/js/mrp_bom_report.js"></script>
<script type="text/javascript" src="/mrp/static/src/js/mrp_slide.js"></script>
</xpath>
</template>

0 comments on commit e862813

Please sign in to comment.
You can’t perform that action at this time.