src/Eccube/Resource/template/admin/Order/confirmationModal_js.twig line 1

Open in your IDE?
  1. <script>
  2.     $(function() {
  3.         var updater;
  4.         // モーダルの表示を制御
  5.         $('#bulkSendMail, .confirmationModal').on('click', function (e) {
  6.             var modal = $('#sentUpdateModal');
  7.             var bootstrapModal = new bootstrap.Modal(modal.get(0));
  8.             bootstrapModal.show();
  9.             var eventTarget = $(e.currentTarget);
  10.             var type = eventTarget.data('type');
  11.             switch (type) {
  12.                 case 'mail':
  13.                     updater = eventTarget.data('bulk-update') ? new BulkSendMail(modal, eventTarget) : new SimpleSendMail(modal, eventTarget);
  14.                     $('#notificationMail').attr('type', 'hidden');
  15.                     $('.notificationMail').hide();
  16.                     $('#viewEmail').removeClass('collapsed').addClass('collapsed');
  17.                     ;
  18.                     break;
  19.                 default:
  20.                 case 'status':
  21.                     updater = new SimpleStatusUpdate(modal, eventTarget); // bulk-update is always false
  22.                     $('#notificationMail').attr('type', 'checkbox');
  23.                     $('.notificationMail').show();
  24.                     $('#viewEmail').removeClass('collapsed').addClass('collapsed');
  25.             }
  26.             $.ajax(updater.getPreviewUrl()).done(function (res) {
  27.                 $('#viewEmail').html(res);
  28.             });
  29.             $('.modal-title', modal).text(updater.modalTitle);
  30.             $('.modal-body > p.modal-message', modal).text(updater.modalMessage);
  31.             $('#bulkChange')
  32.                 .attr({
  33.                     'data-bulk-update': eventTarget.data('bulk-update'),
  34.                     'data-type': eventTarget.data('type'),
  35.                     'data-update-status-url': eventTarget.data('update-status-url'),
  36.                     'data-notify-mail-url': eventTarget.data('notify-mail-url'),
  37.                     'data-update-status-id': eventTarget.data('update-status-id')
  38.                 })
  39.                 .text(updater.modalButton);
  40.         });
  41.         // プログレスバーの表示を制御
  42.         $('#bulkChange, .progressModal').on('click', function (e) {
  43.             //alert(1119);
  44.             var eventTarget = $(e.currentTarget);
  45.             var type = eventTarget.data('type');
  46.             var modal = $('#sentUpdateModal');
  47.             var bootstrapModal = new bootstrap.Modal(modal.get(0));
  48.             bootstrapModal.show();
  49.             switch (type) {
  50.                 case 'mail':
  51.                     updater = eventTarget.data('bulk-update') ? new BulkSendMail(modal, eventTarget) : new SimpleSendMail(modal, eventTarget);
  52.                     break;
  53.                 default:
  54.                 case 'status':
  55.                     if (eventTarget.data('bulk-update')) {
  56.                         if ($('#option_bulk_status').val() == '') {
  57.                             alert('対応状況を選択してください');
  58.                             return;
  59.                         }
  60.                         updater = new BulkStatusUpdate(modal, eventTarget);
  61.                         modal.modal();
  62.                     } else {
  63.                         updater = new SimpleStatusUpdate(modal, eventTarget);
  64.                     }
  65.             }
  66.             $('.modal-title', modal).text(updater.modalTitle);
  67.             $('.modal-body > p.modal-message', modal).text("{{ 'admin.order.bulk_action__in_progress_message'|trans }}");
  68.             $('button', modal).hide();
  69.             $('#bulk-options').hide();
  70.             $('.progress', modal).show();
  71.             updater.totalCount = updater.getTotalCount();
  72.             var progress = new $.Deferred();
  73.             progress.progress(function () {
  74.                 updater.progress(this, progress);
  75.             }).fail(function () {
  76.                 updater.fail(this);
  77.             }).always(function () {
  78.                 updater.always(this);
  79.             });
  80.             updater.getPromises(progress);
  81.         });
  82.     });
  83.     /*
  84.      * Super class
  85.      */
  86.     function ConfirmationModal(modal) {
  87.         this.modal = modal;
  88.         this.mailCount = 0;
  89.         this.currentCount = 0;
  90.         this.totalCount = 0;
  91.     }
  92.     ConfirmationModal.prototype = {
  93.         modalTitle: "{{ 'admin.order.to_shipped__confirm_title'|trans }}",
  94.         modalMessage: "{{ 'admin.order.to_shipped__confirm_message'|trans }}",
  95.         modalButton: "{{ 'admin.common.execute'|trans }}",
  96.         getPreviewUrl: function () {
  97.             return null;
  98.         },
  99.         getTotalCount: function () {
  100.             return 1;
  101.         },
  102.         progress: function (result, progress) {
  103.             $('.progress-bar', this.modal).css('width', (++this.currentCount / this.totalCount * 100) + '%');
  104.             if (result['message']) {
  105.                 $('<li><span class="badge bg-warning">NOTICE</span> </li>')
  106.                     .append($('<span></span>').text(result['message']))
  107.                     .appendTo('#bulkErrors');
  108.             }
  109.             if (this.currentCount >= this.totalCount) {
  110.                 progress.resolve();
  111.             }
  112.         },
  113.         fail: function (result) {
  114.             $('<li><span class="badge bg-danger">ERROR</span> </li>')
  115.                 .append($('<span></span>').text("{{ 'admin.common.system_error'|trans }}"))
  116.                 .appendTo('#bulkErrors');
  117.         },
  118.         always: function (result) {
  119.             $('.progress', this.modal).hide();
  120.             $('.modal-body > p.modal-message', this.modal).text("{{ 'admin.order.bulk_action__complete_message'|trans }}");
  121.             $('#bulkChangeComplete').show();
  122.         },
  123.         getPromises: function (progress, url, data) {
  124.             if (data == undefined) {
  125.                 data = {'notificationMail': $('input#notificationMail:checked').val()};
  126.             }
  127.             return $.ajax({
  128.                 'url': url,
  129.                 'type': 'PUT',
  130.                 'data': data
  131.             })
  132.                 .fail(function () {
  133.                     progress.reject();
  134.                     ConfirmationModal.prototype.fail.call(this);
  135.                 })
  136.                 .always(function (data) {
  137.                     progress.notifyWith(data);
  138.                 });
  139.         }
  140.     };
  141.     /*
  142.      * ステータス一括更新
  143.      */
  144.     function BulkStatusUpdate(modal, eventTarget) {
  145.         ConfirmationModal.call(this, modal);
  146.         this.eventTarget = eventTarget;
  147.     }
  148.     // extend super class
  149.     BulkStatusUpdate.prototype = Object.create(ConfirmationModal.prototype, {
  150.         constructor: {
  151.             value: ConfirmationModal
  152.         },
  153.         modalTitle: {
  154.             value: "{{ 'admin.order.change_status'|trans }}"
  155.         },
  156.         getTotalCount: {
  157.             value: function () {
  158.                 return $('input[data-id]:checked').length;
  159.             }
  160.         },
  161.         getPromises: {
  162.             value: function (progress) {
  163.                 var statuses = [];
  164.                 $('input[data-id]:checked').each(function () {
  165.                     statuses.push({
  166.                         'url': $(this).data('update-status-url'),
  167.                         'data': {'order_status': $('#option_bulk_status').val()}
  168.                     });
  169.                 });
  170.                 // ポイントや在庫の加算・減算は非同期で実行できないため、同期処理で実行
  171.                 var callback = function () {
  172.                     var status = statuses.shift();
  173.                     var url = status.url;
  174.                     var data = status.data;
  175.                     ConfirmationModal.prototype.getPromises.call(this, progress, url, data)
  176.                         .done(function () {
  177.                             if (statuses.length) {
  178.                                 callback();
  179.                             }
  180.                         })
  181.                 }
  182.                 callback();
  183.             }
  184.         }
  185.     });
  186.     /*
  187.      * ステータス個別更新
  188.      */
  189.     function SimpleStatusUpdate(modal, eventTarget) {
  190.         ConfirmationModal.call(this, modal);
  191.         this.eventTarget = eventTarget;
  192.         this.notifierCompleteMessage = '';
  193.     }
  194.     // extend super class
  195.     SimpleStatusUpdate.prototype = Object.create(ConfirmationModal.prototype, {
  196.         constructor: {
  197.             value: ConfirmationModal
  198.         },
  199.         getPreviewUrl: {
  200.             value: function () {
  201.                 return this.eventTarget.data('preview-notify-mail-url');
  202.             }
  203.         },
  204.         progress: {
  205.             value: function (result, progress) {
  206.                 if (result.mail) {
  207.                     this.mailCount++;
  208.                     this.notifierCompleteMessage = '{{ 'admin.order.shipping_mail_send__complete_message'|trans }}'.replace(/%count%/, this.mailCount);
  209.                 }
  210.                 ConfirmationModal.prototype.progress.call(this, result, progress);
  211.             }
  212.         },
  213.         always: {
  214.             value: function (result) {
  215.                 ConfirmationModal.prototype.always.call(this, result);
  216.                 $('.modal-body > p.modal-message', this.modal).text("{{ 'admin.order.bulk_action__complete_message'|trans }}" + this.notifierCompleteMessage);
  217.             }
  218.         },
  219.         getPromises: {
  220.             value: function (progress) {
  221.                 var url = this.eventTarget.data('update-status-url');
  222.                 var data = {
  223.                     'order_status': this.eventTarget.data('update-status-id'),
  224.                     'notificationMail': $('input#notificationMail:checked').val()
  225.                 };
  226.                 return ConfirmationModal.prototype.getPromises.call(this, progress, url, data);
  227.             }
  228.         }
  229.     });
  230.     /*
  231.      * メール一括送信
  232.      */
  233.     function BulkSendMail(modal) {
  234.         SimpleStatusUpdate.call(this, modal);
  235.     }
  236.     // extend BulkUpdate
  237.     BulkSendMail.prototype = Object.create(SimpleStatusUpdate.prototype, {
  238.         constructor: {
  239.             value: SimpleStatusUpdate
  240.         },
  241.         modalTitle: {
  242.             value: "{{ 'admin.order.shipping_mail_send__confirm_title'|trans }}"
  243.         },
  244.         modalMessage: {
  245.             value: "{{ 'admin.order.shipping_mail_send__confirm_message'|trans }}"
  246.         },
  247.         modalButton: {
  248.             value: "{{ 'admin.common.send'|trans }}"
  249.         },
  250.         getPreviewUrl: {
  251.             value: function () {
  252.                 return $('input[data-preview-notify-mail-url]:checked').data('preview-notify-mail-url');
  253.             }
  254.         },
  255.         getTotalCount: {
  256.             value: function () {
  257.                 return $('input[data-preview-notify-mail-url]:checked').length;
  258.             }
  259.         },
  260.         getPromises: {
  261.             value: function (progress) {
  262.                 return $('input[data-notify-mail-url]:checked').map(function () {
  263.                     var url = $(this).data('notify-mail-url');
  264.                     return ConfirmationModal.prototype.getPromises.call(this, progress, url);
  265.                 });
  266.             }
  267.         }
  268.     });
  269.     /*
  270.      * 個別メール送信
  271.      */
  272.     function SimpleSendMail(modal, relatedTarget) {
  273.         SimpleStatusUpdate.call(this, modal, relatedTarget);
  274.     }
  275.     // extends SimpleUpdate
  276.     SimpleSendMail.prototype = Object.create(SimpleStatusUpdate.prototype, {
  277.         constructor: {
  278.             value: SimpleStatusUpdate
  279.         },
  280.         modalTitle: {
  281.             value: "{{ 'admin.order.shipping_mail_send__confirm_title'|trans }}"
  282.         },
  283.         modalMessage: {
  284.             value: "{{ 'admin.order.shipping_mail_send__confirm_message'|trans }}"
  285.         },
  286.         modalButton: {
  287.             value: "{{ 'admin.common.send'|trans }}"
  288.         },
  289.         getPromises: {
  290.             value: function (progress) {
  291.                 var url = this.eventTarget.data('notify-mail-url');
  292.                 return ConfirmationModal.prototype.getPromises.call(this, progress, url);
  293.             }
  294.         }
  295.     });
  296. </script>