...
|
...
|
@@ -6,21 +6,22 @@ require('../util/jquery.gritter'); |
|
|
|
|
|
|
|
|
var components=function(el,option){
|
|
|
this.registerEvent = {
|
|
|
this.registerEvent = {
|
|
|
validate: [],
|
|
|
render: [],
|
|
|
file_onComplete: []
|
|
|
render: []
|
|
|
};
|
|
|
this.el = el;
|
|
|
this.option = option || {};
|
|
|
}
|
|
|
components.prototype={
|
|
|
constructor:components,
|
|
|
on: function(name, callback) {
|
|
|
constructor:components,
|
|
|
on: function(name, callback) {
|
|
|
var __self = this;
|
|
|
var _e = __self.registerEvent[name];
|
|
|
if (_e) {
|
|
|
if (_e&&{}.toString.call(_e)=="[object Array]") {
|
|
|
_e.push(callback);
|
|
|
}else{
|
|
|
__self.registerEvent[name]=callback;
|
|
|
}
|
|
|
return _e;
|
|
|
},
|
...
|
...
|
@@ -42,9 +43,10 @@ components.prototype={ |
|
|
this.__fileRender();
|
|
|
this.__dropDownRender();
|
|
|
this.__checkboxRadioRender();
|
|
|
this.__timeRender();
|
|
|
return this;
|
|
|
},
|
|
|
validate:function(isTip){
|
|
|
validate:function(){
|
|
|
var that = this;
|
|
|
|
|
|
var err = [];
|
...
|
...
|
@@ -57,14 +59,14 @@ components.prototype={ |
|
|
var name = $(this).attr("prompt") || $(this).attr("placeholder");
|
|
|
var value = $.trim($(this).val());
|
|
|
|
|
|
if ($(this).attr("required")) {
|
|
|
new Validator.init($(this)[0], {
|
|
|
rules: {
|
|
|
required: true
|
|
|
}
|
|
|
}).validate(function(obj) {
|
|
|
err.push("<p>" + name + "不可为空</p>");
|
|
|
});
|
|
|
if ($(this).attr("required") && !value) {
|
|
|
//new Validator.init($(this)[0], {
|
|
|
// rules: {
|
|
|
// required: true
|
|
|
// }
|
|
|
//}).validate(function(obj) {
|
|
|
err.push("<p>" + name + "不可为空</p>");
|
|
|
//});
|
|
|
return false;
|
|
|
}
|
|
|
});
|
...
|
...
|
@@ -74,6 +76,7 @@ components.prototype={ |
|
|
var value = $.trim($(this).attr("value"));
|
|
|
if ($(this).attr("required") && !value) {
|
|
|
err.push("<p>请上传文件</p>");
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
//下拉选择
|
...
|
...
|
@@ -81,98 +84,70 @@ components.prototype={ |
|
|
var value = $.trim($(this).val());
|
|
|
var name = $(this).children(":first").text().replace(/[请选择]/g, "");
|
|
|
|
|
|
if ($(this).attr("required") && (+value == -1 || +value == "")) {
|
|
|
if ($(this).attr("required") && (value == -1 || value == "")) {
|
|
|
err.push("<p>请选择 " + name + "</p>");
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// var v = Validator.make(data, rules);
|
|
|
// v.mergeAttribute(attributes);
|
|
|
// var err=[];
|
|
|
// if (v.fails()) {
|
|
|
// for(var key in v.messages()){
|
|
|
// err.push("<p>"+v.messages()[key]+"</p>");
|
|
|
// }
|
|
|
// that.__err(err.join(''));
|
|
|
// return false;
|
|
|
// }
|
|
|
if (err.length > 0) {
|
|
|
if (!isTip) {
|
|
|
that.__err(err.join(''));
|
|
|
} else {
|
|
|
that.errMessage = err.join('');
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
var zierr = 0;
|
|
|
that.__listen("validate", '', function(data) {
|
|
|
if (data == false || typeof data == "string") {
|
|
|
zierr++;
|
|
|
typeof data == "string" ? err.push("<p>" + data + "</p>") : '';
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (zierr > 0) {
|
|
|
if (!isTip) {
|
|
|
that.__err(err.join(''));
|
|
|
} else {
|
|
|
that.errMessage = err.join('');
|
|
|
}
|
|
|
|
|
|
that.__err(err.join(''));
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
},
|
|
|
__fileRender:function(){
|
|
|
|
|
|
var that=this;
|
|
|
|
|
|
if ($('input[type="file"]', that.el).length > 0) {
|
|
|
|
|
|
var that=this;
|
|
|
|
|
|
if ($('input[type="file"]', that.el).length > 0) {
|
|
|
|
|
|
$('input[type="file"]', that.el).each(function() {
|
|
|
|
|
|
var bucket= $(this).data("bucket")||that.option.bucket;
|
|
|
|
|
|
if(!bucket){
|
|
|
alert("bucket 不存在");
|
|
|
}
|
|
|
|
|
|
$(this).wrap("<div class='fileinput-button'></div>");
|
|
|
var parent=$(this).parent(".fileinput-button");
|
|
|
|
|
|
|
|
|
if($(this).attr("value")){
|
|
|
parent.append('<a class="fileinput-button-icon" href="javascript:void(0);"><img src="'+$(this).attr("value")+'" width=100 height=100/></a>');
|
|
|
}else{
|
|
|
parent.append('<a class="fileinput-button-icon" href="javascript:void(0);">+</a>');
|
|
|
}
|
|
|
|
|
|
|
|
|
$('input[type="file"]', that.el).ajaxfileupload({
|
|
|
'action': '/ajax/upload',
|
|
|
'params': {
|
|
|
"bucket": bucket,
|
|
|
__type: "upload"
|
|
|
},
|
|
|
'onComplete': function(response) {
|
|
|
if (response.status && response.code == 200) {
|
|
|
that.__listen("file_onComplete", {
|
|
|
field: $(this).data("field"),
|
|
|
data: response.data,
|
|
|
datas:response.datas
|
|
|
});
|
|
|
var parent=$(this).parent(".fileinput-button");
|
|
|
if(response.data){
|
|
|
parent.find(".fileinput-button-icon").html("<img src='"+response.data+"' width=76 height=80/>");
|
|
|
}
|
|
|
$(this).attr("value", response.data);
|
|
|
} else {
|
|
|
that.$tip(response.message);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
})
|
|
|
var bucket= $(this).data("bucket")||that.option.bucket;
|
|
|
|
|
|
if(!bucket){
|
|
|
alert("bucket 不存在");
|
|
|
}
|
|
|
|
|
|
if($(this).hasClass("excel-upload")) {
|
|
|
return true ;
|
|
|
}
|
|
|
|
|
|
$(this).wrap("<div class='fileinput-button'></div>");
|
|
|
var parent=$(this).parent(".fileinput-button");
|
|
|
|
|
|
|
|
|
if($(this).attr("value")){
|
|
|
parent.append('<a class="fileinput-button-icon" href="javascript:void(0);"><img src="'+$(this).attr("value")+'" width=100 height=100/></a>');
|
|
|
}else{
|
|
|
parent.append('<a class="fileinput-button-icon" href="javascript:void(0);">+</a>');
|
|
|
}
|
|
|
|
|
|
|
|
|
$('input[type="file"]', that.el).ajaxfileupload({
|
|
|
'action': '/ajax/upload',
|
|
|
'params': {
|
|
|
"bucket": bucket,
|
|
|
__type: "upload"
|
|
|
},
|
|
|
'onComplete': function(response) {
|
|
|
if (response.status && response.code == 200) {
|
|
|
that.__listen("file_onComplete", {
|
|
|
field: $(this).data("field"),
|
|
|
data: response.data,
|
|
|
datas:response.datas
|
|
|
});
|
|
|
var parent=$(this).parent(".fileinput-button");
|
|
|
if(response.data){
|
|
|
parent.find(".fileinput-button-icon").html("<img src='"+response.data+"' width='100%' height='100%'/>");
|
|
|
$(this).attr("value", response.data);
|
|
|
}
|
|
|
} else {
|
|
|
that.$tip(response.message);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
}
|
|
|
},
|
...
|
...
|
@@ -186,6 +161,10 @@ components.prototype={ |
|
|
},
|
|
|
__checkboxRadioRender:function() {
|
|
|
var that=this;
|
|
|
//$(":checkbox").each(function () {
|
|
|
// var chosen = $(this).attr("chosen");
|
|
|
// var value = $(this).attr("value");
|
|
|
//});
|
|
|
$("input:hidden", that.el).each(function() {
|
|
|
var $this = $(this);
|
|
|
var name = $this.attr("id"),
|
...
|
...
|
@@ -204,9 +183,46 @@ components.prototype={ |
|
|
}
|
|
|
});
|
|
|
},
|
|
|
__timeRender:function() {
|
|
|
/*时间插件初始化*/
|
|
|
var that = this;
|
|
|
var fdatepicker = {};
|
|
|
$("input[jsaction]", that.el)
|
|
|
.add("input[jsaction]", that.el)
|
|
|
.each(function() {
|
|
|
var $this = $(this);
|
|
|
var name = $this.attr("id"),
|
|
|
arr = String.prototype.split.call($this.attr("jsaction"), ':');
|
|
|
var obj = $("#" + name).fdatepicker({
|
|
|
format: arr[0] == "date" ? 'yyyy-mm-dd' : 'yyyy-mm-dd hh:ii:ss',
|
|
|
pickTime: arr[0] == "date" ? false : true
|
|
|
}).data("datepicker");
|
|
|
|
|
|
fdatepicker[name] = {
|
|
|
obj: obj,
|
|
|
action: arr[1] ? (arr[1] === "end" ? "setEndDate" : "setStartDate") : false,
|
|
|
target: arr[2] ? "#" + arr[2] : false
|
|
|
};
|
|
|
});
|
|
|
for (var key in fdatepicker) {
|
|
|
var obj = fdatepicker[key].obj;
|
|
|
var action = fdatepicker[key].action;
|
|
|
var target = fdatepicker[key].target;
|
|
|
if (action) {
|
|
|
(function(obj, action, target) {
|
|
|
$("#" + key).click(function() {
|
|
|
obj[action]($(target).val().replace(/\s.*/, ''));
|
|
|
});
|
|
|
})(obj, action, target);
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
__listen: function(key, o, callback) {
|
|
|
var __self = this;
|
|
|
if (__self.registerEvent[key] && __self.registerEvent[key].length > 0) {
|
|
|
if (typeof __self.registerEvent[key]=="function") {
|
|
|
__self.registerEvent[key](o);
|
|
|
|
|
|
}else{
|
|
|
for (_e in __self.registerEvent[key]) {
|
|
|
var a = __self.registerEvent[key][_e](o);
|
|
|
if (callback) {
|
...
|
...
|
|