[IMP] action button (almost working)
bzr revid: mat@openerp.com-20130324180557-ttos23t09uayh6zx
This commit is contained in:
parent
c22dd46610
commit
8a04406a28
|
@ -309,25 +309,22 @@ class gamification_goal(osv.Model):
|
|||
"""Get the ir.action related to update the goal
|
||||
|
||||
In case of a manual goal, should return a wizard to update the value
|
||||
:return: dict like
|
||||
{
|
||||
'name':'Action name',
|
||||
'id': goal_id,
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': goal.type_id.model_id,
|
||||
'view': 'form',
|
||||
}
|
||||
:return: action description in a dictionnary
|
||||
"""
|
||||
goal = self.browse(cr, uid, goal_id, context=context)
|
||||
action = {
|
||||
'name': "Update %s" % goal.type_id.name,
|
||||
'id': goal_id,
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
if goal.computation_mode == 'manually':
|
||||
action['res_model'] = 'gamification.goal.wizard'
|
||||
action['views'] = [[False, 'form']]
|
||||
action['context'] = {'default_goal_id': goal_id, 'default_current': goal.current},
|
||||
else:
|
||||
action['res_model'] = goal.type_id.model_id # TOCHECK
|
||||
action['res_model'] = goal.type_id.model_id.model
|
||||
action['views'] = [[False, 'tree']]
|
||||
return action
|
||||
|
||||
|
||||
|
@ -336,5 +333,22 @@ class goal_manual_wizard(osv.TransientModel):
|
|||
_name = 'gamification.goal.wizard'
|
||||
_columns = {
|
||||
'goal_id': fields.many2one("gamification.goal", string='Goal'),
|
||||
'current': fields.text('Current'),
|
||||
'current': fields.float('Current'),
|
||||
}
|
||||
|
||||
def action_update_current(self, cr, uid, ids, context=None):
|
||||
"""Wizard action for updating the current value"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
goal_obj = self.pool.get('gamification.goal')
|
||||
|
||||
for wiz in self.browse(cr, uid, ids, context=context):
|
||||
towrite = {
|
||||
'current': wiz.current,
|
||||
'goal_id': wiz.goal_id.id,
|
||||
}
|
||||
print(towrite)
|
||||
goal_obj.write(cr, uid, [wiz.goal_id.id], towrite, context=context)
|
||||
goal_obj.update(cr, uid, [wiz.goal_id.id], context=context)
|
||||
return {}
|
||||
|
|
|
@ -246,6 +246,26 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_goal_wizard_update_current" model="ir.ui.view">
|
||||
<field name="name">Update the current value of the Goal</field>
|
||||
<field name="model">gamification.goal.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Grant Badge To" version="7.0">
|
||||
Set the current value you have reached for this goal
|
||||
<group>
|
||||
<field name="goal_id" invisible="1"/>
|
||||
<field name="current" />
|
||||
</group>
|
||||
<footer>
|
||||
<button string="Update" type="object" name="action_update_current" class="oe_highlight" /> or
|
||||
<button string="Cancel" special="cancel" class="oe_link"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!-- menus in settings - technical feature required -->
|
||||
<menuitem id="gamification_menu" name="Gamification Tools" parent="base.menu_administration" groups="base.group_no_one" />
|
||||
<menuitem id="gamification_goal_menu" parent="gamification_menu" action="goal_list_action" sequence="0"/>
|
||||
|
|
|
@ -27,29 +27,16 @@ openerp.gamification = function(instance) {
|
|||
'click a.oe_goal_action': function(event) {
|
||||
var self = this;
|
||||
var goal_id = parseInt(event.currentTarget.id);
|
||||
var goal_action = new instance.web.Model('gamification.goal').call('get_action', [goal_id]);
|
||||
|
||||
var goal_action = new instance.web.Model('gamification.goal').call('get_action', [goal_id]).then(function(res) {
|
||||
goal_action['action'] = res;
|
||||
});
|
||||
$.when(goal_action).done(function() {
|
||||
console.log(goal_action);
|
||||
// var action = {
|
||||
// name : 'Complete Profile',
|
||||
// type: 'ir.actions.act_window',
|
||||
// res_model: 'res.users',
|
||||
// views: [[false, 'form']],
|
||||
// res_id : event.data.uid,
|
||||
// target: 'new',
|
||||
// flags : { action_buttons: true },
|
||||
// };
|
||||
// var action_manager = new instance.web.ActionManager(this);
|
||||
// action_manager.do_action(action);
|
||||
// var form = action_manager.dialog_widget.views.form.controller;
|
||||
// form.on('load_record', self, function(){
|
||||
// form.fields[$(self).attr('id')].$el.find("input").focus()
|
||||
// })
|
||||
// form.on("on_button_cancel", action_manager.dialog, action_manager.dialog.close);
|
||||
// form.on('save', self, function() {
|
||||
// action_manager.dialog.close();
|
||||
// location.reload();
|
||||
// });
|
||||
var action_manager = new instance.web.ActionManager(this);
|
||||
action_manager.do_action(goal_action.action);
|
||||
|
||||
//var form = action_manager.dialog_widget.views.form.controller;
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue