Sha256: a445e40b7b390d2d03e03e9566936985e2a6d19bd8c1f7039043290964569236

Contents?: true

Size: 1.7 KB

Versions: 33

Compression:

Stored size: 1.7 KB

Contents

class Quby.Models.QuestionOption extends Backbone.Model
  defaults: ->
    hidesQuestions: new Quby.Collections.Questions
    showsQuestions: new Quby.Collections.Questions
    hidesQuestionsKeys: []
    showsQuestionsKeys: []
    startChosen: false
  initialize: ->
    @on "checkChosen", @checkChosen, @
    @on "add", @addedToCollection, @
  addedToCollection: ->
    if !_.isEmpty(@get("hidesQuestionsKeys")) or !_.isEmpty(@get("showsQuestionsKeys"))
      @collection.on "initShowsHides", @initShowsHides, @
  initShowsHides: (allQuestions) ->
    showsQuestionsKeys = @get("showsQuestionsKeys")
    showsQuestions = allQuestions.select( (question) ->
      _.contains(showsQuestionsKeys, question.get("key"))
    )
    @get("showsQuestions").add(showsQuestions)

    hidesQuestionsKeys = @get("hidesQuestionsKeys")
    hidesQuestions = allQuestions.select( (question) ->
      _.contains(hidesQuestionsKeys, question.get("key"))
    )
    @get("hidesQuestions").add(hidesQuestions)
    if @get("startChosen")
      @hideQuestions()
      @showQuestions()
      @trigger "setLastClickedOption", @

  checkChosen: ->
    if @get("view").chosen()
      @hideQuestions()
      @showQuestions()
    else
      @unhideQuestions()
      @unshowQuestions()

  hideQuestions: ->
    option = @
    @get("hidesQuestions").each (question) ->
      question.trigger "hide", option
  unhideQuestions: ->
    option = @
    @get("hidesQuestions").each (question) ->
      question.trigger "unhide", option
  showQuestions: ->
    option = @
    @get("showsQuestions").each (question) ->
      question.trigger "show", option
  unshowQuestions: ->
    option = @
    @get("showsQuestions").each (question) ->
      question.trigger "unshow", option

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
quby-5.6.5 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.6.3 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.6.2 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.6.1 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.6.0 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.5.0 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.4.0 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.3.1 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.3.0 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.2.0 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.1.3 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.1.2 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.1.1 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.1.0 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.0.5 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.0.4 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.0.3 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.0.2 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.0.1 app/assets/javascripts/quby/backbone/models/question_option.js.coffee
quby-5.0.0 app/assets/javascripts/quby/backbone/models/question_option.js.coffee