Skip to content

Commit

Permalink
[#771] fix in-place editing and broken integer-select-editor
Browse files Browse the repository at this point in the history
  • Loading branch information
al2o3cr committed Sep 21, 2011
1 parent 3a1f398 commit aa33235
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion hobo/lib/generators/hobo/rapid/templates/hobo-rapid.js
Expand Up @@ -34,6 +34,7 @@ var Hobo = {
var params = Hobo.fieldSetParam(el, val)
var p = el.getAttribute("hobo-ajax-params")
if (p) params = params + "&" + p
params = params + '&_method=PUT'

var opts = Object.merge(options || {}, { params: params, message: el.getAttribute("hobo-ajax-message")})
Hobo.ajaxRequest(Hobo.putUrl(el), updates, opts)
Expand Down Expand Up @@ -257,8 +258,9 @@ var Hobo = {


putUrl: function(el) {
/* we used to append _method=put here, but it doesn't work in Rails 3 */
var spec = Hobo.modelSpecForElement(el)
return urlBase + "/" + Hobo.pluralise(spec.name) + "/" + spec.id + "?_method=PUT"
return urlBase + "/" + Hobo.pluralise(spec.name) + "/" + spec.id
},


Expand Down
4 changes: 4 additions & 0 deletions hobo/lib/hobo/helper.rb
Expand Up @@ -179,6 +179,10 @@ def model_id_class(object=this, attribute=nil)
object.respond_to?(:typed_id) ? "model::#{typed_id(object, attribute).to_s.dasherize}" : ""
end

def update_elements_class(updates)
'update::'+comma_split(updates).join(':') unless updates.blank?
end

def can_create?(object=this)
if object.is_a?(Class) and object < ActiveRecord::Base
object = object.new
Expand Down
5 changes: 3 additions & 2 deletions hobo/lib/hobo/rapid/helper.rb
Expand Up @@ -120,8 +120,9 @@ def in_place_editor(attributes, this=nil)
edit_text = this._?.to_s
attributes.update(:hobo_edit_text => edit_text) unless edit_text.nil?

update = attributes.delete(:update)
attributes[:hobo_update] = update if update
if update = attributes.delete(:update)
attributes = add_classes(attributes, update_elements_class(update))
end

view(attributes)
end
Expand Down
2 changes: 1 addition & 1 deletion hobo/lib/hobo/rapid/taglibs/rapid_editing.dryml
Expand Up @@ -218,7 +218,7 @@ This tag does not sanitize HTML; this is provided by HtmlString before saving to
-->
<def tag="integer-select-editor" attrs="options, min, max, update, nil-option, message">
<% options ||= (min.to_i..max.to_i).to_a %>
<select class="integer editor #{'update:' + comma_split(update).join(':') unless update.blank?} #{model_id_class(this_parent, this_field)}"
<select class="integer editor #{update_elements_class(update)} #{model_id_class(this_parent, this_field)}"
merge-attrs="&message ? attributes.merge(:hobo_message => message) : attributes">
<if test="&this.nil?"><option value=""><%= nil_option || "Choose a value" %></option></if>
<%= options_for_select(options.*.to_s, this.to_s) %>
Expand Down

0 comments on commit aa33235

Please sign in to comment.