CKEDITOR.plugins.add('rf_preview', {
    requires: ['dialog'],
    init: function (editor) {
        var pluginName = 'rf_preview';
        //给自定义插件注册一个调用命令
        editor.addCommand(pluginName, {
            exec: function() {

                //预览前要先发布
                var attJSON = formAttributeJSON;
                var eventJSON = formEventsJSON;
                var subtableJSON = formSubtabsJSON;
                var html = ckEditor.getData();

                //这里是清理设置了又删除的子表，清理多余的JSON
                var subtableJSON1 = new Array();
                if (subtableJSON && subtableJSON.length > 0) {
                    var $html = $('<div>' + html + '</div>');
                    var $subtables = $("[data-type='subtable']", $html);
                    for (var i = 0; i < subtableJSON.length; i++) {
                        if ($("[data-type='subtable'][data-secondtable='" + subtableJSON[i].secondtable + "']", $html).size() > 0) {
                            subtableJSON1.push(subtableJSON[i]);
                        }
                    }
                }
                var formHtml = compileForm(attJSON, eventJSON, subtableJSON1, html);
                var url = "../FormDesignerPlugin/PreView?" + query
                new RoadUI.Window().open({ url: url, title: "预览表单", data: { "html": formHtml, "id": attJSON.id }, width:1200, height:600 });
            }
        });
        
        //注册一个按钮，来调用自定义插件
        editor.ui.addButton(pluginName, {
            label: "预览表单",
            command: pluginName,
            icon: this.path + "preview.png",
            toolbar: 'rf_plugins,21'
        });
       
    }
});