[IMP] Improved code.

bzr revid: jra@tinyerp.com-20120625110701-ihz5d55hxwoyoak1
This commit is contained in:
Jiten (OpenERP) 2012-06-25 16:37:01 +05:30
parent 55ddb1c1e1
commit 6e5be26efa
4 changed files with 65 additions and 77 deletions

View File

@ -46,11 +46,8 @@ class base_config_settings(osv.osv_memory):
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], {'default_linkedin_api_key': data.default_linkedin_api_key}, context=context)
company_obj.write(cr, uid, [company_id], {'linkedin_api_key': data.default_linkedin_api_key}, context=context)
base_config_settings()

View File

@ -27,7 +27,7 @@
<group colspan="4" col="4">
<separator string="Linkedin Settings" colspan="4"/>
<newline/>
<field name="default_linkedin_api_key" />
<field name="linkedin_api_key" />
</group>
</xpath>
</field>

View File

@ -16,9 +16,31 @@ openerp.web_linkedin = function(instance) {
this.$element.find('#loader').hide();
if (!this.get("effective_readonly")) {
this._super();
var context = new instance.web.CompoundContext(this.build_context());
var build_context = this.build_context();
this.apikey = build_context.__contexts[0].api_key;
self.user = new instance.web.DataSetSearch(self, 'res.users', null, null)
.read_slice(['id','name','company_id'], {"domain": [['id','=',self.session.uid]]}).then(function(results) {
self.company_id = results[0].company_id[0];
self.company = new instance.web.DataSetSearch(self, 'res.company', null, null)
.read_slice(['linkedin_api_key','name'], {"domain": [['id','=',self.company_id]]}).then(function(records) {
self.apikey = records[0].linkedin_api_key;
if (self.apikey) {
var head = document.head || document.getElementsByTagName('head')[0];
var tag = document.createElement('script');
tag.type = 'text/javascript';
tag.src = "http://platform.linkedin.com/in.js";
tag.innerHTML = 'api_key : '+self.apikey+'\n';
tag.innerHTML = tag.innerHTML + 'authorize : true';
var temp = 0;
$(head).find('script').each( function(i,val) {
if($(val).attr('src')=="http://platform.linkedin.com/in.js"){
temp = 1;
}
});
if(temp != 1) {
head.appendChild( tag );
}
}
});
});
if(this.view.fields['linkedin_id']){
if(this.view.datarecord['linkedin_id']){
this.$element.find('#linkedindefault').hide();
@ -28,39 +50,6 @@ openerp.web_linkedin = function(instance) {
this.$element.find('#linkedindefault').show();
}
}
try {
IN.init({ api_key : this.apikey });
} catch(e) {
if(!this.apikey){
this.APIWarning = e;
}
if (e.type == "undefined_method") {
this.APIWarning = e;
}
}
var head = document.head || document.getElementsByTagName('head')[0];
var tag = document.createElement('script');
tag.type = 'text/javascript';
tag.src = "http://platform.linkedin.com/in.js";
if(this.apikey){
// Registered API key is necessary to integrate with LinkedIn.
tag.innerHTML = 'api_key : '+this.apikey+'\n';
}
tag.innerHTML = tag.innerHTML + 'authorize : true';
// On load script Loading text is displayed
/*if(this.$element.find("#imagediv").find('.oe_loading')){
this.$element.find("#imagediv").find('.oe_loading').remove();
}
tag.onload=this.$element.find("#imagediv").append('<span class="oe_loading">Loading....</span>');*/
var temp = 0;
$(head).find('script').each( function(i,val) {
if($(val).attr('src')=="http://platform.linkedin.com/in.js"){
temp = 1;
}
});
if(temp != 1) {
head.appendChild( tag );
}
this.notification = new instance.web.Notification(this);
this.notification.appendTo(this.$element);
this.$element.find(".linkedin_icon").click( this.do_load_linkedin );
@ -111,42 +100,44 @@ openerp.web_linkedin = function(instance) {
var self = this;
this.msg_Counter=0; /* used to display notification, when record not found on Linkedin search */
this.removeTemplate( 1 );
if(!this.apikey){
this.APIKeyWarning(this.APIWarning);
if (this.apikey){
if (IN.ENV.auth.oauth_token) {
if (self.$element.find("input").val()) {
self.$element.find('#loader').show();
$('.linkedin_icon').css('display', 'none');
/* People Search */
IN.API.Raw("/people-search:(people:(id,first-name,last-name,picture-url,public-profile-url,formatted-name,location,phone-numbers,im-accounts,main-address,headline))")
.params({
"first-name": self.$element.find("input").val(),
"count" : 4
})
.result( self.do_fetch_detail );
/* Company Search */
IN.API.Raw("/company-search:(companies:(id,name,description,industry,logo-url,website-url,locations,twitter-id))")
.params({
"keywords": self.$element.find("input").val(),
"count" : 4
})
.result( self.do_fetch_detail );
}else{
this.notification.warn(_t("Linkedin Search"), _t("Please Enter Required Field."));
}
}
else {
self.do_authorize();
//IN.User.authorize();
}
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
} else {
this.APIKeyWarning();
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return false;
}
if (IN.ENV.auth.oauth_token) {
if (self.$element.find("input").val()) {
self.$element.find('#loader').show();
$('.linkedin_icon').css('display', 'none');
/* People Search */
IN.API.Raw("/people-search:(people:(id,first-name,last-name,picture-url,public-profile-url,formatted-name,location,phone-numbers,im-accounts,main-address,headline))")
.params({
"first-name": self.$element.find("input").val(),
"count" : 4
})
.result( self.do_fetch_detail );
/* Company Search */
IN.API.Raw("/company-search:(companies:(id,name,description,industry,logo-url,website-url,locations,twitter-id))")
.params({
"keywords": self.$element.find("input").val(),
"count" : 4
})
.result( self.do_fetch_detail );
}else{
this.notification.warn(_t("Linkedin Search"), _t("Please Enter Required Field."));
}
}
else {
//self.do_authorize();
IN.User.authorize();
}
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
},
do_authorize: function(resultCallback){
this.check_authorized();
@ -180,7 +171,7 @@ openerp.web_linkedin = function(instance) {
var user = new instance.web.DataSet(self, "res.users");
user.call("set_linkedin_api_key", [key]);
self.dialog.remove(),
user.__parentedParent.view.reload();
self.__parentedParent.reload();
}
else {
$("#apikey").css({'background-color':'#F66 '})

View File

@ -32,7 +32,7 @@ from osv import fields, osv
class company(osv.osv):
_inherit = 'res.company'
_columns = {
'default_linkedin_api_key': fields.char('LinkedIn API key', size=128),
'linkedin_api_key': fields.char('LinkedIn API key', size=128),
}
company()
@ -43,10 +43,10 @@ class users(osv.osv):
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], {'default_linkedin_api_key': key })
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()
@ -63,7 +63,7 @@ class res_partner(osv.osv):
company_obj = self.pool.get('res.company')
res = super(res_partner, self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
company_id = company_obj._company_default_get(cr, user, 'res.users', context=context)
linkedin_api_key = company_obj.browse(cr, user, company_id, context=context).default_linkedin_api_key
linkedin_api_key = company_obj.browse(cr, user, company_id, context=context).linkedin_api_key
fields = res['fields']
if fields.get('name'):
ctx = fields.get('name').get('context')