在执行cutsom CbuttonColumn操作之前提示确认



我有一个自定义的删除按钮,我只需要在执行删除操作之前进行某种确认。。我尝试了多种方法,但迄今为止没有成功。

这是我的代码,我使用的是CArrayDataProvider,因此不得不为删除按钮创建一个模板。

 array(
       'class' => 'CButtonColumn',
       'template' => '{delete}{reset}',
       'deleteConfirmation'=>"js:'Are You Sure?'",
       'afterDelete'=>'function(link,success,data){ if(success) alert("Delete completed successfully"); }',
       'buttons' => array(
           'delete' => array(
               'label'=> 'Remove this device',
               'imageUrl'=> Yii::app()->request->baseUrl.'/img/delete.png',
               'url' => 'Yii::app()->controller->createUrl("controller/action", array("trace_id"=>$data["trace_id"], "mac"=>$data["mac"]))',
               'click'=><<<EOD
                      function(){
                      confirm('Are you sure?')
                      }EOD
                ),
            'status' => array(
                'label'=>"<i class='fa fa-eye-slash'></i>",     // text label of the button
                'url'=>function ($data)
                {
                    return $this->createUrl("counters/changeStatus",array('id'=>$data->counter_id, "status"=>$data->status ? 0 : 1  ));
                },       // a PHP expression for generating the URL of the button
                'imageUrl'=>false,  // image URL of the button. If not set or fa lse, a text link is used
                'options'=>array(
                    'class'=>'btn roundPoint4 btn-xs green btn-warning statusBtn',
                    'title'=>"Activate/Deactivate",
                ), // HTML options for the button tag
                'click'=>'function(e){
                                                  e.preventDefault();
                            //open confirmation box write ur code here

                                       }',     // a JS function to be invoked when the button is clicked
                'visible'=>function ()
                {
                    return true;
                },   // a PHP expression for determining whether the button is visible
            ),

现在我向您展示我在代码中为您想做的事情做了什么

            'status' => array(
                'label'=>"<i class='fa fa-eye-slash'></i>",     // text label of the button
                'url'=>function ($data)
                {
                    return $this->createUrl("counters/changeStatus",array('id'=>$data->counter_id, "status"=>$data->status ? 0 : 1  ));
                },       // a PHP expression for generating the URL of the button
                'imageUrl'=>false,  // image URL of the button. If not set or fa lse, a text link is used
                'options'=>array(
                    'class'=>'btn roundPoint4 btn-xs green btn-warning statusBtn',
                    'title'=>"Activate/Deactivate",
                ), // HTML options for the button tag
                'click'=>'function(e){
                                                  e.preventDefault();
                                                  $(this).parents("table").find("tr.workingRowClass").removeClass("workingRowClass");
                                                  $("#secretForm").html("");
                                                  var parts =  getMyIdNew($(this).attr("href"), "/status/", "/id/") ;
                                                  setAction($("#secretForm"), "POST",  parts[2], 1)
                                                  moslakeFormInput( $("#secretForm") , "Counters[id]", "hidden", parts[1] , "id");
                                                  moslakeFormInput( $("#secretForm") , "Counters[status]", "hidden", parts[0], "status");
                                                  moslakeFormInput( $("#secretForm") , "operation", "hidden", "statusChange", "operation");
                                                  $("#promptAlert").find(".modal-body").html("<p>Are you sure you want to change status of the this Item ?</p>");
                                                  $("#promptAlert").modal("show"); $(this).parents("table").find("tr").removeClass("deleteMode");
                                                  $(this).parents("tr").addClass("workingRowClass");

                                       }',     // a JS function to be invoked when the button is clicked
                'visible'=>function ()
                {
                    return true;
                },   // a PHP expression for determining whether the button is visible
            ),

我有复制粘贴代码。所以这将是额外的。当有人点击"状态"按钮时。它将打开引导模式。并要求确认。在执行这个过程中,我创建了一个带有操作和一些字段的表单。在该模式下,我有继续按钮。单击"继续"按钮,将提交表单。并且在关闭时该表单将变为空。该表单将不显示任何表单。并且将隐藏所有字段。。我知道它比你更复杂。。。但我用post但您可以在该函数中指定HREF来发布按钮链接,然后单击它将被重定向

最新更新