使按钮在CJuiDialog中不可见

时间:2012-11-07 09:24:14

标签: yii

我的yii中的CJuiDialog有问题。我想将'删除'按钮设置为'不可见',但这不起作用,按钮仍然显示。 这是我的代码:

$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'dlg_EventCal',
'options' => array(
    'title' => Yii::t('CalModule.fullCal', 'Event detail'),
    'modal' => true,
    'autoOpen' => false,
    'hide' => 'slide',
    'show' => 'slide',
    'width'=> 400,
    'buttons' => array(
        array(
            'text' => Yii::t('CalModule.fullCal', 'OK'),
            'click' => "js:function() { eventDialogOK(); }"
        ),
        array(
            'text' => Yii::t('CalModule.fullCal', 'Cancel'),
            'click' => 'js:function() { $(this).dialog("close"); }',

        ),  
         array( 
    'text' => Yii::t('CalModule.fullCal', 'Delete'),
    'click' => 'js:function() { eventDialogDelete(); }',
   'visible'=>Yii::app()->user->checkAccess('deleteAllEvents'),

            ),

))));

1 个答案:

答案 0 :(得分:1)

CJuiDialog仅将数据传递到jQuery.dialog插件

查看此功能(来自https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.dialog.js#L322):

_createButtons: function( buttons ) {
    var that = this,
        hasButtons = false;

    // if we already have a button pane, remove it
    this.uiDialogButtonPane.remove();
    this.uiButtonSet.empty();

    if ( typeof buttons === "object" && buttons !== null ) {
        $.each( buttons, function() {
            return !(hasButtons = true);
        });
    }
    if ( hasButtons ) {
        $.each( buttons, function( name, props ) {
            var button, click;
            props = $.isFunction( props ) ?
                { click: props, text: name } :
                props;
            // Default to a non-submitting button
            props = $.extend( { type: "button" }, props );
            // Change the context for the click callback to be the main element
            click = props.click;
            props.click = function() {
                click.apply( that.element[0], arguments );
            };
            button = $( "<button></button>", props )
                .appendTo( that.uiButtonSet );
            if ( $.fn.button ) {
                button.button();
            }
        });
        this.uiDialog.addClass( "ui-dialog-buttons" );
        this.uiDialogButtonPane.appendTo( this.uiDialog );
    } else {
        this.uiDialog.removeClass( "ui-dialog-buttons" );
    }
}

您的所有属性都将传递到props对象,之后将用作button元素的属性:

button = $( "<button></button>", props )

所以你需要这样的代码:

array( 
    'text' => Yii::t('CalModule.fullCal', 'Delete'),
    'click' => 'js:function() { eventDialogDelete(); }',
    'style' => Yii::app()->user->checkAccess('deleteAllEvents') ? '' : 'display: none;',
)

但在这种情况下,您需要额外检查服务器端的权限!