【问题标题】:Custom product delete with confirmation dialogue box带有确认对话框的自定义产品删除
【发布时间】:2013-04-14 09:22:13
【问题描述】:

我已经更改了一些默认的 opencart admin 产品列表过滤功能,如下所示:如果我需要从列表中删除产品,我将替换复选框,单击每个产品删除图标,截图附在此处...

它工作正常,但是我如何设置带有对话框确认删除?的jquery函数,就像我们默认的opencart产品删除确认...当点击删除按钮时询问确认删除?带有确认和取消按钮对话框...有什么想法吗?

我的产品删除按钮,带有 html 列表:

<?php if ($products) { ?>
<?php foreach ($products as $result) { ?>    
<div class="product">      
    <a href="<?php echo $result['delete']; ?>"><img src="delete.png" title="<?php echo $button_delete; ?>" /></a>
    <img src="<?php echo $result['image']; ?>" alt="<?php echo $result['name']; ?>"/>
    <a href="<?php echo $result['view']; ?>"><?php echo $result['name']; ?></a>         
</div>
<?php } ?>
<div class="pagination"></div>
<?php } else { ?>
<div class="empty"><?php echo $text_empty; ?></div>
<?php } ?>

从上面的代码删除按钮:

<a href="<?php echo $result['delete']; ?>"><img src="delete.png" title="<?php echo $button_delete; ?>" /></a>

有什么想法吗?

【问题讨论】:

    标签: php jquery opencart confirm


    【解决方案1】:

    非 jQuery

    HTML:

    <a href="#" onclick='confirm_delete("<?php echo $result['delete']; ?>", "<?php echo $result['name']; ?>"); return false;'>
      <img src="delete.png" title="<?php echo $button_delete; ?>" />
    </a>
    

    Javascript:

    <script>
    function confirm_delete(link_to_delete, product_name) {
      var msg=confirm("Are you sure you want to delete " + product_name + " ?");
      if (msg==true)
      {
        window.location.href = link_to_delete;
      }
    }
    </script>
    

    jQuery

    HTML:

    <a class="delete_button" href="<?php echo $result['delete']; ?>">
      <img src="delete.png" title="<?php echo $button_delete; ?>" />
    </a>
    

    javascript(jQuery):

    <script>
    jQuery(".delete_button").on("click", function(e) {
      e.preventDefault();
      var clicked = jQuery(this);
      var clicked_url = clicked.attr("href");
      var product_name = clicked.siblings("img").attr("alt");
      var msg=confirm("Are you sure you want to delete " + product_name + " ?");
      if (msg==true)
      {
        window.location.href = clicked_url;
      }
    });
    </script>
    

    【讨论】:

      【解决方案2】:

      你可以使用 jQuery:-

      $('div.product a img[src="delete.png"]').on('click', function(event){
          if( ! confirm('Delete?')) {
              event.preventDefault();
              return false;
          }
          return true;
      });
      

      【讨论】:

        【解决方案3】:

        以下是我对一行项目的处理方式,每一项都称为“报价”。这是模板代码:

        <a href="<?php echo $offer['delete']; ?>" data-toggle="tooltip" title="<?php echo $button_delete; ?>" class="btn btn-primary" onclick="confirm('<?php echo $text_confirm; ?>') ? $('#form-discount_chooser').submit() : false;"><i class="fa fa-trash-o"></i></a>
        

        在调用模板之前,您的控制器将设置$offer['delete'],如下所示:

               $data['offers'][] = array(
                   ... 
                    'delete' => $this->url->link('extension/module/discount_chooser/delete', 'token=' . $this->session->data['token'] . '&offer=' . $discount['id'] . $url, true)
                );
        

        那么在控制器的delete()方法中,一定要处理好这是一个单独的item,而不是一个或多个checkbox:

        // Handle onesies
        if (!isset($this->request->post['selected'])) {
           if (isset($this->request->get['offer'])) {
             $this->request->post['selected'] = array($this->request->get['offer']);
           }
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-04-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多