Blame view

resources/views/modals/chats/answer_to_admin_chat.blade.php 2.21 KB
7f3406fc6   Hayk Nazaryan   fix subscribe and...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  <div class="hide">
      <div id="answer_to_admin_chat_modal" class="modal-dialog">
          <div class="modal-dialog-title">
              <h2>Ответить</h2>
          </div>
          <div class="modal-dialog-body">
              <textarea class="textarea" name="text" placeholder="" required></textarea>
          </div>
          <div class="modal-dialog-footer">
              <button type="button" class="button answer_to_admin_chat_modal">Отправить</button>
              <button type="button" class="button button_light" onclick="$.fancybox.close();">Закрыть</button>
          </div>
      </div>
  </div>
  
  <script>
      $(function (){
          $('.admin-chat-answer').on('click', function () {
              var button = $(this);
              var modal = $('#answer_to_admin_chat_modal');
              modal.data('to-user-id', button.data('to-user-id'));
              modal.data('message-id', button.data('message-id'));
          });
  
          $('.answer_to_admin_chat_modal').click(function(){
              spinStart($(this));
              var wrap = $(this).closest('#answer_to_admin_chat_modal');
              console.log(wrap);
              var to_user_id = wrap.data('to-user-id');
              var reply_message_id = wrap.data('message-id');
              var textarea = wrap.find('[name="text"]');
              var text = textarea.val()
              textarea.removeClass('border-red');
              if (!text.trim()){
                  textarea.addClass('border-red');
                  return;
              }
  
              $.ajax({
                  type: "POST",
                  url: "{{ route('employer.send_message')  }}",
                  data: {
                      to_user_id: to_user_id,
                      reply_message_id: reply_message_id,
                      text: text
                  },
                  dataType: 'json',
                  headers: {
                      'X-CSRF-TOKEN': $('[name="_token"]').val()
                  },
                  success: function(res){
                      if (res && res.success && res.url_redirect){
                          window.location.replace(res.url_redirect);
                      } else{
                          location.reload();
                      }
                  }
              });
          });
      });
  </script>