From 3a4dd54c00ad4a1c5412e98698bd092af32f94e4 Mon Sep 17 00:00:00 2001 From: feibinyang Date: Thu, 12 Nov 2015 14:17:45 +0800 Subject: [PATCH 01/16] AutoValidate --- src/ui/extension/AutoValidate.js | 92 ++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/ui/extension/AutoValidate.js diff --git a/src/ui/extension/AutoValidate.js b/src/ui/extension/AutoValidate.js new file mode 100644 index 0000000..bbb4ca0 --- /dev/null +++ b/src/ui/extension/AutoValidate.js @@ -0,0 +1,92 @@ +/** + * @file 让输入控件在特定事件下自动校验rule + * @author feibinyang + */ +define( + function (require) { + var u = require('underscore'); + var lib = require('esui/lib'); + var Extension = require('esui/Extension'); + + /** + * 让输入控件在特定事件下自动校验rule + * + * @param {Object} [options] 配置项 + * @extends esui.Extension + * @constructor + */ + function AutoValidate(options) { + options = options || {}; + if (typeof options.events === 'string') { + options.events = u.map( + lib.splitTokenList(options.events), + lib.trim + ); + } + + Extension.apply(this, arguments); + } + + /** + * 扩展的类型,始终为`"AutoValidate"` + * + * @type {string} + * @override + */ + AutoValidate.prototype.type = 'AutoValidate'; + + /** + * 指定用于提交表单的事件名称,默认为`change`和`input`事件 + * + * @type {string[]} + */ + AutoValidate.prototype.events = ['change', 'input']; + + /** + * 验证rule + * + * @param {esui.Control} this 触发事件的控件 + * @ignore + */ + function validate() { + this.target.validate(); + } + + /** + * 激活扩展 + * + * @override + */ + AutoValidate.prototype.activate = function () { + u.each( + this.events, + function (eventName) { + this.target.on(eventName, validate, this); + }, + this + ); + Extension.prototype.activate.apply(this, arguments); + }; + + /** + * 取消激活 + * + * @override + */ + AutoValidate.prototype.inactivate = function () { + u.each( + this.events, + function (eventName) { + this.target.un(eventName, validate, this); + }, + this + ); + + Extension.prototype.inactivate.apply(this, arguments); + }; + + lib.inherits(AutoValidate, Extension); + require('esui').registerExtension(AutoValidate); + return AutoValidate; + } +); From 8e753aa0ae97c2b59fba7cbe45b503cd34bafbcd Mon Sep 17 00:00:00 2001 From: feibinyang Date: Thu, 12 Nov 2015 14:23:30 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tpl.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tpl.js b/src/tpl.js index e352933..d757a20 100644 --- a/src/tpl.js +++ b/src/tpl.js @@ -67,7 +67,8 @@ define( TableTip: './ui/extension', TableSubrow: 'esui/extension', WordCount: './ui/extension', - QuickTip: './ui/extension' + QuickTip: './ui/extension', + AutoValidate: './ui/extension' }; /** From fcd9fd8b9dcbda8c4707c35f9c22eef2676ccb26 Mon Sep 17 00:00:00 2001 From: feibinyang Date: Mon, 16 Nov 2015 11:16:19 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E5=88=A4=E6=96=ADtarget=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/extension/AutoValidate.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ui/extension/AutoValidate.js b/src/ui/extension/AutoValidate.js index bbb4ca0..86d8d25 100644 --- a/src/ui/extension/AutoValidate.js +++ b/src/ui/extension/AutoValidate.js @@ -7,6 +7,7 @@ define( var u = require('underscore'); var lib = require('esui/lib'); var Extension = require('esui/Extension'); + var InputControl = require('esui/InputControl'); /** * 让输入控件在特定事件下自动校验rule @@ -49,7 +50,13 @@ define( * @ignore */ function validate() { - this.target.validate(); + if (this.target instanceof InputControl) { + // target是InputControl类型时,才有校验意义 + this.target.validate(); + } + else { + throw new Error('Current target is not a InputControl type.'); + } } /** From 7e1bd49126894115a4b6e3e40374db3dcc65a4fb Mon Sep 17 00:00:00 2001 From: feibinyang Date: Mon, 16 Nov 2015 22:09:47 +0800 Subject: [PATCH 04/16] =?UTF-8?q?guard=20clauses=20=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84if=20else?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/extension/AutoValidate.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ui/extension/AutoValidate.js b/src/ui/extension/AutoValidate.js index 86d8d25..7799398 100644 --- a/src/ui/extension/AutoValidate.js +++ b/src/ui/extension/AutoValidate.js @@ -50,13 +50,10 @@ define( * @ignore */ function validate() { - if (this.target instanceof InputControl) { - // target是InputControl类型时,才有校验意义 - this.target.validate(); - } - else { + if (!(this.target instanceof InputControl)) { throw new Error('Current target is not a InputControl type.'); } + this.target.validate(); } /** From 613a021454e82cedf0115038b2f5445f2f809ca9 Mon Sep 17 00:00:00 2001 From: Justineo Date: Tue, 17 Nov 2015 11:01:53 +0800 Subject: [PATCH 05/16] refine wording --- src/ui/extension/AutoValidate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/extension/AutoValidate.js b/src/ui/extension/AutoValidate.js index 7799398..8f18644 100644 --- a/src/ui/extension/AutoValidate.js +++ b/src/ui/extension/AutoValidate.js @@ -51,7 +51,7 @@ define( */ function validate() { if (!(this.target instanceof InputControl)) { - throw new Error('Current target is not a InputControl type.'); + throw new Error('Current target is not an instance of InputControl.'); } this.target.validate(); } From 3064981f409380fd40b09857d416a46a8d100d9d Mon Sep 17 00:00:00 2001 From: feibinyang Date: Thu, 17 Dec 2015 15:59:06 +0800 Subject: [PATCH 06/16] =?UTF-8?q?w3=E6=96=87=E6=A1=A3=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/AuthPanel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/AuthPanel.js b/src/ui/AuthPanel.js index 6e58770..aa732fa 100644 --- a/src/ui/AuthPanel.js +++ b/src/ui/AuthPanel.js @@ -60,7 +60,7 @@ define(function (require) { root = root || me.main; // 可以通过设置disabled属性禁用的控件 - // 见 http://www.w3.org/html/wg/drafts/html/master/disabled-elements.html + // 见 http://www.w3.org/html/wg/drafts/html/master/semantics.html#enabling-and-disabling-form-controls:-the-disabled-attribute var disableableTagNames = [ 'BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'OPTGROUP', 'OPTION', 'COMMAND', 'FIELDSET' From 2cc8856df22707aa182f35dac0420258117f85d9 Mon Sep 17 00:00:00 2001 From: feibinyang Date: Fri, 18 Dec 2015 15:54:28 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E5=9C=B0=E5=9D=80=E5=BC=84=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/AuthPanel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/AuthPanel.js b/src/ui/AuthPanel.js index aa732fa..7753342 100644 --- a/src/ui/AuthPanel.js +++ b/src/ui/AuthPanel.js @@ -60,7 +60,7 @@ define(function (require) { root = root || me.main; // 可以通过设置disabled属性禁用的控件 - // 见 http://www.w3.org/html/wg/drafts/html/master/semantics.html#enabling-and-disabling-form-controls:-the-disabled-attribute + // 见 http://www.w3.org/TR/html/disabled-elements.html var disableableTagNames = [ 'BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'OPTGROUP', 'OPTION', 'COMMAND', 'FIELDSET' From 9df1308f5c7008ea773b684d8e4146236b7cbe4c Mon Sep 17 00:00:00 2001 From: Justineo Date: Thu, 24 Dec 2015 15:44:46 +0800 Subject: [PATCH 08/16] update phone rules --- CHANGELOG.md | 3 +++ package.json | 2 +- src/mvc/rule.js | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6f097c..437b261 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* 0.2.9 + - 升级 `rule` 模块下的 `phone`/`mobile` 规则,支持 `17` 开头的手机号 + * 0.2.8 - 优先使用 `underscore` 原生支持的 `mapObject` - 支持在初始化数据请求结束后设置 ER 启动选项 diff --git a/package.json b/package.json index 2fcb635..b877bff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bat-ria", - "version": "0.2.8", + "version": "0.2.9", "description": "RIA extension for Brand Ads Team", "main": "main.js", "repository": { diff --git a/src/mvc/rule.js b/src/mvc/rule.js index b5c85e5..ba4c7cf 100644 --- a/src/mvc/rule.js +++ b/src/mvc/rule.js @@ -52,7 +52,7 @@ define( /** * 手机号码,以13、14、15、18开头的11位数字 */ - pattern: '^(1(3|4|5|8)\\d{9})$' + pattern: '^(1[34578]\\d{9})$' }, phone: { @@ -60,7 +60,7 @@ define( * 电话号码和手机号码,可为空,固话区号和分机号可选 * 固话格式{3到4位区号}-{7到8位号码}-{3到5位分机号} */ - pattern: '(^((0\\d{2,3})-)(\\d{7,8})(-(\\d{3,}))?$)|(^(1(3|4|5|8)\\d{9})$)' + pattern: '(^((0\\d{2,3})-)(\\d{7,8})(-(\\d{3,}))?$)|(^(1[34578]\\d{9})$)' }, url: { From e5d251bfc0479a3516a5d563e9a5ebda8d924eb3 Mon Sep 17 00:00:00 2001 From: feibinyang Date: Tue, 5 Jan 2016 17:14:32 +0800 Subject: [PATCH 09/16] =?UTF-8?q?=E9=BB=98=E8=AE=A4options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mvc/BaseView.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mvc/BaseView.js b/src/mvc/BaseView.js index ba5724c..cea45a1 100644 --- a/src/mvc/BaseView.js +++ b/src/mvc/BaseView.js @@ -171,6 +171,8 @@ define(function (require) { dialog.hide(); } + options = options || {}; + // 使用默认foot时,改变显示文字 if (options.needFoot || dialog.getFoot()) { var okBtn = dialog.getFoot().getChild('btnOk'); From 49765636b86ec07da211d49f43a633a2b74ee388 Mon Sep 17 00:00:00 2001 From: feibinyang Date: Fri, 8 Jan 2016 11:07:58 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E6=89=A9=E5=B1=95=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E6=95=B0=E5=92=8C=E5=AD=97=E8=8A=82=E6=95=B0=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/extension/WordCount.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/ui/extension/WordCount.js b/src/ui/extension/WordCount.js index 98f1856..faf5672 100644 --- a/src/ui/extension/WordCount.js +++ b/src/ui/extension/WordCount.js @@ -3,7 +3,7 @@ * Copyright 2013 Baidu Inc. All rights reserved. * * @ignore - * @file 计算文本框可输入字符的扩展 + * @file 计算文本框可输入字符的扩展(包含字符数和字节数两种检查) * @author otakustay * @date $DATE$ */ @@ -92,13 +92,27 @@ define( }; /** - * 获取最大可输入字符数 + * 获取最大可输入字符数(字节数) + * 当控件属性中有maxByteLength为字节数检查 + * 当控件属性中有maxLength和length时为字符数检查 * * @return {number} * @protected */ - WordCount.prototype.getMaxLength = function () { - return this.target.get('maxLength') || this.target.get('length'); + WordCount.prototype.getLengths = function () { + var target = this.target; + var maxLength = target.get('maxByteLength') || target.get('maxLength') || target.get('length'); + var value = target.getValue(); + var currentLength = value.length; + if (target.get('maxByteLength')) { + // 正则来源于esui中MaxByteLengthRule.js + // 获取当前字节数 + currentLength = value.replace(/[^\x00-\xff]/g, 'xx').length; + } + return { + maxLength: maxLength, + currentLength: currentLength + }; }; /** @@ -107,13 +121,12 @@ define( * @ignore */ function checkLength() { - var maxLength = this.getMaxLength(); - var currentLength = this.target.getValue().length; + var lengths = this.getLengths(); var data = { - max: maxLength, - current: currentLength, - available: maxLength - currentLength + max: lengths.maxLength, + current: lengths.currentLength, + available: lengths.maxLength - lengths.currentLength }; var validState = data.available < 0 ? 'error' : 'hint'; @@ -133,7 +146,7 @@ define( */ WordCount.prototype.activate = function () { var target = this.target; - var maxLength = target.get('maxLength') || target.get('length'); + var maxLength = target.get('maxByteLength') || target.get('maxLength') || target.get('length'); if (maxLength) { this.target.on('input', checkLength, this); From 5ad6288f846febd51b1b9ce624ed44a0d79678df Mon Sep 17 00:00:00 2001 From: feibinyang Date: Fri, 8 Jan 2016 14:39:09 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E5=8D=95=E4=BD=8D=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/extension/WordCount.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ui/extension/WordCount.js b/src/ui/extension/WordCount.js index faf5672..04267d2 100644 --- a/src/ui/extension/WordCount.js +++ b/src/ui/extension/WordCount.js @@ -41,7 +41,7 @@ define( * * @type {string} */ - WordCount.prototype.initialTemplate = '最多可输入${available}个字符'; + WordCount.prototype.initialTemplate = '最多可输入${available}个${unit}'; /** * 设置还可以输入字符时的提示信息模板,可用以下占位符: @@ -52,7 +52,7 @@ define( * * @type {string} */ - WordCount.prototype.remainingTemplate = '还可输入${available}个字符'; + WordCount.prototype.remainingTemplate = '还可输入${available}个${unit}'; /** * 设置已超出可输入字符限制时的提示信息模板,可用以下占位符: @@ -63,7 +63,7 @@ define( * * @type {string} */ - WordCount.prototype.exceededTemplate = '已超出${available}个字符'; + WordCount.prototype.exceededTemplate = '已超出${available}个${unit}'; /** * 获取提示信息 @@ -77,6 +77,11 @@ define( */ WordCount.prototype.getHintMessage = function (data) { var template; + var unit = '字符'; + if (this.target.get('maxByteLength')) { + unit = '字节(1个汉字等于2个字节,1个字母或数字等于1个字节)'; + } + data.unit = unit; if (!data.current) { template = this.initialTemplate; } From 4d93ab450acad8f26ccba97201a3a27b407ed3b8 Mon Sep 17 00:00:00 2001 From: feibinyang Date: Thu, 28 Jan 2016 13:27:02 +0800 Subject: [PATCH 12/16] fixed issue 94 --- src/mvc/FormAction.js | 3 ++- src/ui/extension/WordCount.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mvc/FormAction.js b/src/mvc/FormAction.js index c6bfd41..6995485 100644 --- a/src/mvc/FormAction.js +++ b/src/mvc/FormAction.js @@ -45,7 +45,8 @@ define(function (require) { } if (message) { - return u.template(message, result || {}); + var compiled = u.template(message); + return compiled(result || {}); } else { return '保存成功'; diff --git a/src/ui/extension/WordCount.js b/src/ui/extension/WordCount.js index 04267d2..1e790c4 100644 --- a/src/ui/extension/WordCount.js +++ b/src/ui/extension/WordCount.js @@ -79,7 +79,7 @@ define( var template; var unit = '字符'; if (this.target.get('maxByteLength')) { - unit = '字节(1个汉字等于2个字节,1个字母或数字等于1个字节)'; + unit = '字节'; } data.unit = unit; if (!data.current) { From f3a2adce2c1e10d07ff63db1e0534ae556daa943 Mon Sep 17 00:00:00 2001 From: chestnut Date: Thu, 10 Mar 2016 17:40:57 +0800 Subject: [PATCH 13/16] =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=94=AF=E6=8C=81=E5=B8=A6=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9A=84url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/Image.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/Image.js b/src/ui/Image.js index 72ca37d..d33e3c5 100644 --- a/src/ui/Image.js +++ b/src/ui/Image.js @@ -171,7 +171,7 @@ define( * @return {boolean} 返回是否能预览该扩展类型 */ Image.prototype.checkExtension = function () { - var match = /\.\w+$/.exec(this.url); + var match = /\.\w+?(?=\?|#|$)/.exec(this.url); if (!match) { return false; } From d8287c0c9bf3e603a6949771693e0ea654d11f0f Mon Sep 17 00:00:00 2001 From: chestnut Date: Tue, 15 Mar 2016 10:27:01 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=A7=E5=86=99?= =?UTF-8?q?=E7=9A=84=E5=90=8E=E7=BC=80=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/Image.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/Image.js b/src/ui/Image.js index d33e3c5..26b4c5b 100644 --- a/src/ui/Image.js +++ b/src/ui/Image.js @@ -177,7 +177,7 @@ define( } var extension = match[0]; - return !!this.extentionTypes[extension]; + return !!this.extentionTypes[extension.toLowerCase()]; }; var imageTemplate = '${alt}'; From 4f65d38b953f9254454f21faf8d57c6233d42200 Mon Sep 17 00:00:00 2001 From: feibinyang Date: Thu, 17 Mar 2016 20:32:34 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E5=85=88=E6=A3=80=E6=9F=A5=E5=AD=90?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E4=B8=8D=E5=AD=98=E5=9C=A8=E5=B0=B1=E4=B8=8D?= =?UTF-8?q?=E6=94=B9=E5=8F=98=E6=A8=A1=E6=9D=BF=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mvc/BaseView.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mvc/BaseView.js b/src/mvc/BaseView.js index cea45a1..2f223a8 100644 --- a/src/mvc/BaseView.js +++ b/src/mvc/BaseView.js @@ -8,6 +8,7 @@ define(function (require) { var UIView = require('ef/UIView'); var Deferred = require('er/Deferred'); var Dialog = require('esui/Dialog'); + var template = require('etpl'); /** * 业务`View`基类 @@ -35,7 +36,6 @@ define(function (require) { throw new Error('Container not found when rendering ' + (url ? '"' + url + '"' : 'view')); } - var template = require('etpl'); var html = template.render(this.getTemplateName(), this.getTemplateData()); container.innerHTML = html; @@ -56,7 +56,10 @@ define(function (require) { // 作为子Action嵌入页面时,模板使用`xxxMain`这个target if (this.model && this.model.get('isChildAction')) { - templateName += '_child'; + var childName = templateName + '_child'; + if (template.getRenderer(childName)) { + templateName = childName; + } } return templateName; From dac4fd420e617487cae10837855c5b474df74b2e Mon Sep 17 00:00:00 2001 From: yibuyisheng Date: Wed, 22 Jun 2016 11:03:34 +0800 Subject: [PATCH 16/16] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E9=94=A6=E5=9B=8A=E4=BA=8C=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/AuthPanel.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/AuthPanel.js b/src/ui/AuthPanel.js index 7753342..ad7647f 100644 --- a/src/ui/AuthPanel.js +++ b/src/ui/AuthPanel.js @@ -1,5 +1,5 @@ /** - * @file 锦囊进行权限验证的基础容器 + * @file 进行权限验证的基础容器 * @author Justineo(justice360@gmail.com) */ @@ -10,7 +10,7 @@ define(function (require) { var auth = require('../system/auth'); /** - * 锦囊权限编辑器权限节点 + * 权限编辑器权限节点 * * @param {Object} [options] 初始化参数 * @extends esui.Panel