Removed all stuff

bzr revid: nicolas.vanhoren@openerp.com-20120731095510-svyw6im3mhubgitt
This commit is contained in:
niv-openerp 2012-07-31 11:55:10 +02:00
parent e34d7fc798
commit fc5163b31a
10 changed files with 2 additions and 824 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

View File

@ -5,684 +5,6 @@
openerp.web_linkedin = function(instance) {
var QWeb = instance.web.qweb;
var _t = instance.web._t;
instance.web.form.widgets.add(
'Linkedin', 'instance.web_linkedin.Linkedin');
instance.web_linkedin.Linkedin = instance.web.form.FieldChar.extend({
template: 'Linkedin',
isAuthorized: false,
render_value: function() {
this._super();
var self = this;
this.$element.find('#loader').hide();
if (!this.get("effective_readonly")) {
this._super();
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) {
self.add_ldn_script(self.apikey);
}
});
});
self.linkedin_icon_color();
this.notification = new instance.web.Notification(this);
this.notification.appendTo(this.$element);
this.$element.find(".linkedin_icon").click( this.do_load_linkedin );
this.removeTemplate();
if(this.get('value') != false){
/* if value get then display button of profile url */
if (this.view.fields['profile_id'].get_value() || this.view.datarecord['profile_id']) {
this.setTemplate(this.view.datarecord['profile_id'] , false );
}
/* if value get then display button of twitter */
if (this.view.fields['twitter_id'].get_value() || this.view.datarecord['twitter_id']) {
this.setTemplate( false, this.view.datarecord['twitter_id']);
}
}
if (this.view.datarecord['linkedin_id']) {
if (this.view.datarecord['profile_id'] && !this.view.datarecord['twitter_id']) {
if (this.$element.find('#twitterid')) {
this.$element.find('#twitterid').remove();
}
}
else if (!this.view.datarecord['profile_id'] && this.view.datarecord['twitter_id']) {
if (this.$element.find('#profileid')) {
this.$element.find('#profileid').remove();
}
}
}else{
this.removeTemplate();
}
} else {
this.removeTemplate();
if(this.get('value') != false){
var tagtr = document.createElement('tr');
tagtr.id = "profiletwittor-tr";
this.$element.append(tagtr);
/* if value get then display button of profile url */
if (this.view.fields['profile_id'] && this.view.datarecord['profile_id']) {
this.setTemplate( this.view.datarecord['profile_id'] , false );
}
/* if value get then display button of twitter */
if (this.view.fields['twitter_id'] && this.view.datarecord['twitter_id']) {
this.setTemplate( false, this.view.datarecord['twitter_id'] );
}
}
}
},
/* Load Linkedin Data On search */
do_load_linkedin: function( e ) {
var self = this;
this.msg_Counter=0; /* used to display notification, when record not found on Linkedin search */
this.removeTemplate( 1 );
if (this.apikey){
if (IN.ENV.auth) {
if (IN.ENV.auth.api_key != this.apikey){
return false;
}
}else{
return false;
}
if (IN.ENV.auth.oauth_token) {
if (self.$element.find("input").val()) {
self.$element.find('#loader').show();
$('.linkedin_icon').css('display', 'none');
var firstNames = [];
var lastNames = [];
var text = self.$element.find("input").val().split(' ');
/* People Search */
if (text.length == 2) {
firstNames.push(text[0]);
lastNames.push(text[1]);
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": firstNames[0],
"last-name": lastNames[0],
"count" : 4
})
.result( self.do_fetch_detail );
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": lastNames[0],
"last-name": firstNames[0],
"count" : 4
})
.result( self.do_fetch_detail );
} else {
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 );
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({
"last-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();
}
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
} else {
this.APIKeyWarning();
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return false;
}
},
do_authorize: function(resultCallback){
this.check_authorized();
if (this.isAuthorized == false){
IN.User.authorize(resultCallback);
}
},
check_authorized: function(){
this.isAuthorized = IN.User.isAuthorized();
},
APIKeyWarning: function(e) {
var self = this;
this.dialog = instance.web.dialog($(QWeb.render("Register.Linkedin")), {
title: _t("Connect to LinkedIn"),
modal: true,
width : 700,
height:500,
close: function(){ self.dialog.remove();},
buttons:[
{
text: _t("Cancel"),
click: function() { self.dialog.remove(); }
}]
});
$("#register").click(function() {
var key = $("#apikey").val();
if(key){
//self.apikey = key;
self.add_ldn_script(key);
var user = new instance.web.DataSet(self, "res.users");
user.call("set_linkedin_api_key", [key]);
self.dialog.remove();
//self.__parentedParent.reload();
}
else {
$("#apikey").css({'background-color':'#F66 '})
self.notification.warn(_t("Linkedin Search"), _t("Please Enter Required Key."));
}
})
},
setTemplate: function( URL, AccountName ) {
if(AccountName){
var AccountName = AccountName.replace(/[^a-zA-Z 0-9]+/g, '');
Twitt = "https://twitter.com/intent/follow?original_referer=http%3A%2F%2Flocalhost%3A8069%2Fweb%2Fwebclient%2Fhome&screen_name="+AccountName+"&source=followbutton&variant=2.0"
this.$element.find('tr#profiletwittor-tr').append(QWeb.render('TwitterURL',{'URLID': Twitt, 'account': AccountName}))
}else if(URL){
this.$element.find('tr#profiletwittor-tr').append(QWeb.render('ProfileURL',{'URLID': URL }))
}
},
removeTemplate: function( flag ) {
if (flag) {
this.$element.find('#searchresults').remove();
} else {
if (this.$element.find('#profileid')) {
this.$element.find('#profileid').remove();
}
if (this.$element.find('#twitterid')) {
this.$element.find('#twitterid').remove();
}
}
},
/* Fetch Result from Linkedin and set in searchbox */
do_fetch_detail: function(result, metadata) {
var self = this;
if (result.people) {
if (result.people._total==0) {
this.msg_Counter++;
}
var count = 0;
for (i in result.people.values) {
var temp = self.validName(result.people.values[i].firstName, result.people.values[i].lastName)
if (temp) {
count++;
}
}
if (count == 4 || count==result.people._total) {
result.people._total = 0;
}
this.resultcontact = result;
}else if (result.companies) {
if (result.companies._total == 0) {
this.msg_Counter++;
}
this.resultcompany = result;
}
this.removeTemplate( 1 );
if (this.msg_Counter == 3) {
this.notification.warn(_t("Linkedin Search"), _t("Record Not Found."));
this.$element.find('#loader').hide();
self.linkedin_icon_color();
} else {
if (this.resultcontact || this.resultcompany) {
this.$element.find('#linkedin-field-name').append(QWeb.render( 'Linkedincontact', {'result' : this.resultcontact, 'resultcompany' : this.resultcompany})) ;
}
}
if(this.$element.find('#searchresults .search-box ul li')){
this.$element.find('#loader').hide();
self.linkedin_icon_color();
}
this.$element.find('#searchresults .search-box ul li').click( function() {
self.getdata( this );
});
$(document).click( function() {
self.removeTemplate( 1 );
});
},
/* Selected record's data fetched */
getdata: function( e ) {
var self = this;
if (this.resultcontact) {
for (i in this.resultcontact.people.values) {
if (self.resultcontact.people.values[i].id == $(e).attr('id')) {
self.removeTemplate( 1 );
this.getTwitterAccount( self.resultcontact.people.values[i] )
}
}
}
if(this.resultcompany){
for ( i in this.resultcompany.companies.values ) {
if ( self.resultcompany.companies.values[i].id == $(e).attr('id') ) {
self.removeTemplate( 1 );
self.map_values(self.resultcompany.companies.values[i]);
}
}
}
},
/* Based on Linkedin Id of record fetch Twitter Account Detail for People */
getTwitterAccount: function( values, flag, mainfield ){
var self = this;
IN.API.Profile(values.id).fields('twitter-accounts')
.result(function(acname){
values.twitterAccounts = acname.values[0].twitterAccounts
if(flag){
self.map_values(values, flag, mainfield);
}else{
self.map_values(values);
}
});
},
/* Mapping of Linkedin Fields with res.partner Fields
linkedinrecord : contains linkedin record's data
flag : indicates mapping of People search record or for company's contacts/connections (people)
if(flag) mapping for contacts of company
if(!flag) mapping for people search
mainfield : class of child_ids field
*/
map_values: function (linkedinrecord, flag, mainfield){
var self = this, tempdata = {}, temp_data = 0, id = this.view.datarecord.id;
_(this.view.fields).each(function (field, f) {
if (f=='name') {
if (!flag) {
if (linkedinrecord.formattedName) {
field.set_value(linkedinrecord['formattedName'] || false);
} else if(linkedinrecord.name) {
field.set_value(linkedinrecord['name'] || false);
}
} else {
tempdata[f] = linkedinrecord.firstName+' '+linkedinrecord.lastName;
}
}
else if (f=='property_account_payable') {
if(flag == 1)tempdata[f] = field.get_value()
}
else if (f=='property_account_receivable') {
if(flag == 1)tempdata[f] = field.get_value()
}
else if (f=='type') {
(flag == 1) ? tempdata[f] = field.get_value() : field.get_value();
}
else if (f=='linkedin_id') {
(flag == 1) ? tempdata[f] = linkedinrecord['id'] : field.set_value(linkedinrecord['id']);
}
else if (f=='profile_id') {
if (linkedinrecord.publicProfileUrl) {
(flag == 1) ? tempdata[f] = linkedinrecord.publicProfileUrl : field.set_value(linkedinrecord.publicProfileUrl);
} else {
field.set_value(false);
tempdata[f] = false;
}
}
else if (f=='twitter_id') {
if (linkedinrecord.twitterAccounts && linkedinrecord.twitterAccounts._total >= 1) {
(flag == 1) ? tempdata[f] = linkedinrecord.twitterAccounts.values[0].providerAccountName : field.set_value(linkedinrecord.twitterAccounts.values[0].providerAccountName);
}else if (linkedinrecord.twitterId) {
(flag == 1) ? tempdata[f] = linkedinrecord.twitterId : field.set_value(linkedinrecord.twitterId);
} else {
(flag == 1) ? tempdata[f] = false : field.set_value(false);
}
}
else if (f=='mobile') {
if (!flag && linkedinrecord.phoneNumbers && linkedinrecord['phoneNumbers']._total>=1 && linkedinrecord['phoneNumbers'].values[0].phoneType == "mobile") {
field.set_value( linkedinrecord['phoneNumbers'].values[0].phoneNumber || false );
}else if (flag == 1) {
tempdata[f] = field.get_value();
} else {
field.set_value(false);
}
}
else if (f=='phone') {
if (!flag && linkedinrecord.phoneNumbers && linkedinrecord['phoneNumbers']._total>=1 && linkedinrecord['phoneNumbers'].values[0].phoneType != "mobile") {
field.set_value(linkedinrecord['phoneNumbers'].values[0].phoneNumber || false);
} else if(flag == 1) {
tempdata[f] = field.get_value();
} else {
field.set_value(false);
}
}
else if (f=='email') {
if (!flag && linkedinrecord.imAccounts && linkedinrecord['imAccounts']._total>=1) {
field.set_value(linkedinrecord['imAccounts'].values[0].imAccountName);
} else if(flag == 1) {
tempdata[f] = field.get_value();
} else {
field.set_value(false);
}
}
else if (f=='photo') {
if (!flag) {
if (linkedinrecord.pictureUrl && linkedinrecord['pictureUrl']) {
/* Fetch binary data from URL for People */
self.rpc('/web_linkedin/binary/url2binary',{'url':linkedinrecord['pictureUrl']},function(data){
field.set_value(data);
});
} else if (linkedinrecord.logoUrl && linkedinrecord['logoUrl']) {
/* Fetch binary data from URL for Company */
self.rpc('/web_linkedin/binary/url2binary',{'url':linkedinrecord['logoUrl']},function(data){
field.set_value(data);
});
} else {
field.set_value(false);
}
}
else{
if (linkedinrecord['pictureUrl']) {
temp_data = 1;
/* Fetch binary data from URL for contact of Company */
self.rpc('/web_linkedin/binary/url2binary',{'url':linkedinrecord['pictureUrl']}).done(function(res){
tempdata[f] = res;
self.set_o2mdata(tempdata,mainfield)
});
} else {
tempdata[f] = "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABHNCSVQICAgIfAhki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W6fBQCYWZoF2pL4qOq721dNtkVd135nZ2dnMBhcXFtb+1ev13tz//79V1944QXZC/htEdhrZgDo NE11p9Ohy5cvz3rv50UkNcbEzrmYmZM4jlOlVBbHceq9BzMXzDyqqmqkta5EpGTmOkmSkfd+49ix Yzubm5v87rvvhpdeekmee+652z4XTPxfifbHvPG2V7wGgBvf5F7PftL2bxhUblkxIzmaAAAAAElF TkSuQmCC";
}
}
}
else if (f=='street') {
if (!flag && linkedinrecord.mainAddress && linkedinrecord['mainAddress']) {
field.set_value(linkedinrecord['mainAddress']);
} else if(flag == 1) {
tempdata[f] = field.get_value();
} else {
field.set_value(false);
}
}
else if (f=='country_id') {
if (!flag && linkedinrecord.location && linkedinrecord['location']) {
field.field.domain = [['code', '=', linkedinrecord['location'].country['code'].toUpperCase()]];
(new instance.web.DataSetSearch(self, field.field.relation,field.field.context,field.field.domain)).read_slice(['id','name'],{}).then(function(res){
field.original_value = [res[0].id, res[0].name];
field.set_value(res[0].id)
})
} else if (!flag && linkedinrecord.locations && linkedinrecord.locations._total>0) {
if (linkedinrecord.locations.values[0].address['country-code']) {
field.field.domain = ['code', '=', linkedinrecord.locations.values[0].address['country-code'].toUpperCase()];
(new instance.web.DataSetSearch(self, field.field.relation,field.field.context,field.field.domain)).read_slice(['id','name'],{}).then(function(res){
field.original_value = [res[0].id, res[0].name];
field.set_value(res[0].id)
})
} else {
field.set_value(false);
}
} else if(flag == 1) {
tempdata[f] = field.get_value();
} else {
field.set_value(false);
}
}
else if (f=='city') {
if (!flag && linkedinrecord.location && linkedinrecord['location']) {
field.set_value(linkedinrecord['location'].name.split(' ')[0] || false);
} else if (!flag && linkedinrecord.locations && linkedinrecord.locations._total>0) {
if (linkedinrecord.locations.values[0].address['city']) {
field.set_value(linkedinrecord.locations.values[0].address['city']);
} else {
field.set_value(false);
}
} else if (flag == 1) {
tempdata[f] = field.get_value();
} else {
field.set_value(false);
}
}
else if (f=='website') {
if (!flag && linkedinrecord.websiteUrl) {
field.set_value(linkedinrecord['websiteUrl'] || false);
} else if (flag == 1) {
tempdata[f] = field.get_value();
} else {
field.set_value(false);
}
}
else if (f=='customer') {
if(flag == 1)tempdata[f] = true;
}
else if (f=='supplier') {
}
else if (f=='active') {
(flag == 1) ? tempdata[f] = true : field.set_value(true);
}
else if (f=='is_company') {
if (!flag && linkedinrecord.formattedName) {
field.set_value(false);
} else {
field.set_value(true);
tempdata[f] = false;
}
}
else if (f=='zip') {
if (!flag && linkedinrecord.locations && linkedinrecord.locations._total>0) {
if (linkedinrecord.locations.values[0].address['postalCode']) {
field.set_value(linkedinrecord.locations.values[0].address['postalCode']);
} else {
field.set_value(false);
}
}else if (flag == 1) {
tempdata[f] = field.get_value();
} else {
field.set_value(false);
}
}
else if (f=='parent_id') {
if (!flag && linkedinrecord.formattedName) {
field.set_value(false);
} else if (!flag && linkedinrecord.name) {
field.set_value(false);
} else {
if (linkedinrecord.formattedName) {
tempdata[f] = [id,self.view.fields['name'].get_value()];
}
}
}
else if (f=='fax') {
if (!flag && linkedinrecord.locations && linkedinrecord.locations._total>0) {
if (linkedinrecord.locations.values[0].contactInfo['fax']) {
field.set_value(linkedinrecord.locations.values[0].contactInfo['fax']);
} else {
field.set_value(false);
}
} else if (flag == 1) {
tempdata[f] = field.get_value();
} else {
field.set_value(false);
}
}
else if (f=='use_parent_address') {
(flag == 1) ? tempdata[f] = true : field.set_value(false);
}
else if (f=='child_ids') {
/* For Company Set value of child_ids field */
if (!flag && linkedinrecord.name) {
self.$element.find('#loader').show();
$('.linkedin_icon').css('display', 'none');
/* Fetch contact of Company */
IN.API.Raw("/people-search:(people:(id,first-name,last-name,formatted-name,picture-url,publicProfileUrl,phone-numbers,im-accounts,main-address,location,relation-to-viewer:(related-connections)))")
//"id", "firstName", "lastName", "pictureUrl", "publicProfileUrl", "formatted-name", "headline", "location", "industry", "languages", "phone-numbers", "im-accounts", "main-address"
.params({
"company-name" : linkedinrecord.name,
"current-company": true,
"count" : 25
})
.result( function (getresult){
if(getresult.people._total==0){
self.$element.find('#loader').hide();
if(self.view.fields['linkedin_id']){
if(self.view.datarecord['linkedin_id']){
self.$element.find('#linkedindefault').hide();
self.$element.find('#linkedinrecord').show();
}else{
self.$element.find('#linkedinrecord').hide();
self.$element.find('#linkedindefault').show();
}
}
}
self.totalids = [],self.updteids = [];
_(field.dataset.ids).each( function(i) {
if (typeof(i)=="number") {
self.totalids.push(i);
var mobile = self.view.fields['mobile'].get_value();
var phone = self.view.fields['phone'].get_value();
var email = self.view.fields['email'].get_value();
var fax = self.view.fields['fax'].get_value();
var website = self.view.fields['website'].get_value();
var zip = self.view.fields['zip'].get_value();
var city = self.view.fields['city'].get_value();
var country_id = self.view.fields['country_id'].get_value();
var street = self.view.fields['street'].get_value();
field.dataset.write(i,{'mobile':mobile,'phone':phone,'email':email,'fax':fax,'website':website,'zip':zip,'city':city,'country_id':country_id,'street':street},{});
}
});
field.dataset.ids = self.totalids;
var counter = 0;/* Indicates All searched records are Invalid or valid */
self.t_count=0;
self.o2m_count = 0;
for (i in getresult.people.values) {
var connectTemp = self.validName(getresult.people.values[i].firstName, getresult.people.values[i].lastName)
if (connectTemp) {
counter++;
} else {
self.t_count++;
self.getTwitterAccount(getresult.people.values[i], 1, field);
}
}
if (getresult.people._count) {
var total_Count = getresult.people._count;
}else if (getresult.people._total) {
var total_Count = getresult.people._total;
}
/* If counter == total no. of people then all searched records are invalid */
if (counter == total_Count) {
field.dataset.to_create = [];
field.dataset.ids = [];
field.reload_current_view();
}else if(getresult.people._total == 0 || getresult.people._count == 0){
field.dataset.ids = self.totalids;
field.reload_current_view();
}
});
}
/* For People Set value of child_ids field */
else if (!flag && linkedinrecord.formattedName) {
field.set_value(false);
field.set({'invisible':true});
}
/* For Contact of company Set value of child_ids field */
else {
tempdata[f] = false;
}
}
else {
(flag == 1) ? tempdata[f] = false : field.set_value(false);
}
field._dirty_flag = true;
field.on('changed_value', self, function() {
if (!flag) {
self.view.do_onchange(field);
self.view.on_form_changed(true);
self.view.do_notify_change();
}
});
});
if (!flag) {
this.removeTemplate();
if (linkedinrecord.publicProfileUrl) {
this.setTemplate( linkedinrecord.publicProfileUrl , false );
}
if (linkedinrecord.twitterId) {
this.setTemplate( false , linkedinrecord.twitterId );
}
if (linkedinrecord.twitterAccounts && linkedinrecord.twitterAccounts._total >= 1) {
this.setTemplate( false , linkedinrecord.twitterAccounts.values[0].providerAccountName );
}
}
if (flag && temp_data == 0) {
self.set_o2mdata(tempdata, mainfield);
}
},
/* Update existing value of child_ids field */
set_childids: function( ids ) {
var self = this;
_(ids).each(function(i){
self.view.fields['child_ids'].dataset.set_ids(self.view.fields['child_ids'].dataset.ids.concat([i]));
self.view.fields['child_ids'].dataset.write(i, {"parent_id":false}, {});
});
},
/* Set/create o2m contacts of child_ids field */
set_o2mdata: function(data,field){
var self = this;
self.o2m_count++;
field.dataset.create(data).then( function(r) {
self.totalids.push(r.result);
field.dataset.set_ids(field.dataset.ids.concat([r.result]));
field.dataset.on_change();
}).then();
field.dataset.ids = self.totalids;
field.reload_current_view();
if (self.t_count == self.o2m_count) {
self.$element.find('#loader').hide();
self.linkedin_icon_color();
}
},
/* Name of Searched Linkedin Record is valid or Not */
validName: function(fname, lname){
if ((fname == "Private" || fname == "private") || (lname == "Private" || lname == "private") || (fname == "" && lname == "")) {
return true;
} else {
return false;
}
},
// Linkedin icon color changed to distinguise record based on linkedin or not.
linkedin_icon_color: function(e) {
if(this.view.fields['linkedin_id']){
if(this.view.datarecord['linkedin_id']){
this.$element.find('#linkedindefault').hide();
this.$element.find('#linkedinrecord').show();
}else{
this.$element.find('#linkedinrecord').hide();
this.$element.find('#linkedindefault').show();
}
}
},
// Add script of linkedin lib in head
add_ldn_script: function(key){
var self = this;
self.apikey = key;
var head = document.head || document.getElementsByTagName('head')[0];
var tag = document.createElement('script');
tag.setAttribute('id', 'addedScript');
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')) {
if ($(val).attr('src') == "http://platform.linkedin.com/in.js") {
temp = 1;
}
}
});
if (temp != 1 ) {
head.appendChild( tag );
}
}
});
};
// vim:et fdc=0 fdl=0:

View File

@ -1,150 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- vim:fdl=1:
-->
<templates id="template" xml:space="preserve">
<t t-name="Linkedin">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td width="100%" id="linkedin-field-name">
<t t-call="FieldChar"/>
</td>
<td id="linkedindiv" class="oe_form_group_cell" style="padding:0px;">
<div id="imagediv" name="search1">
<span style="display:inline;">
<a href="#">
<img id="linkedinrecord" class="linkedin_icon" src="/web_linkedin/static/src/img/Linkedin_blue.png" width="40" alt="Search on LinkedIn"/>
<img id="linkedindefault" class="linkedin_icon" src="/web_linkedin/static/src/img/Linkedin_grey.png" width="40" alt="Search on LinkedIn"/>
</a>
<img id="loader" class="loading" src="/web_linkedin/static/src/img/loading.png" width="24" height="24"/>
</span>
</div>
</td>
</tr>
<tr id="profiletwittor-tr"></tr>
</table>
</t>
<templates xml:space="preserve">
<t t-name="ProfileURL">
<td id="profileid">
<a t-att-href="URLID" target="_blank" id="profileid">
<img src="/web_linkedin/static/src/img/linkedin-profile.gif" width="130" height="24" border="0" alt="View profile on LinkedIn"/>
</a>
</td>
</t>
<t t-name="Register.Linkedin" style="height:300px;overflow:auto;">
<div>
<p style="color:grey;"> Connect OpneERP to LinkedIn to allow synchronizing companies and people with LinkedIn contacts in order to <br/>
get their data automatically (photos, address, news). You just need to setup the API key once, and it will work <br/>
for all users of your system.
</p>
<br/>
<p>1) Go to this URL:
<a href="https://www.linkedin.com/secure/developer" class="oe_secondary_menu_section" target="_blank">
https://www.linkedin.com/secure/developer
</a>
</p>
<p>2) Log you into LinkedIn if you din't yet</p>
<pre>
3) Add New Application and fill the form,
- JavaScript API Domain is Your domain name
(e.g. https://yourcompany.my.openerp.com),
- You can give multiple domain (e.g. yourcompany.my.openerp.com),
- programming tools is Javascript
</pre>
<p>4) Copy the API key here:
<input type="text" id="apikey"/><button id="register" style="margin-left:10px; color:white;" class="btn_api" >Apply</button>
</p>
</div>
</t>
<t t-name="TwitterURL">
<td id="twitterid">
<a t-att-href="URLID" target="_blank">
<img src="/web_linkedin/static/src/img/twitt-follow.png" width="100" height="24" border="0" alt="Follow"/>
</a>
</td>
</t>
<t t-name="SearchWarning">
<div>Record Not Found.</div>
</t>
<t t-name="Linkedincontact">
<div id="searchresults" class="openerp">
<div class="search-box" >
<table>
<t t-if="result and result.people._total>0">
<tr id="searchresultscontact">
<td width="70px;">
<span>
<label class="lbl-ldnbox"><b>Persons</b></label>
</span>
<br/>
</td>
<td>
<ul class="ul-ldn-dropdown">
<t t-if="result.people.values">
<li class="li-ldn-dropdown" t-foreach="result.people.values" t-as="data" t-if="(data.firstName!='' and data.firstName!='Private' and data.firstName!='private') or (data.lastName!='' and data.lastName!='Private' and data.lastName!='private')" t-att-id="data.id">
<table>
<tr>
<td>
<!-- picture url not always there, must be defensive -->
<t t-if="data.hasOwnProperty('pictureUrl')">
<img align='baseline' t-att-src="data.pictureUrl" width="30"/>
</t>
<t t-if="!data.hasOwnProperty('pictureUrl')">
<img align='baseline' width="30" src='http://static02.linkedin.com/scds/common/u/img/icon/icon_no_photo_80x80.png' />
</t>
</td>
<td>
<b><t t-esc="data.firstName+' '+data.lastName" /></b><br/>
<t t-esc="data.headline" />
</td>
</tr>
</table>
</li>
</t>
</ul>
</td>
</tr>
</t>
<t t-call="Linkedincompany" />
</table>
</div>
</div>
</t>
<t t-name="Linkedincompany">
<t t-if="resultcompany and resultcompany.companies._total>0">
<tr id="searchresultscompany">
<td width="70px;">
<span>
<label class="lbl-ldnbox"><b>Companies</b></label>
</span>
<br/>
</td>
<td>
<ul class="ul-ldn-dropdown">
<li class="li-ldn-dropdown" t-foreach="resultcompany.companies.values" t-as="data" t-att-id="data.id">
<table>
<tr>
<td>
<t t-if="data.hasOwnProperty('logoUrl')">
<img align='baseline' t-att-src="data.logoUrl" width="30" />
</t>
<t t-if="!data.hasOwnProperty('logoUrl')">
<img align='baseline' width="30" src='http://static02.linkedin.com/scds/common/u/img/icon/icon_no_photo_80x80.png' />
</t>
</td>
<td>
<b><t t-esc="data.name" /></b><br/>
<t t-esc="data.industry" />
</td>
</tr>
</table>
</li>
</ul>
</td>
</tr>
</t>
</t>
</templates>