| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- form_parameter = {
- first : '(0)',
- last : '(0)',
- count : 20
- };
- function form_list_next(id) {
- var id = (id ? id : form_parameter.last);
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : '../jaxrs/form/list/' + id + '/next/' + form_parameter.count,
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(json) {
- if (json.type == 'success') {
- if (json.data.length > 0) {
- form_parameter.first = json.data[0].id;
- form_parameter.last = json.data[json.data.length - 1].id;
- } else {
- form_parameter.first = '(0)';
- }
- form_list_grid(json);
- }
- }).always(function(json) {
- $('#result').html(JSON.stringify(json, null, 4));
- });
- }
- function form_list_prev(id) {
- var id = (id ? id : form_parameter.first);
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : '../jaxrs/form/list/' + id + '/prev/' + form_parameter.count,
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(json) {
- if (json.type == 'success') {
- if (data.data.length > 0) {
- form_parameter.first = json.data[0].id;
- form_parameter.last = json.data[json.data.length - 1].id;
- } else {
- form_parameter.last = '(0)';
- }
- form_list_grid(json);
- }
- }).always(function(json) {
- $('#result').html(JSON.stringify(json, null, 4));
- });
- }
- function form_list_grid(json) {
- var str = '<table border="1" width="100%">';
- str += '<tr><td colspan="6"> <a href="#" id="prev">prev</a> <a href="#" id="next">next</a> <span id="total">' + json.count + '</span></td></tr>';
- str += '<tr><th>id</th><th>name</th><th>application</th><th>operate</th></tr>';
- if (json.data) {
- $.each(json.data, function(index, item) {
- str += '<tr>';
- str += '<td>' + item.id + '</td>';
- str += '<td>' + item.name + '</td>';
- str += '<td>' + item.application + '</td>';
- str += '<td>';
- str += '<a href="#" onclick="form_edit(\'' + item.id + '\')">edit</a> ';
- str += '<a href="#" onclick="form_delete(\'' + item.id + '\')">delete</a>';
- str += '</td>';
- str += '</tr>';
- });
- }
- str += '</table>';
- $('#content').html(str);
- $('#next').click(function() {
- form_list_next();
- });
- $('#prev').click(function() {
- form_list_prev();
- });
- }
- function form_query() {
- str = '<table border="1" width="100%">';
- str += '<tr><td colspan="2"><a href="#" id="listWithApplication">listWithApplication</a> <a href="#" id="listFormFieldWithApplication">listFormFieldWithApplication</a> <a href="#" id="listFormFieldWithForm">listFormFieldWithForm</a></td></tr>';
- str += '<tr><td>application id</td><td><input type="text" id="applicationId" style="width:95%"></td>';
- str += '<tr><td>form id</td><td><input type="text" id="formId" style="width:95%"></td>';
- str += '</tr></table>';
- $('#content').html(str);
- $('#listWithApplication').click(function() {
- form_listWithApplication($('#applicationId').val());
- });
- $('#listFormFieldWithApplication').click(function() {
- form_listFormFieldWithApplication($('#applicationId').val());
- });
- $('#listFormFieldWithForm').click(function() {
- form_listFormFieldWithForm($('#formId').val());
- });
- }
- function form_create_init() {
- str = '<table border="1" width="100%">';
- str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
- str += '<tr><td>application:</td><td><input type="text" id="application" style="width:95%"/></td></tr>';
- str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
- str += '<tr><td>description:</td><td><textarea id="description" style="width:95%"/></td></tr>';
- str += '<tr><td colspan="2">data:</td></tr>';
- str += '<tr><td colspan="2"><textarea id="data" style="width:95%;height:500px"/></td></tr>';
- str += '<tr><td colspan="2"><textarea id="formFieldList" style="width:95%;height:500px"/></td></tr>';
- str += '</table>';
- $('#content').html(str);
- $('#post').click(function() {
- form_post();
- });
- }
- function form_post() {
- $.ajax({
- type : 'post',
- dataType : 'json',
- contentType : 'application/json; charset=utf-8',
- url : '../jaxrs/form',
- data : JSON.stringify({
- name : $('#name').val(),
- application : $('#application').val(),
- description : $('#description').val(),
- data : $('#data').val(),
- formFieldList : $('#formFieldList').val()
- }),
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).always(function(json) {
- $('#result').html(JSON.stringify(json, null, 4));
- });
- }
- function form_edit(id) {
- str = '<table border="1" width="100%">';
- str += '<tr><td colspan="2"><a href="#" id="put">put</a></td></tr>';
- str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
- str += '<tr><td>form category:</td><td><select id="formCategory"/></td></tr>';
- str += '<tr><td>description:</td><td><textarea id="description" style="width:95%"/></td></tr>';
- str += '<tr><td>id:</td><td id="id"> </td></tr>';
- str += '<tr><td>sequence:</td><td id="sequence"> </td></tr>';
- str += '<tr><td colspan="2">data:</td></tr>';
- str += '<tr><td colspan="2"><textarea id="data" style="width:95%;height:500px"/></td></tr>';
- str += '<tr><td colspan="2"><textarea id="formFieldList" style="width:95%;height:500px"/></td></tr>';
- str += '</table>';
- $('#content').html(str);
- $('#put', '#content').click(function() {
- form_put(id);
- });
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : '../jaxrs/form/' + id,
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(json) {
- if (json.type == 'success') {
- $('#name').val(json.data.name);
- $('#application').val(json.data.application);
- $('#description').val(json.data.description);
- $('#data').val(json.data.data);
- $('#formFieldList').val(joinValue(json.data.formFieldList));
- $('#id').html(json.data.id);
- }
- }).always(function(json) {
- $('#result').html(JSON.stringify(json, null, 4));
- });
- }
- function form_put(id) {
- $.ajax({
- type : 'put',
- dataType : 'json',
- url : '../jaxrs/form/' + id,
- contentType : 'application/json; charset=utf-8',
- data : JSON.stringify({
- name : $('#name').val(),
- application : $('#application').val(),
- description : $('#description').val(),
- data : $('#data').val(),
- formFieldList : JSON.parse($('#formFieldList').val())
- }),
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).always(function(json) {
- $('#result').html(JSON.stringify(json, null, 4));
- });
- }
- function form_delete(id) {
- $.ajax({
- type : 'delete',
- dataType : 'json',
- url : '../jaxrs/form/' + id,
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).always(function(json) {
- $('#result').html(JSON.stringify(json, null, 4));
- });
- }
- function form_listWithApplication(id) {
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : '../jaxrs/form/application/' + id,
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).done(function(data) {
- if (data.type == 'success') {
- var str = '<table border="1" width="100%">';
- str += '<tr><th>id</th><th>name</th><th>application</th><th>operate</th></tr>';
- $.each(data.data, function(index, item) {
- str += '<tr>';
- str += '<td>' + item.id + '</td>';
- str += '<td>' + item.name + '</td>';
- str += '<td>' + item.application + '</td>';
- str += '<td>';
- str += '<a href="#" onclick="form_edit(\'' + item.id + '\')">edit</a> ';
- str += '<a href="#" onclick="form_delete(\'' + item.id + '\')">delete</a>';
- str += '</td>';
- str += '</tr>';
- });
- str += '</table>';
- $('#content').html(str);
- }
- }).always(function(json) {
- $('#result').html(JSON.stringify(json, null, 4));
- });
- }
- function form_listFormFieldWithApplication(id) {
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : '../jaxrs/form/list/formfield/application/' + id,
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).always(function(json) {
- $('#result').html(JSON.stringify(json, null, 4));
- });
- }
- function form_listFormFieldWithForm(id) {
- $.ajax({
- type : 'get',
- dataType : 'json',
- url : '../jaxrs/form/list/' + id + '/formfield',
- xhrFields : {
- 'withCredentials' : true
- },
- crossDomain : true
- }).always(function(json) {
- $('#result').html(JSON.stringify(json, null, 4));
- });
- }
|