msgsForTable.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <div>
  2. <?php if (!empty($msgs)) : ?>
  3. <?php foreach ($msgs as $msgId => $msg) : ?>
  4. <div class="alert alert-<?php echo V::get('type', 'info', $msg); ?>">
  5. <?php echo $msg['message']; ?>
  6. <?php if ('ajax' == V::get('linkType', '', $msg)) : ?>
  7. <a class="btn btn-primary btn-xs" target="_blank" onclick="return msgAjaxAction(this);" href="<?php echo $msg['link']; ?>">uruchom</a>
  8. <?php else : ?>
  9. <a class="btn btn-primary btn-xs" target="_blank" href="<?php echo $msg['link']; ?>">uruchom</a>
  10. <?php endif; ?>
  11. </div>
  12. <?php endforeach; ?>
  13. <?php endif; ?>
  14. </div>
  15. <script type="text/javascript">
  16. function msgAjaxAction(n) {
  17. var $n = jQuery(n);
  18. $n.text($n.text() + '...').attr('disabled', 'disabled');
  19. function notifyAjaxCallback(data) {
  20. var notify = {};
  21. notify.type = (data && data.type)? data.type : '';
  22. notify.msg = (data && data.msg)? data.msg : '';
  23. switch (notify.type) {
  24. case 'success':
  25. if (!notify.msg) notify.msg = 'Gotowe';
  26. break;
  27. case 'error':
  28. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  29. break;
  30. case 'warning':
  31. notify.type = 'warn';
  32. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  33. break;
  34. default:
  35. notify.msg = 'Nieznany błąd';
  36. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  37. notify.type = '';
  38. }
  39. jQuery.notify(notify.msg, notify.type);
  40. }
  41. $.ajax({
  42. data: {},
  43. dataType: 'json',
  44. type: "GET",
  45. url: $n.attr('href')
  46. })
  47. .done(function(data, textStatus, jqXHR){
  48. notifyAjaxCallback(data);
  49. $n.closest('.alert').fadeOut('slow');//.remove()
  50. })
  51. .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
  52. if (jqXHR.responseJSON) {
  53. notifyAjaxCallback(jqXHR.responseJSON);
  54. }
  55. else {
  56. var txt = jqXHR.responseText || 'Wystąpiły błędy';
  57. if (jqXHR.status == 404) {
  58. jQuery.notify(jqXHR.responseText, 'error');
  59. } else {
  60. jQuery.notify(jqXHR.responseText, 'warn');
  61. }
  62. }
  63. });
  64. return false;
  65. }
  66. </script>