Module: Ztree::Helpers

Included in:
ApplicationHelper
Defined in:
lib/ztree/helpers.rb

Instance Method Summary collapse

Instance Method Details

#init_tree_js(link_title = '') ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ztree/helpers.rb', line 10

def init_tree_js(link_title = '')
  js = '$(document).ready(function(){
      $.fn.zTree.init($("#" + treeOpts.current_tree), ztreeSetting, treeOpts.zNodes);
    '
  js += '$(".new_btn").click(function (){
       loading(".menu_content");
       $(".menu_content").load(treeOpts.url + "new");
         return false;
       })' unless link_title.empty?
  js += '});'
  javascript_tag(js)
end

#tip_messagesObject



41
42
43
44
# File 'lib/ztree/helpers.rb', line 41

def tip_messages
  (:span, "操作成功!", class: 'success hide') +
    (:span, "操作失败,原因:"+(flash[:error].to_s), class: 'failed hide')
end

#tree_content(link_title = '', opts = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ztree/helpers.rb', line 23

def tree_content(link_title = '', opts = {})
  if link_title.empty?
    header = ''.html_safe
  else
    title_link = link_to link_title, opts[:url], :class => "btn btn-small btn-primary new_btn"
    header =  :div, title_link + tip_messages, class: 'page-header'
  end
  right_content =  :div, '', class: "menu_content fl"
  list_content =  :div, tree_list(link_title, style: '') + right_content
  js = '$(document).ready(function(){'
  js += '$(".menu_content").load("' + opts[:current_url] + '");' if opts[:current_url].present?
  js += 'var current_node = $.fn.zTree.getZTreeObj("tree-list").getNodeByParam("id", '+ opts[:current_id] +');
     $.fn.zTree.getZTreeObj("tree-list").selectNode(current_node);
    ' if opts[:current_id].present?
  js += '});'
  (:section, header + list_content + javascript_tag(js), id: 'tables')
end

#tree_list(link_title = '', opts = {}) ⇒ Object



4
5
6
7
8
# File 'lib/ztree/helpers.rb', line 4

def tree_list(link_title = '', opts = {})
  id, cls_name = opts[:id] || 'tree-list', opts[:class] || 'menus_ztree ztree small' 
  ul =  :ul, '', {id: id, class: cls_name, style: "width:260px; overflow:auto;"}.merge(opts)
  init_tree_js(link_title) +  (:div, ul, class: 'ground fl')
end