从嵌入式提交表单

时间:2015-06-20 12:22:03

标签: date variables events time calendar

我使用this脚本作为从提交表单创建日历事件的基础:

我的脚本有效,但我也希望能够安排开始时间和结束时间。

我添加了一个列表框,允许用户选择开始和结束时间,但不能组合2个变量来创建可用于创建事件的单个日期时间。

//
//Create the GUI form

function doGet() {
var app = UiApp.createApplication().setTitle('Form and Calendar Events');

//Create a penel which holds all the form elelemnts
var panel = app.createVerticalPanel().setId('panel');

//Create the form elelemnts
var eventDateLabel = app.createLabel('Event Date:');
var eventDate = app.createDateBox().setId('eventDate');
var eventStartTimeLabel = app.createLabel('Event Start Time:');
var listBox = app.createListBox().setName('eventStartTime').setWidth('80px');
listBox.addItem('08:00:00 UTC+8');
listBox.addItem('08:20:00 UTC+8');
listBox.addItem('08:40:00 UTC+8');
listBox.addItem('09:00:00 UTC+8');
var eventFinishTimeLabel = app.createLabel('Event Finish Time:');
var listBox1 =    app.createListBox().setName('eventFinishTime').setWidth('80px');
listBox1.addItem('08:20:00 UTC+8');
listBox1.addItem('08:40:00 UTC+8');
listBox1.addItem('09:00:00 UTC+8');
listBox1.addItem('09:20:00 UTC+8');
var eventTitleLabel = app.createLabel('Event title:');
var eventTitle = app.createTextBox().setName('eventTitle').setId('eventTitle');
var eventDeatilLabel = app.createLabel('Event Details:');
var eventDetail = app.createTextArea()
  .setSize('200', '100').setId('eventDetail').setName('eventDetail');
var btn = app.createButton('createEvents');

//Create handler which will execute 'createEvents(e)' on clicking the button
var handler = app.createServerClickHandler('createEvents');
handler.addCallbackElement(panel);
//Add this handler to the button
btn.addClickHandler(handler);

//Add all the elemnts to the panel 
panel.add(eventDateLabel)
.add(eventDate)
.add(eventTitleLabel)
.add(eventTitle)
.add(eventStartTimeLabel)
.add(listBox)
.add(eventFinishTimeLabel)
.add(listBox1)
.add(eventDeatilLabel)
.add(eventDetail)
.add(btn);
//Add this panel to the application
app.add(panel);
//return the application
return app;
}

function createEvents(e){

//Get the active application
var app = UiApp.getActiveApplication();

try{
//get the entries;
var eventDate = e.parameter.eventDate;
var eventTitle = e.parameter.eventTitle;
var eventDetails = e.parameter.eventDetail;
var eventStartTime = e.paremeter.eventStartTime;
var eventFinishTime = e.paremeter.eventFinishTime;
var eventBegin = eventDate + eventStartTime;
var eventEnd = eventDate + eventFinishTime;


    //Get the calendar
 //var cal = CalendarApp.getCalendarsByName('Calendar-Name')[0];//Change the calendar name
 //End time is calculated by adding an hour in the event start time 
 //var eventEndTime = new Date(eventDate.valueOf()+60*60*1000);
 //Create the events
 //cal.createEvent(eventTitle, eventStartTime,eventEndTime ,{description:eventDetails});





 // Creates an event for the moon landing and logs the ID.
var event = CalendarApp.getCalendarsByName('Test')[0].createEvent(eventTitle,
 new Date(eventBegin),
 new Date(eventEnd),
 {location: 'test'});
Logger.log('Event ID: ' + event.getId());






//Log the entries in a spreadsheet
var ss = SpreadsheetApp.openById('15lMblqQvgJqhmI7KP5J-ROEsfiUyX-MfJLiqU9hQJRQ');//Change the spreadhseet key to yours
var sheet = ss.getSheets()[0];
sheet.getRange(sheet.getLastRow()+1, 1, 1, 5).setValues([[new Date(), eventDate,eventTitle, eventDetails, 'Event created']]);

//Show the confirmation message
app.add(app.createLabel('Event created Successfully'));
//make the form panel invisible
app.getElementById('panel').setVisible(false);
return app;
}

//If an error occurs, show it on the panel
catch(e){
app.add(app.createLabel('Error occured: '+e));
return app;
  }
}

有很多评论出来的地方,我一直在玩这个,但希望你得到的要点。相当新的,如果不清楚,请道歉。

0 个答案:

没有答案