westdc-zf1/htdocs/js/lib/custom/models/author-literature.js

193 lines
5.6 KiB
JavaScript

$(document).ready(function(e) {
$('.edit').click(function(e) {
$(this).litedit({'id':$(this).attr('rel')});
});
$('.order').click(function(e) {
$(this).litorder({'id':$(this).attr('rel')});
});
});
// JavaScript Document
(function( $ ){
$.fn.litedit = function( options ) {
var settings = $.extend( {
id:'',
content : '',
uuid:''
}, options);
var methods = {
edit : function(id)
{
methods.creatWindow(id);
},
creatWindow : function(id,html){
$.colorbox({
initialHeight: '0',
initialWidth: '0',
html: html,
opacity: '0.3',
onComplete: function(){
$('.confirm_yes').click(function(e){
e.preventDefault();
methods.submited(id);
$.colorbox.close();
});
$('.confirm_no').click(function(e){
e.preventDefault();
$.colorbox.close();
});
}
});
},
submited : function(id){
$.ajax({
'type':"POST",
'url':'/author/literature/',
'data':'ac=edit&'+$('#edit-mdref').serialize(),
'success':function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{alert(data.error);}
if(typeof(data.success)!='undefined')
{
window.location.reload();
}
}
else{
alert('出现错误,请稍候再试');
}
},
'timeout': 30000,
'error': function(){
alert('出现错误,请刷新后重试');
}
});
},
loadinfo : function(id){
$.ajax({
'type':"POST",
'url':'/author/literature/',
'data':'ac=get&id='+id,
'success':function(data){
html = methods.dialog(data);
methods.creatWindow(id,html);
},
'timeout': 30000,
'error': function(){
alert('出现错误,请刷新后重试');
}
});
},
dialog : function(data){
HTML = '<div class=""><div class="modal-header"><h3>修改文献</h3></div>'
+ '<div class="modal-body"><form id="edit-mdref">'
+ '<div><textarea class="span8" id="content_input_area" name="content">'+data.reference+'</textarea></div>'
+ '<div><input type="text" name="link" value="'+((data.link == null) ? "":data.link)+'" class="span8" placeholder="链接" /></div>'
+ '<div><label class="radio"><input type="radio" name="reftype" value="0" '+ ((data.reftype == 0) ? "checked":"") +'>作者文献</label></div>'
+ '<div><label class="radio"><input type="radio" name="reftype" value="1" '+ ((data.reftype == 1) ? "checked":"") +'>用户文献</label></div>'
+ '<div><label class="radio"><input type="radio" name="reftype" value="2" '+ ((data.reftype == 2) ? "checked":"") +'>数据的参考文献</label></div>'
+ '<div><label class="radio"><input type="radio" name="reftype" value="3" '+ ((data.reftype == 3) ? "checked":"") +'>作者要求的文献引用方式(多篇)</label></div>'
+ '<input type="hidden" name="refid" value="'+data.refid+'" />'
+ '<input type="hidden" name="uuid" value="'+settings.uuid+'" />'
+ '<input type="hidden" name="id" value="'+settings.id+'" />'
+ '</form></div>'
+ '<div class="modal-footer"><a href="javascript:void(0);" class="btn btn-primary confirm_yes">是</a><a href="javascript:void(0);" class="btn confirm_no">否</a></div></div>';
return HTML;
}
}
this.each(function() {
if( settings.id == '')
{
alert('参数错误');
}
settings.uuid = $(this).attr('rev');
methods.loadinfo(settings.id);
});
};
})( jQuery );
(function( $ ){
$.fn.litorder = function( options ) {
var settings = $.extend( {
id:'',
order : '',
}, options);
var methods = {
edit : function(id)
{
methods.creatWindow(id);
},
creatWindow : function(id){
$.colorbox({
initialHeight: '0',
initialWidth: '0',
html: methods.dialog,
opacity: '0.3',
onComplete: function(){
$('.confirm_yes').click(function(e){
e.preventDefault();
methods.submited(id);
$.colorbox.close();
});
$('.confirm_no').click(function(e){
e.preventDefault();
$.colorbox.close();
});
}
});
},
submited : function(id){
$.ajax({
'type':"POST",
'url':'/author/literature/',
'data':'ac=order&id='+id+'&order='+$('#order_input').val(),
'success':function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{alert(data.error);}
if(typeof(data.success)!='undefined')
{
window.location.reload();
}
}
else{
alert('出现错误,请稍候再试');
}
},
'timeout': 30000,
'error': function(){
alert('出现错误,请刷新后重试');
}
});
},
dialog : function(content){
HTML = '<div class=""><div class="modal-header"><h3>修改排序</h3></div>'
+ '<div class="modal-body">数字越小排序越靠前<br />'
+ '请输入排序数字<input type="text" id="order_input" value="'+settings.order+'"/></div>'
+ '<div class="modal-footer"><a href="javascript:void(0);" class="btn btn-primary confirm_yes">是</a><a href="javascript:void(0);" class="btn confirm_no">否</a></div></div>';
return HTML;
}
}
this.each(function() {
if( settings.id == '')
{
alert('参数错误');
}
settings.order = $(this).attr('rev');
methods.edit(settings.id);
});
};
})( jQuery );