Sha256: bd9250208cf034c30622478a1d12289d28ad2c1dd924315f3eec1aa85f4310c2

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

# bootstrap-editable-rails.js.coffee
# Modify parameters of X-editable suitable for Rails.

jQuery ($) ->
  EditableForm = $.fn.editableform.Constructor
  unless EditableForm::saveWithUrlHook?
    EditableForm::saveWithUrlHook = (value) ->
      originalUrl = @options.url
      resource = @options.resource
      @options.url = (params) =>
        # TODO: should not send when create new object
        if typeof originalUrl == 'function' # user's function
          originalUrl.call(@options.scope, params)
        else if originalUrl? && @options.send != 'never'
          # send ajax to server and return deferred object
          obj = {}
          obj[params.name] = params.value
          # support custom inputtypes (eg address)
          if resource
            params[resource] = obj
          else
            params = obj
          delete params.name
          delete params.value
          delete params.pk
          $.ajax($.extend({
            url     : originalUrl
            data    : params
            type    : 'PUT' # TODO: should be 'POST' when create new object
            dataType: 'json'
          }, @options.ajaxOptions))
      @saveWithoutUrlHook(value)
    EditableForm::saveWithoutUrlHook = EditableForm::save
    EditableForm::save = EditableForm::saveWithUrlHook

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bootstrap-editable-rails-0.0.9 app/assets/javascripts/bootstrap-editable-rails.js.coffee
bootstrap-editable-rails-0.0.8 app/assets/javascripts/bootstrap-editable-rails.js.coffee
bootstrap-editable-rails-0.0.7 vendor/assets/javascripts/bootstrap-editable-rails.js.coffee