generate url from the widget if needed

bzr revid: al@openerp.com-20120820234008-olfcnxj7np6hwwgz
This commit is contained in:
Antony Lesuisse 2012-08-21 01:40:08 +02:00
parent f313d35c85
commit 72c5fe278b
5 changed files with 63 additions and 61 deletions

View File

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from osv import fields, osv
DEFAULT_PAD_TEMPLATE = 'http://beta.etherpad.org/p/%(db)s-%(model)s-%(salt)s'
DEFAULT_PAD_TEMPLATE = 'http://pad.openerp.com/p/%(db)s-%(model)s-%(salt)s'
DEFAULT_PAD_TEMPLATE = ''
class company_pad(osv.osv):
_inherit = 'res.company'

View File

@ -1,52 +1,39 @@
.oe_etherpad_head{
.oe_pad_head {
width: 100%;
display: block;
padding-left:3px;
cursor:pointer;
padding: 4px;
}
.oe_etherpad_fullscreen div.oe_etherpad_head .oe_normal {
display: none;
.oe_pad_readonly {
border: 1px solid #ddd;
padding: 8px;
}
.oe_etherpad_normal div.oe_etherpad_head .oe_fullscreen {
display: none;
}
.oe_etherpad_fullscreen {
.oe_pad_fullscreen {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: white;
z-index:10001 !important;
}
.etherpad_default{
width: 100%;
height: 450px;
}
.oe_etherpad_fullscreen .etherpad_default{
height: 100%
z-index: 1000;
}
.etherpad_body{
overflow:hidden;
.oe_pad_fullscreen .oe_pad_content {
height: 100%;
}
.etherpad_readonly{
width: 100%;
height: 450px;
overflow:auto;
.etherpad_readonly ul, .etherpad_readonly ol {
margin-before: 1em;
margin-after: 1em;
margin-start: 0px;
margin-end: 0px;
padding-start: 40px !important;
}
.etherpad_readonly ul,.etherpad_readonly ol{
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 40px !important;
}
.etherpad_readonly ul li{
.etherpad_readonly ul li{
list-style-type: disc;
}
.etherpad_readonly ol li{
.etherpad_readonly ol li{
list-style-type: decimal;
}
.etherpad_readonly .indent li{

View File

@ -1,32 +1,47 @@
openerp.pad = function(instance) {
instance.web.form.FieldPad = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeFieldMixin, {
instance.web.form.FieldPad = instance.web.form.AbstractField.extend({
template: 'FieldPad',
initialize_content: function() {
start: function() {
this._super();
var self = this;
this.$textarea = undefined;
this.$element.find('div.oe_etherpad_head').click(function(ev) {
self.$element.toggleClass('oe_etherpad_fullscreen').toggleClass('oe_etherpad_normal');
this.$element.find('div.oe_pad_head').click(function(ev) {
self.$element.toggleClass('oe_pad_fullscreen');
});
this.on("change:effective_readonly", this, function() {
this.render_value();
});
},
set_value: function(value_) {
this._super(value_);
this.render_value();
set_value: function(val) {
var self = this;
var _super = self._super;
_super.apply(self,[val]);
if (val === false || val === "") {
self.field_manager.dataset.call('pad_generate_url').then(function(r) {
_super.apply(self,[r]);
self.render_value();
});
} else {
self.render_value();
}
},
render_value: function() {
console.log("display");
var self = this;
var value = this.get('value');
if(value !== false) {
var url = value.split('\n')[0];
if (!_.str.startsWith(value, "http")) {
self.$('.oe_pad_content').html(instance.web.qweb.render('FieldPad.unconfigured'));
} else {
if (!this.get("effective_readonly")) {
var pad_username = this.session.username;
var code = '<iframe width="100%" height="100%" frameborder="0" src="'+url+'?showChat=false&userName='+pad_username+'"></iframe>';
this.$element.find('div.oe_etherpad_default').html(code);
var code = '<iframe width="100%" height="100%" frameborder="0" src="'+value+'?showChat=false&userName='+pad_username+'"></iframe>';
this.$('.oe_pad_content').html(code);
} else {
$.get(url+'/export/html').success(function(data) {
self.$element.html('<div class="etherpad_readonly">'+data+'</div>');
$.get(value+'/export/html').success(function(data) {
self.$('.oe_pad_content').html('<div class="oe_pad_readonly">'+data+'</div>');
}).error(function() {
self.$element.text('Unable to load pad');
self.$('.oe_pad_content').text('Unable to load pad');
});
}
}

View File

@ -2,17 +2,19 @@
<!-- vim:fdl=1:
-->
<templates id="template" xml:space="preserve">
<t t-name="FieldPad">
<t t-if="!widget.get('effective_readonly')">
<div class="oe_form_field_text oe_etherpad_normal">
<div class="oe_etherpad_head">
<span class="oe_normal">Fullscreen</span>
<span class="oe_fullscreen">Return to Record</span>
</div>
<div class="oe_etherpad_default" ></div>
<div class="oe_form_field_text oe_pad">
<div class="oe_pad_head">
<span class="oe_pad_switch">Fullscreen</span>
</div>
</t>
<div class="oe_pad_content"></div>
</div>
</t>
<t t-name="FieldPad.unconfigured">
Please configure your etherpad server.<br/>
OpenERP Entreprise customers may safely use pad.openerp.com as a server using the following template:<br/>
<blockquote>
http://pad.openerp.com/p/%(db)s-%(model)s-%(salt)s
</blockquote>
</t>
</templates>

View File

@ -9,6 +9,3 @@ class task(osv.osv):
_columns = {
'description_pad': fields.char('Description PAD', size=250)
}
_defaults = {
'description_pad': lambda self, cr, uid, context: self.pad_generate_url(cr, uid, context),
}