Sha256: 5af13b1e3158ceec69f080ff6ccbf6e38639eefa0227e5535b7efb81d110f609

Contents?: true

Size: 1022 Bytes

Versions: 2

Compression:

Stored size: 1022 Bytes

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

Version data entries

2 entries across 2 versions & 1 rubygems

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