werein/x-editable-rails — pull request #5 by joelvh (2013-10-26 22:53:53+00:00)
Title: More defaults and toggling between CSS class names

I've added the ability to specify the HTML element tag name, class names, and data attributes. I've also added some basic handling of booleans by converting them to 1 and 0. I also have the default display value pull from the "source" if it exists. Added default "source" for booleans to display "Yes" or "No" by default.

Also created a helper that mimics "select" Hashes, but used to toggle between CSS class names based on the selected value. As an example, the following "success" callback (CoffeeScript) will swap out classes
based on the new value selected:

$('.editable').editable(
success: (response, value) ->
element = $(this)
css = element.data('classes') || {}
element.removeClass(class_name) for key, class_name of css
element.addClass(css[value])
element.css('background-color', '')
)

For instance, if you have "Active" and "Inactive" states (boolean), this could be used to change the Bootstrap `label` class from `label-success` to `label-default`.

Lastly, I'm working on the ability to use a YAML file to specify options on a per-class basis, so you don't have to put "sources", placeholders, and other options in-line.