"use strict";

angular.module('arethusa.sg').directive('sgAncestors', [
  'sg',
  function(sg) {
    return {
      restrict: 'A',
      scope: {
        obj: '=sgAncestors'
      },
      link: function(scope, element, attrs) {
        scope.requestGrammar = function(el) {
          if (el.sections) {
            if (sg.readerRequested === el) {
              sg.readerRequested = false;
            } else {
              sg.readerRequested = el;
            }
          }
        };

        scope.requested = function(obj) {
          return sg.readerRequested.short === obj.short;
        };

        function updateHierarchy(ancestors) {
          scope.hierarchy = scope.obj.definingAttrs.concat(scope.obj.ancestors);
        }

        scope.$watch('obj.hasChanged', function(newVal, oldVal) {
          if (newVal) {
            updateHierarchy();
            scope.obj.hasChanged = false;
          }
        });

        scope.$watchCollection('obj.ancestors', function(newVal, oldVal) {
          updateHierarchy();
        });
      },
      templateUrl: './templates/arethusa.sg/ancestors.html'
    };
  }
]);

@@ -1068,18 +1068,9 @@
 l: '
-./template
+j
 s/ar
@@ -1079,16 +1079,26 @@
 husa.sg/
+templates/
 ancestor

update path to sg ancestors template