script_parameter = {
root : '../jaxrs/script',
list_action : null,
list_action_parameter : null,
first : '(0)',
last : '(0)',
count : 20,
application : null
};
function script_list_reload() {
if (script_parameter.list_action) {
script_parameter.list_action.call(window, script_parameter.list_action_parameter);
} else {
script_list_next('(0)');
}
}
function script_list_next(id) {
var id = (id ? id : script_parameter.last);
script_parameter.list_action = script_list_next;
script_parameter.list_action_parameter = id;
$.ajax({
type : 'get',
dataType : 'json',
url : script_parameter.root + '/list/' + id + '/next/' + script_parameter.count,
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(data) {
if (data.type == 'success') {
if (data.data.length > 0) {
script_parameter.first = data.data[0].id;
script_parameter.last = data.data[data.data.length - 1].id;
} else {
script_parameter.first = '(0)';
}
$('#content').html(script_list_grid(data.data));
$('#total', '#content').html(data.count);
script_list_init();
} else {
failure(data);
}
});
}
function script_list_prev(id) {
var id = (id ? id : script_parameter.first);
script_parameter.list_action = script_list_prev;
script_parameter.list_action_parameter = id;
$.ajax({
type : 'get',
dataType : 'json',
url : script_parameter.root + '/list/' + id + '/prev/' + script_parameter.count,
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(data) {
if (data.type == 'success') {
if (data.data.length > 0) {
script_parameter.first = data.data[0].id;
script_parameter.last = data.data[data.data.length - 1].id;
} else {
script_parameter.last = '(0)';
}
$('#content').html(script_list_grid(data.data));
$('#total', '#content').html(data.count);
script_list_init();
} else {
failure(data);
}
});
}
function script_list_grid(items) {
var str = '
';
str += '| prev next 0 |
';
str += '| id | name | application | operate |
';
$.each(items, function(index, item) {
str += '';
str += '| ' + item.id + ' | ';
str += '' + item.name + ' | ';
str += '' + item.application + ' | ';
str += '';
str += 'edit ';
str += 'delete';
str += ' | ';
str += '
';
});
str += '
';
return str;
}
function script_list_init() {
$('#next', '#content').click(function() {
script_list_next();
});
$('#prev', '#content').click(function() {
script_list_prev();
});
}
function script_query() {
var str = '';
$('#content').html(str);
$('#listWithApplication', '#content').click(function() {
script_parameter.application = $('#application', '#content').val();
script_listWithApplication($('#application', '#content').val());
});
$('#getWithName', '#content').click(function() {
script_parameter.application = $('#application', '#content').val();
script_getWithName($('#application', '#content').val(), $('#name', '#content').val());
});
}
function script_create() {
str = '';
$('#content').html(str);
$('#post', '#content').click(function() {
script_post();
});
}
function script_post(application) {
script_parameter.application = $('#application', '#content').val();
$.ajax({
type : 'post',
dataType : 'json',
url : script_parameter.root,
contentType : 'application/json; charset=utf-8',
data : JSON.stringify({
application : $('#application', '#content').val(),
name : $('#name', '#content').val(),
alias : $('#alias', '#content').val(),
description : $('#description', '#content').val(),
validated : $('#validated', '#content').val(),
languageType : $('#languageType', '#content').val(),
dependScriptList : splitValue($('#dependScriptList', '#content').val()),
text : $('#text', '#content').val()
}),
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(data) {
if (data.type == 'success') {
script_listWithApplication(script_parameter.application);
} else {
failure(data);
}
});
}
function script_edit(id) {
var str = '';
$('#content').html(str);
$('#put', '#content').click(function() {
script_put(id);
});
$.ajax({
type : 'get',
dataType : 'json',
url : script_parameter.root + '/' + id,
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(data) {
if (data.type == 'success') {
$('#id', '#content').html(data.data.id);
$('#createTime', '#content').html(data.data.createTime);
$('#creatorPerson', '#content').html(data.data.creatorPerson);
$('#lastUpdateTime', '#content').html(data.data.lastUpdateTime);
$('#lastUpdatePerson', '#content').html(data.data.lastUpdatePerson);
$('#application', '#content').val(data.data.application);
$('#name', '#content').val(data.data.name);
$('#alias', '#content').val(data.data.alias);
$('#description', '#content').val(data.data.description);
$('#languageType', '#content').val(data.data.languageType);
$('#validated', '#content').val(data.data.validated);
$('#text', '#content').val(data.data.text);
$('#dependScriptList', '#content').val(joinValue(data.data.dependScriptList));
} else {
failure(data);
}
});
}
function script_put(id) {
$.ajax({
type : 'put',
dataType : 'json',
url : script_parameter.root + '/' + id,
contentType : 'application/json; charset=utf-8',
data : JSON.stringify({
application : $('#application', '#content').val(),
name : $('#name', '#content').val(),
alias : $('#alias', '#content').val(),
description : $('#description', '#content').val(),
validated : $('#validated', '#content').val(),
languageType : $('#languageType', '#content').val(),
dependScriptList : splitValue($('#dependScriptList', '#content').val()),
text : $('#text', '#content').val()
}),
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(data) {
if (data.type == 'success') {
script_listWithApplication(script_parameter.application);
} else {
failure(data);
}
});
}
function script_delete(id) {
$.ajax({
type : 'delete',
dataType : 'json',
url : script_parameter.root + '/' + id,
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(data) {
if (data.type == 'success') {
script_listWithApplication(script_parameter.application);
} else {
failure(data);
}
});
}
function script_listWithApplication(id) {
script_parameter.application = id;
$.ajax({
type : 'get',
dataType : 'json',
url : script_parameter.root + '/application/' + id,
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(data) {
if (data.type == 'success') {
var str = '';
str += '| id | name | alias | operate |
';
$.each(data.data, function(index, item) {
str += '';
str += '| ' + item.id + ' | ';
str += '' + item.name + ' | ';
str += '' + item.alias + ' | ';
str += '';
str += 'edit ';
str += 'delete';
str += ' | ';
str += '
';
});
str += '
';
$('#content').html(str);
} else {
failure(data);
}
});
}
function script_getWithName(application, name) {
script_parameter.application = application;
$.ajax({
type : 'get',
dataType : 'json',
url : script_parameter.root + '/' + name,
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(data) {
if (data.type == 'success') {
var str = '';
str += '| id | name | operate |
';
str += '';
str += '| ' + data.data.id + ' | ';
str += '' + data.data.name + ' | ';
str += '';
str += 'edit ';
str += 'delete';
str += ' | ';
str += '
';
str += '
';
$('#content').html(str);
} else {
failure(data);
}
});
}