niv-openerp 2012-08-01 15:27:33 +02:00
parent fc5163b31a
commit 050b4caa28
10 changed files with 93 additions and 135 deletions

View File

@ -1,2 +1,2 @@
import res_config
import web_linkedin

View File

@ -9,8 +9,7 @@
This module provides the Integration of the LinkedIn with OpenERP.
""",
'update_xml': [
'res_partner_view.xml',
'res_config_view.xml',
'web_linkedin_view.xml',
],
"depends" : ["base"],
"js": [

View File

@ -1,53 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Copyright (C) 2004-2012 OpenERP S.A. (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import osv, fields
class base_config_settings(osv.osv_memory):
_inherit = 'base.config.settings'
_name = 'base.config.settings'
_columns = {
'default_linkedin_api_key': fields.char('LinkedIn API key', size=128, default_model='res.company',
help="""Give API key of linkedin."""),
'generate_key': fields.text('Go to URL', readonly=True,
help="""If you have not generate linkedin API Key yet than Go to URL to generate and enter it in above text field."""),
}
_defaults = {
'generate_key': "To find contact persons from LinkedIn "\
"\n====================================="\
"\n* Go to this URL : https://www.linkedin.com/secure/developer "\
"\n* Add New Application and fill the form,"\
"\n - JavaScript API Domain is Your domain name (e.g. https://yourcompany.my.openerp.com),"\
"\n - You can give multiple domain (e.g. yourcompany.my.openerp.com),"\
"\n - programming tools is Javascript"\
'\n* Copy the "API Key" and paste it in the field "LinkedIn API Key" here above.'
}
def execute(self, cr, uid, ids, context=None):
super(base_config_settings,self).execute(cr, uid, ids, context=context)
company_obj = self.pool.get('res.company')
data = self.browse(cr, uid, ids[0], context=context)
company_id = company_obj._company_default_get(cr, uid, 'res.users', context=context)
company_obj.write(cr, uid, [company_id], {'linkedin_api_key': data.default_linkedin_api_key}, context=context)
base_config_settings()

View File

@ -1,24 +0,0 @@
<openerp>
<data>
<record id="view_general_configuration_linkedin" model="ir.ui.view">
<field name="name">General Settings</field>
<field name="model">base.config.settings</field>
<field name="inherit_id" ref="base_setup.view_general_configuration"/>
<field name="type">form</field>
<field name="priority">20</field>
<field name="arch" type="xml">
<xpath expr="/form/group[@string='External Accesses']" position='after'>
<group colspan="4" col="8">
<separator string="Linkedin Settings" colspan="4"/>
<newline/>
<!-- <field name="import_contact"/>
<newline/>-->
<field name="default_linkedin_api_key"/>
<newline/>
<field name="generate_key" nolabel="1" colspan="4" widget="text_html"/>
</group>
</xpath>
</field>
</record>
</data>
</openerp>

View File

@ -1,6 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
</data>
</openerp>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -5,6 +5,72 @@
openerp.web_linkedin = function(instance) {
var QWeb = instance.web.qweb;
var _t = instance.web._t;
instance.web_linkedin.LinkedinTester = instance.web.Class.extend({
init: function() {
this.api_key = "cxnr0l53n73x";
this.linkedin_added = false;
this.linkedin_def = $.Deferred();
},
test_linkedin: function() {
var self = this;
return this.test_api_key().pipe(function() {
if (self.linkedin_added)
return self.linkedin_def.promise();
var tag = document.createElement('script');
tag.type = 'text/javascript';
tag.src = "http://platform.linkedin.com/in.js";
tag.innerHTML = 'api_key : ' + self.api_key + '\nauthorize : true';
document.getElementsByTagName('head')[0].appendChild(tag);
linkedin_added = true;
$(tag).load(function() {
self.linkedin_def.resolve();
});
return self.linkedin_def.promise();
}, function() {
/*return new instance.web.Model("ir.config_parameter").call("set_param", ["web.linkedin.apikey", "cxnr0l53n73x"]).pipe(function() {
return self.test_linkedin();
});*/
});
},
test_api_key: function() {
if (this.api_key) {
return $.when();
}
return new instance.web.Model("ir.config_parameter").call("get_param", ["web.linkedin.apikey"]).pipe(function(a) {
if (a !== false) {
self.api_key = a;
return true;
} else {
return $.Deferred().reject();
}
});
},
});
instance.web_linkedin.tester = new instance.web_linkedin.LinkedinTester();
instance.web_linkedin.Linkedin = instance.web.form.FieldChar.extend({
init: function() {
this._super.apply(this, arguments);
var self = this;
this.display_dm = new instance.web.DropMisordered(true);
this.on("linkedin_loaded", this, function() {
$("input", self.$element).after(QWeb.render("FieldChar.linkedin"));
});
},
initialize_content: function() {
this._super();
var self = this;
if (! this.get("effective_readonly")) {
this.display_dm.add(instance.web_linkedin.tester.test_linkedin()).then(function() {
self.trigger("linkedin_loaded");
});
} else {
this.display_dm.add($.when());
}
},
});
instance.web.form.widgets.add('linkedin', 'instance.web_linkedin.Linkedin');
};
// vim:et fdc=0 fdl=0:

View File

@ -2,5 +2,7 @@
<!-- vim:fdl=1:
-->
<templates xml:space="preserve">
<t t-name="FieldChar.linkedin">
Yop
</t>
</templates>

View File

@ -18,52 +18,5 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import base64
import urllib2
import xmlrpclib
import zlib
from web import common
openerpweb = common.http
from osv import fields, osv
class company(osv.osv):
_inherit = 'res.company'
_columns = {
'linkedin_api_key': fields.char('LinkedIn API key', size=128),
}
company()
class users(osv.osv):
_inherit = 'res.users'
def set_linkedin_api_key(self, cr, uid, key, context=None):
company_obj = self.pool.get('res.company')
company_id = company_obj._company_default_get(cr, uid, 'res.users', context=context)
company_obj.write(cr, uid, [company_id], {'linkedin_api_key': key })
ir_values = self.pool.get('ir.values')
ir_values.set_default(cr, uid, 'res.company', 'linkedin_api_key', key)
return True
users()
class res_partner(osv.osv):
_inherit = 'res.partner'
_columns = {
}
res_partner()
# don't know yet if I will remove it
class Binary(openerpweb.Controller):
_cp_path = "/web_linkedin/binary"
@openerpweb.jsonrequest
def url2binary(self, req,url):
bfile = urllib2.urlopen(url)
return base64.b64encode(bfile.read())

View File

@ -0,0 +1,21 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_linkedin_partner_form" model="ir.ui.view">
<field name="name">res.partner.linkedin.inherit</field>
<field name="model">res.partner</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="name" position="replace">
<field name="name" default_focus="1" nolabel="1" widget="linkedin" />
</field>
<!--<field name="title" position="before">
<field name="linkedin_id" invisible="1"/>
<field name="profile_id" invisible="1"/>
<field name="twitter_id" invisible="1"/>
</field>-->
</field>
</record>
</data>
</openerp>