Skip to content

Commit

Permalink
added more options
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanvda committed Sep 10, 2010
1 parent f537718 commit a3502cd
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 14 deletions.
41 changes: 34 additions & 7 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@ Run the installation task:

rails g on_the_spot:install

Inside your `routes.rb` you provide the catch-all
Inside your `routes.rb` you either provide the catch-all

match ':controller(/:action(/:id(.:format)))'
match ':controller(/:action(/:id(.:format)))'

This is not ideal: i am looking for a better solution.
or you type something like

But that is all you need to do to start using it!
resources :posts do
collection do
get :update_attribute_on_the_spot
end
end

While this last is the best solution, you need to do this for each controller that uses the on-the-spot editing.
For the moment i do not know of any better solution, but i am always open for suggestions!

Inside your `application.html.haml` you will need to add below the default javascripts:

= javascript_include_tag :on_the_spot

That is all you need to do to start using it!


## Usage
Expand All @@ -41,11 +54,25 @@ And inside your view you will have to specify the fields you want to be "editabl

It should be as simple as that :)

## Detailed options

The `on_the_spot_edit` also accepts options:

* `type` : `textarea` or `select` (none means default edit, select is currently not yet supported)
* `ok_text` : the text for the ok-button
* `cancel_text` : the text for the cancel-button
* `tooltip` : the tooltip-text

For the texts: if a text is not specified, the default is taken from the `on_the_spot.en.yml` (or your current language).

## Example project

Ther is a example rails3-project called on_the_spot_tester here: http://github.com/nathanvda/on_the_spot_tester

## To do

- make sure you can overrule ok/cancel texts
- make sure user can choose to use a textarea instead of just text
- find a clean solution for the routes
- make sure user can choose to use a select instead of just text or textarea
- add tests!

## Note on Patches/Pull Requests

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.0.beta2
0.0.1
1 change: 1 addition & 0 deletions lib/generators/on_the_spot/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def download_jeditable
def copy_glue_javascript
# !!!!! TO DO: check this -> how do a copy?
copy_file "on_the_spot.js", "public/javascripts/on_the_spot.js"
copy_file "on_the_spot.en.yml", "config/locales/on_the_spot.en.yml"
end

end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
en:
on_the_spot:
ok: Ok
cancel: Cancel
tooltip: Click to edit ...
12 changes: 9 additions & 3 deletions lib/generators/on_the_spot/install/templates/on_the_spot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ $(document).ready(function() {
data_url = el.attr('data-url'),
ok_text = el.attr('data-ok') || 'OK',
cancel_text = el.attr('data-cancel') || 'Cancel',
tooltip_text = el.attr('data-tooltip') || 'Click to edit ...';
tooltip_text = el.attr('data-tooltip') || 'Click to edit ...',
edit_type = el.attr('data-edittype');

el.editable(data_url, {
var options = {
tooltip: tooltip_text,
cancel: cancel_text,
submit: ok_text
})
};
if (edit_type != null) {
options.type = edit_type;
}

el.editable(data_url, options)
})

});
26 changes: 23 additions & 3 deletions lib/on_the_spot/on_the_spot_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
module OnTheSpot
module Helpers

EDIT_TYPE_TEXTAREA='textarea'
EDIT_TYPE_SELECT='select'

# Possible options:
# ok_text : the ok-button text
# cancel_text : the cancel-button text
# tooltip : the tooltip to show
# type : {'textarea' || 'select' }
def on_the_spot_edit(object, field, options={})
#!!! to do: translate options to data-fields
# Possible fields:
# url?
# type: textarea or not
# button-translations ok-Text, cancel-Text
#
options.reverse_merge!(:ok_text => t('on_the_spot.ok'),
:cancel_text => t('on_the_spot.cancel'),
:tooltip => t('on_the_spot.tooltip')
)

update_url = url_for(:action => 'update_attribute_on_the_spot')

content_tag("span", :id => "#{object.class.name.underscore}__#{field}__#{object.id}",
:class => 'on_the_spot_editing',
:'data-url' => update_url) do
html_options = { :id => "#{object.class.name.underscore}__#{field}__#{object.id}",
:class => 'on_the_spot_editing',
:'data-url' => update_url}

html_options[:'data-edittype'] = options[:type] unless options[:type].nil?
html_options[:'data-ok'] = options[:ok_text] unless options[:ok_text].nil?
html_options[:'data-cancel'] = options[:cancel_text] unless options[:cancel_text].nil?
html_options[:'data-tooltip'] = options[:tooltip] unless options[:tooltip].nil?

content_tag("span", html_options) do
object.send(field.to_sym).to_s
end
end
Expand Down

0 comments on commit a3502cd

Please sign in to comment.