[ADD] preferences window
bzr revid: xmo@openerp.com-20110901133812-d4exisg1zlg1kgg1
This commit is contained in:
commit
9acba3027f
|
@ -298,7 +298,21 @@ class Session(openerpweb.Controller):
|
|||
"uid": req.session._uid,
|
||||
"context": ctx
|
||||
}
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def change_password (self,req,fields):
|
||||
old_password, new_password,confirm_password = operator.itemgetter('old_pwd', 'new_password','confirm_pwd')(
|
||||
dict(map(operator.itemgetter('name', 'value'), fields)))
|
||||
if not (old_password.strip() and new_password.strip() and confirm_password.strip()):
|
||||
return {'error':'All passwords have to be filled.','title': 'Change Password'}
|
||||
if new_password != confirm_password:
|
||||
return {'error': 'The new password and its confirmation must be identical.','title': 'Change Password'}
|
||||
try:
|
||||
if req.session.model('res.users').change_password(
|
||||
old_password, new_password):
|
||||
return {'new_password':new_password}
|
||||
except:
|
||||
return {'error': 'Original password incorrect, your password was not changed.', 'title': 'Change Password'}
|
||||
return {'error': 'Error, password not changed !', 'title': 'Change Password'}
|
||||
@openerpweb.jsonrequest
|
||||
def sc_list(self, req):
|
||||
return req.session.model('ir.ui.view_sc').get_sc(
|
||||
|
|
|
@ -576,6 +576,7 @@ openerp.base.Header = openerp.base.Widget.extend({
|
|||
this.$content = $(QWeb.render("Header-content", {widget: this}));
|
||||
this.$content.appendTo(this.$element);
|
||||
this.$element.find(".logout").click(this.on_logout);
|
||||
this.$element.find("a.preferences").click(this.on_preferences);
|
||||
return this.shortcut_load();
|
||||
},
|
||||
do_reset: function() {
|
||||
|
@ -634,9 +635,98 @@ openerp.base.Header = openerp.base.Widget.extend({
|
|||
});
|
||||
});
|
||||
},
|
||||
|
||||
on_action: function(action) {
|
||||
},
|
||||
|
||||
on_preferences: function(){
|
||||
var self = this;
|
||||
var action_manager = new openerp.base.ActionManager(this);
|
||||
var dataset = new openerp.base.DataSet (this,'res.users',this.context);
|
||||
dataset.call ('action_get','',function (result){
|
||||
self.rpc('/base/action/load', {action_id:result}, function(result){
|
||||
action_manager.do_action(_.extend(result['result'], {
|
||||
res_id: self.session.uid,
|
||||
res_model: 'res.users',
|
||||
flags: {
|
||||
action_buttons: false,
|
||||
search_view: false,
|
||||
sidebar: false,
|
||||
views_switcher: false,
|
||||
pager: false
|
||||
}
|
||||
}));
|
||||
});
|
||||
});
|
||||
this.dialog = new openerp.base.Dialog(this,{
|
||||
modal: true,
|
||||
title: 'Preferences',
|
||||
width: 600,
|
||||
height: 500,
|
||||
buttons: {
|
||||
"Change password": function(){
|
||||
self.change_password();
|
||||
},
|
||||
Cancel: function(){
|
||||
$(this).dialog('destroy');
|
||||
},
|
||||
Save: function(){
|
||||
var inner_viewmanager = action_manager.inner_viewmanager;
|
||||
inner_viewmanager.views[inner_viewmanager.active_view].controller.do_save(function(){
|
||||
inner_viewmanager.start();
|
||||
});
|
||||
$(this).dialog('destroy')
|
||||
}
|
||||
}
|
||||
});
|
||||
this.dialog.start().open();
|
||||
action_manager.appendTo(this.dialog);
|
||||
action_manager.render(this.dialog);
|
||||
},
|
||||
|
||||
change_password :function() {
|
||||
var self = this;
|
||||
this.dialog = new openerp.base.Dialog(this,{
|
||||
modal : true,
|
||||
title : 'Change Password',
|
||||
width : 'auto',
|
||||
height : 'auto'
|
||||
});
|
||||
this.dialog.start().open();
|
||||
this.dialog.$element.html(QWeb.render("Change_Pwd", self));
|
||||
this.dialog.$element.find("form[name=change_password_form]").validate({
|
||||
submitHandler: function (form) {
|
||||
self.rpc("/base/session/change_password",{
|
||||
'fields': $(form).serializeArray()
|
||||
}, function(result) {
|
||||
if (result.error) {
|
||||
self.display_error(result);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (result.new_password) {
|
||||
self.session.password = result.new_password;
|
||||
var session = new openerp.base.Session(self.session.server, self.session.port);
|
||||
session.start();
|
||||
session.session_login(self.session.db, self.session.login, self.session.password)
|
||||
}
|
||||
}
|
||||
self.notification.notify("Changed Password", "Password has been changed successfully");
|
||||
self.dialog.close();
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
display_error: function (error) {
|
||||
return $('<div>').dialog({
|
||||
modal: true,
|
||||
title: error.title,
|
||||
buttons: {
|
||||
Ok: function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
}).html(error.error);
|
||||
},
|
||||
on_logout: function() {
|
||||
this.$element.find('.oe-shortcuts ul').empty();
|
||||
}
|
||||
|
|
|
@ -1363,4 +1363,28 @@
|
|||
<td><button class="oe_export_button_export" id="delete_export_list">Delete</button></td>
|
||||
</tr>
|
||||
</t>
|
||||
<t t-name="Change_Pwd">
|
||||
<form name="change_password_form" class="oe_forms" method="POST">
|
||||
<table align="center">
|
||||
<tr>
|
||||
<td><label for="old_pwd">Old Password:</label></td>
|
||||
<td><input type="password" name="old_pwd"
|
||||
minlength="1" autofocus="autofocus"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="new_password">New Password:</label></td>
|
||||
<td><input type="password" name="new_password"
|
||||
minlength="1" autofocus="autofocus"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="confirm_pwd">Confirm Password:</label></td>
|
||||
<td><input type="password" name="confirm_pwd"
|
||||
minlength="1"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" align="right"><input type="submit" value="Change Password"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</t>
|
||||
</templates>
|
||||
|
|
Loading…
Reference in New Issue