script.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. script_parameter = {
  2. root : '../jaxrs/script',
  3. list_action : null,
  4. list_action_parameter : null,
  5. first : '(0)',
  6. last : '(0)',
  7. count : 20,
  8. application : null
  9. };
  10. function script_list_reload() {
  11. if (script_parameter.list_action) {
  12. script_parameter.list_action.call(window, script_parameter.list_action_parameter);
  13. } else {
  14. script_list_next('(0)');
  15. }
  16. }
  17. function script_list_next(id) {
  18. var id = (id ? id : script_parameter.last);
  19. script_parameter.list_action = script_list_next;
  20. script_parameter.list_action_parameter = id;
  21. $.ajax({
  22. type : 'get',
  23. dataType : 'json',
  24. url : script_parameter.root + '/list/' + id + '/next/' + script_parameter.count,
  25. xhrFields : {
  26. 'withCredentials' : true
  27. },
  28. crossDomain : true
  29. }).done(function(data) {
  30. if (data.type == 'success') {
  31. if (data.data.length > 0) {
  32. script_parameter.first = data.data[0].id;
  33. script_parameter.last = data.data[data.data.length - 1].id;
  34. } else {
  35. script_parameter.first = '(0)';
  36. }
  37. $('#content').html(script_list_grid(data.data));
  38. $('#total', '#content').html(data.count);
  39. script_list_init();
  40. } else {
  41. failure(data);
  42. }
  43. });
  44. }
  45. function script_list_prev(id) {
  46. var id = (id ? id : script_parameter.first);
  47. script_parameter.list_action = script_list_prev;
  48. script_parameter.list_action_parameter = id;
  49. $.ajax({
  50. type : 'get',
  51. dataType : 'json',
  52. url : script_parameter.root + '/list/' + id + '/prev/' + script_parameter.count,
  53. xhrFields : {
  54. 'withCredentials' : true
  55. },
  56. crossDomain : true
  57. }).done(function(data) {
  58. if (data.type == 'success') {
  59. if (data.data.length > 0) {
  60. script_parameter.first = data.data[0].id;
  61. script_parameter.last = data.data[data.data.length - 1].id;
  62. } else {
  63. script_parameter.last = '(0)';
  64. }
  65. $('#content').html(script_list_grid(data.data));
  66. $('#total', '#content').html(data.count);
  67. script_list_init();
  68. } else {
  69. failure(data);
  70. }
  71. });
  72. }
  73. function script_list_grid(items) {
  74. var str = '<table border="1" width="100%">';
  75. str += '<tr><td colspan="4"> <a href="#" id="prev">prev</a>&nbsp;<a href="#" id="next">next</a>&nbsp;<span id="total">0</span></td></tr>';
  76. str += '<tr><th>id</th><th>name</th><th>application</th><th>operate</th></tr>';
  77. $.each(items, function(index, item) {
  78. str += '<tr>';
  79. str += '<td>' + item.id + '</td>';
  80. str += '<td>' + item.name + '</td>';
  81. str += '<td>' + item.application + '</td>';
  82. str += '<td>';
  83. str += '<a href="#" onclick="script_edit(\'' + item.id + '\')">edit</a>&nbsp;';
  84. str += '<a href="#" onclick="script_delete(\'' + item.id + '\')">delete</a>';
  85. str += '</td>';
  86. str += '</tr>';
  87. });
  88. str += '</table>';
  89. return str;
  90. }
  91. function script_list_init() {
  92. $('#next', '#content').click(function() {
  93. script_list_next();
  94. });
  95. $('#prev', '#content').click(function() {
  96. script_list_prev();
  97. });
  98. }
  99. function script_query() {
  100. var str = '<table border="1" width="100%">';
  101. str += '<tr><td>application id:</td><td><input type="text" id="application" style="width:95%"></td></tr>';
  102. str += '<tr><td>script name:</td><td><input type="text" id="name" style="width:95%"></td></tr>';
  103. str += '<tr><td colspan="2"><button id="listWithApplication">application</button>&nbsp;<button id="getWithName">name</button></td></tr>';
  104. str += '</table>';
  105. $('#content').html(str);
  106. $('#listWithApplication', '#content').click(function() {
  107. script_parameter.application = $('#application', '#content').val();
  108. script_listWithApplication($('#application', '#content').val());
  109. });
  110. $('#getWithName', '#content').click(function() {
  111. script_parameter.application = $('#application', '#content').val();
  112. script_getWithName($('#application', '#content').val(), $('#name', '#content').val());
  113. });
  114. }
  115. function script_create() {
  116. str = '<table border="1" width="100%">';
  117. str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
  118. str += '<tr><td>application:</td><td><input type="text" id="application" style="width:95%"/></td></tr>';
  119. str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
  120. str += '<tr><td>alias:</td><td><input type="text" id="alias" style="width:95%"/></td></tr>';
  121. str += '<tr><td>description:</td><td><textarea id="description" style="width:95%"/></td></tr>';
  122. str += '<tr><td>languageType:</td><td><select id="languageType"><option value="JavaScript">JavaScript</option></select></td></tr>';
  123. str += '<tr><td>validated:</td><td><select id="validated"><option value="true">true</option><option value="false">false</option></select></td></tr>';
  124. str += '<tr><td>dependScriptList:</td><td><textarea id="dependScriptList" style="width:95%;height:100px"/></td></tr>';
  125. str += '<tr><td colspan="2">text:</td></tr>';
  126. str += '<tr><td colspan="2"><textarea id="text" style="width:95%;height:500px"/></td></tr>';
  127. str += '</table>';
  128. $('#content').html(str);
  129. $('#post', '#content').click(function() {
  130. script_post();
  131. });
  132. }
  133. function script_post(application) {
  134. script_parameter.application = $('#application', '#content').val();
  135. $.ajax({
  136. type : 'post',
  137. dataType : 'json',
  138. url : script_parameter.root,
  139. contentType : 'application/json; charset=utf-8',
  140. data : JSON.stringify({
  141. application : $('#application', '#content').val(),
  142. name : $('#name', '#content').val(),
  143. alias : $('#alias', '#content').val(),
  144. description : $('#description', '#content').val(),
  145. validated : $('#validated', '#content').val(),
  146. languageType : $('#languageType', '#content').val(),
  147. dependScriptList : splitValue($('#dependScriptList', '#content').val()),
  148. text : $('#text', '#content').val()
  149. }),
  150. xhrFields : {
  151. 'withCredentials' : true
  152. },
  153. crossDomain : true
  154. }).done(function(data) {
  155. if (data.type == 'success') {
  156. script_listWithApplication(script_parameter.application);
  157. } else {
  158. failure(data);
  159. }
  160. });
  161. }
  162. function script_edit(id) {
  163. var str = '<table border="1" width="100%">';
  164. str += '<tr><td colspan="2"><a href="#" id="put">put</a></td></tr>';
  165. str += '<tr><td>id:</td><td id="id">&nbsp;</td></tr>';
  166. str += '<tr><td>createTime:</td><td id="createTime">&nbsp;</td></tr>';
  167. str += '<tr><td>creatorPerson:</td><td id="creatorPerson">&nbsp;</td></tr>';
  168. str += '<tr><td>lastUpdateTime:</td><td id="lastUpdateTime">&nbsp;</td></tr>';
  169. str += '<tr><td>lastUpdatePerson:</td><td id="lastUpdatePerson">&nbsp;</td></tr>';
  170. str += '<tr><td>application:</td><td><input type="text" id="application" style="width:95%"/></td></tr>';
  171. str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
  172. str += '<tr><td>alias:</td><td><input type="text" id="alias" style="width:95%"/></td></tr>';
  173. str += '<tr><td>description:</td><td><textarea id="description" style="width:95%"/></td></tr>';
  174. str += '<tr><td>languageType:</td><td><select id="languageType"><option value="JavaScript">JavaScript</option></select></td></tr>';
  175. str += '<tr><td>validated:</td><td><select id="validated"><option value="true">true</option><option value="false">false</option></select></td></tr>';
  176. str += '<tr><td>dependScriptList:</td><td><textarea id="dependScriptList" style="width:95%;height:100px"/></td></tr>';
  177. str += '<tr><td colspan="2">text:</td></tr>';
  178. str += '<tr><td colspan="2"><textarea id="text" style="width:95%;height:500px"/></td></tr>';
  179. str += '</table>';
  180. $('#content').html(str);
  181. $('#put', '#content').click(function() {
  182. script_put(id);
  183. });
  184. $.ajax({
  185. type : 'get',
  186. dataType : 'json',
  187. url : script_parameter.root + '/' + id,
  188. xhrFields : {
  189. 'withCredentials' : true
  190. },
  191. crossDomain : true
  192. }).done(function(data) {
  193. if (data.type == 'success') {
  194. $('#id', '#content').html(data.data.id);
  195. $('#createTime', '#content').html(data.data.createTime);
  196. $('#creatorPerson', '#content').html(data.data.creatorPerson);
  197. $('#lastUpdateTime', '#content').html(data.data.lastUpdateTime);
  198. $('#lastUpdatePerson', '#content').html(data.data.lastUpdatePerson);
  199. $('#application', '#content').val(data.data.application);
  200. $('#name', '#content').val(data.data.name);
  201. $('#alias', '#content').val(data.data.alias);
  202. $('#description', '#content').val(data.data.description);
  203. $('#languageType', '#content').val(data.data.languageType);
  204. $('#validated', '#content').val(data.data.validated);
  205. $('#text', '#content').val(data.data.text);
  206. $('#dependScriptList', '#content').val(joinValue(data.data.dependScriptList));
  207. } else {
  208. failure(data);
  209. }
  210. });
  211. }
  212. function script_put(id) {
  213. $.ajax({
  214. type : 'put',
  215. dataType : 'json',
  216. url : script_parameter.root + '/' + id,
  217. contentType : 'application/json; charset=utf-8',
  218. data : JSON.stringify({
  219. application : $('#application', '#content').val(),
  220. name : $('#name', '#content').val(),
  221. alias : $('#alias', '#content').val(),
  222. description : $('#description', '#content').val(),
  223. validated : $('#validated', '#content').val(),
  224. languageType : $('#languageType', '#content').val(),
  225. dependScriptList : splitValue($('#dependScriptList', '#content').val()),
  226. text : $('#text', '#content').val()
  227. }),
  228. xhrFields : {
  229. 'withCredentials' : true
  230. },
  231. crossDomain : true
  232. }).done(function(data) {
  233. if (data.type == 'success') {
  234. script_listWithApplication(script_parameter.application);
  235. } else {
  236. failure(data);
  237. }
  238. });
  239. }
  240. function script_delete(id) {
  241. $.ajax({
  242. type : 'delete',
  243. dataType : 'json',
  244. url : script_parameter.root + '/' + id,
  245. xhrFields : {
  246. 'withCredentials' : true
  247. },
  248. crossDomain : true
  249. }).done(function(data) {
  250. if (data.type == 'success') {
  251. script_listWithApplication(script_parameter.application);
  252. } else {
  253. failure(data);
  254. }
  255. });
  256. }
  257. function script_listWithApplication(id) {
  258. script_parameter.application = id;
  259. $.ajax({
  260. type : 'get',
  261. dataType : 'json',
  262. url : script_parameter.root + '/application/' + id,
  263. xhrFields : {
  264. 'withCredentials' : true
  265. },
  266. crossDomain : true
  267. }).done(function(data) {
  268. if (data.type == 'success') {
  269. var str = '<table border="1" width="100%"><tbody>';
  270. str += '<tr><th>id</th><th>name</th><th>alias</th><th>operate</th></tr>';
  271. $.each(data.data, function(index, item) {
  272. str += '<tr>';
  273. str += '<td>' + item.id + '</td>';
  274. str += '<td>' + item.name + '</td>';
  275. str += '<td>' + item.alias + '</td>';
  276. str += '<td>';
  277. str += '<a href="#" onclick="script_edit(\'' + item.id + '\')">edit</a>&nbsp;';
  278. str += '<a href="#" onclick="script_delete(\'' + item.id + '\')">delete</a>';
  279. str += '</td>';
  280. str += '</tr>';
  281. });
  282. str += '</tbody></table>';
  283. $('#content').html(str);
  284. } else {
  285. failure(data);
  286. }
  287. });
  288. }
  289. function script_getWithName(application, name) {
  290. script_parameter.application = application;
  291. $.ajax({
  292. type : 'get',
  293. dataType : 'json',
  294. url : script_parameter.root + '/' + name,
  295. xhrFields : {
  296. 'withCredentials' : true
  297. },
  298. crossDomain : true
  299. }).done(function(data) {
  300. if (data.type == 'success') {
  301. var str = '<table border="1" width="100%">';
  302. str += '<tr><th>id</th><th>name</th><th>operate</th></tr>';
  303. str += '<tr>';
  304. str += '<td>' + data.data.id + '</td>';
  305. str += '<td>' + data.data.name + '</td>';
  306. str += '<td>';
  307. str += '<a href="#" onclick="script_edit(\'' + data.data.id + '\')">edit</a>&nbsp;';
  308. str += '<a href="#" onclick="script_delete(\'' + data.data.id + '\')">delete</a>';
  309. str += '</td>';
  310. str += '</tr>';
  311. str += '</table>';
  312. $('#content').html(str);
  313. } else {
  314. failure(data);
  315. }
  316. });
  317. }