Sha256: a4353c8811c0181920ff83f6c74c32d6f47afdead78ffa93c16092dd0c6d44e2

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

'use strict'

# TODO implement default viewer presenteer
define () ->

  observable = require('observable').mixin
  extend     = require 'segmentio-extend'
  self       = null
  view       = null

  normalizer =
    normalize: (model) ->
      observable extend
        name : model.code
        image : null
        selected : false
        model : model
        normalized : true
        , self.handlers.item

    drawings: ->
      selection = view.select (binding) ->
        binding.keypath == 'items'

      items_binding = selection[0]

      for item_view in items_binding.iterated
        selection = item_view.select (binding) ->
          binding.keypath == 'image'

        image_binding  = selection[0]
        drawing        = self.drawing $(image_binding.el), image_binding.model.model
        drawing.width  = (parseInt(drawing.width ) / 4) + 'px'
        drawing.height = (parseInt(drawing.height) / 4) + 'px'

  self = (items) ->

    # TODO create view_model
    presentation =
      presented: (v) -> view = v
      viewer: observable
        items: self._.map items, normalizer.normalize

    presentation.viewer.subscribe 'items', (items) ->
      for item in items
        unless item.normalized
          index = @items.indexOf item
          @observed.items[index] = normalizer.normalize item

      normalizer.drawings()

    presentation

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ende-0.2.7 lib/assets/javascripts/widgets/viewer/presenters/default.js.coffee
ende-0.2.6 lib/assets/javascripts/widgets/viewer/presenters/default.js.coffee
ende-0.2.5 lib/assets/javascripts/widgets/viewer/presenters/default.js.coffee
ende-0.2.4 lib/assets/javascripts/widgets/viewer/presenters/default.js.coffee
ende-0.2.3 lib/assets/javascripts/widgets/viewer/presenters/default.js.coffee
ende-0.2.2 lib/assets/javascripts/widgets/viewer/presenters/default.js.coffee
ende-0.2.1 lib/assets/javascripts/widgets/viewer/presenters/default.js.coffee
ende-0.2.0 lib/assets/javascripts/widgets/viewer/presenters/default.js.coffee
ende-0.1.14 lib/assets/javascripts/widgets/viewer/presenters/default.js.coffee
ende-0.1.13 lib/assets/javascripts/widgets/viewer/presenters/default.js.coffee
ende-0.1.12 lib/assets/javascripts/widgets/viewer/presenters/default.js.coffee
ende-0.1.11 lib/assets/javascripts/widgets/viewer/presenters/default.js.coffee