Vishmita Jadeja (openerp) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-preferences-vja into lp:openerp-web.

Requested reviews:
  OpenERP R&D Web Team (openerp-dev-web)

For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-preferences-vja/+merge/72534

-Implement Preference functionality.
-User can change there password using change password.
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-preferences-vja/+merge/72534
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openerp-web/trunk-preferences-vja.
=== modified file 'addons/base/controllers/main.py'
--- addons/base/controllers/main.py	2011-08-19 03:02:35 +0000
+++ addons/base/controllers/main.py	2011-08-23 07:48:25 +0000
@@ -278,7 +278,7 @@
         except xmlrpclib.Fault, e:
             if e.faultCode and e.faultCode.split(':')[0] == 'AccessDenied':
                 return {'error': e.faultCode, 'title': 'Change Password'}
-        return {'error': 'Error, password not changed !', 'title': 'Change Password'}
+                return {'error': 'Error, password not changed !', 'title': 'Change Password'}
 
 class Session(openerpweb.Controller):
     _cp_path = "/base/session"
@@ -293,7 +293,19 @@
             "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_pwd','confirm_pwd')(
+                dict(map(operator.itemgetter('name', 'value'), fields)))
+        try:
+            if req.session.model('res.users').change_password(
+                old_password, new_password):
+                req.session.password = new_password
+            return dict(changed=True)
+            raise redirect('/')
+        except xmlrpclib.Fault, e:
+            return {'error': 'Original password incorrect, your password was not changed.', 'title': 'Change Password'}
+            
     @openerpweb.jsonrequest
     def sc_list(self, req):
         return req.session.model('ir.ui.view_sc').get_sc(

=== modified file 'addons/base/static/src/js/chrome.js'
--- addons/base/static/src/js/chrome.js	2011-08-22 16:34:32 +0000
+++ addons/base/static/src/js/chrome.js	2011-08-23 07:48:25 +0000
@@ -573,6 +573,7 @@
     do_update: function () {
         this.$element.html(QWeb.render("Header", this));
         this.$element.find(".logout").click(this.on_logout);
+        this.$element.find("a.preferences").click(this.on_preferences);
         return this.shortcut_load();
     },
     shortcut_load :function(){
@@ -622,9 +623,98 @@
                 });
         });
     },
+    
     on_action: function(action) {
     },
-
+    on_preferences: function(){
+        var self = this;
+        var action_manager = new openerp.base.ActionManager(this);
+        this.rpc('/base/dataset/call', {model: 'res.users',method:"action_get",args: []},function(result){
+            self.rpc('/base/action/load', { action_id: result}, function(result){
+                result['result']['res_id'] = self.session.uid;
+                result['result']['res_model']= 'res.users';
+                result['result']['view_id']=result['result']['views'][0][0];
+                result['result']['flags']['action_buttons']=false;
+                result['result']['flags']['search_view']=false;
+                result['result']['flags']['sidebar']=false;
+                result['result']['view_mode']="form";
+                result['result']['flags']['views_switcher']=false;
+                result['result']['flags']['pager']=false;
+                action_manager.do_action(result['result']);
+            });
+     });
+        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();
+       this.dialog.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();
+        this.dialog.open();
+        this.dialog.$element.html(QWeb.render("Change_Pwd", self));
+        this.dialog.$element.find("form[name=change_password_form]").validate({
+            messages: {
+                old_password: "Please enter your previous password",
+                new_password: "Please enter your new password",
+                confirm_password: {
+                    required: "Please confirm your new password",
+                    equalTo: "The confirmation does not match the password"
+                },
+            },
+            submitHandler: function (form) {
+                self.rpc("/base/session/change_password",{
+                    'fields': $("form[name=change_password_form]").serializeArray()
+                }, function(result) {
+                    if (result.error) {
+                        self.display_error(result);
+                        return;
+                    }
+                    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();
     }

=== modified file 'addons/base/static/src/js/form.js'
--- addons/base/static/src/js/form.js	2011-08-22 15:08:08 +0000
+++ addons/base/static/src/js/form.js	2011-08-23 07:48:25 +0000
@@ -66,7 +66,6 @@
         var self = this;
         this.fields_view = data.fields_view;
         var frame = new (this.registry.get_object('frame'))(this, this.fields_view.arch);
-
         this.$element.html(QWeb.render(this.template, { 'frame': frame, 'view': this }));
         _.each(this.widgets, function(w) {
             w.start();
@@ -581,6 +580,7 @@
         this.$element = $('#' + this.element_id);
     },
     stop: function() {
+        this.$element = $('#' + this.element_id);
         this.$element.remove();
     },
     process_modifiers: function() {

=== modified file 'addons/base/static/src/xml/base.xml'
--- addons/base/static/src/xml/base.xml	2011-08-22 15:33:07 +0000
+++ addons/base/static/src/xml/base.xml	2011-08-23 07:48:25 +0000
@@ -1306,4 +1306,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" class="db_option_table">
+            <tr>
+                <td><label for="old_pwd">Old Password:</label></td>
+                <td><input type="password" name="old_pwd" class="required"
+                           minlength="1" autofocus="autofocus"/></td>
+            </tr>
+            <tr>
+            <td><label for="new_pwd">New Password:</label></td>
+            <td><input type="password" name="new_pwd" class="required"
+                       minlength="1"/></td>
+            </tr>
+        <tr>
+                <td><label for="confirm_pwd">Confirm Password:</label></td>
+                <td><input type="password" name="confirm_pwd" class="required"
+                           equalTo="input[name=new_pwd]" minlength="1"/></td>
+            </tr>
+            <tr>
+                <td colspan="2" align="right"><input type="submit" value="Change Password"/></td>
+            </tr>
+        </table>
+    </form>
+</t>
 </templates>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to