...
|
...
|
@@ -17,28 +17,28 @@ $("button").click(function(){ |
|
|
});
|
|
|
})*/
|
|
|
|
|
|
var $=require('jquery');
|
|
|
var $ = require('jquery');
|
|
|
var Validator = require('./validate');
|
|
|
require('./upload');
|
|
|
require('../util/datepicker');
|
|
|
require('../util/jquery.gritter');
|
|
|
|
|
|
|
|
|
var edit=function(el,option){
|
|
|
this.registerEvent={
|
|
|
validate:[],
|
|
|
bind:[],
|
|
|
render:[],
|
|
|
callback:[]
|
|
|
};
|
|
|
this.el=el;
|
|
|
this.option=option||{};
|
|
|
//typeof option==="string"?option:option.el;
|
|
|
var edit = function(el, option) {
|
|
|
this.registerEvent = {
|
|
|
validate: [],
|
|
|
bind: [],
|
|
|
render: [],
|
|
|
callback: []
|
|
|
};
|
|
|
this.el = el;
|
|
|
this.option = option || {};
|
|
|
//typeof option==="string"?option:option.el;
|
|
|
// new edit.prototype.init(this);
|
|
|
}
|
|
|
edit.prototype={
|
|
|
constructor:edit,
|
|
|
on:function (name,callback) {
|
|
|
edit.prototype = {
|
|
|
constructor: edit,
|
|
|
on: function(name, callback) {
|
|
|
var __self = this;
|
|
|
var _e = __self.registerEvent[name];
|
|
|
if (_e) {
|
...
|
...
|
@@ -46,40 +46,40 @@ edit.prototype={ |
|
|
}
|
|
|
return _e;
|
|
|
},
|
|
|
off:function (name, callback) {
|
|
|
off: function(name, callback) {
|
|
|
var __self = this;
|
|
|
var _e = __self.registerEvent[name];
|
|
|
var e = [];
|
|
|
me.each(_e, function (name, _callback) {
|
|
|
me.each(_e, function(name, _callback) {
|
|
|
if (_callback === callback) {
|
|
|
e.push(name);
|
|
|
}
|
|
|
});
|
|
|
me.each(e.reverse(), function (name, _callback) {
|
|
|
me.each(e.reverse(), function(name, _callback) {
|
|
|
_e.splice(_callback, 1);
|
|
|
});
|
|
|
},
|
|
|
init:function(){
|
|
|
init: function() {
|
|
|
var __self = this;
|
|
|
this.render();
|
|
|
this.bind();
|
|
|
return this;
|
|
|
},
|
|
|
render:function(){
|
|
|
var that=this;
|
|
|
|
|
|
render: function() {
|
|
|
var that = this;
|
|
|
|
|
|
/*初始化checkbox和radis*/
|
|
|
$("input:hidden",that.el).each(function(){
|
|
|
var $this=$(this);
|
|
|
var name=$this.attr("id"),
|
|
|
values=String.prototype.split.call($this.val(),'|'),
|
|
|
type=$this.attr("for");
|
|
|
|
|
|
if(type){
|
|
|
$(":"+type+"[name="+name+"]").each(function(){
|
|
|
var $that=$(this);
|
|
|
$.each(values,function(index,value){
|
|
|
if($that.val()===value){
|
|
|
$("input:hidden", that.el).each(function() {
|
|
|
var $this = $(this);
|
|
|
var name = $this.attr("id"),
|
|
|
values = String.prototype.split.call($this.val(), '|'),
|
|
|
type = $this.attr("for");
|
|
|
|
|
|
if (type) {
|
|
|
$(":" + type + "[name=" + name + "]").each(function() {
|
|
|
var $that = $(this);
|
|
|
$.each(values, function(index, value) {
|
|
|
if ($that.val() === value) {
|
|
|
$that.prop("checked", true);
|
|
|
}
|
|
|
})
|
...
|
...
|
@@ -87,14 +87,14 @@ edit.prototype={ |
|
|
}
|
|
|
});
|
|
|
/*初始化dropdown*/
|
|
|
$("select").each(function(){
|
|
|
var _value=$(this).attr("value");
|
|
|
if(_value){
|
|
|
$("option[value='"+_value+"']",$(this)).attr("selected", true);
|
|
|
$("select").each(function() {
|
|
|
var _value = $(this).attr("value");
|
|
|
if (_value) {
|
|
|
$("option[value='" + _value + "']", $(this)).attr("selected", true);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
/*时间插件初始化*/
|
|
|
/*时间插件初始化*/
|
|
|
var fdatepicker = {};
|
|
|
$("input[jsaction]", that.el)
|
|
|
.add("input[jsaction]", that.el)
|
...
|
...
|
@@ -127,6 +127,21 @@ edit.prototype={ |
|
|
}
|
|
|
|
|
|
/*初始化文件上传*/
|
|
|
<<<<<<< HEAD
|
|
|
if ($('input[type="file"]', that.el).length > 0) {
|
|
|
$('input[type="file"]', that.el).each(function() {
|
|
|
var src = $(this).attr("value");
|
|
|
var _id = $(this).attr("id") || $(this).attr("name");
|
|
|
var Temp = '<ul class="upload-image-list" id="img-' + _id + '">';
|
|
|
Temp += '<li class="fileinput-button">';
|
|
|
Temp += '<a class="fileinput-button-icon" href="javascript:void(0);">';
|
|
|
if (src) {
|
|
|
var ext = src.split('.').pop().toLowerCase();
|
|
|
if (ext == "mp4") {
|
|
|
Temp += '<video width="76" height="80" src="' + src + '"></video>';
|
|
|
} else {
|
|
|
Temp += '<img width="76" height="80" src="' + src + '">';
|
|
|
=======
|
|
|
if($('input[type="file"]',that.el).length>0){
|
|
|
$('input[type="file"]',that.el).each(function(){
|
|
|
var src=$(this).attr("value");
|
...
|
...
|
@@ -136,17 +151,21 @@ edit.prototype={ |
|
|
Temp+='<a class="fileinput-button-icon" href="javascript:void(0);">';
|
|
|
if(src){
|
|
|
var ext = src.split('.').pop().toLowerCase();
|
|
|
if(ext=="mp4"){
|
|
|
if("mp4,rmvb,avi,mov".indexOf(ext)>-1){
|
|
|
Temp+='<video width="76" height="80" src="'+src+'"></video>';
|
|
|
}else{
|
|
|
Temp+='<img width="76" height="80" src="'+src+'">';
|
|
|
}
|
|
|
}else{
|
|
|
Temp+='+';
|
|
|
>>>>>>> master
|
|
|
}
|
|
|
Temp+='</a>';
|
|
|
Temp+='</li>';
|
|
|
Temp+='</ul>';
|
|
|
} else {
|
|
|
Temp += '+';
|
|
|
}
|
|
|
Temp += '</a>';
|
|
|
Temp += '</li>';
|
|
|
Temp += '</ul>';
|
|
|
$(this).after(Temp);
|
|
|
});
|
|
|
// edit.ajaxfileupload(that.el+" input[type='file']",{
|
...
|
...
|
@@ -161,128 +180,152 @@ edit.prototype={ |
|
|
// $(this).attr("value",response.data);
|
|
|
// }
|
|
|
// });
|
|
|
<<<<<<< HEAD
|
|
|
$('input[type="file"]', that.el).ajaxfileupload({
|
|
|
'action': '/ajax/upload',
|
|
|
'params': {
|
|
|
"userId": 543883,
|
|
|
"bucket": that.option.bucket || 'smart',
|
|
|
__type: "upload"
|
|
|
},
|
|
|
=======
|
|
|
if(!that.option.bucket){
|
|
|
alert("bucket不存在");
|
|
|
}
|
|
|
$('input[type="file"]',that.el).ajaxfileupload({
|
|
|
'action': '/ajax/upload',
|
|
|
'params':{"userId":543883,"bucket":that.option.bucket||'smart',__type:"upload"},
|
|
|
'params':{"userId":543883,"bucket":that.option.bucket,__type:"upload"},
|
|
|
>>>>>>> master
|
|
|
'onComplete': function(response) {
|
|
|
if(response.status&&response.code==200){
|
|
|
var _w=$(this).next().find('.fileinput-button-icon');
|
|
|
var _img=$('img',_w).add('video',_w);
|
|
|
if(_img.length>0){
|
|
|
_img.attr("src",response.data);
|
|
|
}else{
|
|
|
if (response.status && response.code == 200) {
|
|
|
var _w = $(this).next().find('.fileinput-button-icon');
|
|
|
var _img = $('img', _w).add('video', _w);
|
|
|
if (_img.length > 0) {
|
|
|
_img.attr("src", response.data);
|
|
|
} else {
|
|
|
var ext = response.data.split('.').pop().toLowerCase();
|
|
|
if(ext=="mp4"){
|
|
|
_w.prepend('<video width="76" height="80" src="'+response.data+'"></video>');
|
|
|
}else{
|
|
|
_w.prepend('<img width="76" height="80" src="'+response.data+'">');
|
|
|
if (ext == "mp4") {
|
|
|
_w.prepend('<video width="76" height="80" src="' + response.data + '"></video>');
|
|
|
} else {
|
|
|
_w.prepend('<img width="76" height="80" src="' + response.data + '">');
|
|
|
}
|
|
|
}
|
|
|
$(this).attr("value",response.data);
|
|
|
that.__listen("callback",{key:"file_onComplete_"+$(this).attr("id"),data:response.data});
|
|
|
}else{
|
|
|
$(this).attr("value", response.data);
|
|
|
that.__listen("callback", {
|
|
|
key: "file_onComplete_" + $(this).attr("id"),
|
|
|
data: response.data
|
|
|
});
|
|
|
} else {
|
|
|
that.$tip(response.message);
|
|
|
}
|
|
|
|
|
|
|
|
|
},
|
|
|
'onStart': function() {
|
|
|
that.__listen("callback",{key:"file_onStart_"+$(this).attr("id")});
|
|
|
that.__listen("callback", {
|
|
|
key: "file_onStart_" + $(this).attr("id")
|
|
|
});
|
|
|
},
|
|
|
'onCancel': function() {
|
|
|
that.__listen("callback",{key:"file_onCancel_"+$(this).attr("id")});
|
|
|
that.__listen("callback", {
|
|
|
key: "file_onCancel_" + $(this).attr("id")
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
that.__listen("render");
|
|
|
},
|
|
|
bind:function(){
|
|
|
var that=this;
|
|
|
var cr={};
|
|
|
$(":checkbox",that.el).add(":radio",that.el).change(function(){
|
|
|
var $this=$(this);
|
|
|
var id=$this.attr("name"),
|
|
|
value=$this.val();
|
|
|
bind: function() {
|
|
|
var that = this;
|
|
|
var cr = {};
|
|
|
$(":checkbox", that.el).add(":radio", that.el).change(function() {
|
|
|
var $this = $(this);
|
|
|
var id = $this.attr("name"),
|
|
|
value = $this.val();
|
|
|
|
|
|
cr[id]=[];
|
|
|
cr[id] = [];
|
|
|
|
|
|
if($this.is(":checkbox")){
|
|
|
$(":checked[name="+id+"]",that.el).each(function(){
|
|
|
cr[id].push($(this).val())
|
|
|
if ($this.is(":checkbox")) {
|
|
|
$(":checked[name=" + id + "]", that.el).each(function() {
|
|
|
cr[id].push($(this).val())
|
|
|
});
|
|
|
}
|
|
|
if($this.is(":radio")){
|
|
|
cr[id][0]=value;
|
|
|
if ($this.is(":radio")) {
|
|
|
cr[id][0] = value;
|
|
|
}
|
|
|
$("#"+id,that.el).val(cr[id].join('|'));
|
|
|
$("#" + id, that.el).val(cr[id].join('|'));
|
|
|
});
|
|
|
that.__listen("bind");
|
|
|
},
|
|
|
validate:function(){
|
|
|
var that=this;
|
|
|
var rules = {},data = {},attributes={};
|
|
|
validate: function() {
|
|
|
var that = this;
|
|
|
var rules = {},
|
|
|
data = {},
|
|
|
attributes = {};
|
|
|
|
|
|
var err=[];
|
|
|
var err = [];
|
|
|
|
|
|
$("input:text",that.el)
|
|
|
.add("input[type=number]",that.el)
|
|
|
.add("input:hidden",that.el)
|
|
|
.add("textarea",that.el)
|
|
|
.each(function() {
|
|
|
var id = $(this).attr("id");
|
|
|
var name = $(this).attr("name");
|
|
|
var value =$.trim($(this).val());
|
|
|
if($(this).attr("type")=="file"){
|
|
|
value=!!$(this).attr("value")?$(this).attr("value"):$(this).val();
|
|
|
}
|
|
|
var name=$(this).attr("placeholder")&&!(/^\d+$/.test($(this).attr("placeholder")))?$(this).attr("placeholder").replace(/请填写/g,''):$(this).parents(".form-group").find("label").text().replace(/\*/g,'');
|
|
|
// var rule = [];
|
|
|
$("input:text", that.el)
|
|
|
.add("input[type=number]", that.el)
|
|
|
.add("input:hidden", that.el)
|
|
|
.add("textarea", that.el)
|
|
|
.each(function() {
|
|
|
var id = $(this).attr("id");
|
|
|
var name = $(this).attr("name");
|
|
|
var value = $.trim($(this).val());
|
|
|
if ($(this).attr("type") == "file") {
|
|
|
value = !!$(this).attr("value") ? $(this).attr("value") : $(this).val();
|
|
|
}
|
|
|
var name = $(this).attr("placeholder") && !(/^\d+$/.test($(this).attr("placeholder"))) ? $(this).attr("placeholder").replace(/请填写/g, '') : $(this).parents(".form-group").find("label").text().replace(/\*/g, '');
|
|
|
// var rule = [];
|
|
|
|
|
|
if ((id||name)&&$(this).attr("required")) {
|
|
|
new Validator.init($(this)[0],{
|
|
|
rules:{required:true}
|
|
|
}).validate(function(obj){
|
|
|
err.push("<p>"+name+"不可为空</p>");
|
|
|
});
|
|
|
}
|
|
|
if ((id || name) && $(this).attr("required")) {
|
|
|
new Validator.init($(this)[0], {
|
|
|
rules: {
|
|
|
required: true
|
|
|
}
|
|
|
}).validate(function(obj) {
|
|
|
err.push("<p>" + name + "不可为空</p>");
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// if ($(this).attr("maxlength")) {
|
|
|
// rule.push("max:" + $(this).attr("maxlength"));
|
|
|
// }
|
|
|
// if ($(this).attr("minlength")) {
|
|
|
// rule.push("max:" + $(this).attr("minlength"));
|
|
|
// }
|
|
|
// if ($(this).attr("maxlength")) {
|
|
|
// rule.push("max:" + $(this).attr("maxlength"));
|
|
|
// }
|
|
|
// if ($(this).attr("minlength")) {
|
|
|
// rule.push("max:" + $(this).attr("minlength"));
|
|
|
// }
|
|
|
|
|
|
// var pattern=$(this).attr("pattern");
|
|
|
// if (pattern) {
|
|
|
// if(/(^\/)|(\/&)/.test(pattern)){
|
|
|
// rule.push("regex:" + $(this).attr("pattern"));
|
|
|
// }else{
|
|
|
// rule.push(pattern);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
});
|
|
|
// var pattern=$(this).attr("pattern");
|
|
|
// if (pattern) {
|
|
|
// if(/(^\/)|(\/&)/.test(pattern)){
|
|
|
// rule.push("regex:" + $(this).attr("pattern"));
|
|
|
// }else{
|
|
|
// rule.push(pattern);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
});
|
|
|
|
|
|
//文件上传
|
|
|
$("input[type=file]",that.el).each(function(){
|
|
|
$("input[type=file]", that.el).each(function() {
|
|
|
var id = $(this).attr("id");
|
|
|
var value =$.trim($(this).attr("value"));
|
|
|
var name=$(this).attr("placeholder")&&!(/^\d+$/.test($(this).attr("placeholder")))?$(this).attr("placeholder").replace(/请填写/g,''):$(this).parents(".form-group").find("label").text().replace(/\*/g,'');
|
|
|
if (id&&$(this).attr("required")&&!value) {
|
|
|
err.push("<p>"+name+"不可为空</p>");
|
|
|
}
|
|
|
var value = $.trim($(this).attr("value"));
|
|
|
var name = $(this).attr("placeholder") && !(/^\d+$/.test($(this).attr("placeholder"))) ? $(this).attr("placeholder").replace(/请填写/g, '') : $(this).parents(".form-group").find("label").text().replace(/\*/g, '');
|
|
|
if (id && $(this).attr("required") && !value) {
|
|
|
err.push("<p>" + name + "不可为空</p>");
|
|
|
}
|
|
|
});
|
|
|
//下拉选择
|
|
|
$("select",that.el).each(function(){
|
|
|
$("select", that.el).each(function() {
|
|
|
var id = $(this).attr("id");
|
|
|
var value =$.trim($(this).val());
|
|
|
var name=$(this).attr("placeholder")&&!(/^\d+$/.test($(this).attr("placeholder")))?$(this).attr("placeholder").replace(/请填写/g,''):$(this).parents(".form-group").find("label").text().replace(/\*/g,'');
|
|
|
|
|
|
if ($(this).attr("required")&&(+value==-1||+value=="")) {
|
|
|
err.push("<p>请选择 "+name+"</p>");
|
|
|
var value = $.trim($(this).val());
|
|
|
var name = $(this).attr("placeholder") && !(/^\d+$/.test($(this).attr("placeholder"))) ? $(this).attr("placeholder").replace(/请填写/g, '') : $(this).parents(".form-group").find("label").text().replace(/\*/g, '');
|
|
|
|
|
|
if ($(this).attr("required") && (+value == -1 || +value == "")) {
|
|
|
err.push("<p>请选择 " + name + "</p>");
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
// var v = Validator.make(data, rules);
|
|
|
// v.mergeAttribute(attributes);
|
...
|
...
|
@@ -294,45 +337,45 @@ edit.prototype={ |
|
|
// that.__err(err.join(''));
|
|
|
// return false;
|
|
|
// }
|
|
|
if(err.length>0){
|
|
|
if (err.length > 0) {
|
|
|
that.__err(err.join(''));
|
|
|
return false;
|
|
|
}
|
|
|
var zierr=0;
|
|
|
that.__listen("validate",'',function(data){
|
|
|
if(data==false||typeof data=="string"){
|
|
|
var zierr = 0;
|
|
|
that.__listen("validate", '', function(data) {
|
|
|
if (data == false || typeof data == "string") {
|
|
|
zierr++;
|
|
|
typeof data=="string"?err.push("<p>"+data+"</p>"):'';
|
|
|
typeof data == "string" ? err.push("<p>" + data + "</p>") : '';
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if(zierr>0){
|
|
|
|
|
|
if (zierr > 0) {
|
|
|
that.__err(err.join(''));
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
},
|
|
|
submit:function(url,callback){
|
|
|
var that=this;
|
|
|
if(!that.validate()){
|
|
|
submit: function(url, callback) {
|
|
|
var that = this;
|
|
|
if (!that.validate()) {
|
|
|
return false;
|
|
|
}
|
|
|
var data={};
|
|
|
$("input:text",that.el)//number
|
|
|
.add("input[type=number]",that.el)
|
|
|
.add("input:hidden",that.el)
|
|
|
.add("select",that.el)
|
|
|
.add("textarea",that.el)
|
|
|
.each(function(){
|
|
|
var name=$(this).attr("id");
|
|
|
var value=$.trim($(this).val());
|
|
|
data[name]=value;
|
|
|
});
|
|
|
$("input[type=file]",that.el).each(function(){
|
|
|
var name=$(this).attr("id");
|
|
|
var value=$(this).attr("value");
|
|
|
data[name]=value;
|
|
|
var data = {};
|
|
|
$("input:text", that.el) //number
|
|
|
.add("input[type=number]", that.el)
|
|
|
.add("input:hidden", that.el)
|
|
|
.add("select", that.el)
|
|
|
.add("textarea", that.el)
|
|
|
.each(function() {
|
|
|
var name = $(this).attr("id");
|
|
|
var value = $.trim($(this).val());
|
|
|
data[name] = value;
|
|
|
});
|
|
|
$("input[type=file]", that.el).each(function() {
|
|
|
var name = $(this).attr("id");
|
|
|
var value = $(this).attr("value");
|
|
|
data[name] = value;
|
|
|
});
|
|
|
|
|
|
var options = {
|
...
|
...
|
@@ -348,52 +391,53 @@ edit.prototype={ |
|
|
return false;
|
|
|
}
|
|
|
};
|
|
|
callback&&callback(options);
|
|
|
if(!options.debug){
|
|
|
callback && callback(options);
|
|
|
if (!options.debug) {
|
|
|
$.ajax(options);
|
|
|
} else {
|
|
|
return options.data;
|
|
|
}
|
|
|
//return false;
|
|
|
},
|
|
|
__listen:function(key,o,callback){
|
|
|
var __self=this;
|
|
|
if (__self.registerEvent[key]&&__self.registerEvent[key].length > 0) {
|
|
|
__listen: function(key, o, callback) {
|
|
|
var __self = this;
|
|
|
if (__self.registerEvent[key] && __self.registerEvent[key].length > 0) {
|
|
|
for (_e in __self.registerEvent[key]) {
|
|
|
var a=__self.registerEvent[key][_e](o);
|
|
|
if(callback){
|
|
|
var a = __self.registerEvent[key][_e](o);
|
|
|
if (callback) {
|
|
|
callback(a);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
__err:function(msg,callback){
|
|
|
if(msg){
|
|
|
this.$tip(msg,callback);
|
|
|
__err: function(msg, callback) {
|
|
|
if (msg) {
|
|
|
this.$tip(msg, callback);
|
|
|
}
|
|
|
},
|
|
|
$tip:function(msg,callback,type){
|
|
|
$tip: function(msg, callback, type) {
|
|
|
$.gritter.add({
|
|
|
title: msg,
|
|
|
class_name: type||'growl-warning',
|
|
|
class_name: type || 'growl-warning',
|
|
|
sticky: false,
|
|
|
time:1000,
|
|
|
time: 1000,
|
|
|
after_open: setTimeout(function() {
|
|
|
callback&&callback();
|
|
|
},1000)
|
|
|
});
|
|
|
callback && callback();
|
|
|
}, 1000)
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
edit.ajaxfileupload=function(el,option){
|
|
|
edit.ajaxfileupload = function(el, option) {
|
|
|
$(el).ajaxfileupload({
|
|
|
'action': '/ajax/upload',
|
|
|
'params':$.extend({},{__type:"fileupload-upload"},option.params),
|
|
|
onComplete:option.onComplete,
|
|
|
onStart: option.onStart,
|
|
|
valid_extensions:option.valid_extensions||["xlsx"]
|
|
|
'params': $.extend({}, {
|
|
|
__type: "fileupload-upload"
|
|
|
}, option.params),
|
|
|
onComplete: option.onComplete,
|
|
|
onStart: option.onStart,
|
|
|
valid_extensions: option.valid_extensions || ["xlsx"]
|
|
|
})
|
|
|
}
|
|
|
edit.prototype.init.prototype=edit.prototype;
|
|
|
|
|
|
module.exports=edit;
|
|
|
|
|
|
|
|
|
edit.prototype.init.prototype = edit.prototype;
|
|
|
|
|
|
module.exports = edit; |
|
|
\ No newline at end of file |
...
|
...
|
|