List
新建
1.switch to the form view with no active res_id,
2.so it is in 'create' mode, or we can edit inline.
服务器动作按钮
- 形如
1
2
3
4
5
6
7
8
9
10<record id="mdm_bank__action_server_audit_cancel" model="ir.actions.server" >
<field name="name">Anti Audit</field>
<field name="model_id" ref="model_mdm_bank"/>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="code">
action=records.action_server_run(opt="audit_cancel", check_ref=True)
</field>
<field name="binding_model_id" ref="model_mdm_bank"/>
</record> - 事件链
- sidebar: “click a.dropdown-item” -> “_onDropdownClicked”根据动作下拉中的按钮类型处理事件,这里主要跟踪上述xml对应的action
- sidebar: _onItemActionClicked, 触发sidebar_data_asked,并指定了callback函数,callbackh中触发了/web/action/load
1
{"label":"提交","action":{"activity_type_id":false,"partner_ids":[],"help":false,"create_uid":[1,"inSuiteBot"],"child_ids":[],"create_date":"2020-03-23 02:03:19","model_id":[299,"银行"],"code":"\n action=records.action_server_run(opt=\"submit\")\n ","fields_lines":[],"name":"提交","sms_mass_keep_log":true,"crud_model_id":false,"activity_note":false,"groups_id":[],"xml_id":"ps_mdm.mdm_bank__action_server_submit","activity_user_id":false,"usage":"ir_actions_server","write_uid":[1,"inSuiteBot"],"activity_user_type":"specific","activity_date_deadline_range_type":"days","model_name":"mdm.bank","template_id":false,"activity_summary":false,"binding_view_types":"list,form","id":276,"state":"code","activity_date_deadline_range":0,"display_name":"提交","channel_ids":[],"binding_type":"action","type":"ir.actions.server","binding_model_id":[299,"银行"],"sequence":5,"activity_user_field_name":"user_id","sms_template_id":false,"crud_model_name":false,"write_date":"2020-03-27 12:19:53","link_field_id":false,"__last_update":"2020-03-27 12:19:53"}}"
- basic: sidebar_data_asked ->_onSidebarDataAsked, 获取env进入 ev.data.callback(sidebarEnv);
xml中普通按钮
形如
1
2
3
4
5<header>
<button type="object" name="button_create_bank_account" string="Create Bank Account" class="oe_highlight" attrs="{'invisible': ['|', ('state', '!=', 'audit'), ('forbid_state','!=','normal')]}"/>
<field name="forbid_state" invisible="1"/>
<field name="state" widget="statusbar"/>
</header>事件链
form_renderer: _renderStatButton 渲染按钮之后处理按钮绑定事件_addOnClickAction
form_renderer:_addOnClickAction给每个按钮绑定点击事件button_clicked
1
2
3
4
5self.trigger_up('button_clicked', {
attrs: node.attrs,
record: self.state,
});
其中node中的信息有:{"tag":"button","attrs":{"type":"object","name":"button_create_bank_account","string":"创建银行账号","class":"oe_highlight","attrs":"{'invisible': ['|', ('state', '!=', 'audit'), ('forbid_state','!=','normal')]}","modifiers":{"invisible":["|",["state","!=","audit"],["forbid_state","!=","normal"]]},"options":{},"context":{"active_fields":{}}},"children":[]}- form_conroller: button_clicked -> _onButtonClicked, 根据传过来的attrs.special处理了几种情况, 最终走入saveRecord方法,
form_conroller:saveRecord方法返回了更改的字段,走完之后进入_callButtonAction
basic_contrller: _callButtonAction,触发
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16self.trigger_up('execute_action', {
action_data: _.extend({}, attrs, {
context: record.getContext({additionalContext: attrs.context || {}}),
}),
env: {
context: record.getContext(),
currentID: record.data.id,
model: record.model,
resIDs: record.res_ids,
},
on_success: resolve,
on_fail: function () {
self.update({}, { reload: false }).then(reject).guardedCatch(reject);
},
on_closed: reload,
});- action_manager_act_window: execute_action -> ‘_onExecuteAction’,根据ctionData.type处理
// --------------------------------------------------------------------
_addOnClickAction
1. 存在confirm属性
2. special === ‘cancle’ =》 _callButtonAction
2. !special || special === ‘save’ =》 saveAndExecuteAction
1 |
1 |