<commit_before>/*jslint browser: true, undef: true *//*global Ext*/
/**
 * people.Profile controller handles events for the people.details.Profile
 */
Ext.define('SlateAdmin.controller.people.Profile', {
    extend: 'Ext.app.Controller',
    requires: [
        'Ext.window.MessageBox',
        'Slate.API'
    ],


    // controller config
    views: [
        'people.Manager',
        'people.details.Profile'
    ],

    refs: {
        profilePanel: {
            selector: 'people-details-profile',
            autoCreate: true,

            xtype: 'people-details-profile'
        },
        profileForm: 'people-details-profile form',
        cancelBtn: 'people-details-profile button[action=cancel]',
        saveBtn: 'people-details-profile button[action=save]',
        loginFieldSet: 'people-details-profile fieldset#loginFields',
        usernameField: 'people-details-profile field[name=Username]',
        studentNumberField: 'people-details-profile field[name=StudentNumber]',
        temporaryPasswordFieldCt: 'people-details-profile fieldcontainer#temporaryPasswordFieldCt',
        temporaryPasswordField: 'people-details-profile field[name=TemporaryPassword]',
        resetTemporaryPasswordBtn: 'people-details-profile button[action=reset-temporary-password]',
        groupsField: 'people-details-profile field[name=groupIDs]',
        manager: 'people-manager'
    },

    control: {
        'people-manager #detailTabs': {
            beforerender: 'onBeforeTabsRender'
        },
        'people-details-profile': {
            personloaded: 'onPersonLoaded'
        },
        'people-details-profile form': {
            dirtychange: 'syncButtons',
            validitychange: 'syncButtons'
        },
        cancelBtn: {
            click: 'onCancelButtonClick'
        },
        saveBtn: {
            click: 'onSaveButtonClick'
        },
        resetTemporaryPasswordBtn: {
            click: 'onResetTemporaryPasswordClick'
        }
    },


    // event handlers

    /**
     * Event Handler. Adds the profile panel to the details tab panel
     * @param {Ext.tab.Panel} detailsTabs The details tab panel defined in SlateAdmin.view.people.Manager
     * @return {void}
     */
    onBeforeTabsRender: function(detailTabs) {
        detailTabs.add(this.getProfilePanel());
    },

    /**
     * Event Handler. Handles personloaded event defined by SlateAdmin.view.people.details.AbstractDetails which fires when
     * the tab is activated or a new person is selected.  This initializes the form for the selected user.
     * @param {SlateAdmin.controller.people.Profile} profilePanel The profile panel.
     * @param {Slate.model.person.Person} person The person record.
     * @return {void}
     */
    onPersonLoaded: function(profilePanel, person) {
        var me = this,
            personClass = person.get('Class'),
            profileForm = me.getProfileForm(),
            groupsField = me.getGroupsField(),
            groupsStore = groupsField.getStore(),
            siteEnv = window.SiteEnvironment || {},
            siteUserAccountLevel = siteEnv.user && siteEnv.user.AccountLevel,
            siteUserIsAdmin = siteUserAccountLevel == 'Administrator' || siteUserAccountLevel == 'Developer';

        me.getStudentNumberField().setVisible(personClass == 'Slate\\People\\Student');
        me.getLoginFieldSet().setVisible(personClass != 'Emergence\\People\\Person');
        me.getTemporaryPasswordFieldCt().setVisible(siteUserIsAdmin);
        me.getUsernameField().setReadOnly(!siteUserIsAdmin);

        // ensure groups store is loaded before loading record because boxselect doesn't hande re-setting unknown values after local store load
        if (groupsStore.isLoaded()) {
            profileForm.loadRecord(person);
        } else {
            profilePanel.setLoading('Loading groups&hellip;');
            groupsStore.load({
                callback: function() {
                    profileForm.loadRecord(person);
                    profilePanel.setLoading(false);
                }
            });
        }
    },

    /**
     * Event Handler. Discards changes and resets form to last loaded state when cancel button is clicked.
     * @return {void}
     */
    onCancelButtonClick: function() {
        this.getProfileForm().getForm().reset();
    },
<commit_msg>Unload phantom person model when cancel button clicked<commit_after>/*jslint browser: true, undef: true *//*global Ext*/
/**
 * people.Profile controller handles events for the people.details.Profile
 */
Ext.define('SlateAdmin.controller.people.Profile', {
    extend: 'Ext.app.Controller',
    requires: [
        'Ext.window.MessageBox',
        'Slate.API'
    ],


    // controller config
    views: [
        'people.Manager',
        'people.details.Profile'
    ],

    refs: {
        profilePanel: {
            selector: 'people-details-profile',
            autoCreate: true,

            xtype: 'people-details-profile'
        },
        profileForm: 'people-details-profile form',
        cancelBtn: 'people-details-profile button[action=cancel]',
        saveBtn: 'people-details-profile button[action=save]',
        loginFieldSet: 'people-details-profile fieldset#loginFields',
        usernameField: 'people-details-profile field[name=Username]',
        studentNumberField: 'people-details-profile field[name=StudentNumber]',
        temporaryPasswordFieldCt: 'people-details-profile fieldcontainer#temporaryPasswordFieldCt',
        temporaryPasswordField: 'people-details-profile field[name=TemporaryPassword]',
        resetTemporaryPasswordBtn: 'people-details-profile button[action=reset-temporary-password]',
        groupsField: 'people-details-profile field[name=groupIDs]',
        manager: 'people-manager'
    },

    control: {
        'people-manager #detailTabs': {
            beforerender: 'onBeforeTabsRender'
        },
        'people-details-profile': {
            personloaded: 'onPersonLoaded'
        },
        'people-details-profile form': {
            dirtychange: 'syncButtons',
            validitychange: 'syncButtons'
        },
        cancelBtn: {
            click: 'onCancelButtonClick'
        },
        saveBtn: {
            click: 'onSaveButtonClick'
        },
        resetTemporaryPasswordBtn: {
            click: 'onResetTemporaryPasswordClick'
        }
    },


    // event handlers

    /**
     * Event Handler. Adds the profile panel to the details tab panel
     * @param {Ext.tab.Panel} detailsTabs The details tab panel defined in SlateAdmin.view.people.Manager
     * @return {void}
     */
    onBeforeTabsRender: function(detailTabs) {
        detailTabs.add(this.getProfilePanel());
    },

    /**
     * Event Handler. Handles personloaded event defined by SlateAdmin.view.people.details.AbstractDetails which fires when
     * the tab is activated or a new person is selected.  This initializes the form for the selected user.
     * @param {SlateAdmin.controller.people.Profile} profilePanel The profile panel.
     * @param {Slate.model.person.Person} person The person record.
     * @return {void}
     */
    onPersonLoaded: function(profilePanel, person) {
        var me = this,
            personClass = person.get('Class'),
            profileForm = me.getProfileForm(),
            groupsField = me.getGroupsField(),
            groupsStore = groupsField.getStore(),
            siteEnv = window.SiteEnvironment || {},
            siteUserAccountLevel = siteEnv.user && siteEnv.user.AccountLevel,
            siteUserIsAdmin = siteUserAccountLevel == 'Administrator' || siteUserAccountLevel == 'Developer';

        me.getStudentNumberField().setVisible(personClass == 'Slate\\People\\Student');
        me.getLoginFieldSet().setVisible(personClass != 'Emergence\\People\\Person');
        me.getTemporaryPasswordFieldCt().setVisible(siteUserIsAdmin);
        me.getUsernameField().setReadOnly(!siteUserIsAdmin);

        // ensure groups store is loaded before loading record because boxselect doesn't hande re-setting unknown values after local store load
        if (groupsStore.isLoaded()) {
            profileForm.loadRecord(person);
        } else {
            profilePanel.setLoading('Loading groups&hellip;');
            groupsStore.load({
                callback: function() {
                    profileForm.loadRecord(person);
                    profilePanel.setLoading(false);
                }
            });
        }
    },

    /**
     * Event Handler. Discards changes and resets form to last loaded state when cancel button is clicked.
     * @return {void}
     */
    onCancelButtonClick: function() {
        var me = this,
            manager = me.getManager(),
            person = manager.getSelectedPerson();

        if (person.phantom) {
            manager.setSelectedPerson(null);
        } else {
            me.getProfileForm().getForm().reset();
        }
    },

{'fraction_non_alphanumeric': 0.10960591133004927, 'fraction_numerical': 0.0, 'mean_word_length': 2.4530344027831466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3631283', 'n_tokens_mistral': 2358, 'n_tokens_neox': 2299, 'n_words': 498}