jobcode.index.1.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. content: I18n.system_please_input + I18n.jobinfo_glue_remark ,
  35. icon: '2'
  36. });
  37. return;
  38. }
  39. if (glueRemark.length <4 || glueRemark.length > 100) {
  40. layer.open({
  41. title: I18n.system_tips ,
  42. content: I18n.jobinfo_glue_remark_limit ,
  43. icon: '2'
  44. });
  45. return;
  46. }
  47. $.ajax({
  48. type : 'POST',
  49. url : base_url + '/jobcode/save',
  50. data : {
  51. 'id' : id,
  52. 'glueSource' : glueSource,
  53. 'glueRemark' : glueRemark
  54. },
  55. dataType : "json",
  56. success : function(data){
  57. if (data.code == 200) {
  58. layer.open({
  59. title: I18n.system_tips,
  60. content: (I18n.system_save + I18n.system_success) ,
  61. icon: '1',
  62. end: function(layero, index){
  63. //$(window).unbind('beforeunload');
  64. window.location.reload();
  65. }
  66. });
  67. } else {
  68. layer.open({
  69. title: I18n.system_tips,
  70. content: (data.msg || (I18n.system_save + I18n.system_fail) ),
  71. icon: '2'
  72. });
  73. }
  74. }
  75. });
  76. });
  77. // before upload
  78. /*$(window).bind('beforeunload',function(){
  79. return 'Glue尚未保存,确定离开Glue编辑器?';
  80. });*/
  81. });