Sha256: f57ed672804f1435331c2096e3db7995693a9945d32e0cbd4d890ddfaf4146c4

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

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

jQuery ($) ->
  EditableForm = $.fn.editableform.Constructor
  EditableForm.prototype.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(@, params)
      else # send ajax to server and return deferred object
        obj = {}
        data = {}
        obj[params.name] = params.value
        data[resource] = obj
        ajaxOptions = $.extend({
          url     : originalUrl
          data    : data
          type    : 'PUT' # TODO: should be 'POST' when create new object
          dataType: 'json'
        }, @options.ajaxOptions)
        $.ajax(ajaxOptions)
    @saveWithoutUrlHook(value)
  EditableForm.prototype.saveWithoutUrlHook = EditableForm.prototype.save
  EditableForm.prototype.save = EditableForm.prototype.saveWithUrlHook

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bootstrap-editable-rails-0.0.1 vendor/assets/javascripts/bootstrap-editable-rails.js.coffee