<commit_before>/*
Copyright 2011 Museum of Moving Image

Licensed under the Educational Community License (ECL), Version 2.0. 
ou may not use this file except in compliance with this License.

You may obtain a copy of the ECL 2.0 License at
https://source.collectionspace.org/collection-space/LICENSE.txt
*/

/*global jQuery, fluid, cspace:true*/

cspace = cspace || {};

(function ($, fluid) {

    "use strict";
    
    fluid.log("Admin.js loaded");

    fluid.defaults("cspace.admin", {
        gradeNames: ["fluid.rendererComponent", "autoInit"],
        produceTree: "cspace.admin.produceTree",
        components: {
            instantiator: "{instantiator}",
            showAddButton: {
                type: "cspace.admin.showAddButton",
                options: {
                    model: "{admin}.model",
                    applier: "{admin}.applier"
                }
            },
            banner: {
                type: "cspace.admin.banner",
                container: "{admin}.dom.banner",
                createOnEvent: "afterRender",
                options: {
                    recordType: "{admin}.options.recordType",
                    recordEditor: "{admin}.dom.recordEditor",
                    model: {
                        strings: "{admin}.model.strings"
                    }
                }
            },
            adminListView: {
                type: "cspace.listView",
                container: "{admin}.dom.listView",
                createOnEvent: "afterRender",
                options: {
                    recordType: "{admin}.options.recordType",
                    urls: cspace.componentUrlBuilder({
                        listUrl: "%tenant/%tname/%recordType?pageNum=%pageNum&pageSize=%pageSize&sortDir=%sortDir&sortKey=%sortKey"
                    }),
                    elPath: "items",
                    produceTree: "cspace.listView.produceTreeSidebar",
                    model: {
                        pageSizeList: ["5", "10", "20", "50"],
                        columns: [{
                            sortable: false,
                            id: "number",
                            name: "%recordType-number"
                        }]
                    },
                    events: {
                        onSelect: "{admin}.events.onSelect"
                    },
                    listeners: {
                        ready: "{loadingIndicator}.events.hideOn.fire",
                        onModelChange: "{loadingIndicator}.events.showOn.fire",
                        afterUpdate: "{loadingIndicator}.events.hideOn.fire",
                        onError: "{loadingIndicator}.events.hideOn.fire"
                    },
                    components: {
                        pager: {
                            options: {
                                summary: {
                                    options: {
                                        message: {
                                            expander: {
                                                type: "fluid.deferredInvokeCall",
                                                func: "cspace.util.resolveMessage",
                                                args: ["{globalBundle}", "listView-total-short"]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            },
            adminRecordEditor: {
                type: "cspace.recordEditor",
                container: "{admin}.dom.recordEditor",
                options: {
                    csid: "{admin}.selectedRecordCsid",
                    recordType: "{admin}.options.recordType",
                    globalRef: "adminModel",
                    listeners: {
                        afterRecordRender: "{loadingIndicator}.events.hideOn.fire",
                        afterSave: "{admin}.afterRecordSave",
                        afterRemove: {
                            listener: "{admin}.afterRecordRemove",
                            priority: "last"
                        }
                    },
                    strings: "{admin}.model.strings"
                },
                createOnEvent: "onSelect"
            }
        },
        events: {
            onSelect: null,
            onCreateNewRecord: null
        },
        listeners: {
            onCreateNewRecord: "{admin}.onCreateNewRecord",
            onSelect: [
                "{loadingIndicator}.events.showOn.fire",
                "{admin}.onSelectHandler"
            ]
        },
        preInitFunction: "cspace.admin.preInit",
        finalInitFunction: "cspace.admin.finalInit",
        parentBundle: "{globalBundle}",
        selectors: {
            listViewHeader: ".csc-admin-listViewHeader",
            listView: ".csc-admin-listView",
            recordEditorHeader: ".csc-admin-recordEditorHeader",
            recordEditor: ".csc-admin-recordEditor",
            add: ".csc-admin-add",
            banner: ".csc-admin-banner"
        },
        selectorsToIgnore: ["recordEditor", "listView", "banner"],
        model: {
            query: "",
            strings: {
                add: "%recordType-admin-add",
                listViewHeader: "%recordType-admin-listHeader",
                recordEditorHeader: "%recordType-admin-detailsHeader",
                bannerTop: "%recordType-admin-detailsNone",
                bannerBottom: "%recordType-admin-detaulsNoneSelected",
                removeSuccessfulMessage: "recordEditor-removeSuccessfulMessage",
                deleteFailedMessage: "recordEditor-deleteFailedMessage",
                fetchFailedMessage: "recordEditor-fetchFailedMessage"
            }
        },
        addButtonPermission: "create",
        strings: {}
    });

    cspace.admin.preInit = function (that) {
        that.model.strings = cspace.util.stringBuilder(that.model.strings, {
            vars: {
                recordType: that.options.recordType
            }
        });
        that.afterRecordSave = function (model) {
            that.adminListView.updateModel();
        };
        that.afterRecordRemove = function () {
            var instantiator = that.instantiator,
                banner = "banner";
            that.adminListView.updateModel();
            instantiator.clearComponent(that, "adminRecordEditor");
            instantiator.clearComponent(that, banner);
            fluid.initDependent(that, banner, instantiator);
        };
        that.onSelectHandler = function (record) {
            that.selectedRecordCsid = record.csid;
        };
        that.onCreateNewRecord = function () {
            that.events.onSelect.fire({
                recordType: that.options.recordType
            });
        };
        that.add = function () {
            var globalNavigator = fluid.get(that, "adminRecordEditor.globalNavigator");
            if (!globalNavigator) {
                that.events.onCreateNewRecord.fire();
                return;
            }
            globalNavigator.events.onPerformNavigation.fire(function () {
                that.events.onCreateNewRecord.fire();
            });
        };
    };
<commit_msg>CSPACE-5393: Clearing password field added just in case server returns password.<commit_after>/*
Copyright 2011 Museum of Moving Image

Licensed under the Educational Community License (ECL), Version 2.0. 
ou may not use this file except in compliance with this License.

You may obtain a copy of the ECL 2.0 License at
https://source.collectionspace.org/collection-space/LICENSE.txt
*/

/*global jQuery, fluid, cspace:true*/

cspace = cspace || {};

(function ($, fluid) {

    "use strict";
    
    fluid.log("Admin.js loaded");

    fluid.defaults("cspace.admin", {
        gradeNames: ["fluid.rendererComponent", "autoInit"],
        produceTree: "cspace.admin.produceTree",
        components: {
            instantiator: "{instantiator}",
            showAddButton: {
                type: "cspace.admin.showAddButton",
                options: {
                    model: "{admin}.model",
                    applier: "{admin}.applier"
                }
            },
            banner: {
                type: "cspace.admin.banner",
                container: "{admin}.dom.banner",
                createOnEvent: "afterRender",
                options: {
                    recordType: "{admin}.options.recordType",
                    recordEditor: "{admin}.dom.recordEditor",
                    model: {
                        strings: "{admin}.model.strings"
                    }
                }
            },
            adminListView: {
                type: "cspace.listView",
                container: "{admin}.dom.listView",
                createOnEvent: "afterRender",
                options: {
                    recordType: "{admin}.options.recordType",
                    urls: cspace.componentUrlBuilder({
                        listUrl: "%tenant/%tname/%recordType?pageNum=%pageNum&pageSize=%pageSize&sortDir=%sortDir&sortKey=%sortKey"
                    }),
                    elPath: "items",
                    produceTree: "cspace.listView.produceTreeSidebar",
                    model: {
                        pageSizeList: ["5", "10", "20", "50"],
                        columns: [{
                            sortable: false,
                            id: "number",
                            name: "%recordType-number"
                        }]
                    },
                    events: {
                        onSelect: "{admin}.events.onSelect"
                    },
                    listeners: {
                        ready: "{loadingIndicator}.events.hideOn.fire",
                        onModelChange: "{loadingIndicator}.events.showOn.fire",
                        afterUpdate: "{loadingIndicator}.events.hideOn.fire",
                        onError: "{loadingIndicator}.events.hideOn.fire"
                    },
                    components: {
                        pager: {
                            options: {
                                summary: {
                                    options: {
                                        message: {
                                            expander: {
                                                type: "fluid.deferredInvokeCall",
                                                func: "cspace.util.resolveMessage",
                                                args: ["{globalBundle}", "listView-total-short"]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            },
            adminRecordEditor: {
                type: "cspace.recordEditor",
                container: "{admin}.dom.recordEditor",
                options: {
                    csid: "{admin}.selectedRecordCsid",
                    recordType: "{admin}.options.recordType",
                    globalRef: "adminModel",
                    listeners: {
                        afterRecordRender: [
                            "{loadingIndicator}.events.hideOn.fire",
                            "{admin}.events.recordEditorReady.fire"
                        ],
                        afterSave: "{admin}.afterRecordSave",
                        afterRemove: {
                            listener: "{admin}.afterRecordRemove",
                            priority: "last"
                        }
                    },
                    strings: "{admin}.model.strings"
                },
                createOnEvent: "onSelect"
            }
        },
        events: {
            onSelect: null,
            onCreateNewRecord: null,
            recordEditorReady: null,
            cleanPassword: {
                events: {
                    recordEditorReady: "{admin}.events.recordEditorReady"
                },
                args: ["{admin}"]
            }
        },
        listeners: {
            cleanPassword: <PASSWORD>",
            onCreateNewRecord: "{admin}.onCreateNewRecord",
            onSelect: [
                "{loadingIndicator}.events.showOn.fire",
                "{admin}.onSelectHandler"
            ]
        },
        preInitFunction: "cspace.admin.preInit",
        finalInitFunction: "cspace.admin.finalInit",
        parentBundle: "{globalBundle}",
        selectors: {
            listViewHeader: ".csc-admin-listViewHeader",
            listView: ".csc-admin-listView",
            recordEditorHeader: ".csc-admin-recordEditorHeader",
            recordEditor: ".csc-admin-recordEditor",
            add: ".csc-admin-add",
            banner: ".csc-admin-banner"
        },
        selectorsToIgnore: ["recordEditor", "listView", "banner"],
        model: {
            query: "",
            strings: {
                add: "%recordType-admin-add",
                listViewHeader: "%recordType-admin-listHeader",
                recordEditorHeader: "%recordType-admin-detailsHeader",
                bannerTop: "%recordType-admin-detailsNone",
                bannerBottom: "%recordType-admin-detaulsNoneSelected",
                removeSuccessfulMessage: "recordEditor-removeSuccessfulMessage",
                deleteFailedMessage: "recordEditor-deleteFailedMessage",
                fetchFailedMessage: "recordEditor-fetchFailedMessage"
            }
        },
        addButtonPermission: "create",
        strings: {}
    });

    cspace.admin.preInit = function (that) {
        that.model.strings = cspace.util.stringBuilder(that.model.strings, {
            vars: {
                recordType: that.options.recordType
            }
        });
        that.cleanPassword = function (that) {
            that.locate("password").val("");
        };
        that.afterRecordSave = function (model) {
            that.adminListView.updateModel();
        };
        that.afterRecordRemove = function () {
            var instantiator = that.instantiator,
                banner = "banner";
            that.adminListView.updateModel();
            instantiator.clearComponent(that, "adminRecordEditor");
            instantiator.clearComponent(that, banner);
            fluid.initDependent(that, banner, instantiator);
        };
        that.onSelectHandler = function (record) {
            that.selectedRecordCsid = record.csid;
        };
        that.onCreateNewRecord = function () {
            that.events.onSelect.fire({
                recordType: that.options.recordType
            });
        };
        that.add = function () {
            var globalNavigator = fluid.get(that, "adminRecordEditor.globalNavigator");
            if (!globalNavigator) {
                that.events.onCreateNewRecord.fire();
                return;
            }
            globalNavigator.events.onPerformNavigation.fire(function () {
                that.events.onCreateNewRecord.fire();
            });
        };
    };

{'fraction_non_alphanumeric': 0.10478747789639138, 'fraction_numerical': 0.002226733905298317, 'mean_word_length': 1.1873657069187795, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6702739', 'n_tokens_mistral': 3608, 'n_tokens_neox': 3418, 'n_words': 569}