Sha256: 3eb414f2d9f4f91ffb3a47427d2e9ed90cc0e12ff03463fd66c3ae8a87921680

Contents?: true

Size: 1.62 KB

Versions: 28

Compression:

Stored size: 1.62 KB

Contents

# = require lunr/lunr

# TODO reconstruir usando https://github.com/javve/list.js
define ['./states/index', './presenter'], (templates, presenter) ->

  # TODO move lunar and lunr to an extension
  luna =
    index : null
    store : Map()
    fields: ['name', 'description']
    sandbox:
      search:
       index: lunr
    initialize: (records) ->
      throw 'no records provided' unless records?

      @sample = records[0]
      @index  = @sandbox.search.index(@indexate)

      for record in records
        @index.add record
        @store.set record._id, record

      @store.all = records

    # TODO put bold face on matched texts
    search: (params...) ->
      findings = @index.search params...

      results = []
      results.push @store.get finding.ref for finding in findings

      @index.eventEmitter.emit 'searched', results
      results

    indexate: () ->
      sample = luna.sample
      fields = luna.fields

      sample[name] and @field name for name in fields
      @ref '_id'
      true


  # Widget Prototype

  type: 'Base'

  initialize: (options) ->
    widget  = @
    sandbox = @sandbox
    sandbox.logger.log "initialized!"

    record = sandbox.models[options.model]

    # Will also initialize sandbox!
    @html templates.default
    @$el.addClass 'list widget'

    # Forward the models to the presenter

    model.all (records) ->

      # Bind presenter to template
      presentation = presenter records, luna

      luna.initialize presentation.list.items
      luna.index.on 'searched', (results) ->
        sandbox.emit 'list.searched', results


      sandbox.view.bind widget.$el.children(), presentation

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
ende-0.3.9 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.3.8 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.3.7 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.3.6 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.3.5 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.3.4 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.3.3 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.3.2 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.3.1 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.3.0 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.21 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.20 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.19 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.18 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.17 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.16 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.15 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.14 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.13 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.12 lib/assets/javascripts/widgets/list/main.js.coffee