westdc-zf1/htdocs/js/lib/custom/models/dataservice.js

152 lines
4.1 KiB
JavaScript
Raw Normal View History

var westdc = {};
westdc.dataservice = {
//wsn 选择数据
choiceData : function(uuid,btn)
{
this.uuid = uuid;
_btn = {
html : $(btn).html(),
onclick : $(btn).attr('onclick')
};
$.ajax({
'type':"POST",
'url':'/data/dataservice',
'data':'uuid=' + this.uuid,
'success':function(data){
if(typeof(data) == 'undefined')
{
alert("数据源错误,请联系管理员");
return false;
}
if(!$.isEmptyObject(data.error))
{
alert(data.error);
return false;
}
if(data.type == "wsn")
{
html = westdc.dataservice.wsn.dialog.site(data);
westdc.dataservice.creatWindow(html);
}
},
'timeout': 30000,
'beforeSend': function(){
$(btn).attr('onclick','');
$(btn).html("加载中...");
$(btn).addClass('disabled');
},
'complete': function(){
$(btn).attr('onclick', _btn.onclick);
$(btn).html(_btn.html);
$(btn).removeClass('disabled');
},
'error': function(){
alert('出现错误,请刷新后重试');
}
});
},
creatWindow : function(html){
$.colorbox({
initialHeight: '0',
initialWidth: '0',
html: html,
opacity: '0.3',
onComplete: function(){
$('.confirm_yes').click(function(e){
e.preventDefault();
});
$('.confirm_no').click(function(e){
e.preventDefault();
$.colorbox.close();
});
}
});
}
}
westdc.dataservice.wsn = {
request : function()
{
$.ajax({
'type':"POST",
'url':'/data/wsn/',
'data':$('#dataservice-wsn-form').serialize(),
'success':function(data){
if(typeof(data) == 'undefined')
{
alert("数据源错误,请联系管理员");
return false;
}
if(!$.isEmptyObject(data.error))
{
alert(data.error);
return false;
}
html = westdc.dataservice.wsn.dialog.vars(data);
westdc.dataservice.creatWindow(html);
},
'timeout': 30000,
'error': function(){
alert('出现错误,请刷新后重试');
}
});
},
dialog : {
site : function(data){
this.input = new Array();
for(i in data.data)
{
this.li = '<label class="checkbox">'
+ '<input type="checkbox" value="' + data.data[i].siteid + '" name="siteid[]" checked="checked" /> '
+ data.data[i].sitename
+ '</label>';
this.input.push(this.li);
}
this.HTML = '<div class=""><div class="modal-header"><h3>'+data.info.service_title+'</h3></div>'
+ '<div class="modal-body"><form id="dataservice-wsn-form">'
+ '<div>请选择要下载数据的观测点</div>'
+ '<div>'
+ this.input.join("")
+ '</div>'
+ '<input type="hidden" name="uuid" value="'+data.info.uuid+'" />'
+ '<input type="hidden" name="type" value="var" />'
+ '</form></div>'
+ '<div class="modal-footer"><a href="javascript:void(0);" class="btn btn-primary confirm_yes" onclick=' + data.callback + '>下一步</a>'
+ '<a href="javascript:void(0);" class="btn confirm_no">取消</a></div></div>';
return this.HTML;
},
vars : function(data){
this.input = new Array();
for(i in data.data)
{
for(i in data.data)
this.li = '<label class="checkbox">'
+ '<input type="checkbox" value="' + data.data[i].varid + '" name="siteid[]" checked="checked" /> '
+ data.data[i].nameview
+ '</label>';
this.input.push(this.li);
}
this.HTML = '<div class=""><div class="modal-header"><h3>'+data.info.service_title+'</h3></div>'
+ '<div class="modal-body"><form id="dataservice-wsn-form">'
+ '<div>请选择需要下载的变量</div>'
+ '<div>'
+ this.input.join("")
+ '</div>'
+ '<input type="hidden" name="uuid" value="'+data.uuid+'" />'
+ '<input type="hidden" name="type" value="var" />'
+ '</form></div>'
+ '<div class="modal-footer"><a href="javascript:void(0);" class="btn btn-primary confirm_yes" onclick=' + data.callback + '>提交</a>'
+ '<a href="javascript:void(0);" class="btn confirm_no">取消</a></div></div>';
return this.HTML;
}
}
}