building_parameter = {
};
function building_grid(items, gridRoom) {
var str = '
';
str += '| id | name | address | operate |
';
if (items) {
$.each(items, function(index, item) {
str += '';
str += '| ' + item.id + ' | ';
str += '' + item.name + ' | ';
str += '' + item.address + ' | ';
str += '';
str += 'edit ';
str += 'delete';
str += ' | ';
str += '
';
if (gridRoom) {
str += building_grid_room(item.roomList);
}
});
}
str += '
';
$('#content').html(str);
}
function building_grid_room(items) {
var str = "";
if (items) {
$.each(items, function(index, item) {
str += '';
str += '| ' + item.name + ' | ';
str += '' + item.id + ' | ';
if (item.photo && item.photo != '') {
str += ' ';
} else {
str += ' ';
}
str += ' | ';
str += 'edit ';
str += 'delete ';
str += 'photo';
str += ' | ';
str += '
';
});
}
return str;
}
function building_list() {
$('#result').html('');
$.ajax({
type : 'get',
dataType : 'json',
url : '../jaxrs/building/list',
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(json) {
$('#result').html(JSON.stringify(json, null, 4));
if (json.type == 'success') {
building_grid(json.data, true);
}
});
}
function building_listCheckRoomIdle_select() {
$('#result').html('');
var str = '';
$('#content').html(str);
$('#list').click(function() {
building_listCheckRoomIdle($('#start').val(), $('#completed').val());
});
}
function building_listCheckRoomIdle(start, completed) {
$('#result').html('');
$.ajax({
type : 'get',
dataType : 'json',
url : '../jaxrs/building/list/start/' + start + '/completed/' + completed,
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(json) {
$('#result').html(JSON.stringify(json, null, 4));
if (json.type == 'success') {
building_grid(json.data, true);
}
});
}
function building_post_select() {
$('#result').html('');
var str = '';
$('#content').html(str);
$('#post').click(function() {
building_post();
});
}
function building_post() {
$('#result').html('');
$.ajax({
type : 'post',
dataType : 'json',
url : '../jaxrs/building',
contentType : 'application/json; charset=utf-8',
data : JSON.stringify({
name : $('#name').val(),
address : $('#address').val()
}),
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(json) {
$('#result').html(JSON.stringify(json, null, 4));
});
}
function building_put_select() {
$('#result').html('');
var str = '';
$('#content').html(str);
$('#select').click(function() {
building_put_init($('#id').val());
});
}
function building_put_init(id) {
$('#result').html('');
var str = '';
$('#content').html(str);
$('#put').click(function() {
building_put(id);
});
$.ajax({
type : 'get',
dataType : 'json',
url : '../jaxrs/building/' + id,
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(json) {
$('#result').html(JSON.stringify(json, null, 4));
if (json.type == 'success') {
$('#id').html(json.data.id);
$('#name').val(json.data.name);
$('#address').val(json.data.address);
}
});
}
function building_put(id) {
$('#result').html('');
$.ajax({
type : 'put',
dataType : 'json',
url : '../jaxrs/building/' + id,
contentType : 'application/json; charset=utf-8',
data : JSON.stringify({
name : $('#name').val(),
address : $('#address').val()
}),
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(json) {
$('#result').html(JSON.stringify(json, null, 4));
});
}
function building_delete_select() {
$('#result').html('');
var str = '';
$('#content').html(str);
$('#select').click(function() {
building_delete($('#id').val());
});
}
function building_delete(id) {
$('#result').html('');
$.ajax({
type : 'delete',
dataType : 'json',
url : '../jaxrs/building/' + id,
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(json) {
$('#result').html(JSON.stringify(json, null, 4));
});
}
function building_search_select() {
$('#result').html('');
var str = '';
$('#content').html(str);
$('#listPinyinInitial').click(function() {
building_listPinyinInitial($('#key').val());
});
$('#listLike').click(function() {
building_listLike($('#key').val());
});
$('#listLikePinyin').click(function() {
building_listLikePinyin($('#key').val());
});
}
function building_listPinyinInitial(key) {
$('#result').html('');
$.ajax({
type : 'get',
dataType : 'json',
url : '../jaxrs/building/list/pinyininitial/' + key,
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(json) {
$('#result').html(JSON.stringify(json, null, 4));
building_grid(json.data, false);
});
}
function building_listLike(key) {
$('#result').html('');
$.ajax({
type : 'get',
dataType : 'json',
url : '../jaxrs/building/list/like/' + key,
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(json) {
$('#result').html(JSON.stringify(json, null, 4));
building_grid(json.data, false);
});
}
function building_listLikePinyin(key) {
$('#result').html('');
$.ajax({
type : 'get',
dataType : 'json',
url : '../jaxrs/building/list/like/pinyin/' + key,
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(json) {
$('#result').html(JSON.stringify(json, null, 4));
building_grid(json.data, false);
});
}