public
Description: HomeMarks is a web based GUI to build HTML start pages.
Homepage: http://www.homemarks.com/
Clone URL: git://github.com/metaskills/homemarks.git
Click here to lend your support to: homemarks and make a donation at www.pledgie.com !
homemarks / app / helpers / application_helper.rb
100644 260 lines (213 sloc) 9.831 kb
1
2
3
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
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
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
106
107
108
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
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
260
module ApplicationHelper
  
  include AuthSystem::Helpers
  include CacheMasters::UrlPaths
  
  
  def make_msg(type,message)
    page.hide :loading
    page.<< "Element.addClassName('hud','#{type}');"
    page.replace_html :message_wrapper, "<span id='message' class='msg_#{type}'>#{message}</span>"
    page.delay(5) do
      page.<< "Element.removeClassName('hud','#{type}');"
      page.visual_effect :fade, 'message'
    end
  end
  
  def toggle_ajaxsiteform
    visual_effect(:toggle_blind, 'ajaxforms_wrapper', :duration => 0.4, :queue => {:position => 'end', :scope => 'ajaxforms'})
  end
  
  def complete_ajax_form(mood, formid, loadid='form_loading')
    page.replace_html loadid, %|<span id="complete_ajax_form_#{loadid}" style="margin:0;padding:0;"><img src="/stylesheets/images/site/#{mood}.png" /></span>|
    page.delay(2) do
      page.visual_effect :fade, "complete_ajax_form_#{loadid}"
    end
    page.<< "Form.enable('#{formid}');"
  end
  
  def complete_forgotpw_form(mood)
    page.complete_ajax_form(mood,'forgotpw_form')
    if mood=='good'
      page['forgotpw_email'].value = 'Reset password email sent.'
      page<< %| $('forgotpw_email').setStyle({backgroundColor:'#96ff1f'}) |
      page['forgotpw_submit'].disable
      page['forgotpw_cancel'].disable
    end
  end
  
  def complete_support_form(mood)
    page.complete_ajax_form(mood,'request_support_form')
    if mood=='good'
      page.delay(1.5){toggle_ajaxsiteform}
      page.delay(2){page['request_support_form'].reset}
    end
  end
  
  def redirect_function(location)
    %Q{window.location.href='#{location}'}
  end
  
  def redirect_function_url_for(location)
    %Q{window.location.href='#{url_for(location)}'}
  end
  
  
  
  def link_to_remote_for_column_delete(col)
    link_to_remote( content_tag('span', '', :class => 'ctl_close'),
                  { :confirm => 'Are you sure? Deleting a COLUMN will also delete all the boxes and bookmarks within it.',
                    :url => column_destroy_url(:id => col.id),
                    :before => 'this.blur(); globalLoadingBehavior()' })
  end
  
  def link_to_remote_for_column_add(col)
    link_to_remote( content_tag('span', '', :class => 'ctl_add'),
                  { :url => box_new_url(:id => col.id),
                    :before => 'this.blur(); globalLoadingBehavior()' })
  end
  
  def link_to_remote_for_box_actions(box, action_dir)
    span_class = 'box_action' if action_dir == 'down'
    span_class = 'box_action box_action_down' if action_dir == 'up'
    link_to_remote( content_tag('span', '', :id => "boxid_#{box.id}_action", :class => span_class),
                  { :url => {:controller => 'box', :action => "actions_#{action_dir}", :id => box.id, :collapsed => box.collapsed?},
                    :before => "this.blur(); globalLoadingBehavior(); loadLameActionSpan(#{box.id},'#{action_dir}')" },
                    :id => "boxid_#{box.id}_action_alink" )
  end
  
  def link_to_remote_for_box_title(box)
    link_to_remote( h(box.title),
                  { :url => box_collapse_url(:id => box.id),
                    :before => "this.blur(); globalLoadingBehavior(); loadLameActionSpan(#{box.id},'up')" },
                    :id => "boxid_#{box.id}_title" )
  end
  
  def link_to_remote_for_box_delete(box)
    link_to_remote( content_tag('span', '', :class => 'box_delete'),
                  { :confirm => 'Are you sure? Deleting a BOX will also delete all the bookmarks within it.',
                    :url => box_destroy_url(:id => box.id),
                    :before => 'this.blur(); globalLoadingBehavior()' } )
  end
  
  def link_to_remote_for_box_color_swatches(box,swatch)
    link_to_remote( content_tag('span', '', :class => "box_swatch swatch_#{swatch}"),
                    :url => change_color_url(:id => box.id, :color => swatch),
                    :before => "this.blur(); $('boxid_#{box.id}_style').classNames().set('box #{swatch}')" )
  end
  
  def link_to_remote_for_box_edit_links(box)
    link_to_remote( content_tag('span', '', :class => 'box_edit'),
                    :url => edit_links_url(:id => box.id),
                    :before => "this.blur(); setupModal(#{box.id})",
                    :loading => "Element.show('modal_progress')" )
  end
  
  def link_to_remote_for_bookmark_new(box)
    link_to_remote( image_tag('/stylesheets/images/modal/command_new-bookmark2.png', :alt => 'New Bookmark', :class => 'modal_command_new'),
                    :url => new_in_box_url(:id => box.id),
                    :before => 'this.blur()' )
  end
  
  def link_to_remote_for_actionarea_inbox
    link_to_remote( content_tag('span', '', :id => 'legend_inbox' ),
                   {:url => show_inbox_url,
                    :condition => 'isActionAreaDisplayed(this)',
                    :before => "loadingActionArea(this)"},
                    :id => 'legend_inbox_link')
  end
  
  def link_to_remote_for_actionarea_trashbox
    link_to_remote( content_tag('span', '', :id => 'legend_trash' ),
                   {:url => show_trashbox_url,
                    :condition => 'isActionAreaDisplayed(this)',
                    :before => "loadingActionArea(this)"},
                    :id => 'legend_trash_link')
  end
  
  def bookmark_list_item
    %q|<li id="<%= box_type %>bmark_<%= bmark.id %>" class="dragable_bmarks clearfix <%= box_type %>"><span class="bmrk_handle">&nbsp;</span><span class="boxlink"><a href="<%= h(bmark.url) %>"><%= h(bmark.name) %></a></span></li>|
  end
  
  def complete_action_area(box_list)
    page['fieldset_progress_wrap'].visual_effect :blind_up, { :duration => 0.35 }
    page[box_list].visual_effect :blind_down, { :duration => 0.35 }
  end
  
  def update_new_trashboxmark_ui_elements_and_message
    page.<< "$('trashcan').classNames().set('trash_full'); showOrHideEmptyTrashBox();"
    page.make_msg('good','Bookmark moved to trash.')
  end
  
  def remove_all_trashboxmark_ui_elements_and_message(trashempty)
    page.<< "$('trashcan').classNames().set('trash_empty'); showOrHideEmptyTrashBox();" if trashempty
    page.make_msg('good','Permanently deleted.')
  end
  
  def empty_trash_function
    remote_function( :url => empty_trash_url,
                     :confirm => 'Are you sure? This will permanently delete all bookmarks in your trash.' )
  end
  
  
  
  def create_box_sortables(user)
    user.columns.each do |col|
      page.create_box_sortables_code(user, col)
    end
  end
  
  def create_bookmark_sortables(user)
    user.boxes.each do |box|
      page.create_bookmark_sortables_code(user, box)
    end
  end
  
  def create_column_sortable
    page.sortable :col_wrapper,
                  :handle => 'ctl_handle',
                  :tag => 'div',
                  :only => 'dragable_columns',
                  :containment => 'col_wrapper',
                  :constraint => false,
                  :dropOnEmpty => true,
                  :url => {:controller => 'column', :action => 'sort'},
                  :before => 'globalLoadingBehavior()',
                  :with => 'findSortedInfo(this)'
  end
  
  def create_box_sortables_code(user, col)
    page.sortable "col_#{col.id}",
                  :tag => 'div',
                  :only => 'dragable_boxes',
                  :hoverclass => 'column_hover',
                  :accept => 'dragable_boxes',
                  :handle => 'box_handle',
                  :containment => user.column_containment_array,
                  :constraint => false,
                  :dropOnEmpty => true,
                  :url => { :controller => 'box', :action => 'sort' },
                  :before => 'globalLoadingBehavior()',
                  :with => 'findDroppedBoxInfo(this)'
  end
  
  def create_bookmark_sortables_code(user, box)
    sortable_id = case box
                  when Box : "boxid_list_#{box.id}"
                  when Inbox : 'inbox_list'
                  when Trashbox : 'trashbox_list'
                  end
    page.sortable sortable_id,
                  :accept => 'dragable_bmarks',
                  :handle => 'bmrk_handle',
                  :containment => user.box_containment_array,
                  :constraint => false,
                  :dropOnEmpty => true,
                  :url => { :controller => 'bookmark', :action => 'sort' },
                  :before => 'globalLoadingBehavior()',
                  :with => 'findDroppedBookmarkInfo(this)'
  end
  
  def reorder_then_create_box_sortables(col,user)
    # Due to some bug, affected column needs to be first in the array before create sortable code fires.
    ucols = user.columns
    ucols.slice!(ucols.index(col))
    ucols.unshift(col).each do |sortcol|
      page.create_box_sortables_code(user, sortcol)
    end
  end
  
  
  
  def blind_box_parts(box, node, direction)
    case
      when direction == :up
        page["boxid_#{box.id}_#{node}"].visual_effect :blind_up, { :duration => 0.35, :queue => {:position => 'end', :scope => "boxid_#{box.id}"} }
      when direction == :down
        page["boxid_#{box.id}_#{node}"].visual_effect :blind_down, { :duration => 0.35, :queue => {:position => 'end', :scope => "boxid_#{box.id}"} }
    end
  end
  
  def blind_new_box(box)
    page["boxid_#{box.id}"].visual_effect :blind_down, { :duration => 0.35, :queue => {:position => 'end', :scope => "boxid_#{box.id}"} }
  end
  
  
  
  def render_bookmarklet
    js = render :partial => 'bookmarklet/bookmarklet'
    js.gsub!('<script>','')
    js.gsub!('</script>','')
    js.gsub!(/ {2,}/,'')
    js.gsub!(/\n/,'')
    js.gsub!(/ /,'%20')
    js
  end
  
  def render_bookmarklet_save_button
    js = render :partial => 'bookmarklet/add_button'
    js.gsub!('<script>','')
    js.gsub!('</script>','')
    js.gsub!(/ {2,}/,'')
    js.gsub!(/\n/,'')
    js
  end
  
 
  
  
end