summaryrefslogtreecommitdiff
path: root/addons/hr/static/src
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2013-05-15 12:35:18 +0200
committerThibault Delavallée <tde@openerp.com>2013-05-15 12:35:18 +0200
commit0525c965a9aa4f86d77c76ec272f864e3614ff51 (patch)
treed914b1fba6f21e7215ad1621c84bb435babdeb45 /addons/hr/static/src
parent863ad714898182776be3c0f85e8f588fbb70b1d5 (diff)
[CLEAN] [REF] mail, hr: cleaned JS/CSS/XML code for suggestion widgets. Those are now 2 widgets extending web.Widget, included inside a Sidebar widget.
bzr revid: tde@openerp.com-20130515103518-2djzogjdtjh0n7rl
Diffstat (limited to 'addons/hr/static/src')
-rw-r--r--addons/hr/static/src/js/suggestions.js107
-rw-r--r--addons/hr/static/src/xml/suggestions.xml42
2 files changed, 66 insertions, 83 deletions
diff --git a/addons/hr/static/src/js/suggestions.js b/addons/hr/static/src/js/suggestions.js
index 294143da733..3bc37e71344 100644
--- a/addons/hr/static/src/js/suggestions.js
+++ b/addons/hr/static/src/js/suggestions.js
@@ -3,89 +3,76 @@ openerp.hr = function(session) {
var QWeb = session.web.qweb;
var suggestions = session.suggestions;
- var removed_suggested_employee = session.removed_suggested_employee = [];
- suggestions.Employees = session.mail.Wall.include({
+ var removed_suggested_employee = session.suggestions.removed_suggested_employee = [];
+
+ suggestions.Employees = session.web.Widget.extend({
events: {
- 'click .oe_remove_suggestion_employees': "remove_suggestion_employees",
- 'click .oe_remove_suggested_employee': "remove_suggested_employee",
- 'click .oe_follow_employee': "follow_employee",
- 'click .oe_open_employee': "open_employee"
+ 'click .oe_suggestion_remove.oe_suggestion_employee': 'stop_employee_suggestion',
+ 'click .oe_suggestion_remove_item.oe_suggestion_employee': 'remove_employee_suggestion',
+ 'click .oe_suggestion_follow': 'follow_employee',
},
- init: function (parent, action) {
- var self = this;
- this._super(parent, action);
- this.deferred = $.Deferred();
+
+ init: function () {
+ this._super(this, arguments);
this.hr_employee = new session.web.DataSetSearch(this, 'hr.employee');
this.res_users = new session.web.DataSetSearch(this, 'res.users');
- this.suggestions = [];
+ this.employees = [];
},
- start: function() {
- var tmp = this._super.apply(this, arguments);
- var self = this;
- var res = self.get_suggested_employee();
- $.when(res).done(function() {});
- return tmp;
+ start: function () {
+ this._super.apply(this, arguments);
+ return this.fetch_suggested_employee();
},
- get_suggested_employee: function () {
+
+ fetch_suggested_employee: function () {
var self = this;
- var employee = self.hr_employee.call('get_suggested_thread', {'removed_suggested_threads':removed_suggested_employee}).then(function(res) {
- _(res).each(function(result) {
+ var employee = self.hr_employee.call('get_suggested_thread', {'removed_suggested_threads': removed_suggested_employee}).then(function (res) {
+ _(res).each(function (result) {
result['image']=self.session.url('/web/binary/image', {model: 'hr.employee', field: 'image_small', id: result.id});
});
- self.suggestions = res;
- });
- return $.when(employee).done(function() {
- self.$el.find('.oe_suggestions_employees').html( QWeb.render("hr.suggestions.employee", {'widget': self}) );
- if (self.suggestions.length === 0) {
- self.$(".oe_sidebar_employee").hide();
- }
- });
- },
- renderFollowButtons: function() {
- var self = this;
- self.dfm = new session.web.form.DefaultFieldManager(self);
- // Generate a FieldMonetary for each .oe_goal_field_monetary
- self.$el.find(".oe_follow_employee").each(function() {
- follower_field = new session.mail_followers.Followers(self.dfm, {
- attrs: {
- view: self.view
- }
- });
- follower_field.set('value', parseInt($(this).text(), 10));
- // follower_field.replace($(this));
+ self.employees = res;
});
+ return $.when(employee).done(this.proxy('display_suggested_employees'));
},
- open_employee:function(event) {
- var self = this;
- var id = JSON.parse($(event.currentTarget).attr("id"));
- action = {
- type: 'ir.actions.act_window',
- res_model: 'hr.employee',
- res_id: id,
- views: [[false, 'form']],
- target: 'current'
- };
- this.do_action(action);
+
+ display_suggested_employees: function () {
+ var suggested_employees = this.$('.oe_sidebar_suggestion.oe_suggestion_employee');
+ if (suggested_employees) {
+ suggested_employees.remove();
+ }
+ if (this.employees.length === 0) {
+ return this.$el.empty();
+ }
+ return this.$el.empty().html(QWeb.render('hr.suggestions.employees', {'widget': this}));
},
- follow_employee:function(event) {
+
+ follow_employee: function (event) {
var self = this;
- employee_id = parseInt($(event.currentTarget).attr('id'), 10);
+ var employee_id = parseInt($(event.currentTarget).attr('id'), 10);
return this.hr_employee.call('message_subscribe_users', [[employee_id], [this.session.uid], undefined]).then(function(res) {
- self.get_suggested_employee();
+ self.fetch_suggested_employee();
});
},
- remove_suggested_employee: function(event) {
- var self = this;
+
+ remove_employee_suggestion: function (event) {
removed_suggested_employee.push($(event.currentTarget).attr('id'));
- self.get_suggested_employee();
+ return this.fetch_suggested_employee();
},
- remove_suggestion_employees: function(event) {
+
+ stop_employee_suggestion: function (event) {
var self = this;
return this.res_users.call('stop_showing_employees_suggestions', [this.session.uid]).then(function(res) {
- self.$(".oe_sidebar_employee").hide();
+ self.$(".oe_sidebar_suggestion.oe_suggestion_employee").hide();
});
}
});
+ session.mail.WallSidebar.include({
+ start: function () {
+ this._super.apply(this, arguments);
+ var sug_employees = new suggestions.Employees(this);
+ return sug_employees.appendTo(this.$('.oe_suggestions_employees'));
+ },
+ });
+
};
diff --git a/addons/hr/static/src/xml/suggestions.xml b/addons/hr/static/src/xml/suggestions.xml
index a4c949ae7ad..f3095627bae 100644
--- a/addons/hr/static/src/xml/suggestions.xml
+++ b/addons/hr/static/src/xml/suggestions.xml
@@ -1,40 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
- <t t-extend="mail.suggestions">
- <t t-jquery=".oe_suggestions_groups" t-operation="after">
- <div class="oe_suggestions_employees">No employee</div>
+ <!-- Employees placeholder in sidebar -->
+ <t t-extend="mail.wall.sidebar">
+ <t t-jquery=".oe_mail_wall_sidebar" t-operation="append">
+ <div class="oe_suggestions_employees"></div>
</t>
</t>
<!-- Suggested employees -->
- <div t-name="hr.suggestions.employee" class="oe_sidebar_suggestion oe_sidebar_employee">
- <p class="oe_suggestion_display">
- Suggested Employees
- <a class="oe_remove_suggestion oe_remove_suggestion_employees" rol="button">
- <span class="oe_kanban_action oe_kanban_action_a">X</span>
- </a>
- </p>
- <div class="oe_suggest_employees">
- <t t-foreach="widget.suggestions" t-as="result">
+ <div t-name="hr.suggestions.employees" class="oe_sidebar_suggestion oe_suggestion_employee">
+ <div class="oe_suggest_title">
+ <a class="oe_suggestion_remove oe_suggestion_employee oe_e">X</a>
+ <h2>Suggested Employees</h2>
+ </div>
+ <div class="oe_suggest_items">
+ <t t-foreach="widget.employees" t-as="result">
<div class="oe_suggested_item">
- <div class="oe_item_image">
- <img class="oe_item_image_content oe_open_employee" t-attf-src="{result.image}" t-attf-id="{result.id}"/>
- </div>
- <div class="oe_item">
- <a class="oe_item_name oe_open_employee" t-attf-id="{result.id}">
- <t t-esc="result.name"/>
- </a>
- <a class="oe_remove_suggested_item oe_remove_suggested_employee" rol="button" t-attf-id="{result.id}">
- <span class="oe_kanban_action oe_kanban_action_a">X</span>
+ <div class="oe_suggested_item_image">
+ <a t-attf-href="#model=hr.employee&amp;id=#{result.id}">
+ <img t-attf-src="{result.image}" t-attf-alt="{result.name}"/>
</a>
+ </div>
+ <div class="oe_suggested_item_content">
+ <a class="oe_suggestion_item_name" t-attf-href="#model=hr.employee&amp;id=#{result.id}"><t t-esc="result.name"/></a>
+ <a class="oe_suggestion_remove_item oe_suggestion_employee oe_e" t-attf-id="{result.id}">X</a>
<br/>
- <button class="oe_suggestion_action oe_follow_employee" t-att-id="result.id">Follow</button>
+ <button class="oe_suggestion_follow" t-att-id="result.id">Follow</button>
</div>
</div>
</t>
</div>
</div>
-
</template>