Newer
Older
dmpopidor / app / javascript / views / plans / share.js
@Bodacious Bodacious on 19 Oct 2018 636 bytes Update asset structure with webpacker gem
import * as notifier from '../../utils/notificationHelper';
import { isObject, isString } from '../../utils/isType';

$(() => {
  $('#set_visibility [name="plan[visibility]"]').click((e) => {
    $(e.target).closest('form').submit();
  });
  $('#set_visibility').on('ajax:success', (e, data) => {
    if (isObject(data) && isString(data.msg)) {
      notifier.renderNotice(data.msg);
    }
  });
  $('#set_visibility').on('ajax:error', (e, xhr) => {
    if (isObject(xhr.responseJSON)) {
      notifier.renderAlert(xhr.responseJSON.msg);
    } else {
      notifier.renderAlert(`${xhr.statusCode} - ${xhr.statusText}`);
    }
  });
});