ProjectEdit

Feature that displays the project editor allowing users to edit the project settings.

This demo shows the project edit feature, click "Edit project" button to start editing:

Project edit
//<code-header>
fiddle.title = 'Project edit';
//</code-header>
// Project contains all the data and is responsible for correct scheduling
const project = new ProjectModel({
    name      : 'Writing documentation',
    startDate : new Date(2017, 0, 1),
    calendar  : 'default',
    calendars : [{
        id        : 'default',
        name      : 'Default calendar',
        intervals : [{
            id                 : 1,
            recurrentStartDate : 'on Sat',
            recurrentEndDate   : 'on Mon',
            isWorking          : false
        }]
    }],
    tasks : [
        {
            id       : 1,
            name     : 'Write docs',
            expanded : true,
            children : [
                { id : 2, name : 'Proof-read docs', startDate : '2017-01-02', endDate : '2017-01-05' },
                { id : 3, name : 'Release docs', startDate : '2017-01-09', endDate : '2017-01-10' }
            ]
        }
    ],
    dependencies : [
        { fromTask : 2, toTask : 3 }
    ]
});

const gantt = new Gantt({
    appendTo : targetElement,
    flex     : '1 0 100%',
    height   : 200,

    project, // Gantt needs project to get schedule data from
    startDate : new Date(2016, 11, 31),
    endDate   : new Date(2017, 0, 11),

    features : {
        // enable project editing UI
        projectEdit : true
    },

    tbar : [
        {
            text : 'Edit project',
            icon : 'fa fa-edit',
            onAction() {
                gantt.editProject();
            }
        }
    ],

    columns : [
        { type : 'name', field : 'name', text : 'Name' }
    ]
});

Customizing tabs and their widgets

To customize tabs you can:

  • Reconfigure built-in tabs by providing override configs in the items config.
  • Remove existing tabs or add your own in the items config.
  • Advanced: Reconfigure the whole editor widget using editorConfig or replace the whole editor using editorClass.

This example shows a custom Project Editor configuration. The built-in "Description" tab is hidden, the "General" tab is renamed to "Common" and "Custom" field is appended to it. Click "Edit project" button to start editing::

Custom project edit
//<code-header>
fiddle.title = 'Custom project edit';
//</code-header>
const project = new ProjectModel({
    name      : 'Documenting',
    startDate : new Date(2017, 0, 1),
    calendar  : 'default',
    custom    : 'Custom field value',
    calendars : [{
        id        : 'default',
        name      : 'Default calendar',
        intervals : [{
            id                 : 1,
            recurrentStartDate : 'on Sat',
            recurrentEndDate   : 'on Mon',
            isWorking          : false
        }]
    }],
    tasks : [
        {
            id       : 1,
            name     : 'Write docs',
            expanded : true,
            custom   : 'Parent custom field value',
            children : [
                // 'custom' field is auto exposed to Task model, then its name is used in TaskEditor to get/set values
                {
                    id        : 2,
                    name      : 'Proof-read docs',
                    startDate : '2017-01-02',
                    endDate   : '2017-01-05',
                    custom    : 'Proof-read custom value'
                },
                {
                    id        : 3,
                    name      : 'Release docs',
                    startDate : '2017-01-09',
                    endDate   : '2017-01-10',
                    custom    : 'Release custom value'
                }
            ]
        }
    ],

    dependencies : [
        { id : 1, fromTask : 2, toTask : 3 }
    ]
});

const gantt = new Gantt({
    appendTo : targetElement,
    flex     : '1 0 100%',
    height   : 200,

    project, // Gantt needs project to get schedule data from
    startDate : new Date(2016, 11, 31),
    endDate   : new Date(2017, 0, 11),

    columns : [
        { type : 'name', field : 'name', text : 'Name' }
    ],

    tbar : [
        {
            text : 'Edit project',
            icon : 'fa fa-edit',
            onAction() {
                gantt.editProject();
            }
        }
    ],

    features : {
        projectEdit : {
            items : {
                generalTab : {
                    // Change title of General tab
                    title : 'Common',
                    items : {
                        // Add a new field
                        newCustomField : {
                            type   : 'textfield',
                            weight : 710,
                            label  : 'Custom (New Field)',
                            name   : 'custom' // Name of the field matches data field name, so value is loaded/saved automatically
                        }
                    }
                },
                // Remove Description tab
                descriptionTab : false
            },
            editorConfig : {
                // Custom height of the Project Editor
                height : '40em'
            }
        } // eo projectEdit
    } // eo features
});

Expand to see Default tabs and fields

The project editor contains tabs by default. Each tab is a container with built in widgets.

Tab ref Type Text Weight Description
generalTab ProjectEditorGeneralTab General 100 Shows basic configuration: name, start/end dates, schedule form
descriptionTab ProjectEditorDescriptionTab Description 200 Shows a text area to add a description to the edited project
advancedTab ProjectEditorAdvancedTab Advanced 300 Shows advanced options: number of hours per day, days per week and days per month

General tab

General tab contains widgets for basic configurations

Field ref Type Weight Description
nameField TextField 100 Project name field
startDateField StartDateField 200 Project start date field
endDateField EndDateField 300 Project end date field
calendarField CalendarField 400 Project calendar field
scheduleFromField RadioGroup 500 Project scheduling direction field
readOnlyField Checkbox 600 Project readOnly field

Advanced tab

A tab showing the advanced options for a project.

Field ref Type Weight Description
hoursPerDayField NumberField 100 Project hours per day field
daysPerWeekField NumberField 200 Project days per week field
daysPerMonthField NumberField 300 Project days per month field

Description tab

Notes tab contains a text area to show notes

A tab showing the description for a project.

Field ref Type Weight Description
descriptionField TextField 100 A textarea field, to set a description to the project

Removing a built-in item

To remove a built-in tab or widget, specify its ref as false in the items config:

const gantt = new Gantt({
    features : {
        projectEdit : {
            items : {
                generalTab  : {
                    items : {
                        // Remove the "Calendar" field in the "General" tab
                        calendarField : false
                    }
                },
                // Remove all tabs except the "General" tab
                descriptionTab : false,
                advancedTab    : false
            }
        }
    }
})

The built-in buttons are:

Widget ref Type Weight Description
saveButton Button 100 Save event button on the bbar
cancelButton Button 300 Cancel event editing button on the bbar

Bottom buttons may be hidden using bbar config passed to editorConfig:

const gantt = new Gantt({
    features : {
        projectEdit : {
            editorConfig : {
                bbar : {
                    items : {
                        cancelButton : false
                    }
                }
            }
        }
    }
})

Customizing a built-in item

To customize a built-in tab or field, use its ref as the key in the items config and specify the configs you want to change (they will be merged with the tabs or fields default configs correspondingly):

const gantt = new Gantt({
    features : {
        projectEdit : {
            items : {
                generalTab : {
                    // Rename "General" tab
                    title : 'Main',
                    items : {
                        // Rename "Calendar" field
                        calendarField : {
                            label : 'Work time'
                        }
                    }
                }
            }
        }
    }
})

Adding a custom item

To add a custom tab or field, add an entry to the items config. When you add a field, the name property links the input field to a field in the loaded project record:

const gantt = new Gantt({
    features : {
        projectEdit : {
            items : {
                generalTab : {
                    items : {
                        // Add new field to the last position
                        newGeneralField : {
                            type   : 'textfield',
                            weight : 710,
                            label  : 'New field in General Tab',
                            // Name of the field matches data field name, so value is loaded/saved automatically
                            name   : 'custom'
                        }
                    }
                },
                // Add a custom tab to the first position
                newTab     : {
                    // Tab is a FormTab by default
                    title  : 'New tab',
                    // provide weight less than General tab has to make sure this tab goes first
                    weight : 90,
                    items  : {
                        newTabField : {
                            type   : 'textfield',
                            weight : 710,
                            label  : 'New field in New Tab',
                            // Name of the field matches data field name, so value is loaded/saved automatically.
                            // In this case it is equal to the project "name" field.
                            name   : 'name'
                        }
                    }
                }
            }
        }
    }
})

Manipulating ProjectEditor items at run time

To change input items depending upon the project being edited, use a beforeProjectEditShow listener to access the editor instance.

The available widgets are described here.

The editor exposes all its descendant widgets in its widgetMap.

const gantt = new Gantt({
    features : {
        projectEdit : true
    },
    listeners : {
        beforeProjectEditShow({ projectRecord, editor }) {
            // if editing a project having non empty startDate value.
            if (projectRecord.startDate) {
                // do not allow editing the project start date
                editor.widgetMap.startDate.disabled = true;
            }
        }
    }
});

This feature is disabled by default

Configs

17

Common

disabledInstancePlugin
listenersEvents

Other

A configuration object applied to the internal ProjectEditor. Useful to for example change the title of the editor or to set its dimensions in code:

features : {
    projectEdit : {
        editorConfig : {
            title : 'My title',
            height : 300
        }
    }
}

NOTE: The easiest approach to affect editor contents is to use the items config.

items: Object

A configuration object used to customize the contents of the project editor. Supply a config object or boolean per tab (listed below) to either affects its contents or toggle it on/off.

Supplied config objects will be merged with the tabs predefined configs.

To remove existing items, set corresponding keys to null.

Built-in tab names are:

  • generalTab
  • descriptionTab
  • advancedTab
features : {
    projectEdit : {
        items : {
            // Custom settings and additional items for the general tab
            generalTab : {
                title : 'Common',
                items : {
                    // hide project name field
                    nameField : false,
                    // add a new custom text field
                    myCustomField : {
                        type : 'text',
                        name : 'color'
                    }
                }
            },
            // Hide the advanced tab
            advancedTab : null
        }
    }
}
blurActionTaskEditBase
weekStartDayTaskEditBase

Editor

editorClassTaskEditBase
triggerEventTaskEditBase

Misc

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Properties

19

Common

disabledInstancePlugin

Class hierarchy

isProjectEdit: Boolean= truereadonly
Identifies an object as an instance of ProjectEdit class, or subclass thereof.
isProjectEdit: Boolean= truereadonlystatic
Identifies an object as an instance of ProjectEdit class, or subclass thereof.
isDelayableDelayable
isEventsEvents
isInstancePluginInstancePlugin
isLocalizableLocalizable
isTaskEditBaseTaskEditBase
isTaskEditStmTaskEditStm

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Other

isEditingTaskEditBase

Functions

32

Other

Shows a project editor to edit the passed project. This function is exposed on the Gantt instance and can be called as gantt.editProject().

ParameterTypeDescription
projectProjectModel | function

Project to edit or a function returning a project to edit, the function will be executed within an STM transaction which will be canceled in case user presses "Cancel" button or closes editor w/o hitting "Save". If the argument is not provided the method will oad the Gantt.project.

elementHTMLElement

Element to anchor the editor to

Returns: Promise -

Promise which resolves after the editor is shown

cancelTaskEditBase
createOnFrameDelayable
LstaticLocalizable
onEvents
relayAllEvents
saveTaskEditBase
triggerEvents
unEvents

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Events

11

Fires on the owning Gantt widget instance after project editing is finished by applying changes or cancelling them.

// Adding a listener using the "on" method
projectEdit.on('afterProjectEdit', ({ source, projectRecord, editor }) => {

});
ParameterTypeDescription
sourceGantt

The Gantt instance

projectRecordProjectModel

The edited project record

editorProjectEditor

The editor widget

Fires on the owning Gantt widget instance after a project is saved

// Adding a listener using the "on" method
projectEdit.on('afterProjectSave', ({ source, projectRecord, editor }) => {

});
ParameterTypeDescription
sourceGantt

The Gantt instance

projectRecordProjectModel

The project about to be saved

editorProjectEditor

The editor widget

Fires on the owning Gantt widget instance before a project is displayed in the editor. This may be listened to in order to take over the project editing flow. Returning false stops the default editing UI from being shown.

Allows async flows by awaiting async listeners. For example:

new Gantt({
    listeners : {
        async beforeProjectEdit() {
           await asyncCheckOfRightsOnBackend();
        }
    }
});
// Adding a listener using the "on" method
projectEdit.on('beforeProjectEdit', ({ source, projectEdit, projectRecord }) => {

});
ParameterTypeDescription
sourceGantt

The Gantt instance

projectEditProjectEdit

The projectEdit feature

projectRecordProjectModel

The project about to be shown in the editor.

Fires on the owning Gantt widget when the editor for a project is available but before it is shown. Allows manipulating fields etc.

// Adding a listener using the "on" method
projectEdit.on('beforeProjectEditShow', ({ source, projectEdit, projectRecord, editor }) => {

});
ParameterTypeDescription
sourceGantt

The Gantt instance

projectEditProjectEdit

The projectEdit feature

projectRecordProjectModel

The project about to be shown in the editor.

editorProjectEditor

The editor

Fires on the owning Gantt widget instance before a project is saved, return false to prevent it.

Allows async flows by awaiting async listeners. For example:

new Gantt({
    listeners : {
        async beforeProjectSave() {
           await someAsyncConditionLikeAskingForConfirmation();
        }
    }
});
// Adding a listener using the "on" method
projectEdit.on('beforeProjectSave', ({ source, projectRecord, editor }) => {

});
ParameterTypeDescription
sourceGantt

The Gantt instance

projectRecordProjectModel

The project about to be saved

editorProjectEditor

The editor widget

Fires on the owning Gantt widget when the editor for a project is canceled.

// Adding a listener using the "on" method
projectEdit.on('projectEditCanceled', ({ source, projectRecord, editor }) => {

});
ParameterTypeDescription
sourceGantt

The Gantt instance

projectRecordProjectModel

The edited project

editorProjectEditor

The editor

catchAllEvents
destroyEvents
disableInstancePlugin
enableInstancePlugin

Event handlers

11

Called on the owning Gantt widget instance after project editing is finished by applying changes or cancelling them.

new ProjectEdit({
    onAfterProjectEdit({ source, projectRecord, editor }) {

    }
});
ParameterTypeDescription
sourceGantt

The Gantt instance

projectRecordProjectModel

The edited project record

editorProjectEditor

The editor widget

Called on the owning Gantt widget instance after a project is saved

new ProjectEdit({
    onAfterProjectSave({ source, projectRecord, editor }) {

    }
});
ParameterTypeDescription
sourceGantt

The Gantt instance

projectRecordProjectModel

The project about to be saved

editorProjectEditor

The editor widget

Called on the owning Gantt widget instance before a project is displayed in the editor. This may be listened to in order to take over the project editing flow. Returning false stops the default editing UI from being shown.

Allows async flows by awaiting async listeners. For example:

new Gantt({
    listeners : {
        async beforeProjectEdit() {
           await asyncCheckOfRightsOnBackend();
        }
    }
});
new ProjectEdit({
    onBeforeProjectEdit({ source, projectEdit, projectRecord }) {

    }
});
ParameterTypeDescription
sourceGantt

The Gantt instance

projectEditProjectEdit

The projectEdit feature

projectRecordProjectModel

The project about to be shown in the editor.

Called on the owning Gantt widget when the editor for a project is available but before it is shown. Allows manipulating fields etc.

new ProjectEdit({
    onBeforeProjectEditShow({ source, projectEdit, projectRecord, editor }) {

    }
});
ParameterTypeDescription
sourceGantt

The Gantt instance

projectEditProjectEdit

The projectEdit feature

projectRecordProjectModel

The project about to be shown in the editor.

editorProjectEditor

The editor

Called on the owning Gantt widget instance before a project is saved, return false to prevent it.

Allows async flows by awaiting async listeners. For example:

new Gantt({
    listeners : {
        async beforeProjectSave() {
           await someAsyncConditionLikeAskingForConfirmation();
        }
    }
});
new ProjectEdit({
    onBeforeProjectSave({ source, projectRecord, editor }) {

    }
});
ParameterTypeDescription
sourceGantt

The Gantt instance

projectRecordProjectModel

The project about to be saved

editorProjectEditor

The editor widget

Called on the owning Gantt widget when the editor for a project is canceled.

new ProjectEdit({
    onProjectEditCanceled({ source, projectRecord, editor }) {

    }
});
ParameterTypeDescription
sourceGantt

The Gantt instance

projectRecordProjectModel

The edited project

editorProjectEditor

The editor

onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin

Typedefs

2