Skip to content

Commit

Permalink
Merge pull request #107 from ecomfe/dev
Browse files Browse the repository at this point in the history
0.2.9
  • Loading branch information
Justineo authored Jul 19, 2016
2 parents a09cd33 + eef0b0e commit 2d83697
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* 0.2.9
- 升级 `rule` 模块下的 `phone`/`mobile` 规则,支持 `17` 开头的手机号

* 0.2.8
- 优先使用 `underscore` 原生支持的 `mapObject`
- 支持在初始化数据请求结束后设置 ER 启动选项
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
9 changes: 7 additions & 2 deletions src/mvc/BaseView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`基类
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -171,6 +174,8 @@ define(function (require) {
dialog.hide();
}

options = options || {};

// 使用默认foot时,改变显示文字
if (options.needFoot || dialog.getFoot()) {
var okBtn = dialog.getFoot().getChild('btnOk');
Expand Down
3 changes: 2 additions & 1 deletion src/mvc/FormAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ define(function (require) {
}

if (message) {
return u.template(message, result || {});
var compiled = u.template(message);
return compiled(result || {});
}
else {
return '保存成功';
Expand Down
4 changes: 2 additions & 2 deletions src/mvc/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ define(
/**
* 手机号码,以13、14、15、18开头的11位数字
*/
pattern: '^(1(3|4|5|8)\\d{9})$'
pattern: '^(1[34578]\\d{9})$'
},

phone: {
/**
* 电话号码和手机号码,可为空,固话区号和分机号可选
* 固话格式{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: {
Expand Down
3 changes: 2 additions & 1 deletion src/tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ define(
TableTip: './ui/extension',
TableSubrow: 'esui/extension',
WordCount: './ui/extension',
QuickTip: './ui/extension'
QuickTip: './ui/extension',
AutoValidate: './ui/extension'
};

/**
Expand Down
6 changes: 3 additions & 3 deletions src/ui/AuthPanel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file 锦囊进行权限验证的基础容器
* @file 进行权限验证的基础容器
* @author Justineo([email protected])
*/

Expand All @@ -10,7 +10,7 @@ define(function (require) {
var auth = require('../system/auth');

/**
* 锦囊权限编辑器权限节点
* 权限编辑器权限节点
*
* @param {Object} [options] 初始化参数
* @extends esui.Panel
Expand Down Expand Up @@ -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/TR/html/disabled-elements.html
var disableableTagNames = [
'BUTTON', 'INPUT', 'SELECT', 'TEXTAREA',
'OPTGROUP', 'OPTION', 'COMMAND', 'FIELDSET'
Expand Down
4 changes: 2 additions & 2 deletions src/ui/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ define(
* @return {boolean} 返回是否能预览该扩展类型
*/
Image.prototype.checkExtension = function () {
var match = /\.\w+$/.exec(this.url);
var match = /\.\w+?(?=\?|#|$)/.exec(this.url);
if (!match) {
return false;
}

var extension = match[0];
return !!this.extentionTypes[extension];
return !!this.extentionTypes[extension.toLowerCase()];
};

var imageTemplate = '<img src="${url}" id="${id}" alt="${alt}" />';
Expand Down
96 changes: 96 additions & 0 deletions src/ui/extension/AutoValidate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* @file 让输入控件在特定事件下自动校验rule
* @author feibinyang
*/
define(
function (require) {
var u = require('underscore');
var lib = require('esui/lib');
var Extension = require('esui/Extension');
var InputControl = require('esui/InputControl');

/**
* 让输入控件在特定事件下自动校验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() {
if (!(this.target instanceof InputControl)) {
throw new Error('Current target is not an instance of InputControl.');
}
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;
}
);
44 changes: 31 additions & 13 deletions src/ui/extension/WordCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright 2013 Baidu Inc. All rights reserved.
*
* @ignore
* @file 计算文本框可输入字符的扩展
* @file 计算文本框可输入字符的扩展(包含字符数和字节数两种检查)
* @author otakustay
* @date $DATE$
*/
Expand Down Expand Up @@ -41,7 +41,7 @@ define(
*
* @type {string}
*/
WordCount.prototype.initialTemplate = '最多可输入${available}个字符';
WordCount.prototype.initialTemplate = '最多可输入${available}个${unit}';

/**
* 设置还可以输入字符时的提示信息模板,可用以下占位符:
Expand All @@ -52,7 +52,7 @@ define(
*
* @type {string}
*/
WordCount.prototype.remainingTemplate = '还可输入${available}个字符';
WordCount.prototype.remainingTemplate = '还可输入${available}个${unit}';

/**
* 设置已超出可输入字符限制时的提示信息模板,可用以下占位符:
Expand All @@ -63,7 +63,7 @@ define(
*
* @type {string}
*/
WordCount.prototype.exceededTemplate = '已超出${available}个字符';
WordCount.prototype.exceededTemplate = '已超出${available}个${unit}';

/**
* 获取提示信息
Expand All @@ -77,6 +77,11 @@ define(
*/
WordCount.prototype.getHintMessage = function (data) {
var template;
var unit = '字符';
if (this.target.get('maxByteLength')) {
unit = '字节';
}
data.unit = unit;
if (!data.current) {
template = this.initialTemplate;
}
Expand All @@ -92,13 +97,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
};
};

/**
Expand All @@ -107,13 +126,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';
Expand All @@ -133,7 +151,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);
Expand Down

0 comments on commit 2d83697

Please sign in to comment.