AlloyUI Scheduler 中的保存、编辑、删除和取消事件

Save, Edit, Delete, and Cancel events in AlloyUI Scheduler

如何从 AlloyUI 的调度程序中监听保存、编辑、删除和取消事件?我需要将该值保存在我们的数据库中以供将来使用,但我没有看到任何相关文档。

我目前的代码是这样的:

YUI().use('aui-scheduler', function(Y) {
    var items = [
        {
            content: 'Wake Early'
        },
        {
            content: 'Exercise'
        },
    ];
    var schedulerViews = [
        new Y.SchedulerWeekView(),
        new Y.SchedulerDayView(),
        new Y.SchedulerMonthView(),
        new Y.SchedulerAgendaView()
    ];
   var eventRecorder = new Y.SchedulerEventRecorder();
    new Y.Scheduler({
        boundingBox: '#scheduler',
        items: items,
        views: schedulerViews,
        activeView: schedulerViews[2],
        eventRecorder: eventRecorder,
         firstDayOfWeek: 1,
        // activeView: weekView,
        // views: [dayView, weekView, monthView, agendaView]
    }).render();

    Y.Do.after(function() { 
      this.on("save",function(data){
       alert('Event:'+this.isNew()+' --- '+this.getContentNode().val());
      });   
    }, eventRecorder, 'showPopover');

});

到目前为止我没有运气,有人可以帮助我吗?我也试过 this tutorial and this 一个,但没有用。

您应该使用 SchedulerEventRecorder 的未记录的 saveeditdeletecancel* 事件。例如:

var eventRecorder = new Y.SchedulerEventRecorder({
    on: {
        save: function(event) {
            alert('Save Event:' + this.isNew() + ' --- ' + this.getContentNode().val());
        },
        edit: function(event) {
            alert('Edit Event:' + this.isNew() + ' --- ' + this.getContentNode().val());
        },
        delete: function(event) {
            alert('Delete Event:' + this.isNew() + ' --- ' + this.getContentNode().val());
// Note: The cancel event seems to be buggy and occurs at the wrong times, so I commented it out.
//      },
//      cancel: function(event) {
//          alert('Cancel Event:' + this.isNew() + ' --- ' + this.getContentNode().val());
        }
    }
});

这是一个使用您提供的代码的可运行示例:

YUI().use('aui-scheduler', function(Y) {
  var items = [{
    content: 'Wake Early'
  }, {
    content: 'Exercise'
  }, ];
  var schedulerViews = [
    new Y.SchedulerWeekView(),
    new Y.SchedulerDayView(),
    new Y.SchedulerMonthView(),
    new Y.SchedulerAgendaView()
  ];
  var eventRecorder = new Y.SchedulerEventRecorder({
    on: {
      save: function(event) {
        alert('Save Event:' + this.isNew() + ' --- ' + this.getContentNode().val());
      },
      edit: function(event) {
        alert('Edit Event:' + this.isNew() + ' --- ' + this.getContentNode().val());
      },
      delete: function(event) {
        alert('Delete Event:' + this.isNew() + ' --- ' + this.getContentNode().val());
// Note: The cancel event seems to be buggy and occurs at the wrong times, so I commented it out.
//      },
//      cancel: function(event) {
//        alert('Cancel Event:' + this.isNew() + ' --- ' + this.getContentNode().val());
      }
    }
  });
  new Y.Scheduler({
    boundingBox: '#scheduler',
    items: items,
    views: schedulerViews,
    activeView: schedulerViews[2],
    eventRecorder: eventRecorder,
    firstDayOfWeek: 1,
    // activeView: weekView,
    // views: [dayView, weekView, monthView, agendaView]
  }).render();

});
<script src="https://cdn.rawgit.com/stiemannkj1/701826667a70997013605edcd37e92a6/raw/469fe1ae297e72a5a80eb9015003b7b04eac735e/alloy-ui-3.0.1_aui_aui-min.js"></script>
<link href="https://cdn.rawgit.com/stiemannkj1/90be22de7f48c729b443af14796d91d3/raw/a9f35ceedfac7fc0559b121bed105eaf80f10bf2/aui-css_css_bootstrap.min.css" rel="stylesheet"></link>
<div id="myScheduler"></div>

*cancel 事件似乎有点错误并且发生在错误的时间,所以我将其注释掉了。它似乎在任何其他事件发生时都会发生。