require(['jquery', 'xwiki-meta'], function ($, xm) {

  $(document).ready(function() {
    var input = $('.notificationAutoWatchMode');
    input.change( function (event) {
      var target = input.data('target') == 'wiki' ? 'wiki' : 'user';
      var notification = new XWiki.widgets.Notification("\u60A8\u7684\u8BBE\u7F6E\u6B63\u5728\u4FDD\u5B58\u4E2D......", 'inprogress');
      var url = "http://www.itil4hub.cn:80/bin/get/XWiki/Notifications/Code/NotificationPreferenceService?outputSyntax=plain";
      $.post(url, {
        action: target == 'user' ? 'setAutoWatchMode' : 'setDefaultAutoWatchMode',
        mode: $(this).val(),
        csrf: xm.form_token
      }).done(function() {
        notification.hide();
        new XWiki.widgets.Notification("\u5DF2\u4FDD\u5B58\uFF01", 'done');
      }).error(function() {
        notification.hide();
        new XWiki.widgets.Notification("\u4FDD\u5B58\u60A8\u7684\u8BBE\u7F6E\u5931\u8D25", 'error');
      });
    });
  });

});
