Skip to content

Instantly share code, notes, and snippets.

@edlvj
Created October 4, 2017 10:56
Show Gist options
  • Save edlvj/b9efa4354e676d3ef227d54525690c1f to your computer and use it in GitHub Desktop.
Save edlvj/b9efa4354e676d3ef227d54525690c1f to your computer and use it in GitHub Desktop.
angular.module('MTP').factory 'TemplatesBlockBehavior',() ->
class TemplatesBlockBehavior
allBlocks: ->
return @_allBlocks if @_allBlocks
@_allBlocks = []
if @blocks
for b in @blocks
@_allBlocks.push b
@_allBlocks = @_allBlocks.concat(b.allBlocks())
@_allBlocks
allQuestions: ->
return @_allQuestions if @_allQuestions
if @questions?.length
@_allQuestions = @questions
else
@_allQuestions = []
if @blocks
for b in @blocks
@_allQuestions = @_allQuestions.concat(b.allQuestions())
@_allQuestions
allAnswers: ->
return @_allAnswers if @_allAnswers
@_allAnswers = []
for q in @allQuestions()
@_allAnswers = @_allAnswers.concat(q.answers)
@_allAnswers
max_points: ()->
return if !@allowCountPoints
points = 0
if @questions.length
for q in @questions
points += q.max_points if !q.visit_na && !q.hidden
else
for b in @blocks
#зачем эта проверка if b.coefficient != 0 ?
points += b.max_points() #if b.coefficient != 0
points
points: ()->
return if !@allowCountPoints
points = 0
if @questions.length
for q in @questions
points += q.points() if !q.visit_na && !q.hidden
else
for b in @blocks
points += b.points() #if b.coefficient != 0
points
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment