this also moves the setting page to use inline edit
Signed-off-by: Ohad Levy <ohadlevy@gmail.com>
···
--- app/controllers/settings_controller.rb | 4 ---- app/helpers/application_helper.rb | 2 +- app/helpers/settings_helper.rb | 2 ++ app/models/setting.rb | 12 ++++++++++++ app/views/settings/index.html.erb | 4 +--- config/routes.rb | 2 +- public/images/edit-hover.png | Bin 0 -> 531 bytes public/images/edit.png | Bin 0 -> 528 bytes public/javascripts/application.js | 32 ++++---------------------------- public/stylesheets/style.css | 9 +++++++++ 10 files changed, 30 insertions(+), 37 deletions(-) create mode 100644 public/images/edit-hover.png create mode 100644 public/images/edit.pngdiff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb
index be7a13b…b5f9344 100644
— a/app/controllers/settings_controller.rb
+++ b/app/controllers/settings_controller.rb
@@ -12,10 +12,6 @@ class SettingsController < ApplicationController
end
end
-
def edit
-
@setting = Setting.find(params[:id])
-
end
-
def update
@setting = Setting.find(params[:id])
if @setting.update_attributes(params[:setting])
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 90a7e7a…aba5684 100644
— a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -160,7 +160,7 @@ module ApplicationHelper
klass = options[:type]
update_url = options[:update_url] || url_for(object) -
opts = { :title => “Click to edit”, “data-url” => update_url, :class => klass,
-
opts = { :title => “Click to edit”, “data-url” => update_url, :class => “editable #{klass}”,
:name => name, “data-field” => property, :value => value}content_tag_for :span, object, opts do
diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb
index f822209…f0a8d1f 100644
— a/app/helpers/settings_helper.rb
+++ b/app/helpers/settings_helper.rb
@@ -16,5 +16,7 @@ module SettingsHelper
else
setting.value
end -
rescue
-
setting.value
end
end
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 61d7e0b…1a67ecd 100644
— a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -89,6 +89,18 @@ class Setting < ActiveRecord::Base
self.value = false if value == “false”
when “integer”
self.value = value.to_i if value =~ /\d+/ -
when “array”
-
if value =~ /^\s*\[.*\]\s*$/
-
begin
-
self.value = YAML.load(value.gsub(/(\,)(\S)/, "\\1 \\2"))
-
rescue => e
-
errors.add(:value, "invalid value: #{e}")
-
return false
-
end
-
else
-
errors.add(:value, "Must be an array")
-
return false
-
end
end
Value Description <%= sort :category %>
true
end
diff --git a/app/views/settings/index.html.erb b/app/views/settings/index.html.erb
index 9550bd2…6e9e677 100644
— a/app/views/settings/index.html.erb
+++ b/app/views/settings/index.html.erb
@@ -6,15 +6,13 @@
diff --git a/public/images/edit-hover.png b/public/images/edit-hover.png
new file mode 100644
index 0000000000000000000000000000000000000000…d0eb58f145a682333d3e3e12b3da68c60318cefc
GIT binary patch
literal 531
zcmV+u0_^>XP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00001b5ch_0Itp)
z=>Px#24YJL;(K){{a7>y{D4^000SaNLh0L01ejw01ejxLMWSf00007bV*G
2ipW2
z4jK?)vG=C{00EOpL_t(I%gvHKXcJ)=$A8az=UrM_GKiyCkyHhVV3X7@B%6~6f(S0s
zLELoFT@f8boYcWVaBz^|;L<$^*1Jof$>x@&xE8A>y?FO=!aGDaMS<x=lT4-?*so@ zcC=Q1E^Ofs@piuxH@D1@W5*Ah%WoQ-HtE@9;6L>R69of?+r@Kp2b|??U=M)I9)1~T z)Al!O9%?jp2RZM6SzuAvqM^sYs$YQ6?swwmOtV=EJ
dl3W(7&0?Bdw@HxK|SAZ}C
zY<lhM3(zUVK%Si&J9h@@E+Ao#3K6Qc#slCMu$t%Yq;ubLa1l@j?({qHZL8MiUxP0E
z!qhdXZFp17!0l<djg~mcQ#x1dlsY-M#YR)FNrS!azf!RgU78_D?@f~(_gLZ-}}~u
#r~>7~M(Vy8;
pU<K>10aK)-DZ+{SNY@1)-7c@*TUuJ#%JZxB#!JNI9SHCHNqhqE z00>GeNM&H;na(foC<buoX9P*3?N%EqZ
y_BBuRcd<)Y&$rD+BbhG8B>(I@^(eFuj8
Vl*T;7e7pbv002ovPDHLkV1j5N=cWJv
literal 0
HcmV?d00001
diff --git a/public/images/edit.png b/public/images/edit.png
new file mode 100644
index 0000000000000000000000000000000000000000…ac37b63e5c3b3b0a6c4f7df7e751248fb72900d8
GIT binary patch
literal 528
zcmV+r0L8aP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00001b5ch_0Itp) z=>Px#24YJ
L;(K){{a7>y{D4^000SaNLh0L01ejw01ejxLMWSf00007bVG2ipS? z0}nSQOAG%100EFmL_t(I%gvI%iW6ZJ#eXL=!?<K5h4Bew7kmH_{~%#zKnRE+7{Nxi z5Ib$OS40aDE48o?EG$GUY_>|i5Cm~qQuqco!6GRZ4a}0{n
@IuP!sIHuoOxy_|F4
zzrgz=UxKaEB3uKO&dQ!uXo≥YU}=|vpJ&qFiYkhF@RSPY#
=a~1t2OI@3v&ThI
z9M<2+Y5D-DwWDdU<=rhv}0yZf&Fleg<hJbjc&Jl$jsgYTaxz1<MHKcwR&rQ)32D> z#wz({CNp~loB_Ug?=K
tat^o;81Q7R1?Su&;0~}K1i@+VeF^LWH8Z=HW!YUh=iULA
zmj3#q(dcBoUcUi6116Hrhhg}6GMVg3+LZLR(P&(eWECL(g?QR(wLI`(j;{}g!w<9B
z?2VNpdZKaHAx1bHS)g$$#gnRq9}R@+yuUw@-O628+AUIrkd4y7c=gP193A01!pd
z0H^^6Wm#U#^L(&O^d}1ki<HiL4M5U%p67eNMR{F#f*|k!MNyQ^X7d~WW&HrjC7GAF
S8u)1d0000<MNUMnLSTabyx<G~
literal 0
HcmV?d00001
diff --git a/public/javascripts/application.js b/public/javascripts/application.js
index 04fcb6f…dd4c2c4 100644
— a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -70,34 +70,6 @@ function template_info(div, url) {
}
-// Settings edit
-function edit_setting(name, url) {
- var html = $(’’).appendTo(‘body’).load(url + " #content");
- html.dialog({
- modal: true,
- title: "Editing " + name,
- width: 700,
- height: 250,
- close: function(event, ui) {},
- buttons: [
-
{
-
text: "OK",
-
click: function() {
-
$("form").submit();
-
$( this ).dialog( "close" );
-
},
-
},{
-
text: "Cancel",
-
click: function() {
-
$( this ).dialog( "close" );
-
}
-
}
- ]
- });
- return false;
-}
function get_pie_chart(div, url) {
if($("#"+div)[0] == undefined)
{
@@ -161,11 +133,14 @@ function pie_chart(div, title, data) {
$(document).ready(function() {
var common_settings = {
method : ‘PUT’,
- cancel : ‘Cancel’,
submit : ‘Save’,
indicator : “”,
tooltip : ‘Click to edit…’,
placeholder : ‘Click to edit…’,
submitdata : {authenticity_token: AUTH_TOKEN, format : “json”}, - onedit : function(data) { $(this).removeClass(“editable”); },
- 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’)]);
@@ -181,6 +156,7 @@ $(document).ready(function() {
var settings = {
type : ‘text’,
name : $(this).attr(‘name’), -
};width: '100%',
$(this).editable($(this).attr(‘data-url’), $.extend(common_settings, settings));
});
diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css
index 136cf23…f9d7657 100644
— a/public/stylesheets/style.css
+++ b/public/stylesheets/style.css
@@ -586,3 +586,12 @@ a.button:active span {
overflow: hidden;
display: none;
}
+.editable {
- background: url("…/images/edit.png") no-repeat scroll 98% 6px transparent;
- cursor: pointer;
- padding: 4px 26px 4px 0px;
+}
+.editable:hover { - background: url("…/images/edit-hover.png") no-repeat scroll 98% 6px #F2F2F2;
+}
–
1.7.6.2