Module: ActionView::Helpers
- Defined in:
- lib/ztree/helpers.rb
Instance Method Summary collapse
- #h_to_j(h) ⇒ Object
- #init_tree(link_title = "", opts = {}, ztree_opts = {}) ⇒ Object
- #tree_list(link_title = '', opts = {}, ztree_opts = {}) ⇒ Object
- #ztree_settings(opts = {}) ⇒ Object
Instance Method Details
#h_to_j(h) ⇒ Object
72 73 74 |
# File 'lib/ztree/helpers.rb', line 72 def h_to_j(h) h.to_json.html_safe.delete("\"").gsub("=>",": ") end |
#init_tree(link_title = "", opts = {}, ztree_opts = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ztree/helpers.rb', line 11 def init_tree(link_title = "", opts = {}, ztree_opts = {}) js = "$(document).ready(function(){ if (typeof(treeOpts) == 'undefined'){ treeOpts = #{{ zNodes: ztree_opts[:zNodes] || [], current_tree: "#{opts[:id] || "tree-list"}", url: "#{ztree_opts[:url] || "/"}" }.to_json} } if (typeof(ztreeSetting) == 'undefined'){ ztreeSetting = #{ztree_settings(ztree_opts[:settings] || {})} } $.fn.zTree.init($('#' + treeOpts.current_tree), ztreeSetting, treeOpts.zNodes); " js << '});' javascript_tag(js) end |
#tree_list(link_title = '', opts = {}, ztree_opts = {}) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/ztree/helpers.rb', line 4 def tree_list(link_title = '', opts = {}, ztree_opts = {}) id, cls_name = opts[:id] || 'tree-list', opts[:class] || 'menus_ztree ztree small' ul = content_tag :ul, '', {id: id, class: cls_name, style: "width:260px; overflow:auto;"}.merge(opts) return init_tree_js(link_title) + content_tag(:div, ul, class: 'ground fl') if defined? init_tree_js init_tree(link_title, opts, ztree_opts) + content_tag(:div, ul, class: 'ground fl') end |
#ztree_settings(opts = {}) ⇒ Object
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 |
# File 'lib/ztree/helpers.rb', line 29 def ztree_settings(opts = {}) default_settings = { view: { addHoverDom: "addHoverDom", removeHoverDom: "removeHoverDom", selectedMulti: false, }, check: { #enable: true }, edit: { enable: true, editNameSelectAll: true, showRemoveBtn: true, showRenameBtn: true, drag: { isCopy: true, isMove: true, prev: true, inner: false, next: true, } }, data: { simpleData: { enable: true } }, callback: { beforeDrag: "beforeDrag", beforeDrop: "beforeDrop", beforeEditName: "beforeEditName", beforeRemove: "beforeRemove", onDrop: "onDrop", onRemove: "onRemove", beforeRename: "beforeRename", onRename: "onRename", onClick: "onClick", } } h_to_j default_settings.merge(opts) end |