function getChartKindId() {
    return $('#chartKindId').val();
}

/**
 * 创建文件上传控件。
 * @param el
 * @param bizCode
 * @param bizId
 * @param label
 */
function createFileList(el, bizCode, bizId, label) {
    el.append('<div class="blank_div clearfix"></div>');
    el.append('<div class="ui-attachment-list" id="' + bizCode + '" bizcode="' + bizCode + '" bizid="' + bizId + '"><div class="ui-attachment-title">\t <h5><i class="fa fa-file-text"></i>&nbsp;' + label + '</h5>\t <div class="ui-attachment-tools"><a class="btn btn-warning btn-xs toggle"><i class="fa fa-chevron-up"></i></a>         <a class="btn btn-info btn-xs moreList" title="在窗口中查看"><i class="fa fa-edit"></i>查看</a>         <a class="btn btn-primary btn-xs addFile click_upload webuploader-container" title="添加文件(保存表单后即可上传文件)"><div class="webuploader-pick" style="width: 48px; height: 22px;"><i class="fa fa-plus-circle"></i>上传</div><div id="rt_rt_1e5er00gjhsr1rvc1h6lv291sk91" style="position: absolute; top: 1px; left: 5px; width: 48px; height: 22px; overflow: hidden; bottom: auto; right: auto;"><input type="file" name="file" class="webuploader-element-invisible"><label style="opacity: 0; width: 100%; height: 100%; display: block; cursor: pointer; background: rgb(255, 255, 255);"></label></div></a>     </div></div><div class="ui-attachment-content fileListMain el-contextmenu"></div><iframe name="iframe_attachment" style="display:none;"></iframe></div>');

    el.find('.ui-attachment-list,.ui-attachment-content')
        .css({
            display: 'block'
        });
    // 查询已上传的附件
    Public.ajax(web_app.name + '/attachment/doQuery.ajax',
        {bizCode: bizCode, bizId: bizId},
        function (files) {
            var html = _.map(files, function (file) {
                return '<div class="file" id="' + file.id + '" fileKind="' + file.fileKind + '" attachmentCode="' + file.bizSubKindId + '" createdByName="' + (file.createdByName || file.creator.createdByName) + '" fileSize="' + file.fileSize + '" createdDate="' + (file.createdDate || file.creator.createdDate) + '"><span class="' + file.fileKind + '">&nbsp;</span>&nbsp;<a href="javascript:void(0);" hidefocus title="' + file.fileName + '">' + file.fileName + '</a></div>';
            }).join('');
            el.find('.fileListMain').html(html);
            el.find('#' + bizCode).fileList();
        });
}

function initEditorUi() {
    var editorUiInit = EditorUi.prototype.init;

    EditorUi.prototype.init = function () {
        editorUiInit.apply(this, arguments);
        this.actions.get('export').setEnabled(false);

        // Updates action states which require a backend
        if (!Editor.useLocalStorage) {
            // mxUtils.post(OPEN_URL, '', mxUtils.bind(this, function (req) {
            //     var enabled = req.getStatus() != 404;
            //     this.actions.get('open').setEnabled(enabled || Graph.fileSupport);
            //     this.actions.get('import').setEnabled(enabled || Graph.fileSupport);
            //     this.actions.get('save').setEnabled(enabled);
            //     this.actions.get('saveAs').setEnabled(enabled);
            //     this.actions.get('export').setEnabled(enabled);
            // }));
            var that = this;
            Public.ajax(OPEN_URL,
                {procdefId: $('#procdefId').val()},
                function (resp) {
                    var enabled = true;
                    var xml = resp.xml;
                    //  xml = atob(resp.xml);
                    var filename = resp.filename;
                    var doc = mxUtils.parseXml(xml);
                    that.editor.setGraphXml(doc.documentElement);
                    that.actions.get('open').setEnabled(enabled || Graph.fileSupport);
                    that.actions.get('import').setEnabled(enabled || Graph.fileSupport);
                    that.actions.get('save').setEnabled(enabled);
                    that.actions.get('saveAs').setEnabled(enabled);
                    that.actions.get('export').setEnabled(enabled);
                })
        }
    };

    // Adds required resources (disables loading of fallback properties, this can only
    // be used if we know that all keys are defined in the language specific file)
    mxResources.loadDefaultBundle = false;
    var bundle = mxResources.getDefaultBundle(RESOURCE_BASE, mxLanguage) ||
        mxResources.getSpecialBundle(RESOURCE_BASE, mxLanguage);

    // Fixes possible asynchronous requests
    mxUtils.getAll([bundle, STYLE_PATH + '/default.xml'], function (xhr) {
        // Adds bundle text to resources
        mxResources.parse(xhr[0].getText());

        // Configures the default graph theme
        var themes = new Object();
        themes[Graph.prototype.defaultThemeName] = xhr[1].getDocumentElement();

        // Main
        var editor = new Editor(urlParams['chrome'] == '0', themes);
        editor.setFilename($('#code').val() + '.xml');
        editorUi = new EditorUi(editor);
        editorUi.sidebar.showShapeAndName = true;

    }, function () {
        document.body.innerHTML = '<center style="margin-top:10%;">Error loading resource files. Please check browser console.</center>';
    });
}