openerp7 widget 之 ChangePassword

直奔主题:

         instance.web.client_actions.add("change_password", "instance.web.ChangePassword");

         有个动作叫做change_password,把它的请求最终(在客户端)给instance.web.ChangePassword"给处理了。

         1. 看看后台py代码:

                   \addons\base\res\res_users.py (481~486) 

    def preference_change_password(self, cr, uid, ids, context=None):
        return {
            'type': 'ir.actions.client',
            'tag': 'change_password',
            'target': 'new',
        }

               类型是 ir.actions.client


       2. qweb 

           xml:   \addons\web\static\src\xml\base.xml (333~363)

           js: \addons\web\static\src\js\chrome.js (819~852)

instance.web.ChangePassword =  instance.web.Widget.extend({
    template: "ChangePassword",
    start: function() {
        var self = this;
        this.getParent().dialog_title = _t("Change Password");
        var $button = self.$el.find('.oe_form_button');
        $button.appendTo(this.getParent().$buttons);
        $button.eq(2).click(function(){
           self.getParent().close();
        })
        $button.eq(0).click(function(){
          self.rpc("/web/session/change_password",{
               'fields': $("form[name=change_password_form]").serializeArray()
          }).done(function(result) {
               if (result.error) {
                  self.display_error(result);
                  return;
               } else {
                   instance.webclient.on_logout();
               }
          });
       })
    },
    display_error: function (error) {
        return instance.web.dialog($('<div>'), {
            modal: true,
            title: error.title,
            buttons: [
                {text: _t("Ok"), click: function() { $(this).dialog("close"); }}
            ]
        }).html(error.error);
    },
})
instance.web.client_actions.add("change_password", "instance.web.ChangePassword");

    

<t t-name="ChangePassword">
    <form name="change_password_form" method="POST">
      <div class="oe_form">
        <table align="center">
            <tr>
                <td class="oe_form_group_cell oe_form_group_cell_label"><label for="old_pwd" class="oe_form_label">Old Password:</label></td>
                <td class="oe_form_group_cell"><input type="password" name="old_pwd"
                           minlength="1" autofocus="autofocus"/></td>
            </tr>
            <tr>
            <td class="oe_form_group_cell oe_form_group_cell_label"><label for="new_password" class="oe_form_label">New Password:</label></td>
            <td class="oe_form_group_cell"><input type="password" name="new_password"
                       minlength="1"/></td>
            </tr>
            <tr>
                <td class="oe_form_group_cell oe_form_group_cell_label"><label for="confirm_pwd" class="oe_form_label">Confirm New Password:</label></td>
                <td class="oe_form_group_cell"><input type="password" name="confirm_pwd"
                             minlength="1"/></td>
            </tr>
            <tr>
                <td colspan="2" align="right">
                    <button class='oe_button oe_form_button'>Change Password</button>
                    <span class="oe_fade oe_form_button"> or </span>
                    <button type="button" class="oe_button oe_form_button_cancel oe_form_button oe_link" href="javascript:void(0)"><span>Cancel</span></button>
                </td>
            </tr>
        </table>
      </div>
    </form>
</t>


   3. 过程简单分析:

      


4. widget代码分析:

     


5. 细节

  1). serializeArray

   The serializeArray() method creates an array of objects (name and value) by serializing form values

  将表单的input元素转为为{'name':input标签的name, 'value':input标签的value)

  2).$button.appendTo(this.getParent().$buttons); 此处,讲按钮添加到form的$buttons里面,其原始html为:

   "<span class="oe_dialog_custom_buttons"></span>" 此处用法不明。

    3). rpc 调用路线:

        widget -> instance.web.Controller(.rpc) -> instance.web.Session(.rpc)  ->  instance.web.JsonRPC( rpc) -> $.ajax(ajax)

     ajax 结构

     




作者:深圳-Tommy

邮箱:lion_awake@163.com

有问题可以和我讨论,转载请注明出处,谢谢!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值