Web Etherpad Integration

bzr revid: tta@openerp.com-20120419132916-yzrdnz2y8gus2wlw
This commit is contained in:
Tejas Tank
2012-04-19 18:59:16 +05:30
parent 01a31f08e0
commit 2c780efd12
6 changed files with 195 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
import res_company
+16
View File
@@ -0,0 +1,16 @@
{
"name": "web_etherpad",
"category" : "Hidden",
"description":'Openerp web Etherpad Widget',
"version": "2.0",
'author': 'OpenERP SA',
'website': 'http://openerp.com',
'data': [
'res_company.xml'
],
"depends": ['base','web'],
'qweb' : ['static/src/xml/etherpad.xml'],
"css": [],
"js": ['static/src/js/web_etherpad.js'],
"auto_install": False,
}
+15
View File
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from osv import fields, osv
class company_pad(osv.osv):
_inherit = 'res.company'
_columns = {
'pad_url_template': fields.char('Pad URL Template', size=128, required=True,
help="Template used to generate pad URL."),
}
_defaults = {
'pad_url_template': 'http://ietherpad.com/%(db)s-%(model)s-%(id)d-%(salt)s-%(name)s'
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+16
View File
@@ -0,0 +1,16 @@
<openerp>
<data>
<record id="view_company_form_with_pad" model="ir.ui.view">
<field name="name">res.company.form.pad</field>
<field name="model">res.company</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_company_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@string='Configuration']" position="inside">
<separator string="Pad" colspan="4"/>
<field name="pad_url_template"/>
</xpath>
</field>
</record>
</data>
</openerp>
+125
View File
@@ -0,0 +1,125 @@
openerp.web_etherpad = function (instance) {
instance.web.form.FieldEtherpad = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
template: 'FieldEtherpad',
initialize_content: function() {
this.$textarea = undefined;
if (!this.get("effective_readonly")) {
this.$textarea = this.$element.find('textarea');
//this.$textarea.hide();
this.$textarea.change(_.bind(function() {
this.set({'value': instance.web.parse_value(this.$textarea.val(), this)});
}, this));
this.resized = false;
}
},
set_value: function(value_) {
var self = this ;
var company_id = (self.view.datarecord.hasOwnProperty('id')) ?self.view.datarecord.company_id[0]: self.view.datarecord.company_id ;
/* getting etherpad url and set pad to field. */
self.rpc('/web/dataset/get',{
'model':'res.company',
'ids':[company_id],
'fields':['pad_url_template'],
'context':{}
},function(companies){
var pad_template = companies[0].pad_url_template.replace('-%(salt)s-%(name)s','').replace(/\s/g,'');
var patt_url = (_.str.sprintf(pad_template.replace('-%(id)d',''), {
db : self.session.db,
model : self.view.model,
})).replace(/\s/g,'') ;
//alert("match or not >?"+value_.search(patt_url));
if(value_ == false)
self.add_pad(self,pad_template,value_);
else if(value_.search(patt_url) != 0)
self.add_pad(self,pad_template,value_);
else
self.show_pad_value(self,value_);
});
},
show_pad_value: function(self,value_)
{
self._inhibit_on_change = true;
self.set({'value': value_ });
self._inhibit_on_change = false;
self.invalid = false;
self.update_dom();
self.render_value();
},
add_pad: function(self,pad_template,value_){
var url = (_.str.sprintf(pad_template, {
db : self.session.db,
model : self.view.model,
id : Math.round(new Date().getTime()/100.0),
})).replace(/\s/g,'');
var show_value = instance.web.format_value(value_, this, '');
self.show_pad_value(self,url + '\n'+ show_value);
this.dirty = true;
},
render_value: function() {
var show_value = instance.web.format_value(this.get('value'), this, '');
if (!this.get("effective_readonly")) {
this.$textarea.val(show_value);
this.$element.find('div').html('<iframe frameborder="0" height="217px" width="100%" src="'+show_value.split('\n')[0]+'?showChat=false"></iframe>');
if (!this.resized && this.view.options.resize_textareas) {
this.do_resize(this.view.options.resize_textareas);
this.resized = true;
}
} else {
this.$element.text(show_value);
if(this.get('value') != false)
{
var self = this;
$.get(show_value.split('\n')[0]+'/export/html', function(data) {
console.log(data);
self.$element.html(data);
});
}
}
},
validate: function() {
this.invalid = false;
if (!this.get("effective_readonly")) {
try {
var value_ = instance.web.parse_value(this.$textarea.val(), this, '');
this.invalid = this.get("required") && value_ === '';
} catch(e) {
this.invalid = true;
}
}
},
focus: function($element) {
this._super($element || this.$textarea);
},
do_resize: function(max_height) {
max_height = parseInt(max_height, 10);
var $input = this.$textarea,
$div = $('<div style="position: absolute; z-index: 1000; top: 0"/>').width($input.width()),
new_height;
$div.text($input.val());
_.each('font-family,font-size,white-space'.split(','), function(style) {
$div.css(style, $input.css(style));
});
$div.appendTo($('body'));
new_height = $div.height();
if (new_height < 90) {
new_height = 90;
}
if (!isNaN(max_height) && new_height > max_height) {
new_height = max_height;
}
$div.remove();
$input.height(new_height);
},
reset: function() {
this.resized = false;
}
}));
instance.web.form.widgets = instance.web.form.widgets.extend({
'etherpad': 'instance.web.form.FieldEtherpad',
});
}
+21
View File
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- vim:fdl=1:
-->
<templates id="template" xml:space="preserve">
<t t-name="FieldEtherpad">
<t t-if="!widget.get('effective_readonly')">
<div class="oe_form_field_text">
<textarea rows="6"
t-att-name="widget.name"
class="field_text"
t-att-tabindex="widget.node.attrs.tabindex"
t-att-autofocus="widget.node.attrs.autofocus"
></textarea><img class="oe_field_translate oe_input_icon" t-if="widget.field.translate" t-att-src='_s + "/web/static/src/img/icons/terp-translate.png"' width="16" height="16" border="0"/>
<div t-attf-class="etherpad_field_#{widget.name}" ></div>
</div>
</t>
</t>
</templates>