<commit_before>//fixed a bug with the comment up here ;)
define([
    'app', 'underscore', 'services/app-config-service',
    'views/forms/edit/editFormUtility',
    'views/forms/edit/field-embed-contact.directive',
    'views/forms/edit/edit-contact-base.directive',
    'views/forms/view/view-contact-reference.directive',
    'views/forms/view/view-default-reference.directive',
    'views/forms/view/view-organization-reference.directive',
    'views/forms/view/record-loader.directive',
    'views/forms/view/view-organization.directive',
    'views/forms/view/view-organization-reference.directive',
    'views/forms/view/view-history-directive',
    'views/directives/workflow-std-buttons',
    'views/forms/edit/document-selector',
    'views/register/directives/register-top-menu',
    'scbd-angularjs-services/locale'
  ], function (app, _) {

  app.controller("editController", ["$rootScope", "$scope", "$http", "$window", "guid", "$filter", "Thesaurus", "$q", "$location", "IStorage",
                                   "authentication", "Enumerable", "editFormUtility", "$routeParams", "$timeout","underscore", "$route", 
                                   "breadcrumbs", "appConfigService", "locale",
                                    function ($rootScope, $scope, $http, $window, guid, $filter, thesaurus, $q, $location, storage,
                                              authentication, Enumerable, editFormUtility, $routeParams, $timeout, _, $route, 
                                              breadcrumbs, appConfigService, locale) {


    $scope.type = $route.current.$$route.documentType;
    
    if(_.contains(appConfigService.nationalSchemas, $filter('mapSchema')($scope.type)))
      $scope.schemaType = 'nationalRecords';
    else
      $scope.schemaType = 'referenceRecords';
      
    $scope.status   = "loading";
    $scope.error    = null;
    $scope.tab      = "edit";
    $scope.review   = { locale: locale };

    var breadcrumb = {    
        label : $filter('schemaName')($filter('mapSchema')($scope.type)),
        originalPath : "/register/:document_type",
        param:$scope.type,
        path:"/register/" + $scope.type
    }
    breadcrumbs.breadcrumbs.splice(2, 0 , breadcrumb);

    $scope.options  = {
      countries		: function() {
        return $http.get("/api/v2013/thesaurus/domains/countries/terms", { cache: true }).then(function(o){
          var countries = $filter("orderBy")(o.data, "name");
          _.each(countries, function(element) {
            element.__value = element.name;
          });
          return countries;
        });
      },
      libraries		: function() {
        return $http.get("/api/v2013/thesaurus/domains/cbdClearingHouses/terms", { cache: true }).then(function(o){
          return o.data;
        });
      },
      regions			: function() {
        return $q.all([
          $http.get("/api/v2013/thesaurus/domains/regions/terms", { cache: true }),
          $http.get("/api/v2013/thesaurus/domains/countries/terms",   { cache: true })
        ]).then(function(o) {
          return Enumerable.from($filter("orderBy")(o[0].data, "name")).union(
            Enumerable.from($filter("orderBy")(o[1].data, "name"))
          ).toArray();
        });
      },
    };

    $scope.ac_countries = function() {
      return $scope.options.countries();
    };

    $scope.genericFilter = function($query, items) {
      var matchedOptions = [];
      for(var i=0; i!=items.length; ++i)
        if(items[i].__value.toLowerCase().indexOf($query.toLowerCase()) !== -1)
          matchedOptions.push(items[i]);

      return matchedOptions;
    };

    $scope.genericMapping = function(item) {
      return {identifier: item.identifier};
    };

    //==================================
    //
    //==================================
    $scope.scrollToTop = function() {
          $("body, html").animate({scrollTop: 0}, "slow");
        };

    //==================================
    //
    //==================================
    $scope.isDefined = function(obj) {
      return angular.isDefined(obj);
    };

    //==================================
    //
    //==================================
    $scope.$on("documentInvalid", function(evt, data){
       $scope.tab = "review";
       $scope.validationReport = data;
    });

    $scope.$on("clearDocumentErrors", function(){
      $scope.validationReport = {clearErrors:[]};
    });

    //==================================
    //
    //==================================
    $scope.$watch("tab", function(tab) {
      if(tab == "review")
        validate();
    });


    $scope.isOtherSelected = function(document){

       return document &&  Enumerable.from(document).any(function(type){
              return type.identifier == "5B6177DD-5E5E-434E-8CB7-D63D67D5EBED";
            });
    };


    //==================================
    //
    //==================================
    $scope.isInLibrary = function(name, document) {
      document = document || $scope.document;

      if (!document || !document.libraries)
        return false;

      var qLibraries = Enumerable.from(document.libraries);

      if(name=="chm"  ) return qLibraries.any(function(o){ return o.identifier == "cbdLibrary:chm";    });
      if(name=="absch") return qLibraries.any(function(o){ return o.identifier == "cbdLibrary:abs-ch"; });
      if(name=="bch"  ) return qLibraries.any(function(o){ return o.identifier == "cbdLibrary:bch";    });
      if(name=="ebsa" ) return qLibraries.any(function(o){ return o.identifier == "cbdLibrary:ebsa";   });

      return false;
  };

    //==================================
    //
    //==================================
    $scope.canAddRegionalMeasure = function(document) {
      document = document || $scope.document;

      if (!document)
        return false;
      var allowedRegionalMeasuresMapping = {
        "pe"    : "9C5E1A4D-E8EE-4C74-B9C9-5C7BCDF6B84A",
        "eu"    : "bd12d7fb-91f7-4b2d-996c-e70f18a51f0e",
        "eur"   : "bd12d7fb-91f7-4b2d-996c-e70f18a51f0e" 
      }
      if(document.jurisdiction.identifier == '528B1187-F1BD-4479-9FB3-ADBD9076D361' && allowedRegionalMeasuresMapping[document.government.identifier]){<commit_msg>hold on peru regional msr<commit_after>//fixed a bug with the comment up here ;)
define([
    'app', 'underscore', 'services/app-config-service',
    'views/forms/edit/editFormUtility',
    'views/forms/edit/field-embed-contact.directive',
    'views/forms/edit/edit-contact-base.directive',
    'views/forms/view/view-contact-reference.directive',
    'views/forms/view/view-default-reference.directive',
    'views/forms/view/view-organization-reference.directive',
    'views/forms/view/record-loader.directive',
    'views/forms/view/view-organization.directive',
    'views/forms/view/view-organization-reference.directive',
    'views/forms/view/view-history-directive',
    'views/directives/workflow-std-buttons',
    'views/forms/edit/document-selector',
    'views/register/directives/register-top-menu',
    'scbd-angularjs-services/locale'
  ], function (app, _) {

  app.controller("editController", ["$rootScope", "$scope", "$http", "$window", "guid", "$filter", "Thesaurus", "$q", "$location", "IStorage",
                                   "authentication", "Enumerable", "editFormUtility", "$routeParams", "$timeout","underscore", "$route", 
                                   "breadcrumbs", "appConfigService", "locale",
                                    function ($rootScope, $scope, $http, $window, guid, $filter, thesaurus, $q, $location, storage,
                                              authentication, Enumerable, editFormUtility, $routeParams, $timeout, _, $route, 
                                              breadcrumbs, appConfigService, locale) {


    $scope.type = $route.current.$$route.documentType;
    
    if(_.contains(appConfigService.nationalSchemas, $filter('mapSchema')($scope.type)))
      $scope.schemaType = 'nationalRecords';
    else
      $scope.schemaType = 'referenceRecords';
      
    $scope.status   = "loading";
    $scope.error    = null;
    $scope.tab      = "edit";
    $scope.review   = { locale: locale };

    var breadcrumb = {    
        label : $filter('schemaName')($filter('mapSchema')($scope.type)),
        originalPath : "/register/:document_type",
        param:$scope.type,
        path:"/register/" + $scope.type
    }
    breadcrumbs.breadcrumbs.splice(2, 0 , breadcrumb);

    $scope.options  = {
      countries		: function() {
        return $http.get("/api/v2013/thesaurus/domains/countries/terms", { cache: true }).then(function(o){
          var countries = $filter("orderBy")(o.data, "name");
          _.each(countries, function(element) {
            element.__value = element.name;
          });
          return countries;
        });
      },
      libraries		: function() {
        return $http.get("/api/v2013/thesaurus/domains/cbdClearingHouses/terms", { cache: true }).then(function(o){
          return o.data;
        });
      },
      regions			: function() {
        return $q.all([
          $http.get("/api/v2013/thesaurus/domains/regions/terms", { cache: true }),
          $http.get("/api/v2013/thesaurus/domains/countries/terms",   { cache: true })
        ]).then(function(o) {
          return Enumerable.from($filter("orderBy")(o[0].data, "name")).union(
            Enumerable.from($filter("orderBy")(o[1].data, "name"))
          ).toArray();
        });
      },
    };

    $scope.ac_countries = function() {
      return $scope.options.countries();
    };

    $scope.genericFilter = function($query, items) {
      var matchedOptions = [];
      for(var i=0; i!=items.length; ++i)
        if(items[i].__value.toLowerCase().indexOf($query.toLowerCase()) !== -1)
          matchedOptions.push(items[i]);

      return matchedOptions;
    };

    $scope.genericMapping = function(item) {
      return {identifier: item.identifier};
    };

    //==================================
    //
    //==================================
    $scope.scrollToTop = function() {
          $("body, html").animate({scrollTop: 0}, "slow");
        };

    //==================================
    //
    //==================================
    $scope.isDefined = function(obj) {
      return angular.isDefined(obj);
    };

    //==================================
    //
    //==================================
    $scope.$on("documentInvalid", function(evt, data){
       $scope.tab = "review";
       $scope.validationReport = data;
    });

    $scope.$on("clearDocumentErrors", function(){
      $scope.validationReport = {clearErrors:[]};
    });

    //==================================
    //
    //==================================
    $scope.$watch("tab", function(tab) {
      if(tab == "review")
        validate();
    });


    $scope.isOtherSelected = function(document){

       return document &&  Enumerable.from(document).any(function(type){
              return type.identifier == "5B6177DD-5E5E-434E-8CB7-D63D67D5EBED";
            });
    };


    //==================================
    //
    //==================================
    $scope.isInLibrary = function(name, document) {
      document = document || $scope.document;

      if (!document || !document.libraries)
        return false;

      var qLibraries = Enumerable.from(document.libraries);

      if(name=="chm"  ) return qLibraries.any(function(o){ return o.identifier == "cbdLibrary:chm";    });
      if(name=="absch") return qLibraries.any(function(o){ return o.identifier == "cbdLibrary:abs-ch"; });
      if(name=="bch"  ) return qLibraries.any(function(o){ return o.identifier == "cbdLibrary:bch";    });
      if(name=="ebsa" ) return qLibraries.any(function(o){ return o.identifier == "cbdLibrary:ebsa";   });

      return false;
  };

    //==================================
    //
    //==================================
    $scope.canAddRegionalMeasure = function(document) {
      document = document || $scope.document;

      if (!document)
        return false;
      var allowedRegionalMeasuresMapping = {
        "pe-onhold"    : "9C5E1A4D-E8EE-4C74-B9C9-5C7BCDF6B84A",
        "eu"    : "bd12d7fb-91f7-4b2d-996c-e70f18a51f0e",
        "eur"   : "bd12d7fb-91f7-4b2d-996c-e70f18a51f0e" 
      }
      if(document.jurisdiction.identifier == '528B1187-F1BD-4479-9FB3-ADBD9076D361' && allowedRegionalMeasuresMapping[document.government.identifier]){
{'fraction_non_alphanumeric': 0.22063174730107957, 'fraction_numerical': 0.01791283486605358, 'mean_word_length': 2.7175980975029725, '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': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2239555', 'n_tokens_mistral': 3912, 'n_tokens_neox': 3685, 'n_words': 521}