link()

in public/components/directives/ui-edit-rights.js [68:114]


  link(scope) {
    scope.showAllOptions = false;

    scope.toggleShowAllOptions = () => scope.showAllOptions = !scope.showAllOptions;

    scope.hasAnyRights = () =>
        scope.contentItem.item.rightsSyndicationAggregate ||
        scope.contentItem.item.rightsSubscriptionDatabases  ||
        scope.contentItem.item.rightsDeveloperCommunity;

    scope.updateRights = () => {
      wfComposerService.updateRights(scope.contentItem.composerId, {
        syndicationAggregate: scope.contentItem.item.rightsSyndicationAggregate,
        subscriptionDatabases: scope.contentItem.item.rightsSubscriptionDatabases,
        developerCommunity: scope.contentItem.item.rightsDeveloperCommunity
      })
    };

    /**
     * Because we go back to Composer to set this information, and then wait for Composer
     * to report the new value via flexible-content-stream, sometimes workflow-frontend will
     * update before Composer has a chance to report the new value.
     *
     * Our client cannot distinguish between these sorts of updates, so we lock these values
     * once they're changed for a short duration after editing.
     */
    const lockRightsValuesForDuration = (shouldHaveRights) => {
      const cancelWatch = scope.$watch("contentItem", contentItem => {
        contentItem.item.rightsSyndicationAggregate = shouldHaveRights;
        contentItem.item.rightsSubscriptionDatabases = shouldHaveRights;
        contentItem.item.rightsDeveloperCommunity = shouldHaveRights;
      });

      // Lock rights data for one polling cycle.
      setTimeout(cancelWatch, 5000);
    }

    scope.setAllRights = (hasRights) => {
      scope.contentItem.item.rightsSyndicationAggregate = hasRights;
      scope.contentItem.item.rightsSubscriptionDatabases = hasRights;
      scope.contentItem.item.rightsDeveloperCommunity = hasRights;

      lockRightsValuesForDuration(hasRights);

      scope.updateRights();
    }
  }