Revision 5d8d8a6e
Added by Ohad Levy over 12 years ago
- ID 5d8d8a6e1182ddc8e5f3d083a1aaa7fd97b1e53a
app/helpers/application_helper.rb | ||
---|---|---|
edit_inline(object, property, options.merge({:type => "edit_textarea"}))
|
||
end
|
||
|
||
def edit_select(object, property, options={})
|
||
edit_inline(object, property, options.merge({:type => "edit_select"}))
|
||
end
|
||
|
||
protected
|
||
def edit_inline(object, property, options={})
|
||
... | ... | |
update_url = options[:update_url] || url_for(object)
|
||
|
||
opts = { :title => "Click to edit", "data-url" => update_url, :class => "editable #{klass}",
|
||
:name => name, "data-field" => property, :value => value}
|
||
:name => name, "data-field" => property, :value => value, :select_values => options[:select_values]}
|
||
|
||
content_tag_for :span, object, opts do
|
||
h(value)
|
app/helpers/settings_helper.rb | ||
---|---|---|
module SettingsHelper
|
||
|
||
def value f
|
||
case f.object.settings_type
|
||
def value setting
|
||
case setting.settings_type
|
||
when "boolean"
|
||
f.select :value, options_for_select(["true", "false"], f.object.value.to_s), :class => "span-3 last"
|
||
edit_select(setting, :value, {:select_values => {:true => "true", :false => "false"}.to_json } )
|
||
else
|
||
f.text_field :value, :value => f.object.value, :class => "span-10 last"
|
||
edit_textfield(setting, :value,{:helper => :show_value})
|
||
end
|
||
end
|
||
|
app/views/settings/index.html.erb | ||
---|---|---|
<% for setting in @settings %>
|
||
<tr class="<%= cycle("even", "odd") -%>">
|
||
<td><%=h setting.name %></td>
|
||
<td><%= edit_textfield(setting, :value,{:helper => :show_value}) %></td>
|
||
<td><%= value(setting) %></td>
|
||
<td><%=h setting.description %></td>
|
||
<td><%=h setting.category %></td>
|
||
</tr>
|
public/javascripts/application.js | ||
---|---|---|
callback : function(value, settings) { $(this).addClass("editable"); },
|
||
onsuccess : function(data) {
|
||
var parsed = $.parseJSON(data);
|
||
$(this).html(parsed[$(this).attr('name').split("[")[0]][$(this).attr('data-field')]);
|
||
var key = $(this).attr('name').split("[")[0]
|
||
var val = $(this).attr('data-field');
|
||
$(this).html(String(parsed[key][val]));
|
||
},
|
||
onerror : function(settings, original, xhr) {
|
||
original.reset();
|
||
... | ... | |
$(this).editable($(this).attr('data-url'), $.extend(common_settings, settings));
|
||
});
|
||
|
||
});
|
||
$('.edit_select').each(function() {
|
||
var settings = {
|
||
type : 'select',
|
||
name : $(this).attr('name'),
|
||
data : $(this).attr('select_values'),
|
||
width: '100%',
|
||
};
|
||
$(this).editable($(this).attr('data-url'), $.extend(common_settings, settings));
|
||
});
|
||
|
||
|
||
});
|
Also available in: Unified diff
refs #1184 - added editing of true / false values in settings page