From e9f1287d7eeff3ef7f39511aa0ad5b6bf3ef70c6 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 22 Aug 2012 11:10:13 +0200 Subject: [PATCH] [IMP] web_linkedin: changed way people and companies are presented bzr revid: nicolas.vanhoren@openerp.com-20120822091013-dsfz80vn7b1r2kht --- addons/web_linkedin/static/src/js/linkedin.js | 43 ++++++++++--------- .../web_linkedin/static/src/xml/linkedin.xml | 5 ++- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/addons/web_linkedin/static/src/js/linkedin.js b/addons/web_linkedin/static/src/js/linkedin.js index 8fcc17ba41e..483452d4278 100644 --- a/addons/web_linkedin/static/src/js/linkedin.js +++ b/addons/web_linkedin/static/src/js/linkedin.js @@ -155,7 +155,7 @@ openerp.web_linkedin = function(instance) { } }); var positions = entity.positions.values || []; - to_change.function = positions ? positions[0].title : false; + to_change.function = positions.length > 0 ? positions[0].title : false; /* TODO to_change.linkedinUrl = entity.publicProfileUrl; */ @@ -177,7 +177,7 @@ openerp.web_linkedin = function(instance) { init: function(parent, text) { this._super(parent, {title:_t("LinkedIn search")}); this.text = text; - this.limit = 15; + this.limit = 5; }, start: function() { this._super(); @@ -197,38 +197,41 @@ openerp.web_linkedin = function(instance) { encodeURI(this.text), this.limit)).result(function (result) { cdef.resolve(result); }); + var def = cdef.pipe(function(companies) { + var lst = companies.companies.values || []; + lst = _.first(lst, self.limit); + lst = _.map(lst, function(el) { + el.__type = "company"; + return el; + }); + console.debug("Linkedin companies found:", lst.length, lst); + return self.display_result(lst, self.$(".oe_linkedin_pop_c")); + }); IN.API.PeopleSearch().fields(commonPeopleFields). params({"keywords": this.text, "count": this.limit}).result(function(result) { pdef.resolve(result); }); - return $.when(cdef, pdef).then(function(companies, people) { - var lst = companies.companies.values || []; + var def2 = pdef.pipe(function(people) { var plst = people.people.values || []; - lst = _.initial(lst, _.min([self.limit / 2, plst.length])); - _.map(lst, function(el) { - el.__type = "company"; - return el; - }); - plst = _.first(plst, self.limit - lst.length) - _.map(plst, function(el) { + plst = _.first(plst, self.limit); + plst = _.map(plst, function(el) { el.__type = "people"; return el; }); - lst = plst.concat(lst); - console.log("Linkedin search found:", lst.length, lst); - self.result = lst; - self.display_result(); + console.debug("Linkedin people found:", plst.length, plst); + return self.display_result(plst, self.$(".oe_linkedin_pop_p")); }); + return $.when(def, def2); }, - display_result: function() { + display_result: function(result, $elem) { var self = this; var i = 0; var $row; - _.each(self.result, function(el) { + _.each(result, function(el) { var pc = new instance.web_linkedin.EntityWidget(self, el); if (i % 5 === 0) { $row = $("
"); - $row.appendTo(self.$(">div")); + $row.appendTo($elem); } pc.appendTo($row); pc.$element.css("display", "table-cell"); @@ -239,8 +242,8 @@ openerp.web_linkedin = function(instance) { }); i++; }); - if (self.result.length === 0) { - self.$(">div").text(_t("No results found")); + if (result.length === 0) { + $elem.text(_t("No results found")); } }, }); diff --git a/addons/web_linkedin/static/src/xml/linkedin.xml b/addons/web_linkedin/static/src/xml/linkedin.xml index 998918a174c..30a7abb3443 100644 --- a/addons/web_linkedin/static/src/xml/linkedin.xml +++ b/addons/web_linkedin/static/src/xml/linkedin.xml @@ -10,7 +10,10 @@
-
+

People

+
+

Companies

+