jobcode.index.1.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. $(function() {
  2. // init code editor
  3. /*var codeEditor = CodeMirror.fromTextArea(document.getElementById("glueSource"), {
  4. mode : "text/x-java",
  5. lineNumbers : true,
  6. matchBrackets : true
  7. });*/
  8. var codeEditor;
  9. function initIde(glueType, glueSource) {
  10. var ideMode = "text/x-java";
  11. if ('GLUE_GROOVY'==glueType){
  12. ideMode = "text/x-java";
  13. } else if ('GLUE_SHELL'==glueType){
  14. ideMode = "text/x-sh";
  15. } else if ('GLUE_PYTHON'==glueType){
  16. ideMode = "text/x-python";
  17. } else if ('GLUE_NODEJS'==glueType){
  18. ideMode = "text/javascript"
  19. }
  20. codeEditor = CodeMirror(document.getElementById("ideWindow"), {
  21. mode : ideMode,
  22. lineNumbers : true,
  23. matchBrackets : true,
  24. value: glueSource
  25. });
  26. }
  27. initIde(glueType, $("#version_now").val());
  28. // code change
  29. $(".source_version").click(function(){
  30. var glueType = $(this).attr('glueType');
  31. var sourceId = $(this).attr('version');
  32. var temp = $( "#" + sourceId ).val();
  33. codeEditor.setValue('');
  34. initIde(glueType, temp);
  35. });
  36. // code source save
  37. $("#save").click(function() {
  38. $('#saveModal').modal({backdrop: false, keyboard: false}).modal('show');
  39. });
  40. $("#saveModal .ok").click(function() {
  41. var glueSource = codeEditor.getValue();
  42. var glueRemark = $("#glueRemark").val();
  43. if (!glueRemark) {
  44. layer.open({
  45. title: '系统提示',
  46. content: '请输入备注',
  47. icon: '2'
  48. });
  49. return;
  50. }
  51. if (glueRemark.length <4 || glueRemark.length > 100) {
  52. layer.open({
  53. title: '系统提示',
  54. content: '备注长度应该在4至100之间',
  55. icon: '2'
  56. });
  57. return;
  58. }
  59. $.ajax({
  60. type : 'POST',
  61. url : base_url + '/jobcode/save',
  62. data : {
  63. 'id' : id,
  64. 'glueSource' : glueSource,
  65. 'glueRemark' : glueRemark
  66. },
  67. dataType : "json",
  68. success : function(data){
  69. if (data.code == 200) {
  70. layer.open({
  71. title: '系统提示',
  72. content: '保存成功',
  73. icon: '1',
  74. end: function(layero, index){
  75. //$(window).unbind('beforeunload');
  76. window.location.reload();
  77. }
  78. });
  79. } else {
  80. layer.open({
  81. title: '系统提示',
  82. content: (data.msg || "保存失败"),
  83. icon: '2'
  84. });
  85. }
  86. }
  87. });
  88. });
  89. // before upload
  90. /*$(window).bind('beforeunload',function(){
  91. return 'Glue尚未保存,确定离开Glue编辑器?';
  92. });*/
  93. });