Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18927] iOS: Calendar Event: Allow to fetch event Organiser and Invitees/Attendees details

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2016-07-23T18:56:17.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.0.0
ComponentsiOS
Labelscalendar, event, invitee, organizer
ReporterShuo Liang
AssigneeHans Knöchel
Created2015-05-20T01:29:29.000+0000
Updated2016-09-26T21:49:04.000+0000

Description

Customer (Agilent, VMWare) is looking for a way to fetch event Organiser and Invitees/Attendees details form Ti.Calendar.Event

Comments

  1. Hans Knöchel 2016-07-23

    Updated PR: https://github.com/appcelerator/titanium_mobile/pull/8150 Updated demo:
       var currentYear = 2016;
       var currentMonth = 7;
        
       var win = Ti.UI.createWindow({
           translucent: false,
           title: 'Calendar Demo'
       });
       
       var list = Ti.UI.createListView({
           template: Titanium.UI.LIST_ITEM_TEMPLATE_SUBTITLE,
           style: 1
       });
       
       var nav = Ti.UI.iOS.createNavigationWindow({
           window: win
       });
       
       var fetchEventsButton = Ti.UI.createButton({
           title: "Fetch events"
       });
       
       fetchEventsButton.addEventListener("click", handlePermissions);
       list.addEventListener("itemclick", handleAttendee);
       
       win.setRightNavButton(fetchEventsButton);
       win.add(list); 
       
       function handleAttendee(e) {
           var attendee = e.section.getItemAt(e.itemIndex).attendee;
           
           var str = "E-Mail: " + attendee.email;
           
           str += "\nRole: " + formatAttendeeRole(attendee.role);
           str += "\nType: " + formatAttendeeType(attendee.type);
           str += "\nStatus: " + formatAttendeeStatus(attendee.status);
           str += "\nIs organizer: " + (attendee.isOrganizer ? "Yes" : "No");
           
           Ti.UI.createAlertDialog({
               title: attendee.name,
               message: str,
               buttonNames: ["OK"]
           }).show();
           
           list.deselectItem(e.sectionIndex, e.itemIndex);
       }
       
       function formatAttendeeRole(role) {
           switch (role) {
               case Ti.Calendar.ATTENDEE_ROLE_UNKNOWN:
               return "Ti.Calendar.ATTENDEE_ROLE_UNKNOWN";
               
               case Ti.Calendar.ATTENDEE_ROLE_REQUIRED:
               return "Ti.Calendar.ATTENDEE_ROLE_REQUIRED";
           
               case Ti.Calendar.ATTENDEE_ROLE_OPTIONAL:
               return "Ti.Calendar.ATTENDEE_ROLE_OPTIONAL";
           
               case Ti.Calendar.ATTENDEE_ROLE_CHAIR:
               return "Ti.Calendar.ATTENDEE_ROLE_CHAIR";
           
               case Ti.Calendar.ATTENDEE_ROLE_NON_PARTICIPANT:
               return "Ti.Calendar.ATTENDEE_ROLE_NON_PARTICIPANT";        
           }
           
           return "Unknown attendee role: " + role;
       }
       
       function formatAttendeeType(type) {
           switch (type) {
               case Ti.Calendar.ATTENDEE_TYPE_UNKNOWN:
               return "Ti.Calendar.ATTENDEE_ROLE_UNKNOWN";
               
               case Ti.Calendar.ATTENDEE_TYPE_PERSON:
               return "Ti.Calendar.ATTENDEE_TYPE_PERSON";
           
               case Ti.Calendar.ATTENDEE_TYPE_ROOM:
               return "Ti.Calendar.ATTENDEE_TYPE_ROOM";
           
               case Ti.Calendar.ATTENDEE_TYPE_RESOURCE:
               return "Ti.Calendar.ATTENDEE_TYPE_RESOURCE";
           
               case Ti.Calendar.ATTENDEE_TYPE_GROUP:
               return "Ti.Calendar.ATTENDEE_TYPE_GROUP";        
           }
           
           return "Unknown attendee type: " + type;
       }
       
       function formatAttendeeStatus(status) {
           switch (status) {
               case Ti.Calendar.ATTENDEE_STATUS_UNKNOWN:
               return "Ti.Calendar.ATTENDEE_ROLE_UNKNOWN";
               
               case Ti.Calendar.ATTENDEE_STATUS_PENDING:
               return "Ti.Calendar.ATTENDEE_STATUS_PENDING";
           
               case Ti.Calendar.ATTENDEE_STATUS_ACCEPTED:
               return "Ti.Calendar.ATTENDEE_STATUS_ACCEPTED";
           
               case Ti.Calendar.ATTENDEE_STATUS_DECLINED:
               return "Ti.Calendar.ATTENDEE_STATUS_DECLINED";
           
               case Ti.Calendar.ATTENDEE_STATUS_TENTATIVE:
               return "Ti.Calendar.ATTENDEE_STATUS_TENTATIVE"; 
                      
               case Ti.Calendar.ATTENDEE_STATUS_DELEGATED:
               return "Ti.Calendar.ATTENDEE_STATUS_DELEGATED";   
                    
               case Ti.Calendar.ATTENDEE_STATUS_COMPLETED:
               return "Ti.Calendar.ATTENDEE_STATUS_COMPLETED";  
                     
               case Ti.Calendar.ATTENDEE_STATUS_IN_PROCESS:
               return "Ti.Calendar.ATTENDEE_STATUS_IN_PROCESS";        
           }
           
           return "Unknown attendee status: " + status;
       }
       
       function handlePermissions() {
       	if (Ti.Calendar.hasCalendarPermissions()) {
       	    performCalendarReadFunctions();
       	} else {
       	    Ti.Calendar.requestCalendarPermissions(function(e) {
       	        if (e.success) {
       	            performCalendarReadFunctions();
       	        } else {
       	            alert('Access to calendar is not allowed: ' + e.error);
       	        }
       	    });
       	}
       }
        
       function performCalendarReadFunctions() {
           var calendar = Ti.Calendar.defaultCalendar;  
           var events = calendar.getEventsInMonth(currentYear, currentMonth); 
           var sections = [];
           
           if (events && events.length) {
                 console.log(events.length + ' event(s) in ' + currentYear);
                 for (var i = 0; i < events.length; i++) {
                 	sections.push(createSectionFromEvent(events[i]));
                 }
                 list.setSections(sections);
           } else {
                 console.log('No events in ' + currentMonth + '/' + currentYear + ' found');
           }
       }
        
       function createSectionFromEvent(event) {
       
           var items = [];
           var attendees = event.attendees;
           var section = Ti.UI.createListSection({
               headerTitle: event.title + ' (' + attendees.length + ' Attendees)'
           });
           
       	for (var i = 0; i < attendees.length; i++) {
               var attendee = attendees[i];
               var item = {
                   attendee: attendee,
                   properties: {
                       title: attendee.name,
                       subtitle: attendee.email,
                       height: 50,
                       accessoryType: Titanium.UI.LIST_ACCESSORY_TYPE_DISCLOSURE
                   }
               };
              
               items.push(item);
           }
           
           if (attendees.length == 0) {
               items.push({
                   properties: {
                       title: 'No attendees',
                       selectionStyle: Ti.UI.iOS.ListViewCellSelectionStyle.NONE
                   }
               })
           }
           
           section.setItems(items);
           
           return section;
       }
        
       nav.open();
       
  2. Abir Mukherjee 2016-09-26

    Verified fix with Environment: NPM Version: 2.15.9 Node Version: 4.5.0 Mac OS: 10.11.6 Appc CLI: 5.5.0 Appc CLI NPM: 4.2.7 Titanium SDK version: 6.0.0.v20160925202930 Appcelerator Studio, build: 4.7.1.201609100950 Xcode 8.0 GM I was able to reproduce the issue with Titanium SDK version 5.5.0 using the repro code in the Description. I ran the code on an iPhone 6s Plus iOS v10.0.1. I launched the app, clicked on the "Fetch events" button, and an "Application Error" window appeared. I reran the same test script with Titanium SDK version 6.0.0, clicked on "Fetch events", and an event which I had put on the calendar displayed as a list. The name of the event along with a list of attendees was shown. Clicking on each attendee showed whether the attendee was an organizer or not.

JSON Source