<commit_before>define(['app', '/app/views/forms/edit/edit.js',
		"/app/views/forms/view/view-contact.directive.js"
], function(app) {

    app.controller("editContact", ["$scope", "$http", "$filter", "$controller", "$location", "$q", 'IStorage',
	function($scope, $http, $filter, $controller, $location, $q, storage) {
        $controller('editController', {
            $scope: $scope
        });

		$scope.doc = {};
        $scope.path = $location.path();
        _.extend($scope.options, {
            organizationTypes: function() {
                return $http.get("/api/v2013/thesaurus/domains/Organization%20Types/terms", {
                    cache: true
                }).then(function(o) {
                    return o.data;
                });
            },
			addressCountries         : function() {
				return $http.get("/api/v2013/thesaurus/domains/countries/terms",            { cache: true })
						.then(function(o){ return $filter("orderBy")(o.data, "name"); });
			},
			organizationTypes : function() {
				return $q.all([$http.get("/api/v2013/thesaurus/domains/Organization%20Types/terms", { cache: true })
						,$http.get("/api/v2013/thesaurus/terms/5B6177DD-5E5E-434E-8CB7-D63D67D5EBED",   { cache: true })])
				.then(function(o){
					var orgs = o[0].data;
					orgs.push(o[1].data);
					return orgs;
				});
			}
		}) ;

        $scope.setDocument({
            type : 'person'
        });


        //==================================
        //
        //==================================
        $scope.getCleanDocument = function(document) {

            document = document || $scope.document;

            if (!document)
                return undefined;

            document = angular.fromJson(angular.toJson(document));

			document.source = undefined;
            if (/^\s*$/g.test(document.firstName)) document.firstName = undefined;
            if (/^\s*$/g.test(document.middleName)) document.middleName = undefined;
            if (/^\s*$/g.test(document.lastName)) document.lastName = undefined;
            if (/^\s*$/g.test(document.notes)) document.notes = undefined;

            return document;
        };

		$scope.$watch("document.websites", function(){

			var doc_websites = ($scope.document ? $scope.document.websites : []);
			var doc_urls = _.compact(_.pluck(doc_websites||[], "url"));
			var    _urls = _.compact($scope.doc._urls||[]);

			if(!_.isEqual(doc_urls, _urls)) {
				$scope.doc._urls = doc_urls;
			}
		});

		$scope.$watch("doc._urls", function(){

			var doc_websites = ($scope.document ? $scope.document.websites : []);
			var doc_urls = _.compact(_.pick(doc_websites||[], "url"));
			var    _urls = _.compact($scope.doc._urls||[]);

			if(!_.isEqual(doc_urls,  _urls) && $scope.document) {
				$scope.document.websites = _.map(_urls, function(url){
					return { url : url };
				});
			}
		});

		$scope.$watch('document.organizationType', function(newValue){
			if(newValue && newValue.identifier!='5B6177DD-5E5E-434E-8CB7-D63D67D5EBED'){
				if(document.organizationType && document.organizationType.customValue)
					document.organizationType.customValue = undefined;<commit_msg>delete name if type of contact == organization<commit_after>define(['app', '/app/views/forms/edit/edit.js',
		"/app/views/forms/view/view-contact.directive.js"
], function(app) {

    app.controller("editContact", ["$scope", "$http", "$filter", "$controller", "$location", "$q", 'IStorage',
	function($scope, $http, $filter, $controller, $location, $q, storage) {
        $controller('editController', {
            $scope: $scope
        });

		$scope.doc = {};
        $scope.path = $location.path();
        _.extend($scope.options, {            
			addressCountries         : function() {
				return $http.get("/api/v2013/thesaurus/domains/countries/terms",            { cache: true })
						.then(function(o){ return $filter("orderBy")(o.data, "name"); });
			},
			organizationTypes : function() {
				return $q.all([$http.get("/api/v2013/thesaurus/domains/Organization%20Types/terms", { cache: true })
						,$http.get("/api/v2013/thesaurus/terms/5B6177DD-5E5E-434E-8CB7-D63D67D5EBED",   { cache: true })])
				.then(function(o){
					var orgs = o[0].data;
					orgs.push(o[1].data);
					return orgs;
				});
			}
		}) ;

        $scope.setDocument({
            type : 'person'
        });


        //==================================
        //
        //==================================
        $scope.getCleanDocument = function(document) {

            document = document || $scope.document;

            if (!document)
                return undefined;

            document = angular.fromJson(angular.toJson(document));

			document.source = undefined;
            if (/^\s*$/g.test(document.firstName)) document.firstName = undefined;
            if (/^\s*$/g.test(document.middleName)) document.middleName = undefined;
            if (/^\s*$/g.test(document.lastName)) document.lastName = undefined;
            if (/^\s*$/g.test(document.notes)) document.notes = undefined;

			if(document.type == "organization"){
				document.firstName = document.middleName = document.lastName = undefined;
			}

            return document;
        };

		$scope.$watch("document.websites", function(){

			var doc_websites = ($scope.document ? $scope.document.websites : []);
			var doc_urls = _.compact(_.pluck(doc_websites||[], "url"));
			var    _urls = _.compact($scope.doc._urls||[]);

			if(!_.isEqual(doc_urls, _urls)) {
				$scope.doc._urls = doc_urls;
			}
		});

		$scope.$watch("doc._urls", function(){

			var doc_websites = ($scope.document ? $scope.document.websites : []);
			var doc_urls = _.compact(_.pick(doc_websites||[], "url"));
			var    _urls = _.compact($scope.doc._urls||[]);

			if(!_.isEqual(doc_urls,  _urls) && $scope.document) {
				$scope.document.websites = _.map(_urls, function(url){
					return { url : url };
				});
			}
		});

		$scope.$watch('document.organizationType', function(newValue){
			if(newValue && newValue.identifier!='5B6177DD-5E5E-434E-8CB7-D63D67D5EBED'){
				if(document.organizationType && document.organizationType.customValue)
					document.organizationType.customValue = undefined;
{'fraction_non_alphanumeric': 0.19761636334353358, 'fraction_numerical': 0.01707199226928652, 'mean_word_length': 2.7568058076225044, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6189459', 'n_tokens_mistral': 2261, 'n_tokens_neox': 1932, 'n_words': 286}