Sha256: b44fd5b9ac1c04c08e6a10b2af4d3047168a8f3c7d1e6f9d0656580e02701192

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

Ext.Ajax.on 'beforerequest', ->
  Netzke.ajaxCount = window.ajaxCount || 0
  Netzke.ajaxCount += 1

Ext.Ajax.on 'requestcomplete', ->
  Netzke.ajaxCount -= 1

Ext.apply window,
  # Examples:
  #
  #   wait ->
  #     afterAllAjaxActivityIsStopped()
  #
  #   wait 2000, ->
  #     afterTwoSeconds()
  wait: () ->
    if typeof arguments[0] == 'function'
      callback = arguments[0]
      i = 0
      id = setInterval ->
        i += 1
        if i >= 100
          clearInterval(id)
          callback.call()

        # this way we ensure another 20ms cycle before we issue a callback
        i = 100 if Netzke.ajaxCount == 0
      , 200
    else
      delay = arguments[0]
      callback = arguments[1]
      setInterval ->
        callback.call()
      , delay

  click: (cmp) ->
    if Ext.isString(cmp)
      throw "Could not locate " + cmp
    else if (cmp.isXType) # is Ext component
      if (cmp.isXType('tool'))
        # a hack needed for tools
        el = cmp.toolEl
      else
        el = cmp.getEl()

      el.dom.click()
    else if Ext.isElement(cmp)
      cmp.click()

  # Closes the first found window
  closeWindow: ->
    Ext.ComponentQuery.query("window[hidden=false]")[0].close()

  select: (value, params, callback) ->
    params ?= params
    combo = params.in
    if combo.isExpanded
      combo.setValue combo.findRecordByDisplay value
      combo.collapse()
    else
      combo.onTriggerClick()
      if callback
        wait ->
          rec = combo.findRecordByDisplay value
          combo.select rec
          combo.fireEvent('select', combo, rec )
          combo.collapse()
          callback.call()
      else
        rec = combo.findRecordByDisplay value
        combo.select rec
        combo.fireEvent('select', combo, rec )
        combo.collapse()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
netzke-testing-0.12.1 app/assets/javascripts/netzke/testing/helpers/actions.js.coffee