Module: Jipe::Helpers
- Defined in:
- lib/jipe.rb
Instance Method Summary collapse
- #jipe_editor(record, field, options = {}) ⇒ Object
- #jipe_editor_for(record, field, options = {}) ⇒ Object
- #jipe_id_for(record, field, options = {}) ⇒ Object
- #jipe_image_toggle(record, field, true_image, false_image, options = {}) ⇒ Object
- #jipe_select_field(record, field, choices, options = {}, html_options = {}) ⇒ Object
Instance Method Details
#jipe_editor(record, field, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/jipe.rb', line 61 def jipe_editor(record, field, = {}) = { :external_control => true, :class => record.class.to_s, :rows => 1, :editing => true, :on_complete => nil }.update( || {}) rclass = [:class] outstr = <<-ENDDOC <span id="#{jipe_id_for(record, field, )}"> #{record.send(field).to_s} </span> ENDDOC if [:editing] outstr += <<-ENDDOC #{ [:external_control] ? image_tag("jipe/edit-field.png", { :id => "edit_#{jipe_id_for(record, field, )}" }) : "" } #{ jipe_editor_for(record, field, )} ENDDOC end return outstr.html_safe end |
#jipe_editor_for(record, field, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jipe.rb', line 23 def jipe_editor_for(record, field, = {}) = { :external_control => true, :class => record.class.to_s, :rows => 1 }.update( || {}) rclass = [:class] outstr = <<-ENDDOC <script type="text/javascript"> new Jipe.InPlaceEditor("#{jipe_id_for(record, field, )}", #{rclass}, #{record.id}, #{field.to_json}, { ENDDOC if [:external_control] outstr << "externalControl: 'edit_#{jipe_id_for(record, field, )}', " .delete(:external_control) end if [:on_complete] outstr << "onComplete: #{[:on_complete]}, " .delete(:on_complete) end if protect_against_forgery? outstr << "authenticityToken: '#{form_authenticity_token}', " end outstr << "rows: #{[:rows]}," .delete(:rows) .delete(:id) # everything else is ajax options outstr << "ajaxOptions: {" .each_pair do |k, v| outstr << "'#{escape_javascript k.to_s}': '#{escape_javascript v.to_s}'," end unless [:attributes] outstr << "'attributes[]': '#{escape_javascript field.to_s}'" end outstr << "}});\n</script>" return outstr.html_safe end |
#jipe_id_for(record, field, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jipe.rb', line 11 def jipe_id_for(record, field, = {}) = { :class => record.class.to_s, :id => nil }.update( || {}) rclass = [:class] if [:id] return [:id] else return "#{rclass.downcase}_#{record.id}_#{field}" end end |
#jipe_image_toggle(record, field, true_image, false_image, options = {}) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/jipe.rb', line 117 def jipe_image_toggle(record, field, true_image, false_image, = {}) = { :class => record.class.to_s, :on_complete => nil, }.update( || {}) rclass = [:class] value = record.send(field) idprefix = jipe_id_for(record, field, ) = {} ['onComplete'] = [:on_complete] if [:on_complete] if protect_against_forgery? ["authenticityToken"] = form_authenticity_token.to_json end outstr = <<-ENDDOC #{image_tag true_image, :id => "#{idprefix}_true", :style => (value ? "" : "display: none") } #{image_tag false_image, :id => "#{idprefix}_false", :style => (value ? "display: none" : "") } <script type="text/javascript"> new Jipe.ImageToggle("#{idprefix}_true", "#{idprefix}_false", #{rclass}, #{record.id}, #{field.to_json}, #{ }); </script> ENDDOC return outstr.html_safe end |
#jipe_select_field(record, field, choices, options = {}, html_options = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/jipe.rb', line 83 def jipe_select_field(record, field, choices, = {}, = {}) = { :class => record.class.to_s, :on_complete => nil, }.update( || {}) rclass = .delete(:class) value = record.send(field) id = jipe_id_for(record, field, ) = {} ['onComplete'] = .delete(:on_complete) if [:on_complete] if protect_against_forgery? ["authenticityToken"] = form_authenticity_token.to_json end .each do |k, v| if v.nil? .delete(k) elsif v.kind_of? String [k] = "'#{escape_javascript(v)}'" end end ['ajaxOptions'] = () outstr = <<-ENDDOC #{select_tag id, (choices, value), } <script type="text/javascript"> new Jipe.SelectField('#{id}', #{rclass}, #{record.id}, #{field.to_json}, #{ }); </script> ENDDOC return outstr.html_safe end |