diff options
| author | Martin Trigaux <mat@openerp.com> | 2013-12-20 15:45:21 +0100 |
|---|---|---|
| committer | Martin Trigaux <mat@openerp.com> | 2013-12-20 15:45:21 +0100 |
| commit | f77aefc07ace66587bc13f7d2fa55755968437c5 (patch) | |
| tree | ac8d29d536f2181258fb6cb6d76b5f8da8807afd /addons/gamification/static | |
| parent | 90dfa5895d61fae037046aea2b64b25d9903df15 (diff) | |
[REF] gamification: cleaning methods and reports
bzr revid: mat@openerp.com-20131220144521-wyu1gx8bcitu6nk4
Diffstat (limited to 'addons/gamification/static')
| -rw-r--r-- | addons/gamification/static/src/css/gamification.css | 6 | ||||
| -rw-r--r-- | addons/gamification/static/src/js/gamification.js | 55 | ||||
| -rw-r--r-- | addons/gamification/static/src/xml/gamification.xml | 78 |
3 files changed, 70 insertions, 69 deletions
diff --git a/addons/gamification/static/src/css/gamification.css b/addons/gamification/static/src/css/gamification.css index cc20afede80..fd39b130fad 100644 --- a/addons/gamification/static/src/css/gamification.css +++ b/addons/gamification/static/src/css/gamification.css @@ -73,7 +73,7 @@ width: 280px; border-radius: 2px; } -.openerp .oe_mail_wall .oe_mail_wall_aside > .oe_gamification_goal { +.openerp .oe_mail_wall .oe_mail_wall_aside .oe_gamification_challenge_list { background-color: #EDEDF6; } .openerp .oe_mail_wall_aside .oe_gamification_suggestion { @@ -188,7 +188,7 @@ width: 24px; padding-right: 5px; } -.openerp .oe_mail_wall .oe_mail_wall_aside .oe_goal .oe_update_plan.oe_e, +.openerp .oe_mail_wall .oe_mail_wall_aside .oe_goal .oe_update_challenge.oe_e, .openerp .oe_mail_wall .oe_mail_wall_aside .oe_goal .oe_goal_action.oe_e { visibility: hidden; font-size: 25px; @@ -196,7 +196,7 @@ /*margin-right: 15px;*/ position: relative; } -.openerp .oe_mail_wall .oe_mail_wall_aside .oe_goal div:hover > .oe_update_plan, +.openerp .oe_mail_wall .oe_mail_wall_aside .oe_goal div:hover > .oe_update_challenge, .openerp .oe_mail_wall .oe_mail_wall_aside .oe_goal div:hover > .oe_goal_action, .openerp .oe_mail_wall .oe_mail_wall_aside .oe_goal th:hover > .oe_goal_action { visibility: visible; diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 9e34d8f09fc..cf5b2228b08 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -2,12 +2,12 @@ openerp.gamification = function(instance) { var QWeb = instance.web.qweb; instance.gamification.Sidebar = instance.web.Widget.extend({ - template: 'gamification.user_wall_sidebar', + template: 'gamification.UserWallSidebar', init: function (parent, action) { var self = this; this._super(parent, action); this.deferred = $.Deferred(); - this.res_user = new instance.web.DataSetSearch(this, 'res.users'); + // this.res_user = new instance.web.DataSetSearch(this, 'res.users'); this.goals_info = {}; this.challenge_suggestions = {}; }, @@ -51,54 +51,53 @@ openerp.gamification = function(instance) { }); } }, - renderElement: function() { + start: function() { var self = this; this._super.apply(this, arguments); self.get_goal_todo_info(); self.get_challenge_suggestions(); }, - render_template: function(target,template) { - var self = this; - target.append(QWeb.render(template,{'widget': self})); - }, + // render_template: function(target,template) { + // var self = this; + // target.append(QWeb.render(template,{'widget': self})); + // }, render_template_replace: function(target,template) { var self = this; target.html(QWeb.render(template,{'widget': self})); }, get_goal_todo_info: function() { var self = this; - var goals_info = this.res_user.call('get_goals_todo_info', {}).then(function(res) { - self.goals_info['info'] = res; - }); - $.when(goals_info).done(function() { - if(self.goals_info.info.length > 0){ - self.render_template_replace(self.$el.filter(".oe_gamification_goal"),'gamification.goal_list_to_do'); - self.render_money_fields(self.goals_info.info[0].currency); - self.render_user_avatars(); + var challenges = new instance.web.Model('res.users').call('get_serialised_gamification_summary', []).then(function(result) { + if (result.length === 0) { + self.$el.find(".oe_gamification_challenge_list").hide(); } else { - self.$el.filter(".oe_gamification_goal").hide(); + _.each(result, function(item){ + console.log(item); + var $item = $(QWeb.render("gamification.ChallengeSummary", {challenge: item})); + self.render_money_fields($item); + self.render_user_avatars($item); + self.$el.find('.oe_gamification_challenge_list').append($item); + }); } }); }, get_challenge_suggestions: function() { var self = this; - var challenge_suggestions = this.res_user.call('get_challenge_suggestions', {}).then(function(res) { - self.challenge_suggestions['info'] = res; - }); - $.when(challenge_suggestions).done(function() { - if(self.challenge_suggestions.info.length > 0){ - self.render_template_replace(self.$el.filter(".oe_gamification_suggestion"),'gamification.challenge_suggestions'); + var challenge_suggestions = new instance.web.Model('res.users').call('get_challenge_suggestions', []).then(function(result) { + if (result.length === 0) { + self.$el.find(".oe_gamification_suggestion").hide(); } else { - self.$el.filter(".oe_gamification_suggestion").hide(); + var $item = $(QWeb.render("gamification.ChallengeSuggestion", {challenges: result})); + self.$el.find('.oe_gamification_suggestion').append($item); } }); }, - render_money_fields: function(currency_id) { + render_money_fields: function(item) { var self = this; - self.dfm = new instance.web.form.DefaultFieldManager(self); // Generate a FieldMonetary for each .oe_goal_field_monetary - self.$(".oe_goal_field_monetary").each(function() { + item.find(".oe_goal_field_monetary").each(function() { + var currency_id = parseInt( $(this).attr('data-id'), 10); money_field = new instance.web.form.FieldMonetary(self.dfm, { attrs: { modifiers: '{"readonly": true}' @@ -110,9 +109,9 @@ openerp.gamification = function(instance) { money_field.replace($(this)); }); }, - render_user_avatars: function() { + render_user_avatars: function(item) { var self = this; - self.$(".oe_user_avatar").each(function() { + item.find(".oe_user_avatar").each(function() { var user_id = parseInt( $(this).attr('data-id'), 10); var url = instance.session.url('/web/binary/image', {model: 'res.users', field: 'image_small', id: user_id}); $(this).attr("src", url); diff --git a/addons/gamification/static/src/xml/gamification.xml b/addons/gamification/static/src/xml/gamification.xml index 19c622dcb97..6316ca886f0 100644 --- a/addons/gamification/static/src/xml/gamification.xml +++ b/addons/gamification/static/src/xml/gamification.xml @@ -1,10 +1,12 @@ <templates> - <t t-name="gamification.user_wall_sidebar" class="oe_gamification_user_wall_sidebar"> - <div class="oe_gamification_suggestion"><em>No challenge suggestions</em></div> - <div class="oe_gamification_goal"><em>Your goal list is empty</em></div> + <t t-name="gamification.UserWallSidebar" class="oe_gamification_user_wall_sidebar"> + <div> + <div class="oe_gamification_suggestion"></div> + <div class="oe_gamification_challenge_list"></div> + </div> </t> - <t t-name="gamification.goal_list_to_do"> - <div t-foreach="widget.goals_info.info" t-as="challenge" class="oe_goal"> + <t t-name="gamification.ChallengeSummary"> + <div class="oe_goal"> <div> <a class="oe_update_challenge oe_e" rol="button" t-attf-id="{challenge.id}">e</a> <h4><t t-esc="challenge.name" /></h4> @@ -12,29 +14,29 @@ <t t-if="challenge.visibility_mode == 'personal'"> <div class="oe_table oe_goals_list"> - <div t-foreach="challenge.goals" t-as="goal" t-attf-class="oe_row oe_goal_outer_box #{goal.state == 'reached' ? 'oe_goal_reached' : ''} #{goal.definition_display != 'progress' ? 'oe_no_progress' : ''}"> - <t t-if="goal.definition_display == 'progress'"> + <div t-foreach="challenge.lines" t-as="line" t-attf-class="oe_row oe_goal_outer_box #{line.state == 'reached' ? 'oe_goal_reached' : ''} #{line.display_mode != 'progress' ? 'oe_no_progress' : ''}"> + <t t-if="line.display_mode == 'progress'"> <div class="oe_goal_progress_background"></div> - <div class="oe_goal_progress" t-attf-style="#{goal.definition_display == 'progress' ? 'width: '+goal.completeness+'%;' : 'width:0;'}"></div> - <div class="oe_cell oe_goal_current"><t t-esc="goal.current" /></div> + <div class="oe_goal_progress" t-attf-style="#{line.display_mode == 'progress' ? 'width: '+line.completeness+'%;' : 'width:0;'}"></div> + <div class="oe_cell oe_goal_current"><t t-esc="line.current" /></div> </t> <div class="oe_cell"> - <t t-if="goal.computation_mode != 'manually' and !goal.definition_action"> - <span t-att-title="goal.definition_description"><t t-esc="goal.definition_name" /></span> + <t t-if="line.computation_mode != 'manually' and !line.action"> + <span t-att-title="line.description"><t t-esc="line.name" /></span> </t> - <t t-if="goal.definition_action or goal.computation_mode == 'manually'"> - <span t-att-title="goal.definition_description"><a class="oe_goal_action" t-att-id="goal.id"><t t-esc="goal.definition_name" /></a></span> + <t t-if="line.action or line.computation_mode == 'manually'"> + <span t-att-title="line.description"><a class="oe_goal_action" t-att-id="line.id"><t t-esc="line.name" /></a></span> </t> - <t t-if="goal.definition_display == 'progress'"><br/> + <t t-if="line.display_mode == 'progress'"><br/> <div class="oe_grey"> - <t t-if="goal.definition_condition == 'higher'"> + <t t-if="line.definition_condition == 'higher'"> Target: </t> - <t t-if="goal.definition_condition == 'lower'"> + <t t-if="line.definition_condition == 'lower'"> Target: <= </t> - <span t-attf-class="#{goal.definition_monetary ? 'oe_goal_field_monetary' : ''}"><t t-esc="goal.target_goal"/></span> - <t t-if="goal.definition_suffix"><t t-esc="goal.definition_suffix"/></t> + <span t-attf-class="#{line.monetary ? 'oe_goal_field_monetary' : ''}" t-attf-data-id="#{line.monetary ? challenge.currency : ''}"><t t-esc="line.target"/></span> + <t t-if="line.suffix"><t t-esc="line.suffix"/></t> </div> </t> </div> @@ -45,8 +47,8 @@ <t t-if="challenge.visibility_mode == 'ranking'"> <div t-foreach="challenge.lines" t-as="line" class="oe_goals_list oe_table"> <div class="oe_row"> - <div class="oe_cell oe_thead" colspan="3" t-attf-title="#{line.definition_description ? line.definition_description : ''}"> - <strong><t t-esc="line.definition_name"/></strong> + <div class="oe_cell oe_thead" colspan="3" t-attf-title="#{line.description ? line.description : ''}"> + <strong><t t-esc="line.name"/></strong> <br/> <div class="oe_grey"> <t t-if="line.definition_condition == 'higher'"> @@ -55,39 +57,39 @@ <t t-if="line.definition_condition == 'lower'"> Target: <= </t> - <span t-attf-class="#{line.definition_monetary ? 'oe_goal_field_monetary' : ''}"><t t-esc="line.target_goal" /></span><t t-if="line.definition_suffix"> <t t-esc="line.definition_suffix"/></t> + <span t-attf-class="#{line.monetary ? 'oe_goal_field_monetary' : ''}" t-attf-data-id="#{line.monetary ? challenge.currency : ''}"><t t-esc="line.target" /></span><t t-if="line.suffix"> <t t-esc="line.suffix"/></t> </div> </div> </div> <div t-foreach="line.goals" t-as="goal" t-attf-class="#{goal.id == line.own_goal_id ? 'oe_bold' : ''}"> - <div t-attf-class="oe_row oe_goal_outer_box #{goal.state == 'reached' ? 'oe_goal_reached' : ''} #{line.definition_display != 'progress' ? 'oe_no_progress' : ''}"> - <t t-if="line.definition_display == 'progress'"> + <div t-attf-class="oe_row oe_goal_outer_box #{goal.state == 'reached' ? 'oe_goal_reached' : ''} #{line.display_mode != 'progress' ? 'oe_no_progress' : ''}"> + <t t-if="line.display_mode == 'progress'"> <div class="oe_goal_progress_background"></div> - <div class="oe_goal_progress" t-attf-style="#{line.definition_display == 'progress' ? 'width: '+goal.completeness+'%;' : 'width:0;'}"></div> + <div class="oe_goal_progress" t-attf-style="#{line.display_mode == 'progress' ? 'width: '+goal.completeness+'%;' : 'width:0;'}"></div> </t> <div class="oe_cell col0"><t t-esc="goal.rank" /></div> - <div class="oe_cell col1"><img class="oe_user_avatar" t-attf-alt="#{goal.user_name}" t-attf-data-id="#{goal.user_id}"/></div> + <div class="oe_cell col1"><img class="oe_user_avatar" t-attf-alt="#{goal.name}" t-attf-data-id="#{goal.user_id}"/></div> <div class="oe_cell col2"> - <t t-if="line.definition_display == 'progress'"> + <t t-if="line.display_mode == 'progress'"> <!-- progress, action on current value --> - <t t-esc="goal.user_name"/><br/> - <t t-if="goal.id != line.own_goal_id or (line.computation_mode != 'manually' and !line.definition_action)"> - <span t-attf-class="#{line.definition_monetary ? 'oe_goal_field_monetary' : ''}"><t t-esc="goal.current" /></span><t t-if="line.definition_suffix"> <t t-esc="line.definition_suffix"/></t> + <t t-esc="goal.name"/><br/> + <t t-if="goal.id != line.own_goal_id or (line.computation_mode != 'manually' and !line.action)"> + <span t-attf-class="#{line.monetary ? 'oe_goal_field_monetary' : ''}" t-attf-data-id="#{line.monetary ? challenge.currency : ''}"><t t-esc="goal.current" /></span><t t-if="line.suffix"> <t t-esc="line.suffix"/></t> </t> - <t t-if="goal.id == line.own_goal_id and (line.definition_action or line.computation_mode == 'manually')"> + <t t-if="goal.id == line.own_goal_id and (line.action or line.computation_mode == 'manually')"> <a class="oe_goal_action" t-att-id="line.own_goal_id"> - <span t-attf-class="#{line.definition_monetary ? 'oe_goal_field_monetary' : ''}"><t t-esc="goal.current" /></span><t t-if="line.definition_suffix"> <t t-esc="line.definition_suffix"/></t> + <span t-attf-class="#{line.monetary ? 'oe_goal_field_monetary' : ''}" t-attf-data-id="#{line.monetary ? challenge.currency : ''}"><t t-esc="goal.current" /></span><t t-if="line.suffix"> <t t-esc="line.suffix"/></t> </a> </t> </t> - <t t-if="line.definition_display != 'progress'"> + <t t-if="line.display_mode != 'progress'"> <!-- not progress, action on user name --> - <t t-if="goal.id != line.own_goal_id or (line.computation_mode != 'manually' and !line.definition_action)"> - <t t-esc="goal.user_name"/> + <t t-if="goal.id != line.own_goal_id or (line.computation_mode != 'manually' and !line.action)"> + <t t-esc="goal.name"/> </t> - <t t-if="goal.id == line.own_goal_id and (line.definition_action or line.computation_mode == 'manually')"> - <a class="oe_goal_action" t-att-id="line.own_goal_id"><t t-esc="goal.user_name"/></a> + <t t-if="goal.id == line.own_goal_id and (line.action or line.computation_mode == 'manually')"> + <a class="oe_goal_action" t-att-id="line.own_goal_id"><t t-esc="goal.name"/></a> </t> </t> </div> @@ -98,10 +100,10 @@ </div> </t> - <t t-name="gamification.challenge_suggestions"> + <t t-name="gamification.ChallengeSuggestion"> <div class="oe_goal"> <h4>Invited Challenges</h4> - <ul t-foreach="widget.challenge_suggestions.info" t-as="challenge" class="oe_goals_list"> + <ul t-foreach="challenges" t-as="challenge" class="oe_goals_list"> <li> <strong><a class="oe_challenge_reply" t-attf-title="#{challenge.description.value ? challenge.description.value : ''}" t-attf-id="{challenge.id}" title="more details..."><t t-esc="challenge.name"/></a></strong> </li> |
