Module: Ext::Helper
- Defined in:
- lib/ext/helper.rb
Instance Method Summary collapse
- #ext_css_hack ⇒ Object
- #ext_grid(options = {}) ⇒ Object
- #ext_include ⇒ Object
- #ext_js_hack ⇒ Object
- #ext_paginate(*args) ⇒ Object
- #ext_top ⇒ Object
- #ext_tree(options = {}) ⇒ Object
- #ext_tree_default_style ⇒ Object
- #ext_tree_on_move ⇒ Object
Instance Method Details
#ext_css_hack ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/ext/helper.rb', line 40 def ext_css_hack <<-CSS <style type="text/css"> .x-grid-dirty-cell { background-color: pink; } </style> CSS end |
#ext_grid(options = {}) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/ext/helper.rb', line 50 def ext_grid( = {}) = { :id => "item-grid", :style => "border:1px solid #99bbe8;overflow: hidden; height: 280px;", }.merge() content_tag :div, '', end |
#ext_include ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ext/helper.rb', line 15 def ext_include array = [] array << stylesheet_link_tag("#{ext_top}resources/css/ext-all") array << javascript_include_tag("#{ext_top}yui-utilities") array << javascript_include_tag("#{ext_top}ext-yui-adapter") if RAILS_ENV == 'development' array << javascript_include_tag("#{ext_top}ext-all-debug") else array << javascript_include_tag("#{ext_top}ext-all") end array << ext_js_hack array << ext_css_hack array.join("\n") end |
#ext_js_hack ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/ext/helper.rb', line 32 def ext_js_hack url = image_path "#{ext_top}resources/images/default/tree/s.gif" javascript_tag <<-SCRIPT Ext.BLANK_IMAGE_URL = '#{ escape_javascript(url) }'; #{Ext.patch} SCRIPT end |
#ext_paginate(*args) ⇒ Object
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 |
# File 'lib/ext/helper.rb', line 126 def ext_paginate(*args) = args.optionize(:class, :limit, :url) klass = [:class] plural = klass.name.demodulize.pluralize limit = [:limit] url = [:url] || url_for(:action=>"list") ds = [:ds] || [:ds_class].new(:class=>[:class], :url=>url) cm = [:cm] || [:cm_class].new(:class=>[:class]) grid = [:grid_class].to_json <<-EOF <script type="text/javascript"> <!-- Ext.onReady(function(){ var ds = #{ ds }; var cm = #{ cm }; ds.setDefaultSort('#{klass.primary_key}', 'asc'); cm.defaultSortable = true; #{ [:raw] } var grid = new #{grid}('item-grid', {ds: ds, cm: cm}); // render it grid.render(); var gridFoot = grid.getView().getFooterPanel(true); // add a paging toolbar to the grid's footer var paging = new Ext.PagingToolbar(gridFoot, ds, { pageSize: #{ limit }, displayInfo: true, displayMsg: 'Displaying #{plural} {0} - {1} of {2}', emptyMsg: "No #{plural} to display" }); // trigger the data store load ds.load({params:{start:0, limit:#{ limit }}}); }); // --> </script> EOF end |
#ext_top ⇒ Object
2 3 4 |
# File 'lib/ext/helper.rb', line 2 def ext_top Ext.url_prefix end |
#ext_tree(options = {}) ⇒ Object
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 |
# File 'lib/ext/helper.rb', line 77 def ext_tree( = {}) id = [:id] || 'tree-div' url = [:url] || url_for root = [:root] || "Top" style = ext_tree_default_style.merge([:style] || {}) script = <<-EOF <script type="text/javascript"> <!-- Ext.onReady(function(){ // shorthand var Tree = Ext.tree; var tree = new Tree.TreePanel('#{id}', { animate:true, loader: new Tree.TreeLoader({dataUrl:'#{url}'}), enableDD:true, containerScroll: true }); // add a tree sorter in folder mode // new Tree.TreeSorter(tree, {folderSort:true}); // set the root node var root = new Tree.AsyncTreeNode({ text: '#{root}', draggable:false, id:'root' }); tree.setRootNode(root); // render the tree tree.render(); root.expand(); #{ext_tree_on_move if [:move]} }); // --> </script> EOF style = style.map{|key,val| "#{key}:#{val}"}.join(';') div = content_tag(:div, '', :id=>id, :style=>style) return script + div end |
#ext_tree_default_style ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/ext/helper.rb', line 6 def ext_tree_default_style { :overflow => :auto, :height => "300px", :width => "250px", :border => "1px solid #c3daf9;", }.with_indifferent_access end |
#ext_tree_on_move ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ext/helper.rb', line 59 def ext_tree_on_move <<-EOF tree.addListener('move', function(tree, node, oldParent, newParent, index, refNode){ var loader = tree.loader; var buf = [loader.getParams(node)]; buf.push("&parent=", encodeURIComponent(newParent.id)); buf.push("&index=", encodeURIComponent(index)); var params = buf.join(""); loader.transId = Ext.lib.Ajax.request(loader.requestMethod, loader.dataUrl, null, params); } ); EOF end |