简体   繁体   English

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

[英]Prompt for confirmation before executing cutsom CbuttonColumn action

I have a custom delete button, all i want is some sort of confirmation before delete action takes place.. I have tried multiple ways of doing so with no success so far. 我有一个自定义的删除按钮,我想要做的只是在删除操作发生之前进行某种确认。.我尝试了多种方法,但到目前为止没有成功。

here is my code, I am using CArrayDataProvider thus had to create a template for delete button. 这是我的代码,我正在使用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
            ),

NOW I SHOW YOU WHAT I DO IN MY CODE FOR THE THING YOU WANT TO DO 现在,我向您展示我要执行的操作代码

            '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
            ),

I have copy paste code. 我有复制粘贴代码。 so it will be extra. 所以会额外的。 When some one clicks on "Status" button. 当有人点击“状态”按钮时。 It will open bootstrap modal. 它将打开引导模态。 and ask for a confirmation. 并要求确认。 While executing this i have created a form with action and some fields. 执行此操作时,我创建了一个带有动作和一些字段的表单。 and in that modal i have proceed button. 在这种模式下,我有继续按钮。 on proceed button click the form will be submitted. 单击继续按钮,将提交表单。 and on close the form will be made empty. 并在关闭时将表格清空。 the form will be display none form. 该表格将不显示任何表格。 and will have all the fields hidden.. I know it is more complex then urs... but I do it with post... BUT YOU CAN ASSIGN YOUR HREF TO POST BUTTON LINK IN THIS FUNCTION AND ON CLICK ON THAT IT WILL BE REDIRECTED 并且将所有字段都隐藏起来。.我知道它比我们还复杂...但是我使用post ... 但是您可以指派您的参考来在此功能中发布按钮链接,然后单击确定改版

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM