<commit_before>/*
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2016 wcm.io
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
(function (angular, _) {
  "use strict";
  angular.module("io.wcm.caconfig.widgets")
      .directive("caconfigPathbrowser", pathbrowser);

  pathbrowser.$inject = ["templateUrlList", "inputMap", "directivePropertyPrefixes", "$rootScope"];

  function pathbrowser(templateList, inputMap, directivePropertyPrefixes, $rootScope) {
    var directive = {
      restrict: "E",
      replace: true,
      require: "^form",
      templateUrl: templateList.pathbrowser,
      scope: {
        parameter: "="
      },
      link: link
    };

    return directive;

    function link(scope, element, attr, form) {
      var input = inputMap[scope.parameter.metadata.type];
      var inheritedStateChanged = false;

      scope.type = input.type;
      scope.pattern = input.pattern;
      scope.i18n = $rootScope.i18n;

      var prefix = directivePropertyPrefixes.pathbrowser;
      var props = scope.parameter.metadata.properties;
      var options = {};
      for (var prop in props) {
          if (prop && prop.substring(0, prefix.length) != -1) {
              var propName = prop.substring(prefix.length);
              options[propName.charAt(0).toLowerCase() + propName.slice(1)] = props[prop];
          }
      }

      options.rootPath = options.rootPath || "/content";
      options.predicate = options.predicate || "hierarchyNotFile";
      options.pickerSrc = options.pickerSrc || "/libs/wcm/core/content/common/pathbrowser/column.html" + options.rootPath + "?predicate=" + options.predicate;
      options.optionLoader = loadAutocompleteOptions;

      options.element = element.children(".coral-PathBrowser");
      var widget = new CUI.PathBrowser(options);

      scope.$on("$destroy", function() {
          // remove listeners
          widget.off();
      });

      scope.$watch("parameter.inherited", function (isInherited, wasInherited) {
        if (isInherited === wasInherited) {
          return;
        }
        inheritedStateChanged = true;
        form.$setDirty();
      });
    }
  }

  /**
   * Helper method for the CUI:PathBrowser widget<commit_msg>Added a check for property name after the pathbrowser prefix<commit_after>/*
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2016 wcm.io
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
(function (angular, _) {
  "use strict";
  angular.module("io.wcm.caconfig.widgets")
      .directive("caconfigPathbrowser", pathbrowser);

  pathbrowser.$inject = ["templateUrlList", "inputMap", "directivePropertyPrefixes", "$rootScope"];

  function pathbrowser(templateList, inputMap, directivePropertyPrefixes, $rootScope) {
    var directive = {
      restrict: "E",
      replace: true,
      require: "^form",
      templateUrl: templateList.pathbrowser,
      scope: {
        parameter: "="
      },
      link: link
    };

    return directive;

    function link(scope, element, attr, form) {
      var input = inputMap[scope.parameter.metadata.type];
      var inheritedStateChanged = false;

      scope.type = input.type;
      scope.pattern = input.pattern;
      scope.i18n = $rootScope.i18n;

      var prefix = directivePropertyPrefixes.pathbrowser;
      var props = scope.parameter.metadata.properties;
      var options = {};
      for (var prop in props) {
          // if the property starts with the prefix "pathbrowser" followed by a pathbrowser property name
          if (prop && prop.length > prefix.length && prop.substring(0, prefix.length) != -1) {
              var propName = prop.substring(prefix.length);
              options[propName.charAt(0).toLowerCase() + propName.slice(1)] = props[prop];
          }
      }

      options.rootPath = options.rootPath || "/content";
      options.predicate = options.predicate || "hierarchyNotFile";
      options.pickerSrc = options.pickerSrc || "/libs/wcm/core/content/common/pathbrowser/column.html" + options.rootPath + "?predicate=" + options.predicate;
      options.optionLoader = loadAutocompleteOptions;

      options.element = element.children(".coral-PathBrowser");
      var widget = new CUI.PathBrowser(options);

      scope.$on("$destroy", function() {
          // remove listeners
          widget.off();
      });

      scope.$watch("parameter.inherited", function (isInherited, wasInherited) {
        if (isInherited === wasInherited) {
          return;
        }
        inheritedStateChanged = true;
        form.$setDirty();
      });
    }
  }

  /**
   * Helper method for the CUI:PathBrowser widget
{'fraction_non_alphanumeric': 0.11922530206112296, 'fraction_numerical': 0.005685856432125089, 'mean_word_length': 2.8740536820371645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7255513', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1559, 'n_words': 428}