Etherpad API Integration.
bzr revid: tta@openerp.com-20120514134958-21spjsnqjitqw4ie
This commit is contained in:
parent
2af74107d7
commit
2a81f8e452
|
@ -2,6 +2,7 @@
|
|||
from osv import fields, osv
|
||||
import random
|
||||
import string
|
||||
from etherpad import EtherpadLiteClient
|
||||
|
||||
|
||||
class pad_common(osv.osv_memory):
|
||||
|
@ -18,11 +19,21 @@ class pad_common(osv.osv_memory):
|
|||
}
|
||||
return pad_url_template % template_vars
|
||||
|
||||
def _pad_api_key(self, cr, uid, context=None):
|
||||
return self.pool.get('res.users').browse(cr,uid,[uid])[0].company_id.etherpad_api_key
|
||||
def _pad_api_key(self, cr, uid, ids=None, name=None, arg=None , context=None):
|
||||
if not ids:
|
||||
return self.pool.get('res.users').browse(cr,uid,[uid],context)[0].company_id.etherpad_api_key
|
||||
res = {}
|
||||
for id in ids:
|
||||
res[id] = self.pool.get('res.users').browse(cr,uid,[uid],context)[0].company_id.etherpad_api_key
|
||||
return res
|
||||
|
||||
def _pad_user_name(self, cr, uid, context=None):
|
||||
return self.pool.get('res.users').browse(cr,uid,[uid])[0].name
|
||||
def _pad_user_name(self, cr, uid, ids=None, name = None, arg = None, context=None):
|
||||
if not ids:
|
||||
return self.pool.get('res.users').browse(cr,uid,[uid],context=context)[0].name
|
||||
res = {}
|
||||
for id in ids:
|
||||
res[id] = self.pool.get('res.users').browse(cr,uid,[uid],context=context)[0].name
|
||||
return res
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
if not default:
|
||||
|
@ -35,32 +46,22 @@ class pad_common(osv.osv_memory):
|
|||
def create(self, cr, uid, vals, context=None):
|
||||
record_id = super(pad_common, self).create(cr, uid, vals, context=context)
|
||||
res = self.browse(cr,uid, record_id)
|
||||
url = res.pad_url
|
||||
if url:
|
||||
self.pool.get('ir.attachment').create(cr, uid, {
|
||||
'res_model' : self._name,
|
||||
'res_id' : record_id,
|
||||
'type' : 'url',
|
||||
'name' : 'Pad',
|
||||
'url' : url,
|
||||
})
|
||||
url = res.pad_url
|
||||
api_key = self._pad_api_key(cr, uid)
|
||||
if api_key:
|
||||
api_url = url[0:url.find("p/")] + "api/"
|
||||
pad_id = url[url.find("p/")+2:]
|
||||
pad_author = self._pad_user_name(cr,uid)
|
||||
ep_client = EtherpadLiteClient(api_key, api_url)
|
||||
ep_client.createPad(pad_id,"")
|
||||
ep_client.createAuthor(pad_author)
|
||||
return record_id
|
||||
|
||||
_columns = {
|
||||
'pad_url': fields.char('Full Screen', size=512),
|
||||
'pad_api_key': fields.function(_pad_api_key, type='text', string="Pad API Key"),
|
||||
'pad_user_name': fields.function(_pad_user_name, type='text', string="Current Pad User"),
|
||||
'pad_url': fields.char('Full Screen', size=512),
|
||||
}
|
||||
_defaults = {
|
||||
'pad_url': lambda self, cr, uid, context: self.pool.get('ir.attachment').pad_generate_url(cr, uid, self._name)
|
||||
'pad_url': lambda self, cr, uid, context: self.pool.get('ir.attachment').pad_generate_url(cr, uid, self._name),
|
||||
}
|
||||
|
||||
def action_open_pad(self, cr, uid, ids, context=None):
|
||||
"""Get pad action
|
||||
"""
|
||||
url = self.browse(cr, uid, ids[0]).pad_url
|
||||
return {
|
||||
'type': 'ir.actions.act_url',
|
||||
'url': url
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -19,10 +19,14 @@ instance.web.form.FieldEtherpad = instance.web.form.AbstractField.extend(_.exten
|
|||
this.render_value();
|
||||
},
|
||||
render_value: function() {
|
||||
var show_value = instance.web.format_value(this.get('value'), this, '');
|
||||
console.log(this);
|
||||
if (!this.get("effective_readonly")) {
|
||||
this.$element.find('div').html('<iframe width="100%" height="100%" frameborder="0" src="'+show_value.split('\n')[0]+'?showChat=false&showLineNumbers=false"></iframe>');
|
||||
var show_value = instance.web.format_value(this.get('value'), this, '');
|
||||
if (!this.get("effective_readonly")) {
|
||||
// var pad_url = show_value.split('\n')[0];
|
||||
// var api_url = pad_url.substring( 0, (pad_url.search("/p/")+1) );
|
||||
// var pad_id = pad_url.substring((pad_url.search("p/")+2) );
|
||||
// console.log(this);
|
||||
this.$element.find('div').html('<iframe width="100%" height="100%" frameborder="0" src="'+pad_url+'?showChat=false&showLineNumbers=false"></iframe>');
|
||||
|
||||
} else {
|
||||
if(this.get('value') != false)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue