$(function () {
    var editor;
    require.config({paths: {'vs': basePath + '/lib/monaco-editor/min/vs'}});
    require(['vs/editor/editor.main'], function () {
        editor = monaco.editor.create(document.getElementById('editor'), {
            value: $.base64.decode($('#rules').val()),
            language: 'java'
        });
    });


    $('#btn-save').click(function () {
        var url = "/rule/saveRule.ajax";
        var ruleStr = editor.getModel().getLinesContent().join('\n')
        var rules = $.base64.encode(ruleStr, true);
        $("#rules").val(rules);
        $('#submitForm').ajaxSubmit({
            url: web_app.name + url,
            success: function (rule) {
                $('#id').val(rule.id);
            }
        });
    });
});