jobcode.index.1.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. $(function () {
  2. // init code editor
  3. var codeEditor;
  4. function initIde(glueSource) {
  5. if (codeEditor == null) {
  6. codeEditor = CodeMirror(document.getElementById("ideWindow"), {
  7. mode: ideMode,
  8. lineNumbers: true,
  9. matchBrackets: true,
  10. value: glueSource
  11. });
  12. } else {
  13. codeEditor.setValue(glueSource);
  14. }
  15. }
  16. initIde($("#version_now").val());
  17. // code change
  18. $(".source_version").click(function () {
  19. var sourceId = $(this).attr('version');
  20. var temp = $("#" + sourceId).val();
  21. //codeEditor.setValue('');
  22. initIde(temp);
  23. });
  24. // code source save
  25. $("#save").click(function () {
  26. $('#saveModal').modal({backdrop: false, keyboard: false}).modal('show');
  27. });
  28. $("#saveModal .ok").click(function () {
  29. var glueSource = codeEditor.getValue();
  30. var glueRemark = $("#glueRemark").val();
  31. if (!glueRemark) {
  32. layer.open({
  33. title: I18n.system_tips,
  34. btn: [I18n.system_ok],
  35. content: I18n.system_please_input + I18n.jobinfo_glue_remark,
  36. icon: '2'
  37. });
  38. return;
  39. }
  40. if (glueRemark.length < 4 || glueRemark.length > 100) {
  41. layer.open({
  42. title: I18n.system_tips,
  43. btn: [I18n.system_ok],
  44. content: I18n.jobinfo_glue_remark_limit,
  45. icon: '2'
  46. });
  47. return;
  48. }
  49. $.ajax({
  50. type: 'POST',
  51. url: base_url + '/jobcode/save',
  52. data: {
  53. 'id': id,
  54. 'glueSource': glueSource,
  55. 'glueRemark': glueRemark
  56. },
  57. dataType: "json",
  58. success: function (data) {
  59. if (data.code == 200) {
  60. layer.open({
  61. title: I18n.system_tips,
  62. btn: [I18n.system_ok],
  63. content: (I18n.system_save + I18n.system_success),
  64. icon: '1',
  65. end: function (layero, index) {
  66. //$(window).unbind('beforeunload');
  67. window.location.reload();
  68. }
  69. });
  70. } else {
  71. layer.open({
  72. title: I18n.system_tips,
  73. btn: [I18n.system_ok],
  74. content: (data.msg || (I18n.system_save + I18n.system_fail)),
  75. icon: '2'
  76. });
  77. }
  78. }
  79. });
  80. });
  81. // before upload
  82. /*$(window).bind('beforeunload',function(){
  83. return 'Glue尚未保存,确定离开Glue编辑器?';
  84. });*/
  85. });