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