'use strict';

var opts = require('../envoy/opts');

/**
 * @ngdoc directive
 * @name fv.envoy.directive:envoyList
 * Defines a directive which will display a list of all messages
 * for a form.
 *
 * The template for the list is the property `templateUrl` of
 * $envoyProvider.
 *
 * Must have an `envoyMessages` ancestor.
 * @example
 * ```html
 * <div envoy-list="configForm"></div>
 * <!-- or -->
 * <envoy-list for="configForm"></envoy-list>
 * ```
 */
function list($envoy) {
  return {
    restrict: 'EA',
    scope: true,
    require: '^envoyMessages',
    templateUrl: opts.templateUrl,
    link: function (scope, element, attrs, envoyMessages) {
      var parent = $envoy.findParentCtrl(attrs.envoyList ||
        attrs.for, envoyMessages);

      parent.bindView(scope);

      scope.$on('$destroy', function () {
        parent.unbindView();
      });
    }
  };
}
list.$inject = ['$envoy'];

module.exports = list;

@@ -108,16 +108,32 @@
 voyList%0A
+ * @description%0A
  * Defin
@@ -189,16 +189,16 @@
 essages%0A
-
  * for a
@@ -298,17 +298,204 @@
 %0A * 
-Must have
+The target form can be specified, by name (with interpolation available),%0A * in the %60envoyList%60 attribute or the %60for%60 attribute.  This attribute may%0A * be omitted if the %60envoyList%60 directive has
  an 
@@ -674,16 +674,30 @@
 t($envoy
+, $interpolate
 ) %7B%0A  re
@@ -754,16 +754,17 @@
 quire: '
+?
 %5EenvoyMe
@@ -887,70 +887,297 @@
 rent
- = $envoy.findParentCtrl(attrs.envoyList %7C%7C%0A        attrs.f
+Name = attrs.envoyList %7C%7C attrs.for;%0A      var parent;%0A%0A      if (parentName) %7B%0A        parent = $envoy.findParentCtrl($interpolate(parentName)(scope));%0A      %7D else if (envoyMessages) %7B%0A        parent = envoyMessages;%0A      %7D else %7B%0A        throw new Error('envoyList requires an ancest
 or
-,
  env
@@ -1186,18 +1186,67 @@
 Messages
-);
+ ' +%0A          'directive or a form name');%0A      %7D
 %0A%0A      
@@ -1364,16 +1364,16 @@
 %0A  %7D;%0A%7D%0A
-
 list.$in
@@ -1388,16 +1388,32 @@
 '$envoy'
+, '$interpolate'
 %5D;%0A%0Amodu

enable interpolation, add default