From 94cb8a25c44d70e1e2ed49cec7f9dbfc3d405670 Mon Sep 17 00:00:00 2001 From: LiDBear Date: Tue, 1 Mar 2016 16:54:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=89=A9=E5=B1=95?= =?UTF-8?q?=E5=AE=9A=E5=88=B6=E5=8C=96=EF=BC=8C=E5=85=81=E8=AE=B8=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/extension/ui.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/extension/ui.js b/src/extension/ui.js index 099c177..ea9b01e 100644 --- a/src/extension/ui.js +++ b/src/extension/ui.js @@ -10,6 +10,12 @@ define( var u = require('../util'); var lib = require('esui/lib'); + var EXTENSION_MAP = { + validationRule: initializeValidationRules, + tableCellRender: addTableCellRenderers, + controlLinkMode: addControlLinkMode + }; + /** * 加载并配置验证规则 */ @@ -101,7 +107,7 @@ define( } return Rule.prototype.getErrorMessage.apply(this, arguments); }; - } + }; /** * 添加通用的表格单元格内容输出方法 @@ -253,7 +259,7 @@ define( return '' + status.text + ''; }; - } + }; /** * 为几个控件添加链接模式的内容模板 @@ -293,9 +299,14 @@ define( } function enable() { - initializeValidationRules(); - addTableCellRenderers(); - addControlLinkMode(); + var modules = arguments.length ? arguments : u.keys(EXTENSION_MAP); + + u.each( + modules, + function (module) { + EXTENSION_MAP[module] && EXTENSION_MAP[module](); + } + ); } /** From 2edc0a488261da37e1f16b89078121cab4111d6b Mon Sep 17 00:00:00 2001 From: LiDBear Date: Tue, 1 Mar 2016 17:18:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E5=88=86=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/extension/ui.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extension/ui.js b/src/extension/ui.js index ea9b01e..dfac80e 100644 --- a/src/extension/ui.js +++ b/src/extension/ui.js @@ -107,7 +107,7 @@ define( } return Rule.prototype.getErrorMessage.apply(this, arguments); }; - }; + } /** * 添加通用的表格单元格内容输出方法 @@ -259,7 +259,7 @@ define( return '' + status.text + ''; }; - }; + } /** * 为几个控件添加链接模式的内容模板 From 952ff5e9126a14fabf6dd87884c3addfe74f205f Mon Sep 17 00:00:00 2001 From: yanghuabei Date: Tue, 8 Mar 2016 14:41:28 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=88=97=E8=A1=A8mvc=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E6=8A=A5=E5=91=8Acommand=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9command=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mvc/ListView.js | 104 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 91 insertions(+), 13 deletions(-) diff --git a/src/mvc/ListView.js b/src/mvc/ListView.js index 8c68fec..be7a6bb 100644 --- a/src/mvc/ListView.js +++ b/src/mvc/ListView.js @@ -54,8 +54,51 @@ define( }; /* eslint-enable fecs-camelcase */ this.addUIEvents(uiEvents); + + // handler支持字符串,为字符串时表示使用当前view实例上的同名方法 + var commands = { + 'click:modify': u.partial(handleRowAction, 'modify'), + 'click:read': u.partial(handleRowAction, 'read'), + 'click:copy': u.partial(handleRowAction, 'copy'), + 'click:viewReport': handleViewReport + }; + this.addCommands(commands); + }; + + /** + * 添加列表行内command处理 + * + * @method mvc.ListView#addCommands + * @param {Object} newCommands 需要添加的command处理 + * @public + */ + exports.addCommands = function (newCommands) { + this.commands = u.extend(this.commands || {}, newCommands); }; + /** + * 处理修改、复制、查看操作 + * + * @param {string} name command名称 + * @param {string} args command参数 + */ + function handleRowAction(name, args) { + var id = args; + var url = getActionURL.call(this, name, id); + var options = {url: url}; + + this.popDrawerAction(options).show(); + } + + /** + * 处理查看报告操作 + * + * @param {string} args command参数 + */ + function handleViewReport(args) { + this.popDrawerAction({url: args}).show(); + } + /** * 每页条数变更监听函数 * @@ -263,27 +306,62 @@ define( * @protected * @method mvc.ListView#commandHandler * @param {mini-event.Event} e command事件 + * @deprecated */ exports.commandHandler = function (e) { - if (e.triggerType === 'click') { - var transition = u.findWhere(this.model.getStatusTransitions(), {statusName: e.name}); - // 处理状态修改 + this.handleTableCommand(e.triggerType, e.name, e.args); + }; + + /** + * 处理command + * + * @method mvc.ListView#handleTableCommand + * @param {string} triggerType command事件的触发方式 + * @param {string} name command名称 + * @param {string} args command参数 + * @return {boolean} command是否被处理过 + * @protected + */ + exports.handleTableCommand = function (triggerType, name, args) { + var handled = this.handleStatusCommand(triggerType, name, args); + + if (!handled) { + var handler = this.commands[triggerType + ':' + name]; + if (u.isString(handler)) { + handler = this[handler]; + } + + if (u.isFunction(handler)) { + handler.call(this, args); + handled = true; + } + } + return handled; + }; + + /** + * 处理操作状态的command + * + * @method mvc.ListView#handleStatusCommand + * @param {string} triggerType command事件的触发方式 + * @param {string} name command名称 + * @param {string} args command参数 + * @return {boolean} command是否被处理过 + * @private + */ + exports.handleStatusCommand = function (triggerType, name, args) { + if (triggerType === 'click') { + var transition = u.findWhere(this.model.getStatusTransitions(), {statusName: name}); if (transition) { - var args = { - id: e.args, + args = { + id: args, status: transition.status }; this.fire('modifystatus', args); - } - // 处理实体修改和查看 - else if (e.name === 'modify' || e.name === 'read' || e.name === 'copy') { - var id = e.args; - var url = getActionURL.call(this, e.name, id); - var options = {url: url}; - - this.popDrawerAction(options).show(); + return true; } } + return false; }; /**