MindFusion.Scheduling for ASP.NET Programmer's Guide
Manipulating Items on the Client

Events scheduled to occur at an appointed time are represented on the client side in MindFusion.Scheduling for ASP.NET by the Item class. Item comprises the information that should be defined for all schedule events. For example, the values returned from the getStartTime and getEndTime methods represent the time and duration of an event. The getRecurrence method lets you view the Recurrence object, associated with this item instance. There are several other descriptive functions that can provide additional information about an item, such as getPriority, getHeaderTextgetDescriptionText and so forth.

It is possible for an Item to be associated with resources such as Resource, Contact, Location or Task. The id(s) of the associated resource(s) can be obtained by calling getResources, getContacts, getLocation or getTask respectively.

Getting a reference to an item

There are various ways to access one or more items defined in a MindFusion.Scheduling for ASP.NET Calendar from the client. The getItems method returns a collection, containing all the items, currently present in the calendar's schedule. Currently selected items are accessible from the getItemSelection function. Cell objects also contain references to their associated items, which can be accessed through the getCellItems, getCueCellItems, getHeaderItems or getCueHeaderItems. Particular item or items can be accessed through id by calling getItemById or through the id of an associated resource with getItemsByResourceId.

Item object table

In order to programatically set values to one or more of the Item's properties, the createItem and editItem methods should be used, by passing as argument an object which defines the values of some of these properties.

This is a complete table of the names of the item's properties, which can be set programatically from the client side:

Name

Value type

Description

startTime

DateTime

Represents the start time of an event.

endTime

DateTime

Represents the end time of an event.

contacts

Array

Represents a collection, containing the ids of any associated Contact objects.

location

String

Represents the id of an associated Location object.

task

String

Represents the id of an associated Task object.

resources

Array

Represents a collection, containing the ids of any associated Resource objects.

cssClass

String

Represents the name of a user defined CSS Class, used to visually style the item.

allowChangeStart

Boolean

Specifies whether the item's start time can be modified by interactive resize.

allowChangeEnd

Boolean

Specifies whether the item's end time can be modified by interactive resize.

allowMove

Boolean

Specifies whether the item can be moved interactively.

locked

Boolean

Specifies whether the user can interact with the item.

allDayEvent

Boolean

Specifies whether the item is defined as an all-day event or not.

subject

String

Represents the item's header text.

details

String

Represents the item's description text.

reminder

Reminder

Represents a Reminder object, associated with the item.

recurrence

Recurrence

Represents a recurrent pattern, associated with the item.

priority

Number

Represents a user defined priority, used in the order in which items appear in the calendar.

visible

Boolean

Specifies whether the item is visible in the calendar.

tag

Object

Represents a custom field used for storing user defined data.

Creating items

New items can be added programatically on the client side by calling Calendar's createItem method.

The following function will create and add to the calendar an Item, which starts at 09:00 of the current day, with a duration of 9 hours, its header text will display "new item".

JavaScript  Copy Code

function create() {
    // gets a reference to the calnedar, assuming the value of the Calendar's WebControl.ID property is set to "Calendar1"
    var calendar = $find('Calendar1');

    // creates an object holding the properties of the new item
    var data = {
        startTime: MindFusion.Common.DateTime.today().addHours(9),
        endTime: MindFusion.Common.DateTime.today().addHours(18),
        subject: 'new item'
    };

    // creates the item and adds it to the Calendar.
    calendar.createItem(data);
}

Editing items

Items can be edited programatically on the client side by calling Calendar's editItem method. The item parameter should be the edited item, and the args parameter should be an Object, containing the changed properties.

The following function will edit the currently selected item, by assigning a recurrence pattern to it and changing its description text:

 Note

You can find details about programatically creating recurrence patterns in the Recurrences on the Client topic.

JavaScript  Copy Code

funcion edit() {
    // gets a reference to the calendar, assuming the value of the Calendar's WebControl.ID property is set to "Calendar1"
    var calendar = $find('Calendar1');

    // gets a reference to the calendar's item selection.
    var itemSelection = calendar.getItemSelection();

    if (itemSelection.length > 0) {
        // gets a reference to the currently selected item.
        var item = itemSelection[0];

        // define the recurrence pattern data.
        // The exact time on which the occurrences of this recurrent pattern will occur and their duration are defined by the Time component of the item's start and end time.
        var recurrenceData = {
            pattern: MindFusion.Scheduling.RecurrencePattern.Daily,
            dailyRecurrence: MindFusion.Scheduling.DailyRecurrence.EveryWorkday,
            startDate: MindFusion.Common.DateTime.fromDateParts(2010, 1, 8),
            recurrenceEnd: MindFusion.Scheduling.RecurrenceEnd.Never
        };

        // defines the values of the edited properties.
        var data = {
            recurrence: new Recurrence(recurrenceData),
            details: 'Working hard!'
        };

        // edits the item and updates the Calendar accordingly.
        // In this particular case all the visible occurrences of the newly defined recurrence pattern will be displayed.
        calendar.editItem(item, data);
    }
}

Deleting items

Items can be deleted programatically on the client side by calling Calendar's deleteItem method. For example:

JavaScript  Copy Code

function delete() {
    // gets a reference to the calendar, assuming the value of the Calendar's WebControl.ID property is set to "Calendar1"
    var calendar = $find('Calendar1');

    // gets all items defined in the calendar
    var items = calendar.getItems();

    if (items.length > 0) {
        //gets a reference to the first item defined in the calendar
        var item = items[0];

        //deletes the item
        calendar.deleteItem(item);
    }
}

Recurrence series can also be removed from the Calendar by deleting the Recurrence master:

JavaScript  Copy Code

function deleteRecurrence() {
    // gets a reference to the calendar, assuming the value of the Calendar's WebControl.ID property is set to "Calendar1"
    var calendar = $find('Calendar1');

    // gets all items defined in the calendar
    var items = calendar.getItems();

    if (items.length > 0) {
        //gets a reference to the first item defined in the calendar
        var item = items[0];

        if (item.getRecurrence()) {
            var masterItem = item.getRecurrence().getMaster();
            // delete the recurrence series and the original item.
            calendar.deleteItem(masterItem);
        }
    } 
}