jobcode.index.1.js 1.6 KB
Newer Older
X
xueli.xue 已提交
1 2
$(function() {

X
xueli.xue 已提交
3
	// init code editor
4
	var codeEditor = CodeMirror.fromTextArea(document.getElementById("glueSource"), {
X
xueli.xue 已提交
5 6
		mode : "text/x-java",
		lineNumbers : true,
X
xueli.xue 已提交
7 8
		matchBrackets : true
	});
9 10 11 12 13 14 15 16
	codeEditor.setValue( $("#glue_now").val() );
	
	// code change
	$("#glue_version").change(function(){
		var temp = $( "#" + $(this).val() ).val();
		codeEditor.setValue( temp );
	});
	
17
	// editor height
X
xueli.xue 已提交
18 19 20
	var height = Math.max(document.documentElement.clientHeight, document.body.offsetHeight);
	$(".CodeMirror").attr('style', 'height:'+ height +'px');
	
21
	// code source save
X
xueli.xue 已提交
22
	$("#save").click(function() {
23 24
		var glueSource = codeEditor.getValue();
		var glueRemark = $("#glueRemark").val();
X
xueli.xue 已提交
25
		
26
		if (!glueRemark) {
X
xueli.xue 已提交
27
			ComAlert.show(2, "请输入备注");
X
xueli.xue 已提交
28 29
			return;
		}
30
		if (glueRemark.length < 6|| glueRemark.length > 100) {
X
xueli.xue 已提交
31
			ComAlert.show(2, "备注长度应该在6至100之间");
X
xueli.xue 已提交
32
			return;
X
xueli.xue 已提交
33
		}
X
xueli.xue 已提交
34 35 36 37 38 39
		
		ComConfirm.show("是否执行保存操作?", function(){
			$.ajax({
				type : 'POST',
				url : base_url + '/jobcode/save',
				data : {
40
					'id' : id,
41 42
					'glueSource' : glueSource,
					'glueRemark' : glueRemark
X
xueli.xue 已提交
43 44 45 46
				},
				dataType : "json",
				success : function(data){
					if (data.code == 200) {
X
xueli.xue 已提交
47
						ComAlert.show(1, '保存成功', function(){
X
xueli.xue 已提交
48 49 50 51
							//$(window).unbind('beforeunload');
							window.location.reload();
						});
					} else {
52
						ComAlert.show(2, data.msg);
X
xueli.xue 已提交
53 54 55 56 57
					}
				}
			});
		});
		
X
xueli.xue 已提交
58
	});
X
xueli.xue 已提交
59 60 61 62 63 64
	
	// before upload
	/*$(window).bind('beforeunload',function(){
		return 'Glue尚未保存,确定离开Glue编辑器?';
	});*/
	
X
xueli.xue 已提交
65
});