public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
        Requirements::javascript(THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.js');
        Requirements::javascript('memberprofiles/javascript/MemberProfilePageCms.js');
        // Setup tabs
        $fields->addFieldToTab('Root', $profile = new TabSet('Profile'), 'Content');
        $fields->addFieldToTab('Root', $email = new Tab('Email'), 'Behaviour');
        $profile->setTitle(_t('MemberProfiles.PROFILE', 'Profile'));
        $email->setTitle(_t('MemberProfiles.EMAIL', 'Email'));
        $fields->findOrMakeTab('Root.Profile.Fields', _t('MemberProfiles.FIELDS', 'Fields'));
        $fields->findOrMakeTab('Root.Profile.Groups', _t('MemberProfiles.GROUPS', 'Groups'));
        $fields->findOrMakeTab('Root.Profile.PublicProfile', _t('MemberProfiles.PUBLICPROFILE', 'Public Profile'));
        // Profile fields
        $fields->addFieldsToTab('Root.Profile.Fields', array(new HeaderField('ProfileFieldsHeader', _t('MemberProfiles.PROFILEFIELDS', 'Profile Fields')), $table = new OrderableComplexTableField($this, 'Fields', 'MemberProfileField')));
        $table->setPermissions(array('show', 'edit'));
        $table->setCustomSourceItems($this->getProfileFields());
        // Groups
        $fields->addFieldsToTab('Root.Profile.Groups', array(new HeaderField('GroupsHeader', _t('MemberProfiles.GROUPASSIGNMENT', 'Group Assignment')), new LiteralField('GroupsNote', '<p>' . _t('MemberProfiles.GROUPSNOTE', 'Any users registering via this page will always be added to ' . 'the below groups (if registration is enabled). Conversely, a ' . 'member must belong to these groups in order to edit their ' . 'profile on this page.') . '</p>'), new CheckboxSetField('Groups', '', DataObject::get('Group')->map()), new HeaderField('SelectableGroupsHeader', _t('MemberProfiles.USERSELECTABLE', 'User Selectable')), new LiteralField('SelectableGroupsNote', '<p>' . _t('MemberProfiles.SELECTABLEGROUPSNOTE', 'Users can choose to belong to the following groups, if the ' . '"Groups" field is enabled in the "Fields" tab.') . '</p>'), new CheckboxSetField('SelectableGroups', '', DataObject::get('Group')->map())));
        // Public profile
        $fields->addFieldsToTab('Root.Profile.PublicProfile', array(new HeaderField('PublicProfileHeader', _t('MemberProfiles.PUBLICPROFILE', 'Public Profile')), new CheckboxField('AllowProfileViewing', _t('MemberProfiles.ALLOWPROFILEVIEWING', 'Allow people to view user profiles.')), new HeaderField('ProfileSectionsHeader', _t('MemberProfiles.PROFILESECTIONS', 'Profile Sections')), new MemberProfileSectionField($this, 'Sections', 'MemberProfileSection')));
        // Email confirmation and validation
        $fields->addFieldsToTab('Root.Email', array(new HeaderField('EmailHeader', 'Email Confirmation and Validation'), new OptionSetField('EmailType', '', array('Validation' => 'Require email validation to activate an account', 'Confirmation' => 'Send a confirmation email after a user registers', 'None' => 'Do not send any emails')), new ToggleCompositeField('EmailContent', 'Email Content', array(new TextField('EmailSubject', 'Email subject'), new TextField('EmailFrom', 'Email from'), new TextareaField('EmailTemplate', 'Email template'), new LiteralField('TemplateNote', MemberConfirmationEmail::TEMPLATE_NOTE))), new ToggleCompositeField('ConfirmationContent', 'Confirmation Content', array(new LiteralField('ConfirmationNote', '<p>This content is dispayed when
					a user confirms their account.</p>'), new TextField('ConfirmationTitle', 'Title'), new HtmlEditorField('ConfirmationContent', 'Content')))));
        // Content
        $fields->removeFieldFromTab('Root.Content.Main', 'Content');
        $fields->addFieldToTab('Root.Content', $profileContent = new Tab('Profile'), 'Metadata');
        $fields->addFieldToTab('Root.Content', $regContent = new Tab('Registration'), 'Metadata');
        $fields->addFieldToTab('Root.Content', $afterReg = new Tab('AfterRegistration'), 'Metadata');
        $profileContent->setTitle(_t('MemberProfiles.PROFILE', 'Profile'));
        $regContent->setTitle(_t('MemberProfiles.REGISTRATION', 'Registration'));
        $afterReg->setTitle(_t('MemberProfiles.AFTERREG', 'After Registration'));
        $tabs = array('Profile', 'Registration', 'AfterRegistration');
        foreach ($tabs as $tab) {
            $fields->addFieldsToTab("Root.Content.{$tab}", array(new TextField("{$tab}Title", _t('MemberProfiles.TITLE', 'Title')), new HtmlEditorField("{$tab}Content", _t('MemberProfiles.CONTENT', 'Content'))));
        }
        $fields->addFieldToTab('Root.Content.AfterRegistration', new CheckboxField('RegistrationRedirect', _t('MemberProfiles.REDIRECT_AFTER_REG', 'Redirect after registration?')), 'AfterRegistrationContent');
        $fields->addFieldToTab('Root.Content.AfterRegistration', new TreeDropdownField('PostRegistrationTargetID', _t('MemberProfiles.REDIRECT_TARGET', 'Redirect to page'), 'SiteTree'), 'AfterRegistrationContent');
        // Behaviour
        $fields->addFieldToTab('Root.Behaviour', new HeaderField('ProfileBehaviour', _t('MemberProfiles.PROFILEBEHAVIOUR', 'Profile Behaviour')), 'ClassName');
        $fields->addFieldToTab('Root.Behaviour', new CheckboxField('AllowRegistration', _t('MemberProfiles.ALLOWREG', 'Allow registration via this page')), 'ClassName');
        $fields->addFieldToTab('Root.Behaviour', new CheckboxField('AllowProfileEditing', _t('MemberProfiles.ALLOWEDITING', 'Allow users to edit their own profile on this page')), 'ClassName');
        $fields->addFieldToTab('Root.Behaviour', new CheckboxField('AllowAdding', _t('MemberProfiles.ALLOWADD', 'Allow members with member creation permissions to add members via this page')), 'ClassName');
        $requireApproval = new CheckboxField('RequireApproval', _t('MemberProfiles.REQUIREREGAPPROVAL', 'Require registration approval by an administrator?'));
        $fields->addFieldToTab('Root.Behaviour', $requireApproval, 'ClassName');
        $approvalGroups = _t('MemberProfiles.NOTIFYTHESEGROUPS', 'Notify these groups to approve new registrations');
        $approvalGroups = new TreeMultiselectField('ApprovalGroups', $approvalGroups, 'Group');
        $fields->addFieldToTab('Root.Behaviour', $approvalGroups, 'ClassName');
        $pageSettings = new HeaderField('PageSettingsHeader', _t('MemberProfiles.PAGEBEHAVIOUR', 'Page Behaviour'));
        $fields->addFieldToTab('Root.Behaviour', $pageSettings, 'ClassName');
        return $fields;
    }
 /**
  * @return bool
  */
 public function Can($mode)
 {
     if ($mode == 'add') {
         return parent::Can($mode) && $this->getAddableSections();
     } else {
         return parent::Can($mode);
     }
 }