           @update()
 
     update: ()->
-      self = this
       if @hasChanges
-        Restangular.one('metrics', self.id).customPUT(self.params())
+        Restangular.one('metrics', @id).customPUT(@params())
           .then(
             ()-> , #success
             ()-> # failure
           )
-          self.resetChanges()
+          @resetChanges()
 
     delete: (index)->
-      self = this
       if @isSaved()
         if confirm("Are you sure you want to delete this metric? Deleting this metric will delete its tiers as well.")
-          $http.delete("/metrics/#{self.id}").success(
-            (data,status)->
-              self.remove(index)
+          $http.delete("/metrics/#{@id}").success(
+            (data,status)=>
+              @remove(index)
           )
           .error((err)->
             alert("delete failed!")
           )
       else
-        self.remove(index)            
+        @remove(index)            
 ]  
    isSaved: ()->
      @id != null
    change: ()->
      self = this
      if @fullCreditTier
        @updateFullCreditTier()
      if @isSaved()
        self.hasChanges = true
    updateFullCreditTier: ()->
      @tiers[0].points = @max_points
    resetChanges: ()->
      @hasChanges = false
    params: ()->
      self = this
      {
        name: self.name,
        max_points: self.max_points,
        order: self.order(),
        description: self.description,
        rubric_id: self.rubricId
      }
    destroy: ()->

    remove:(index)->
      self = this
      self.$scope.metrics.splice(index,1)
    create: ()->
      self = this
      Restangular.all('metrics').post(@params())
        .then (response)->
          metric = response.existing_metric
          self.id = metric.id
          self.$scope.countSavedMetric()
          self.addTiers(metric.tiers)

    modify: (form)->
      if form.$valid

      #   )

    addTiers: (tiers)->
      angular.forEach(tiers, (tier,index)=>
        @addTier(tier)
      )
    resourceUrl: ()->
      "/metrics/#{self.id}"
    order: ()->
      jQuery.inArray(this, @$scope.metrics)

    loadMetricBadge: (metricBadge)->
      courseBadge = @availableBadges[metricBadge.badge_id]
      loadedBadge = new MetricBadgePrototype(@, angular.copy(courseBadge))
      @badges[courseBadge.id] = loadedBadge # add metric badge to metric
      delete @availableBadges[courseBadge.id] # remove badge from available badges on metric

    # Badges
    loadMetricBadges: (metricBadges)->
      angular.forEach(metricBadges, (metricBadge, index)=>
        if (@availableBadges[metricBadge.badge_id])
          @loadMetricBadge(metricBadge)
      )

    index: ()->
      @order()
    createRubricGrade: ()->
      $http.post("/rubric_grades.json", @rubricGradeParams()).success().error()
    gradeWithTier: (tier)->
      if @isUsingTier(tier)
        @selectedTier = null
