4

如何向 AlloyUIScheduler的事件弹出窗口添加自定义按钮?事件弹出窗口包括SaveCancelDelete按钮,但我想添加另一个(例如Edit)。我查看了Schedulers API Doc,但找不到任何有关向事件弹出窗口添加按钮的信息。

4

2 回答 2

4

该类包含对弹出框SchedulerEventRecorder的引用,其中包含您要添加按钮的表单。但是,我尝试自定义包含按钮的工具栏页脚(在调度程序弹出框内的工具栏内),但这似乎不可能。所以我怀疑是否有自定义这些按钮的标准 API 方法,我也怀疑开发人员是否打算对这些按钮进行自定义。因此,我建议不要自定义按钮。

但是,如果您确定要添加和自定义这些按钮,尽管存在潜在问题,那么我确实找到了一种方法来做您想做的事情。每次Scheduler弹出 's popover 时,它只显示默认按钮。即使您在创建后向其添加按钮,它也会忽略或删除它们,或者(很可能)被销毁然后重新创建并且永远不会显示自定义按钮。因此,必须在弹出框显示后添加任何按钮。为此,您可以在方法之后执行一个方法,SchedulerEventRecorder.showPopover()如下Do.after()所示:

var eventRecorder = new Y.SchedulerEventRecorder();

Y.Do.after(function() {
    // Assuming that the boundingBox of your Scheduler has an id of "bb":
    var toolbarBtnGroup = Y.one('#bb .toolbar .btn-group');
    toolbarBtnGroup.appendChild('<button id="edit" type="button">Edit</button>');
}, eventRecorder, 'showPopover');

这是一个可运行的代码示例:

YUI().use('aui-button', 'aui-scheduler', 'event-custom-base', function (Y) {

    var eventRecorder = new Y.SchedulerEventRecorder();
    var weekView = new Y.SchedulerWeekView();

    new Y.Scheduler({
        boundingBox: '#bb',
        date: new Date(2014, 8, 28),
        eventRecorder: eventRecorder,
        items: [],
        views: [weekView]
    }).render();

    var editButton;

    Y.Do.after(function() {

        var toolbarBtnGroup = Y.one('#bb .toolbar .btn-group');
        toolbarBtnGroup.appendChild('<button id="edit" type="button">Edit</button>');

        editButton = new Y.Button({
            label: 'Edit',
            srcNode: '#edit',
        }).render();

        editButton.on('click', function(event) {
            alert('Edit clicked!');
            eventRecorder.hidePopover();
        });
    }, eventRecorder, 'showPopover');
    
    Y.Do.after(function() {
        
        // Make sure that the editButton is destroyed to avoid a memory leak.
        if (editButton) {
            editButton.destroy();
        }
    }, eventRecorder, 'hidePopover');
});
<link href="http://cdn.alloyui.com/2.5.0/aui-css/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://cdn.alloyui.com/2.5.0/aui/aui-min.js"></script>
<!-- boundingBox of the scheduler -->
<div id="bb"></div>

于 2014-09-28T19:58:26.057 回答
1

我创建了自己的请求记录器:

    var myEventRecorder = A.Component.create({
        EXTENDS: A.SchedulerEventRecorder,

        NAME: 'scheduler-event-recorder',

        prototype: {
            _getFooterToolbar: function() {
                var instance = this,
                event = instance.get('event'),
                strings = instance.get('strings'),
                children = [
                    {
                        label: strings['cancel'],
                        on: {
                            click: A.bind(instance._handleCancelEvent, instance)
                        }
                    }
                ];

                var requestId = event && event.get('requestId');

                if (requestId) {
                    children.push({
                        label: strings['open_request'],
                        on: {
                            click: A.bind(instance._handleOpenRequest, instance)
                        }
                    });
                }

                return [children];
            },

            _handleOpenRequest : function() {
                //console.log(arguments);
                var event = this.get('event');
                var requestUrl = this.get('requestUrl');
                requestUrl.setParameter('REQUEST_PARAM', event.get('requestId'));
                window.location.href = requestUrl.toString();
            }
        }
    });

    var eventRecorder = new myEventRecorder();

然后使用它:

var scheduler = new A.Scheduler(
      {
        boundingBox: '#myScheduler',
        eventRecorder: eventRecorder,
        views: [dayView, weekView]
      }
);
于 2016-04-29T05:51:18.543 回答