首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何自动将用户分配到日历中的下一个可用时隙?

如何自动将用户分配到日历中的下一个可用时隙?
EN

Stack Overflow用户
提问于 2016-10-28 14:38:02
回答 1查看 302关注 0票数 3

我有一个标准的Sap UI5日历,目前允许用户安排会议室的约会,并在提交的时间块中显示它们。我想添加的一个很酷的特性是在约会表单上创建一个按钮,自动将用户分配到下一个可用/空缺的时间段。作为SAP UI5的新手,如何实现这一点?

这是我所拥有的一个工作示例。单击日历将打开约会表单。

控制器

代码语言:javascript
复制
 sap.ui.define([
  'sap/ui/core/mvc/Controller',
  'sap/ui/model/json/JSONModel',
  'sap/m/Dialog',
  'sap/m/Button'
  ],
function(Controller, JSONModel,Dialog, Button) {
"use strict";

var PageController = Controller.extend("sample1.View1", {

    onInit: function () {
        // create model
        var oModel = new JSONModel();
        oModel.setData({
            startDate: new Date("2015", "11", "15", "8", "0"),
            people: [{
                                pic: "sap-icon://employee",
                                name: "Meeting Room 1",
                                role: "101",
                                appointments: [
                                               {
                                                 start: new Date("2015", "11", "15", "10", "0"),
                                                 end: new Date("2015", "11", "15", "12", "0"),
                                                 title: "Team meeting",
                                                 info: "room 1",
                                                 type: "Type01",
                                                 pic: "sap-icon://sap-ui5",
                                                 tentative: false
                                               },
                                               {
                                                 start: new Date("2015", "11", "16", "0", "0"),
                                                 end: new Date("2015", "11", "16", "23", "59"),
                                                 title: "Vacation",
                                                 info: "out of office",
                                                 type: "Type04",
                                                 tentative: false
                                               }
                                               ],
                                headers: [
                                          {
                                            start: new Date("2015", "11", "16", "0", "0"),
                                            end: new Date("2015", "11", "16", "23", "59"),
                                            title: "Private",
                                            type: "Type05"
                                          },
                                          ]
                            },
                            {
                                pic: "sap-icon://employee",
                                name: "Meetin Room 2",
                                role: "201",
                                appointments: [
                                               {
                                                 start: new Date("2015", "11", "15", "08", "30"),
                                                 end: new Date("2015", "11", "15", "09", "30"),
                                                 title: "Meeting",
                                                 type: "Type02",
                                                 tentative: false
                                               },
                                               {
                                                 start: new Date("2015", "11", "15", "10", "0"),
                                                 end: new Date("2015", "11", "15", "12", "0"),
                                                 title: "Team meeting",
                                                 info: "room 1",
                                                 type: "Type01",
                                                 pic: "sap-icon://sap-ui5",
                                                 tentative: false
                                               },
                                               {
                                                 start: new Date("2015", "11", "15", "11", "30"),
                                                 end: new Date("2015", "11", "15", "13", "30"),
                                                 title: "Lunch",
                                                 type: "Type03",
                                                 tentative: true
                                               }
                                               ],
                                headers: [
                                          {
                                            start: new Date("2015", "11", "15", "8", "0"),
                                            end: new Date("2015", "11", "15", "10", "0"),
                                            title: "Reminder",
                                            type: "Type06"
                                          }
                                          ]
                            }
            ]
        });
        this.getView().setModel(oModel);

    },

    handleAppointmentSelect: function (oEvent) {
        var oAppointment = oEvent.getParameter("appointment");
        if (oAppointment) {
            alert("Appointment selected: " + oAppointment.getTitle());
        }else {
            var aAppointments = oEvent.getParameter("appointments");
            var sValue = aAppointments.length + " Appointments selected";
            alert(sValue);
        }
    },
    handleIntervalSelect:function(oEvent){

      var dialogData = {
        newEntry: {
        start: oEvent.getParameter("startDate"),
            end: oEvent.getParameter("endDate"),
            title: "",
            info: "",
            type: "Type01",
            pic: "sap-icon://sap-ui5",
            tentative: false
        },
        people: this.getView().getModel().getProperty("/people").map(function(p,i){ return { name: p.name, index: i, selected: true }; }) //A List of all people. All selected by default.
            };
        var dialogModel = new JSONModel(dialogData);
        var that = this;
        var planningDialog = new Dialog({
          title:"Add Appointment",
          content: sap.ui.xmlview({viewName:"sample1.AppointmentDialog"}).setModel(dialogModel),
          leftButton: new Button({
            text: "Cancel", 
            press: function(){ 
              planningDialog.close(); 
              planningDialog.destroy();
            }}),
          rightButton: new Button({
            text: "Save", 
            type: "Accept",
            press: function(){ 
              planningDialog.close(); 
              that.addAppointment(dialogData);
            }}),

        });
        planningDialog.open();

    },
    addAppointment:function(data){
      var model = this.getView().getModel();
      var peopleList = model.getProperty("/people");
      data.people
        .filter(function(p){return p.selected;})
        .forEach(function(p){ 
          peopleList[p.index].appointments.push(data.newEntry);
        });
        model.setProperty("/people",peopleList); //Updates Bindings
    }

});

return PageController;

}); 

视图

代码语言:javascript
复制
<mvc:View
controllerName="sample1.View1"
xmlns:mvc="sap.ui.core.mvc"
xmlns:unified="sap.ui.unified"
xmlns="sap.m">
<VBox class="sapUiSmallMargin">
    <PlanningCalendar
        id="PC1"
        startDate="{path: '/startDate'}"
        rows="{path: '/people'}"
        appointmentSelect="handleAppointmentSelect"
        intervalSelect=".handleIntervalSelect">
        <toolbarContent>
            <Title text="Title" titleStyle="H4"/>
        </toolbarContent>
        <rows>
            <PlanningCalendarRow
                icon="{pic}"
                title="{name}"
                text="{role}"
                appointments="{appointments}"
                intervalHeaders="{headers}"                 >
                <appointments>
                    <unified:CalendarAppointment
                        startDate="{start}"
                        endDate="{end}"
                        icon="{pic}"
                        title="{title}"
                        text="{info}"
                        type="{type}"
                        tentative="{tentative}">
                    </unified:CalendarAppointment>
                </appointments>
                <intervalHeaders>
                    <unified:CalendarAppointment
                        startDate="{start}"
                        endDate="{end}"
                        icon="{pic}"
                        title="{title}"
                        type="{type}">
                    </unified:CalendarAppointment>
                </intervalHeaders>
            </PlanningCalendarRow>
        </rows>
    </PlanningCalendar>
</VBox>
</mvc:View>
EN

回答 1

Stack Overflow用户

发布于 2016-11-06 09:50:48

恢复会议列表。

按开始日期订购,并检查您的新会议是否有合适的时间间隔:

(meeting[i+1].startDate - meeting[i].enddate > (Time of new meeting))

这会让你走上正轨。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40307484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档