<commit_before>Ext.define('SlateAdmin.controller.progress.Interims', {
    extend: 'Ext.app.Controller',


    views: [
        'progress.interims.Manager'
    ],

    stores: [
        'Terms',
        'progress.interims.Sections',
        'progress.interims.Students',
        'progress.interims.Reports'
    ],

    refs: {
        progressNavPanel: 'progress-navpanel',

        managerCt: {
            selector: 'progress-interims-manager',
            autoCreate: true,

            xtype: 'progress-interims-manager'
        },
        myClassesOnlyCheckbox: 'progress-interims-sectionsgrid checkboxfield[name=myClassesOnly]',
        termSelector: 'progress-interims-sectionsgrid #termSelector',
        sectionsGrid: 'progress-interims-sectionsgrid',
        studentsGrid: 'progress-interims-studentsgrid',
        editorForm: 'progress-interims-editorform',
        revertChangesBtn: 'progress-interims-editorform button#revertChangesBtn',
        saveDraftBtn: 'progress-interims-editorform button#saveDraftBtn',
        saveFinishedBtn: 'progress-interims-editorform button#saveFinishedBtn'
    },

    routes: {
        'progress/interims': 'showInterims'
    },

    control: {
        managerCt: {
            activate: 'onManagerActivate'
        },

        myClassesOnlyCheckbox: {
            change: 'onMyClassesOnlyCheckboxChange'
        },
        termSelector: {
            beforeselect: 'onBeforeTermSelect',
            change: 'onTermChange'
        },
        sectionsGrid: {
            beforeselect: 'onBeforeSectionSelect',
            select: 'onSectionSelect'
        },

        studentsGrid: {
            beforeselect: 'onBeforeStudentSelect',
            select: 'onStudentSelect'
        },
        sectionNotesForm: {
            dirtychange: 'onSectionNotesFormDirtyChange'
        },
        sectionNotesRevertBtn: {
            click: 'onSectionNotesRevertBtnClick'
        },
        sectionNotesSaveBtn: {
            click: 'onSectionNotesSaveBtnClick'
        },

        editorForm: {
            dirtychange: 'onEditorFormDirtyChange',
            validitychange: 'onEditorFormValidityChange'
        },
        'progress-interims-editorform combo': {
            select: 'onComboSelect'
        },
        revertChangesBtn: {
            click: 'onRevertChangesClick'
        },
        saveDraftBtn: {
            click: 'onSaveDraftClick'
        },
        saveFinishedBtn: {
            click: 'onSaveFinishedClick'
        }
    },

    listen: {
        store: {
            '#progress.interims.Sections': {
                load: 'onSectionsStoreLoad'
            },
            '#progress.interims.Students': {
                load: 'onStudentsStoreLoad'
            }
        }
    },


    // route handlers
    showInterims: function () {
        var me = this,
            navPanel = me.getProgressNavPanel();

        Ext.suspendLayouts();

        Ext.util.History.suspendState();
        navPanel.setActiveLink('progress/interims');
        navPanel.expand();
        Ext.util.History.resumeState(false); // false to discard any changes to state

        me.application.getController('Viewport').loadCard(me.getManagerCt());

        Ext.resumeLayouts(true);
    },

    // event handlers
    onManagerActivate: function () {
        this.syncSections();
    },

    onMyClassesOnlyCheckboxChange: function () {
        this.syncSections();
    },

    onBeforeTermSelect: function(termSelector, term) {
        var me = this,
            editorForm = me.getEditorForm(),
            loadedReport = editorForm.getRecord();

        if (loadedReport && editorForm.isDirty()) {
            Ext.Msg.confirm('Unsaved Changes', 'You have unsaved changes to this report.<br/><br/>Do you want to continue without saving them?', function (btn) {
                if (btn != 'yes') {
                    return;
                }

                editorForm.reset();
                termSelector.select(term);
            });

            return false;
        }
    },

    onTermChange: function () {
        this.syncSections();
    },

    onSectionsStoreLoad: function() {
        var sectionsGrid = this.getSectionsGrid(),
            section = sectionsGrid.getSelection()[0];

        // reselect section if already selected
        if (section) {
            sectionsGrid.setSelection(null);
            sectionsGrid.setSelection(section);
        }
    },

    onBeforeSectionSelect: function(sectionsSelModel, section) {
        var me = this,
            editorForm = me.getEditorForm(),
            loadedReport = editorForm.getRecord();

        if (loadedReport && editorForm.isDirty()) {
            Ext.Msg.confirm('Unsaved Changes', 'You have unsaved changes to this report.<br/><br/>Do you want to continue without saving them?', function (btn) {
                if (btn != 'yes') {
                    return;
                }

                editorForm.reset();
                sectionsSelModel.select([section]);
            });

            return false;
        }
    },

    onSectionSelect: function (sectionsGrid, section) {
        var me = this,
            studentsGrid = me.getStudentsGrid(),
            studentsStore = studentsGrid.getStore(),
            reportsStore = me.getProgressInterimsReportsStore(),
            reportsProxy = reportsStore.getProxy(),
            editorForm = me.getEditorForm(),<commit_msg>Reset students list and report form when moving to term without section<commit_after>Ext.define('SlateAdmin.controller.progress.Interims', {
    extend: 'Ext.app.Controller',


    views: [
        'progress.interims.Manager'
    ],

    stores: [
        'Terms',
        'progress.interims.Sections',
        'progress.interims.Students',
        'progress.interims.Reports'
    ],

    refs: {
        progressNavPanel: 'progress-navpanel',

        managerCt: {
            selector: 'progress-interims-manager',
            autoCreate: true,

            xtype: 'progress-interims-manager'
        },
        myClassesOnlyCheckbox: 'progress-interims-sectionsgrid checkboxfield[name=myClassesOnly]',
        termSelector: 'progress-interims-sectionsgrid #termSelector',
        sectionsGrid: 'progress-interims-sectionsgrid',
        studentsGrid: 'progress-interims-studentsgrid',
        editorForm: 'progress-interims-editorform',
        revertChangesBtn: 'progress-interims-editorform button#revertChangesBtn',
        saveDraftBtn: 'progress-interims-editorform button#saveDraftBtn',
        saveFinishedBtn: 'progress-interims-editorform button#saveFinishedBtn'
    },

    routes: {
        'progress/interims': 'showInterims'
    },

    control: {
        managerCt: {
            activate: 'onManagerActivate'
        },

        myClassesOnlyCheckbox: {
            change: 'onMyClassesOnlyCheckboxChange'
        },
        termSelector: {
            beforeselect: 'onBeforeTermSelect',
            change: 'onTermChange'
        },
        sectionsGrid: {
            beforeselect: 'onBeforeSectionSelect',
            select: 'onSectionSelect'
        },

        studentsGrid: {
            beforeselect: 'onBeforeStudentSelect',
            select: 'onStudentSelect'
        },
        sectionNotesForm: {
            dirtychange: 'onSectionNotesFormDirtyChange'
        },
        sectionNotesRevertBtn: {
            click: 'onSectionNotesRevertBtnClick'
        },
        sectionNotesSaveBtn: {
            click: 'onSectionNotesSaveBtnClick'
        },

        editorForm: {
            dirtychange: 'onEditorFormDirtyChange',
            validitychange: 'onEditorFormValidityChange'
        },
        'progress-interims-editorform combo': {
            select: 'onComboSelect'
        },
        revertChangesBtn: {
            click: 'onRevertChangesClick'
        },
        saveDraftBtn: {
            click: 'onSaveDraftClick'
        },
        saveFinishedBtn: {
            click: 'onSaveFinishedClick'
        }
    },

    listen: {
        store: {
            '#progress.interims.Sections': {
                load: 'onSectionsStoreLoad'
            },
            '#progress.interims.Students': {
                load: 'onStudentsStoreLoad'
            }
        }
    },


    // route handlers
    showInterims: function () {
        var me = this,
            navPanel = me.getProgressNavPanel();

        Ext.suspendLayouts();

        Ext.util.History.suspendState();
        navPanel.setActiveLink('progress/interims');
        navPanel.expand();
        Ext.util.History.resumeState(false); // false to discard any changes to state

        me.application.getController('Viewport').loadCard(me.getManagerCt());

        Ext.resumeLayouts(true);
    },

    // event handlers
    onManagerActivate: function () {
        this.syncSections();
    },

    onMyClassesOnlyCheckboxChange: function () {
        this.syncSections();
    },

    onBeforeTermSelect: function(termSelector, term) {
        var me = this,
            editorForm = me.getEditorForm(),
            loadedReport = editorForm.getRecord();

        if (loadedReport && editorForm.isDirty()) {
            Ext.Msg.confirm('Unsaved Changes', 'You have unsaved changes to this report.<br/><br/>Do you want to continue without saving them?', function (btn) {
                if (btn != 'yes') {
                    return;
                }

                editorForm.reset();
                termSelector.select(term);
            });

            return false;
        }
    },

    onTermChange: function () {
        this.syncSections();
    },

    onSectionsStoreLoad: function() {
        var me = this,
            sectionsGrid = me.getSectionsGrid(),
            section = sectionsGrid.getSelection()[0],
            studentsGrid = me.getStudentsGrid(),
            studentsStore = studentsGrid.getStore(),
            reportsStore = me.getProgressInterimsReportsStore(),
            editorForm = me.getEditorForm();

        // reselect section if already selected
        if (section) {
            sectionsGrid.setSelection(null);
            sectionsGrid.setSelection(section);
        } else {
            // reset stores
            studentsStore.removeAll();
            studentsGrid.getView().clearEmptyEl(); // PRIVATE: clearEmptyEl to remove empty text
            reportsStore.removeAll();

            // reset form
            editorForm.disable();
            editorForm.reset(true);

            // reset students list
            studentsGrid.disable();
        }
    },

    onBeforeSectionSelect: function(sectionsSelModel, section) {
        var me = this,
            editorForm = me.getEditorForm(),
            loadedReport = editorForm.getRecord();

        if (loadedReport && editorForm.isDirty()) {
            Ext.Msg.confirm('Unsaved Changes', 'You have unsaved changes to this report.<br/><br/>Do you want to continue without saving them?', function (btn) {
                if (btn != 'yes') {
                    return;
                }

                editorForm.reset();
                sectionsSelModel.select([section]);
            });

            return false;
        }
    },

    onSectionSelect: function (sectionsGrid, section) {
        var me = this,
            studentsGrid = me.getStudentsGrid(),
            studentsStore = studentsGrid.getStore(),
            reportsStore = me.getProgressInterimsReportsStore(),
            reportsProxy = reportsStore.getProxy(),
            editorForm = me.getEditorForm(),
{'fraction_non_alphanumeric': 0.10582194761117396, 'fraction_numerical': 0.00017404925593943085, 'mean_word_length': 1.9078947368421053, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5216557', 'n_tokens_mistral': 3071, 'n_tokens_neox': 2967, 'n_words': 532}