Class: C80Yax::ItemDecorator
- Inherits:
-
ApplicationDecorator
- Object
- ApplicationDecorator
- C80Yax::ItemDecorator
- Defined in:
- app/decorators/c80_yax/item_decorator.rb
Instance Method Summary collapse
- #_uom(v) ⇒ Object
- #btn_order ⇒ Object
- #div_p_desc ⇒ Object
- #div_prices ⇒ Object
-
#fetch_first_photo(thumb_size = 'thumb_md') ⇒ Object
выдать url миниатюры указанного
thumb_sizeтипа первой попавшейся фотки обьекта. - #fetch_hh(thumb_size = 'thumb_md') ⇒ Object
- #fetch_ww(thumb_size = 'thumb_md') ⇒ Object
- #h1_title ⇒ Object
- #h3_title(thumb_size = 'thumb_md') ⇒ Object
- #images_no_main(thumb_size = 'thumb_sm') ⇒ Object
- #main_image(thumb_size = 'thumb_md', options = {}) ⇒ Object
- #my_url ⇒ Object
- #props_list ⇒ Object
Instance Method Details
#_uom(v) ⇒ Object
107 108 109 110 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 107 def _uom(v) return '' if v.nil? v end |
#btn_order ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 112 def btn_order unless model.is_ask_price h.link_to '', '#', class: "add_to_bucket_sm add_to_bucket_sm_#{model.id}", data: {id: model.id} end end |
#div_p_desc ⇒ Object
149 150 151 152 153 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 149 def div_p_desc res = '' res = model.desc.html_safe if model.desc.present? "<div class='work_desc'>#{res}</div>".html_safe end |
#div_prices ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 36 def div_prices # Rails.logger.debug '[TRACE] <ItemDecorator.div_prices> ------[begin]--------' result = '' if model.is_ask_price result = "<p class='is_ask_price c80_refine_price_button' data-item-url='#{ my_url }' data-item-id='#{ model.id }' data-item-title='#{ model.title }'>Уточнить цену</p> " else # <editor-fold desc="# парсим данные в структуру для view"> props = { titles: [], values: [], uoms: [], values_old: [] } model.item_props.each do |ip| # Rails.logger.debug "[TRACE] <ItemDecorator.div_prices> ip.prop_name.related.present? = #{ip.prop_name.related.present?}" if ip.prop_name.is_normal_price props[:titles] << ip.prop_name.title props[:values] << ip.value props[:uoms] << ip.prop_name.uom_title # у свойства "нормальная цена" может быть "старый вариант" if ip.prop_name..present? # фиксируем айдишник свойства "старый вариант этой цены" = ip.prop_name..id # и зафиксирем его значение model.item_props.each do |iip| # Rails.logger.debug "[TRACE] <ItemDecorator.div_prices> iip.prop_name.id = #{iip.prop_name.id} VS #{related_id}" if iip.prop_name.id == # props[:titles] << iip.prop_name.title props[:values_old] << iip.value # props[:uoms] << iip.prop_name.uom_title break end end end end end # Rails.logger.debug "[TRACE] <ItemDecorator.div_prices> props: #{props}" # </editor-fold> # <editor-fold desc="# собираем html-строку (список)"> res = '' props[:titles].each_with_index do |title, i| e = "<p data-title='#{title}' class='old'><span class='pvalue bold'>#{props[:values_old][i]}</span> <span class='puom'>#{_uom(props[:uoms][i])}</span></p>" # 1212,80 руб e += "<p data-title='#{title}' class='cur'><span class='pvalue bold'>#{props[:values][i]}</span> <span class='puom'>#{_uom(props[:uoms][i])}</span></p>" # 1212,80 руб e = "<li>#{e}</li>" res += e end # Rails.logger.debug '[TRACE] <ItemDecorator.div_prices> ------- [end] ------- ' result = "<ul>#{res}</ul>" # </editor-fold> end "<div class='price_props'>#{result}</div>".html_safe end |
#fetch_first_photo(thumb_size = 'thumb_md') ⇒ Object
выдать url миниатюры указанного thumb_size типа первой попавшейся фотки обьекта
158 159 160 161 162 163 164 165 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 158 def fetch_first_photo(thumb_size = 'thumb_md') Rails.logger.debug '[TRACE] <ItemDecorator.fetch_first_photo>' res = '' if model.iphotos.size > 0 res = model.iphotos.first.image.send(thumb_size) end res end |
#fetch_hh(thumb_size = 'thumb_md') ⇒ Object
172 173 174 175 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 172 def fetch_hh(thumb_size = 'thumb_md') Rails.logger.debug '[TRACE] <ItemDecorator.fetch_hh>' @hh ||= ItemPhotosSizesCache.instance.thumb_height(thumb_size) end |
#fetch_ww(thumb_size = 'thumb_md') ⇒ Object
167 168 169 170 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 167 def fetch_ww(thumb_size = 'thumb_md') Rails.logger.debug '[TRACE] <ItemDecorator.fetch_ww>' @ww ||= ItemPhotosSizesCache.instance.thumb_width(thumb_size) end |
#h1_title ⇒ Object
122 123 124 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 122 def h1_title h.content_tag :h1, model.title end |
#h3_title(thumb_size = 'thumb_md') ⇒ Object
31 32 33 34 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 31 def h3_title(thumb_size = 'thumb_md') ww = fetch_ww(thumb_size) h.content_tag :h3, model.title, style: "width:#{ww}px" end |
#images_no_main(thumb_size = 'thumb_sm') ⇒ Object
138 139 140 141 142 143 144 145 146 147 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 138 def images_no_main(thumb_size = 'thumb_sm') res = '' model.iphotos.each_with_index do |wp, index| next if index.zero? img = h.image_tag wp.image.send(thumb_size).url lnk = h.link_to img, wp.image.thumb_lg.url res += "<li>#{lnk}</li>" end "<ul class='item_images_no_main'>#{res}</ul>".html_safe end |
#main_image(thumb_size = 'thumb_md', options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 10 def main_image(thumb_size = 'thumb_md', = {}) rel = .fetch(:rel, 'follow') a_href = .fetch(:a_href, my_url) ww = fetch_ww(thumb_size) hh = fetch_hh(thumb_size) h.render_image_link_lazy({ :alt_image => model.title, # :image => main_image_tag(thumb_size), :image => self.fetch_first_photo(thumb_size), :a_href => a_href, :rel => rel, :a_class => 'item_main_image', :a_css_style => "width:#{ww}px;height:#{hh}px", :image_width => ww, :image_height => hh }) end |
#my_url ⇒ Object
6 7 8 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 6 def my_url "/katalog/#{model.strsubcat.slug}/#{model.id}" end |
#props_list ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/decorators/c80_yax/item_decorator.rb', line 126 def props_list res = '' ps = %w(customer price duration when) ds = %w(клиент бюджет срок\ выполнения дата) ps.each_with_index do |p, index| v = model.send(p) next if v.blank? res += "<li><span class='def'>#{ds[index]}:</span> #{model.send(p)}</li>" end "<ul class='work_props_list'>#{res}</ul>".html_safe end |