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

        
        //注册一个按钮，来调用自定义插件
        editor.ui.addButton(pluginName, {
            label: "表单另存为",
            command: pluginName,
            icon: this.path + "saveas.png",
            toolbar: 'rf_plugins,51'
        });
        
        CKEDITOR.dialog.add(pluginName, function (editor) {
            return {
                title: '表单另存为',
                minWidth: 500,
                minHeight: 200,
                contents: [{
                    id: pluginName + '_attr',
                    label: '表单另存为',
                    title: '表单另存为',
                    elements:
                        [
                            {
                                id: pluginName + '_attr',
                                type: 'html',
                                html: '<iframe style="width:100%;height:200px;border:0;" frameborder="0" src="../FormDesignerPlugin/SaveAs?' + query + '"></iframe>'
                            }
                        ]
                }],
                onShow: function () {
                    //var attrJSON = formAttributeJSON;
                    //if (!attrJSON) {
                    //    return;
                    //}
                    //var $iframe = $("div[name='" + pluginName + "_attr'] iframe");
                    //if ($iframe.size() == 0) {
                    //    return;
                    //}
                    //$iframe.show(function () {
                    //    initAttr();
                    //});
                    //$iframe.load(function () {
                    //    initAttr();
                    //});

                    //function initAttr() {
                    //    var doc = $iframe.get(0).contentWindow.document;
                    //    $("#scripts", doc).val(attrJSON.scripts);
                    //}
                },
                onHide: function () {
                    //currentSelectEditorElement = null;
                },
                onOk: function () {
                    var attrJSON = formAttributeJSON;
                    if (!attrJSON) {
                        alert("未找到表单属性!");
                        return false;
                    }
                    var $iframe = $("div[name='" + pluginName + "_attr'] iframe");
                    if ($iframe.size() == 0) {
                        return;
                    }
                    var doc = $iframe.get(0).contentWindow.document;
                    var formName = $("#formname", doc).val() || '';
                    if ($.trim(formName).length == 0) {
                        alert('表单名称不能为空!');
                        return false;
                    }
                    $.ajax({
                        url: "../FormDesignerPlugin/SaveAs1?" + query, type: "post", data: { "id": attrJSON.id, "formname": $.trim(formName) }, dataType: "json", cache: false, async: false, success: function (json) {
                            alert(json.message);
                            return json.success === 1;
                        }
                    });
                }
            }
        });

    }
});