anchor.diff:  ##
   # Page to edit an already added authentication provider
   ##
  -Application.Controllers.controller "EditAuthenticationController", ["$scope", "$state", "$stateParams", "$rootScope", "dialogs", "growl", 'providerPromise', 'mappingFieldsPromise', 'AuthProvider', '_t'
  -, ($scope, $state, $stateParams, $rootScope, dialogs, growl, providerPromise, mappingFieldsPromise, AuthProvider, _t) ->
  -
  +Application.Controllers.controller "EditAuthenticationController", ["$scope", "$state", "$stateParams", "$rootScope", "$uibModal", "dialogs", "growl", 'providerPromise', 'mappingFieldsPromise', 'AuthProvider', '_t'
  +, ($scope, $state, $stateParams, $rootScope, $uibModal, dialogs, growl, providerPromise, mappingFieldsPromise, AuthProvider, _t) ->
  +
  +  ## parameters of the currently edited authentication provider
     $scope.provider = providerPromise
   
  -  $scope.authMethods = METHODS
  -
     $scope.mode = 'edition'
  -
  -  $scope.mappingFields = mappingFieldsPromise
   
     ##
     # Update the current provider with the new inputs
  
positive.code:     , ->
        growl.error(_t('an_error_occurred_unable_to_update_the_provider'))
  
    ##
    # Changes the admin's view to the members list page
    ##
    $scope.cancel = ->
      $state.go('app.admin.members')
  
  ]
negative.code:     if mapping.local_model == 'user' and mapping.local_field == 'uid' and not mapping._destroy
        return true
    return false
  
  
  ##
  # Provides a set of common callback methods and data to the $scope parameter. These methods are used
  # in the various authentication providers' controllers.
  #
  # Provides :
  #  - $scope.authMethods
  #  - $scope.mappingFields
  #  - $scope.cancel()
  #  - $scope.defineDataMapping(mapping)
  #
  # Requires :
  #  - mappingFieldsPromise: retrieved by AuthProvider.mapping_fields()
  #  - $state (Ui-Router) [ 'app.admin.members' ]
  ##
  class AuthenticationController
    constructor: ($scope, $state, $uibModal, mappingFieldsPromise)->
      ## list of supported authentication methods
      $scope.authMethods = METHODS
  
      ## list of fields that can be mapped through the SSO
      $scope.mappingFields = mappingFieldsPromise
  
      ##
      # Changes the admin's view to the members list page
      ##
      $scope.cancel = ->
        $state.go('app.admin.members')
  
  
  
      ##
      # Open a modal allowing to specify the data mapping for the given field
      ##
      $scope.defineDataMapping = (mapping) ->
        $uibModal.open
          templateUrl: '<%= asset_path "admin/authentications/_data_mapping.html" %>'
          size: 'md'
          resolve:
            field: -> mapping
            datatype: ->
              for field in $scope.mappingFields[mapping.local_model]
                if field[0] == mapping.local_field
                  return field[1]
  
          controller: ['$scope', '$uibModalInstance', 'field', 'datatype', ($scope, $uibModalInstance, field, datatype) ->
            ## parent field
            $scope.field = field
            ## expected data type
            $scope.datatype = datatype
  
            ## close and save the modifications
            $scope.ok = ->
              console.log('TODO')
              $uibModalInstance.close()
  
            ## do not save the modifications
            $scope.cancel = ->
              $uibModalInstance.dismiss()
          ]
  
  
  
  
  