westdc-zf1/public/static/js/custom/models/file_plugin.js

117 lines
2.7 KiB
JavaScript

// JavaScript Document
(function( $ ){
$.fn.deleteatt = function( options ) {
var settings = $.extend( {
id:'',
content:'',
item_prefix:'fileItem_',
url:'/service/delatt',
callback : null
}, options);
var methods = {
edit : function()
{
methods.creatWindow();
},
creatWindow : function(id){
$.colorbox({
initialWidth:0,
initialHeight :0,
closeButton:false,
returnFocus : false,
trapFocus : false,
html: methods.dialog,
opacity: '0',
onComplete: function(){
$('.confirm_yes').click(function(e){
e.preventDefault();
methods.submited();
$.colorbox.close();
});
$('.confirm_no').click(function(e){
e.preventDefault();
$.colorbox.close();
});
}
});
},
submited : function(id){
$.ajax({
'type':"POST",
'url':settings.url,
'data':'id='+settings.id,
'success':function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{
alert(data.error);
f = '#' + settings.item_prefix + settings.id;
$(f).fadeOut(500,function() {
$(f).remove();
});
}
if(typeof(data.success)!='undefined')
{
f = '#' + settings.item_prefix + settings.id;
$(f).fadeOut(500,function() {
$(f).remove();
if(settings.callback != null)
{
settings.callback();
}
});
}
}
else{
alert('出现错误,请稍候再试');
}
},
'timeout': 30000,
'error': function(){
alert('出现错误,请刷新后重试');
}
});
},
dialog : function(content){
this.HTML = '<div class="">'
+' <div class="modal-dialog">'
+' <div class="modal-content">'
+' <div class="modal-header">'
+' <button type="button" class="close" onclick="$.colorbox.close();">&times;</button>'
+' <h4 class="modal-title">删除文件</h4>'
+' </div>'
+' <div class="modal-body">'
+' <p>'+settings.content+'</p>'
+' </div>'
+' <div class="modal-footer">'
+' <button type="button" class="btn btn-default confirm_no" data-dismiss="modal">否</button>'
+' <button type="button" class="btn btn-primary confirm_yes">是</button>'
+' </div>'
+' </div>'
+' </div>'
+'</div>';
return this.HTML;
}
}
this.each(function() {
if( settings.id == '')
{
alert('参数错误');
}
if( settings.content == "")
{
settings.content = '是否删除此文件?';
}
methods.edit();
});
};
})( jQuery );