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',
maxWidth : '80%',
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);
westdc.dataservice.wsn._init.vars();
},
'timeout': 30000,
'error': function(){
alert('出现错误,请刷新后重试');
}
});
},
Submit : 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;
}
if($.isEmptyObject(data.data))
{
alert("提交失败,可能是服务器通信错误,请联系管理员");
return false;
}
if(data.data.success == 1)
{
window.location = '/data/order/ac/offline1';
return true;
}else{
alert('提交失败,请重试');
return false;
}
},
'timeout': 30000,
'error': function(){
alert('出现错误,请刷新后重试');
}
});
},
dialog : {
site : function(data){
this.input = new Array();
for(i in data.data)
{
this.li = '';
this.input.push(this.li);
}
this.HTML = '
';
return this.HTML;
},
vars : function(data){
this.selects = "";
this.uls = new Array();
this.count = 0;
this.first = 0;
for(i in data.data)
{
this.input = new Array();
this.input.push('');
for(x in data.data[i].var)
{
this.li = '';
this.input.push(this.li);
}
this.timemap = '数据时间范围: '
+ ' - '
+ ''
+ '
';
this.uls.push('观测点:'+data.data[i].name+'
可下载的变量: '+ this.input.join("") + this.timemap + '
');
this.count++;
if(this.count == 1)
{
this.first = i;
}
}
this.selects = this.uls.join("");
if(this.count > 1)
{
this.allcontrol = '
';
}else{
this.allcontrol = "";
}
this.HTML = '';
return this.HTML;
}
},
_init : {
vars : function(){
$('.wsnctl').each(function(index, element) {
_this = $(this);
siteid = $(this).attr('rel');
timestart = $(this).children('.wsnctl-time').children('.wsnctl-timestart');
timeend = $(this).children('.wsnctl-time').children('.wsnctl-timeend');
if(timestart.length && timeend.length)
{
year_start=(timestart).val().substr(0,4);
month_start=parseInt((timestart).val().substr(5,2))-1;
day_start=parseInt((timestart).val().substr(8,2));
year_end=(timeend.val()).substr(0,4);
month_end=parseInt((timeend.val()).substr(5,2))-1;
day_end=parseInt((timeend.val()).substr(8,2));
timestart.datepicker({ minDate: new Date(year_start, month_start, day_start), maxDate: new Date(year_end, month_end, day_end) });
timeend.datepicker({ minDate: new Date(year_start, month_start, day_start), maxDate: new Date(year_end, month_end, day_end) });
}
$(this).find('.wsnctl-select-all').click(function(e) {
if($(this).attr('checked') == 'checked')
{
$(this).parent('label').parent('div').find('.wsnctl-select').attr('disabled','disabled');
}else{
$(this).parent('label').parent('div').find('.wsnctl-select').removeAttr('disabled');
}
});
alltimestart = $(this).children('.wsnctl-time').children('.wsnctl-all-timestart');
alltimeend = $(this).children('.wsnctl-time').children('.wsnctl-all-timeend');
if(alltimestart.length)
{
alltimestart.datepicker({});
alltimestart.change(function(e) {
val = $(this).val();
$('.wsnctl').each(function(index, element) {
$(this).children('.wsnctl-time').children('.wsnctl-timestart').val(val);
});
});
}
if(alltimeend.length)
{
alltimeend.datepicker({});
alltimeend.change(function(e) {
val = $(this).val();
$('.wsnctl').each(function(index, element) {
$(this).children('.wsnctl-time').children('.wsnctl-timeend').val(val);
});
});
}
});
}
}
}