<commit_before>(function() {
    var m = angular.module('parkandride.facilityEdit', [
        'ui.router',
        'parkandride.contacts',
        'parkandride.operators',
        'parkandride.SchemaResource',
        'parkandride.ContactResource',
        'parkandride.FacilityResource',
        'parkandride.facilityMap',
        'parkandride.layout',
        'parkandride.multilingual',
        'parkandride.facilityContacts',
        'parkandride.pricing',
        'parkandride.tags',
        'parkandride.address',
        'parkandride.pricingList',
        'parkandride.submitUtil',
        'showErrors'
    ]);

    m.config(function($stateProvider) {
        $stateProvider.state('facility-create', { // dot notation in ui-router indicates nested ui-view
            parent: 'hubstab',
            url: '/facilities/create', // TODO set facilities base path on upper level and say here /create ?
            views: {
                "main": {
                    controller: 'FacilityEditCtrl as editCtrl',
                    templateUrl: 'facilities/facilityEdit.tpl.html'
                }
            },
            data: { pageTitle: 'Create Facility' },
            resolve: {
                // This is a hack, but I found no other way to ensure that tags-input placeholder translation works on page reload
                aliasesPlaceholder: function($translate) {
                    return $translate("facilities.aliases.placeholder");
                },
                facility: function(FacilityResource) {
                    return FacilityResource.newFacility();
                }
            }
        });
        $stateProvider.state('facility-edit', { // dot notation in ui-router indicates nested ui-view
            parent: 'hubstab',
            url: '/facilities/edit/:id',
            views: {
                "main": {
                    controller: 'FacilityEditCtrl as editCtrl',
                    templateUrl: 'facilities/facilityEdit.tpl.html'
                }
            },
            data: { pageTitle: 'Edit Facility' },
            resolve: {
                // This is a hack, but I found no other way to ensure that tags-input placeholder translation works on page reload
                aliasesPlaceholder: function($translate) {
                    return $translate("facilities.aliases.placeholder");
                },
                facility: function($stateParams, FacilityResource) {
                    return FacilityResource.getFacility($stateParams.id);
                }
            }
        });
    });

    m.controller('FacilityEditCtrl', function($scope, $state, schema, FacilityResource, Session, Sequence, facility, aliasesPlaceholder, submitUtilFactory) {
        var self = this;
        self.context = "facilities";
        var submitUtil = submitUtilFactory($scope, self.context);

        self.capacityTypes = schema.capacityTypes.values;
        self.usages = schema.usages.values;
        self.dayTypes = schema.dayTypes.values;
        self.services = schema.services.values;
        self.paymentMethods = schema.paymentMethods.values;
        self.facilityStatuses = schema.facilityStatuses.values;
        self.pricingMethods = schema.pricingMethods.values;

        self.aliasesPlaceholder = aliasesPlaceholder;
        self.showUnavailableCapacityType = function(i) {
            var ucs = self.facility.unavailableCapacities;
            return i === 0 || ucs[i - 1].capacityType != ucs[i].capacityType;
        };

        self.facility = facility;
        if (!self.facility.operatorId) {
            var login = Session.get();
            self.facility.operatorId = login && login.operatorId;
        }

        self.editMode = (facility.id ? "ports" : "location");

        self.save = function(form) {
            var facility = _.cloneDeep(self.facility);
            submitUtil.validateAndSubmit(
                form,
                function() { return FacilityResource.save(facility); },
                function(id) { return $state.go('facility-view', {"id": id }); }
            );
        };
    });

    m.directive('aliases', function() {
        return {
            restrict: 'A',
            require: 'ngModel',
            link: function(scope, element, attr, ngModel) {
                function fromView(text) {
                    return (text || '').split(/\s*,\s*/);
                }
                ngModel.$parsers.push(fromView);
            }
        };<commit_msg>fix(LIIP-210): clear facility.pricing if pricingMethod != CUSTOM<commit_after>(function() {
    var m = angular.module('parkandride.facilityEdit', [
        'ui.router',
        'parkandride.contacts',
        'parkandride.operators',
        'parkandride.SchemaResource',
        'parkandride.ContactResource',
        'parkandride.FacilityResource',
        'parkandride.facilityMap',
        'parkandride.layout',
        'parkandride.multilingual',
        'parkandride.facilityContacts',
        'parkandride.pricing',
        'parkandride.tags',
        'parkandride.address',
        'parkandride.pricingList',
        'parkandride.submitUtil',
        'showErrors'
    ]);

    m.config(function($stateProvider) {
        $stateProvider.state('facility-create', { // dot notation in ui-router indicates nested ui-view
            parent: 'hubstab',
            url: '/facilities/create', // TODO set facilities base path on upper level and say here /create ?
            views: {
                "main": {
                    controller: 'FacilityEditCtrl as editCtrl',
                    templateUrl: 'facilities/facilityEdit.tpl.html'
                }
            },
            data: { pageTitle: 'Create Facility' },
            resolve: {
                // This is a hack, but I found no other way to ensure that tags-input placeholder translation works on page reload
                aliasesPlaceholder: function($translate) {
                    return $translate("facilities.aliases.placeholder");
                },
                facility: function(FacilityResource) {
                    return FacilityResource.newFacility();
                }
            }
        });
        $stateProvider.state('facility-edit', { // dot notation in ui-router indicates nested ui-view
            parent: 'hubstab',
            url: '/facilities/edit/:id',
            views: {
                "main": {
                    controller: 'FacilityEditCtrl as editCtrl',
                    templateUrl: 'facilities/facilityEdit.tpl.html'
                }
            },
            data: { pageTitle: 'Edit Facility' },
            resolve: {
                // This is a hack, but I found no other way to ensure that tags-input placeholder translation works on page reload
                aliasesPlaceholder: function($translate) {
                    return $translate("facilities.aliases.placeholder");
                },
                facility: function($stateParams, FacilityResource) {
                    return FacilityResource.getFacility($stateParams.id);
                }
            }
        });
    });

    m.controller('FacilityEditCtrl', function($scope, $state, schema, FacilityResource, Session, Sequence, facility, aliasesPlaceholder, submitUtilFactory) {
        var self = this;
        var customPricing = [];
        self.context = "facilities";
        var submitUtil = submitUtilFactory($scope, self.context);

        self.capacityTypes = schema.capacityTypes.values;
        self.usages = schema.usages.values;
        self.dayTypes = schema.dayTypes.values;
        self.services = schema.services.values;
        self.paymentMethods = schema.paymentMethods.values;
        self.facilityStatuses = schema.facilityStatuses.values;
        self.pricingMethods = schema.pricingMethods.values;

        self.aliasesPlaceholder = aliasesPlaceholder;
        self.showUnavailableCapacityType = function(i) {
            var ucs = self.facility.unavailableCapacities;
            return i === 0 || ucs[i - 1].capacityType != ucs[i].capacityType;
        };

        self.facility = facility;
        if (!self.facility.operatorId) {
            var login = Session.get();
            self.facility.operatorId = login && login.operatorId;
        }

        self.editMode = (facility.id ? "ports" : "location");

        // Watch pricingMethod because:
        // 1) Invalid pricing rows should be validated iff pricingMethod is CUSTOM.
        // 2) Clearing pricing rows in save method would have to modify self.facility.pricing AND $scope.$apply() for
        //    these changes to be reflected in validation results.
        // 3) Having this customPricing for "discarded" rows allows us to revert to those at any time before
        //    validateAndSubmit success.
        $scope.$watch("editCtrl.facility.pricingMethod", function(newValue) {
            if (self.facility.pricingMethod === "CUSTOM") {
                if (!_.isEmpty(customPricing)) {
                    self.facility.pricing = customPricing;
                }
                customPricing = [];
            } else {
                if (!_.isEmpty(self.facility.pricing)) {
                    customPricing = self.facility.pricing;
                }
                self.facility.pricing = [];
            }
        });

        self.save = function(form) {
            var facility = _.cloneDeep(self.facility);
            submitUtil.validateAndSubmit(
                form,
                function() { return FacilityResource.save(facility); },
                function(id) { return $state.go('facility-view', {"id": id }); }
            );
        };
    });

    m.directive('aliases', function() {
        return {
            restrict: 'A',
            require: 'ngModel',
            link: function(scope, element, attr, ngModel) {
                function fromView(text) {
                    return (text || '').split(/\s*,\s*/);
                }
                ngModel.$parsers.push(fromView);
            }
        };
{'fraction_non_alphanumeric': 0.10910361349570773, 'fraction_numerical': 0.0009982032341784787, 'mean_word_length': 1.7954799107142858, 'pattern_counts': {'":': 6, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2142466', 'n_tokens_mistral': 2628, 'n_tokens_neox': 2517, 'n_words': 545}