Module: AdminHelper

Defined in:
app/helpers/admin_helper.rb

Instance Method Summary collapse

Instance Method Details

#children(i) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'app/helpers/admin_helper.rb', line 175

def children(i)
    html = ""
    html << "<li id=\"list_#{i.id}\">"
    html <<"<div>"

    html << expand_button(i)
    if i.has_attribute?("visible")
      html << visible_button(i)
    end
    html <<"#{link_to i.title, [:edit, :admin, i], :class=>'title'}" 
    

    html << delete_button(i)  
    html << "</div>"
    

    unless i.children.empty?
      html << "<ol>"
      i.children.order('position').each do |child|
        html << children(child)
      end
      html << "</ol>"
    end
    html << "</li>"
    return html
end

#cropable(image_name, x, y, w, h) ⇒ Object



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
# File 'app/helpers/admin_helper.rb', line 58

def cropable(image_name, x,y,w,h)
  %Q{
    <script type="text/javascript">
      function jcropInit() {

        $('.preview_crop').width(#{w}).height(#{h});
        
        $("#cropbox").Jcrop({
          aspectRatio: #{w}/#{h},
          onSelect: showCoords,
          onChange: showCoords,
          minSize: [30,30],
          bgColor: '#fff',
          bgOpacity:   .4,
        });

        function showCoords(c) {
          $("##{image_name}_crop_x").val(c.x);
          $("##{image_name}_crop_y").val(c.y);
          $("##{image_name}_crop_w").val(c.w);
          $("##{image_name}_crop_h").val(c.h);
          updatePreview(c);
        };

        function updatePreview(c) {
          $("#preview").css(
            {'width': Math.round(#{w}/c.w * $("#cropbox").width()) + 'px',
            'height': Math.round(#{h}/c.wh * $("#cropbox").height()) + 'px',
            "margin-left": "-" + Math.round(#{w}/c.w * c.x) + 'px',
            "margin-top": "-" + Math.round(#{h}/c.h * c.y) + 'px'}
            );
        }; 

        $("#cropbox").parents("body").css("min-width","600px");

      };
    </script>
  }.gsub(/[\n ]+/, ' ').strip.html_safe
end

#current_url(overwrite = {}) ⇒ Object



105
106
107
# File 'app/helpers/admin_helper.rb', line 105

def current_url(overwrite={})
  url_for :only_path => false, :params => params.merge(overwrite)
end

#delete_button(object) ⇒ Object



212
213
214
215
216
217
# File 'app/helpers/admin_helper.rb', line 212

def delete_button(object)
  link_to [:admin, object], :class => :del, :confirm => 'Точно удалить?', :method => :delete do
      raw("<span> Удалить </span>")
      raw("<i class='icon-trash icon-large'> </i>")
  end
end

#expand_button(i) ⇒ Object



202
203
204
# File 'app/helpers/admin_helper.rb', line 202

def expand_button(i)
  link_to '', '#', :class=>"expand plus #{'non-display' if i.children.empty?}"
end

#image_sortable(images) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/helpers/admin_helper.rb', line 109

def image_sortable(images)
  sort_url = "sort_admin_#{images.to_s}_path(:auth_token => current_user.authentication_token)"
  %Q{
    <script type="text/javascript">
      $(document).ready(function() {
        $('.image-list').sortable( {
          start: function(){$(this).find("a:not(.del)").unbind("click")},
          stop: function(){lightBox.reload()},            
          dropOnEmpty: false,
          cursor: 'crosshair',
          opacity: 0.75,
          items: 'li',
          scroll: true,
          update: function() {
            $.ajax( {
              type: 'post',
              data: $('.image-list').sortable('serialize') + '&authenticity_token=#{u(form_authenticity_token)}',
              dataType: 'script',
              url: '#{eval(sort_url)}'})
            }
          });
        });
    </script>
  }.gsub(/[\n ]+/, ' ').strip.html_safe
end

#multiple_sortable(table_id, url) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/admin_helper.rb', line 4

def multiple_sortable(table_id, url)
  %Q{
    <script type="text/javascript">
      $(document).ready(function() {
        $("##{table_id} tbody").sortable( {
          placeholder: 'ui-sortable-placeholder',
          forcePlaceholderSize: true,
          dropOnEmpty: false,
          cursor: 'crosshair',
          opacity: 0.75,
          items: 'tr',
          handle: '.handle',
          scroll: true,
          update: function() {
            $.ajax( {
              type: 'post',
              data: $("##{table_id} tbody").sortable('serialize') + '&authenticity_token=#{u(form_authenticity_token)}',
              dataType: 'script',
              url: '#{url}'
              })
            }
          });
        });
    </script>
  }.gsub(/[\n ]+/, ' ').strip.html_safe
end

#show_tree(items) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
# File 'app/helpers/admin_helper.rb', line 161

def show_tree(items)
  html = ""
  html << "<ol#{" class='sortable'"}>"

  items.where(:ancestry => nil).order(:position).each do |i|
    html << children(i)
  end

  html << "</ol>"
  
  return raw(html)
end

#sort_tree(url, maxlevels) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'app/helpers/admin_helper.rb', line 219

def sort_tree(url, maxlevels)
  %Q{
    <script type="text/javascript">
      $(document).ready(function(){

        $('ol.sortable').nestedSortable({
          disableNesting: 'no-nest',
          forcePlaceholderSize: true,
          handle: 'div',
          helper: 'clone',
          items: 'li',
          maxLevels: #{maxlevels},
          opacity: .6,
          placeholder: 'placeholder',
          revert: 250,
          tabSize: 25,
          tolerance: 'pointer',
          toleranceElement: '> div',
          update: function(){
            var serialized = $('ol.sortable').nestedSortable('serialize');
            $.ajax({url: '#{url}', data: serialized});

            $('ol.sortable .expand').each(function(){
              var $inlist = $(this).parent('div').siblings("ol").first();
              if ($inlist.find('li').length === 0) {
                $(this).addClass('non-display');
              } else {
                if ($inlist.css('display') == 'none') {
                  $(this).addClass('plus').removeClass('minus');
                } else {
                  $(this).addClass('minus').removeClass('plus');
                }
                $(this).removeClass('non-display');
              }
            });
          }
        });
      });
    </script>
  }.gsub(/[\n ]+/, ' ').strip.html_safe
end

#sortable(url) ⇒ Object



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
# File 'app/helpers/admin_helper.rb', line 31

def sortable(url)
  %Q{
    <script type="text/javascript">
      $(document).ready(function() {
        $('#sort-list tbody').sortable( {
          placeholder: 'ui-sortable-placeholder',
          forcePlaceholderSize: true,
          dropOnEmpty: false,
          cursor: 'crosshair',
          opacity: 0.75,
          items: 'tr',
          handle: '.handle',
          scroll: true,
          update: function() {
            $.ajax( {
              type: 'post',
              data: $('#sort-list tbody').sortable('serialize') + '&authenticity_token=#{u(form_authenticity_token)}',
              dataType: 'script',
              url: '#{url}'
              })
            }
          });
        });
    </script>
  }.gsub(/[\n ]+/, ' ').strip.html_safe
end

#sortable_columns(column, title = nil) ⇒ Object



98
99
100
101
102
103
# File 'app/helpers/admin_helper.rb', line 98

def sortable_columns(column, title = nil)
  title ||= column.titleize
  css_class = column == sort_column ? "current #{sort_direction}" : nil
  direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
  link_to title, {:sort => column, :direction => direction}, {:class => css_class}
end

#upload_form(parent, image) ⇒ Object



135
136
137
138
139
140
141
# File 'app/helpers/admin_helper.rb', line 135

def upload_form(parent, image)
  new_image = image.new
  undercored_image = image.to_s.underscore
  form_for [:admin, parent, new_image], :id => "upload_form" do |f|
    file_field_tag :image, multiple: true, name: "#{undercored_image}[image]"
  end
end

#upload_scriptObject



143
144
145
146
147
148
149
150
151
152
# File 'app/helpers/admin_helper.rb', line 143

def upload_script
  html = ''
  html << "<script id='template-upload' type=\"text/x-tmpl\">"
  html <<  "<div class='upload'>"
  html << '{%= o.name %}'
  html << "<div class='progress'>"
  html <<  "<div class='bar' style=\"width: 0%\">"
  html <<  "</div></div></div></script>"
  return raw html
end

#uploader(parent, image) ⇒ Object



154
155
156
157
158
159
# File 'app/helpers/admin_helper.rb', line 154

def uploader(parent, image)
  html = ''
  html << "#{upload_form(parent, image)}"
  html << "#{upload_script}"
  return raw html
end

#visible_button(object) ⇒ Object



206
207
208
209
210
# File 'app/helpers/admin_helper.rb', line 206

def visible_button(object)
  link_to [:toggleshow, :admin, object], :remote => true, :class=>"toggleshow" do
    raw("<i class=\'#{object.visible? ? 'icon-eye-open icon-large' : 'icon-eye-close icon-large not-work'}\'></i>")
  end
end