File indexing completed on 2024-12-29 05:24:44

0001 <?php
0002 /**
0003 We need a generic Modal to ask for confirmation.
0004    Please note that:
0005     - we have a placeholder (#delete-confirmation-msg) for displaying delete message
0006     - Confirm proceed button is #delete-confirmation-yes
0007     - Confirm cancel button is #delete-confirmation-no
0008 **/ ?>
0009 <div class="modal fade" id="delete-confirmation">
0010     <div class="modal-dialog">
0011         <div class="modal-content">
0012             <div class="modal-body">
0013                 <p id="delete-confirmation-msg"></p>
0014             </div>
0015             <div class="modal-footer">
0016                 <button type="button" class="btn btn-default" id="delete-confirmation-no" data-dismiss="modal" >Cancel</button>
0017                 <button type="button" class="btn red-pink" id="delete-confirmation-yes">Yes</button>
0018             </div>
0019         </div>
0020     </div>
0021 </div>
0022 <script type="application/javascript">
0023     <?php
0024     // Example javascript callback function
0025     ?>
0026     function defaultCallbackConfirmation(link) {
0027         // Do however you want to handle deleting
0028         // We have the link element and can access it's data attributes
0029         $(link).closest('form').submit();
0030     }
0031 
0032     $(document).ready(function() {
0033         // Now, when the button is clicked, setup the message, attach event with button
0034         // and then show the modal
0035         $(document).on('click', '.remove, .confirm', function(e) {
0036             e.preventDefault();
0037             var link = this;
0038             $('#delete-confirmation-msg').html($(this).data('message'));
0039             $('#delete-confirmation-yes').on('click', function() {
0040                 var callback = $(link).data('callback');
0041 //                if(typeof callback == 'function') {
0042                     window[callback](link);
0043 //                } else {
0044 //                    window.location = $(link).data('url');
0045 //                }
0046 
0047                 $('#delete-confirmation').modal('hide');
0048             });
0049 
0050             if(yesBtn = $(this).data('yes-btn')) {
0051                 $('#delete-confirmation-yes').html(yesBtn);
0052             }
0053             if(noBtn = $(this).data('no-btn')) {
0054                 $('#delete-confirmation-no').html(noBtn);
0055             }
0056 
0057             $('#delete-confirmation').modal('show');
0058         });
0059         $('#delete-confirmation').on('hidden.bs.modal', function (e) {
0060             $('#delete-confirmation-yes').off();
0061 
0062             $('#delete-confirmation-msg').empty();
0063             $('#delete-confirmation-yes').text('Yes');
0064             $('#delete-confirmation-no').text('Cancel');
0065         });
0066     });
0067 </script>
0068 <?php
0069 /** HTML example code
0070  * The delete links should have a common class (.remove here) and the following data attributes:
0071 
0072  * data-message  - The message to show on confirmation modal
0073  * data-callback - OPTIONAL: The name of callback function that will be called if confirmation is positive
0074  *                           This function will receive the delete link element as argument
0075  * data-url      - OPTIONAL: If confirmation affirmative, will forward to this link if no data-callback is mentioned
0076  * data-yes-btn  - OPTIONAL: Label of Yes button of confirmation modal
0077  * data-no-btn   - OPTIONAL: Label of No button of confirmation modal
0078 
0079 <ul class="list-unstyled fileList">
0080  <li class="font-blue-steel" id="attachment-234">
0081   <a href="#" class="remove attachment" title="Remove this file" data-callback="defaultCallbackConfirmation" data-message="Are you sure to delete this <b>InterestingThing<b/>?">
0082    <span class="glyphicon glyphicon-remove"></span> Delete
0083   </a>
0084  </li>
0085  <!-- More list items... -->
0086 </ul>
0087  */