app/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.                     $('#mailCreate, .btn-mail-confirm').hide();
  56.                     updater = eventTarget.data('bulk-update') ? new BulkSendMail(modal, eventTarget) : new SimpleSendMail(modal, eventTarget);
  57.                     break;
  58.                 default:
  59.                 case 'status':
  60.                     if (eventTarget.data('bulk-update')) {
  61.                         updater = new BulkStatusUpdate(modal, eventTarget);
  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.                     'deliveryNote': $('input#deliveryNote:checked').val(),
  226.                 };
  227.                 return ConfirmationModal.prototype.getPromises.call(this, progress, url, data);
  228.             }
  229.         }
  230.     });
  231.     /*
  232.      * メール一括送信
  233.      */
  234.     function BulkSendMail(modal) {
  235.         SimpleStatusUpdate.call(this, modal);
  236.     }
  237.     // extend BulkUpdate
  238.     BulkSendMail.prototype = Object.create(SimpleStatusUpdate.prototype, {
  239.         constructor: {
  240.             value: SimpleStatusUpdate
  241.         },
  242.         modalTitle: {
  243.             value: "{{ 'admin.order.shipping_mail_send__confirm_title'|trans }}"
  244.         },
  245.         modalMessage: {
  246.             value: "{{ 'admin.order.shipping_mail_send__confirm_message'|trans }}"
  247.         },
  248.         modalButton: {
  249.             value: "{{ 'admin.common.send'|trans }}"
  250.         },
  251.         getPreviewUrl: {
  252.             value: function () {
  253.                 return $('input[data-preview-notify-mail-url]:checked').data('preview-notify-mail-url');
  254.             }
  255.         },
  256.         getTotalCount: {
  257.             value: function () {
  258.                 return $('input[data-preview-notify-mail-url]:checked').length;
  259.             }
  260.         },
  261.         getPromises: {
  262.             value: function (progress) {
  263.                 return $('input[data-notify-mail-url]:checked').map(function () {
  264.                     var url = $(this).data('notify-mail-url');
  265.                     if($('#template-change').val() != 8) {          //出荷通知メール
  266.                         url = url.replace('notify_mail', 'notify_mail_order');
  267.                     }
  268.                     var data = {
  269.                         'deliveryNote': $('input#deliveryNote:checked').val(),
  270.                         'template_id': $('#template-change').val(),
  271.                         'subject': $('#admin_order_mail_mail_subject').val(),
  272.                         'tpl_data': $('#admin_order_mail_tpl_data').val()
  273.                     };
  274.                     return ConfirmationModal.prototype.getPromises.call(this, progress, url, data);
  275.                 });
  276.             }
  277.         }
  278.     });
  279.     /*
  280.      * 個別メール送信
  281.      */
  282.     function SimpleSendMail(modal, relatedTarget) {
  283.         SimpleStatusUpdate.call(this, modal, relatedTarget);
  284.     }
  285.     // extends SimpleUpdate
  286.     SimpleSendMail.prototype = Object.create(SimpleStatusUpdate.prototype, {
  287.         constructor: {
  288.             value: SimpleStatusUpdate
  289.         },
  290.         modalTitle: {
  291.             value: "{{ 'admin.order.shipping_mail_send__confirm_title'|trans }}"
  292.         },
  293.         modalMessage: {
  294.             value: "{{ 'admin.order.shipping_mail_send__confirm_message'|trans }}"
  295.         },
  296.         modalButton: {
  297.             value: "{{ 'admin.common.send'|trans }}"
  298.         },
  299.         getPromises: {
  300.             value: function (progress) {
  301.                 var url = this.eventTarget.data('notify-mail-url');
  302.                 var data = {
  303.                     'deliveryNote': $('input#deliveryNote:checked').val(),
  304.                     'template_id': $('#template-change').val(),
  305.                     'subject': $('#admin_order_mail_mail_subject').val(),
  306.                     'tpl_data': $('#admin_order_mail_tpl_data').val()
  307.                 };
  308.                 return ConfirmationModal.prototype.getPromises.call(this, progress, url, data);
  309.             }
  310.         }
  311.     });
  312. </script>