/*
 * @Description: Do not edit
 * @Date: 2021-08-31 11:16:45
 * @LastEditors: viletyy
 * @Author: viletyy
 * @LastEditTime: 2021-08-31 14:19:46
 * @FilePath: /forgeplus/app/assets/javascripts/admins/system_notifications/index.js
 */
$(document).on('turbolinks:load', function(){

    var showSuccessNotify = function() {
      $.notify({
        message: '操作成功'
      },{
        type: 'success'
      });
    }

    // close user
    $('.recruitment-list-container').on('click', '.close-action', function(){
      var $closeAction = $(this);
      var $uncloseAction = $closeAction.siblings('.unclose-action');

      var keywordID = $closeAction.data('id');
      customConfirm({
        content: '确认取消上架吗？',
        ok: function(){
          $.ajax({
            url: '/admins/recruitments/' + keywordID,
            method: 'PUT',
            dataType: 'json',
            data: {
              recruitment: {
                is_public: false
              }
            },  
            success: function() {
              showSuccessNotify();
              $closeAction.hide();
              $uncloseAction.show();
              $(".recruitment-item-"+keywordID).children('td').eq(2).text("")
            }
          });
        }
      });
    });

    // unclose user
    $('.recruitment-list-container').on('click', '.unclose-action', function(){
      var $uncloseAction = $(this);
      var $closeAction = $uncloseAction.siblings('.close-action');

      var keywordID = $uncloseAction.data('id');
      customConfirm({
        content: '确认置顶吗？',
        ok: function () {
          $.ajax({
            url: '/admins/recruitments/' + keywordID,
            method: 'PUT',
            dataType: 'json',
            data: {
              recruitment: {
                is_public: true
              }
            },
            success: function() {
              showSuccessNotify();
              $closeAction.show();
              $uncloseAction.hide();
              $(".recruitment-item-"+keywordID).children('td').eq(2).text("√")
            }
          });
        }
      })
    });
})