lipsiadmin 4.1.8 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. data/CHANGELOG +41 -2
  2. data/lib/access_control/authentication.rb +1 -1
  3. data/lib/access_control/base.rb +18 -11
  4. data/lib/controller/ext.rb +5 -3
  5. data/lib/controller/pdf_builder.rb +22 -6
  6. data/lib/controller/responds_to_parent.rb +1 -1
  7. data/lib/data_base/attachment_table.rb +0 -1
  8. data/lib/lipsiadmin.rb +7 -0
  9. data/lib/mailer/pdf_builder.rb +23 -9
  10. data/lib/version.rb +3 -3
  11. data/lib/view/helpers/backend_helper.rb +137 -97
  12. data/lib/view/helpers/ext/button.rb +62 -0
  13. data/lib/view/helpers/ext/column_model.rb +29 -23
  14. data/lib/view/helpers/ext/component.rb +52 -40
  15. data/lib/view/helpers/ext/configuration.rb +3 -2
  16. data/lib/view/helpers/ext/grid.rb +38 -40
  17. data/lib/view/helpers/ext/store.rb +12 -12
  18. data/lib/view/helpers/ext/templates/grid_functions.js.erb +14 -9
  19. data/lib/view/helpers/ext/tool_bar.rb +9 -10
  20. data/lib/view/helpers/ext_helper.rb +3 -2
  21. data/lib/view/helpers/pdf_helper.rb +45 -0
  22. data/lipsiadmin_generators/attachment/REMEMBER +0 -4
  23. data/lipsiadmin_generators/attachment/templates/migration.rb +1 -1
  24. data/lipsiadmin_generators/backend/templates/config/config.yml +2 -3
  25. data/lipsiadmin_generators/backend/templates/config/locales/backend/en.yml +2 -0
  26. data/lipsiadmin_generators/backend/templates/config/locales/backend/it.yml +2 -0
  27. data/lipsiadmin_generators/backend/templates/config/locales/models/{en.yml → account/en.yml} +0 -0
  28. data/lipsiadmin_generators/backend/templates/config/locales/models/{it.yml → account/it.yml} +0 -0
  29. data/lipsiadmin_generators/backend/templates/controllers/javascripts_controller.rb +1 -1
  30. data/lipsiadmin_generators/backend/templates/images/backend/association_break.png +0 -0
  31. data/lipsiadmin_generators/backend/templates/images/backend/association_ok.png +0 -0
  32. data/lipsiadmin_generators/backend/templates/images/backend/categories.gif +0 -0
  33. data/lipsiadmin_generators/backend/templates/images/ext/charts.swf +0 -0
  34. data/lipsiadmin_generators/backend/templates/images/ext/{slate/sizer/se-handle.gif → default/button/arrow.gif} +0 -0
  35. data/lipsiadmin_generators/backend/templates/images/ext/default/button/btn.gif +0 -0
  36. data/lipsiadmin_generators/backend/templates/images/ext/default/button/group-cs.gif +0 -0
  37. data/lipsiadmin_generators/backend/templates/images/ext/{slate/grid/grid-blue-split.gif → default/button/group-lr.gif} +0 -0
  38. data/lipsiadmin_generators/backend/templates/images/ext/{slate/grid/arrow-right-white.gif → default/button/group-tb.gif} +0 -0
  39. data/lipsiadmin_generators/backend/templates/images/ext/default/button/s-arrow-b-noline.gif +0 -0
  40. data/lipsiadmin_generators/backend/templates/images/ext/default/button/s-arrow-b.gif +0 -0
  41. data/lipsiadmin_generators/backend/templates/images/ext/default/button/s-arrow-bo.gif +0 -0
  42. data/lipsiadmin_generators/backend/templates/images/ext/{slate/grid/grid3-hrow.gif → default/button/s-arrow-noline.gif} +0 -0
  43. data/lipsiadmin_generators/backend/templates/images/ext/default/button/s-arrow-o.gif +0 -0
  44. data/lipsiadmin_generators/backend/templates/images/ext/default/button/s-arrow.gif +0 -0
  45. data/lipsiadmin_generators/backend/templates/images/ext/default/form/checkbox.gif +0 -0
  46. data/lipsiadmin_generators/backend/templates/images/ext/default/form/radio.gif +0 -0
  47. data/lipsiadmin_generators/backend/templates/images/ext/default/form/trigger.gif +0 -0
  48. data/lipsiadmin_generators/backend/templates/images/ext/default/grid/group-collapse.gif +0 -0
  49. data/lipsiadmin_generators/backend/templates/images/ext/default/grid/group-expand.gif +0 -0
  50. data/lipsiadmin_generators/backend/templates/images/ext/default/grid/refresh.gif +0 -0
  51. data/lipsiadmin_generators/backend/templates/images/ext/default/grid/sort-hd.gif +0 -0
  52. data/lipsiadmin_generators/backend/templates/images/ext/default/panel/tool-sprites.gif +0 -0
  53. data/lipsiadmin_generators/backend/templates/images/ext/default/panel/tools-sprites-trans.gif +0 -0
  54. data/lipsiadmin_generators/backend/templates/images/ext/default/qtip/tip-anchor-sprite.gif +0 -0
  55. data/lipsiadmin_generators/backend/templates/images/ext/default/shadow-c.png +0 -0
  56. data/lipsiadmin_generators/backend/templates/images/ext/default/slider/slider-bg.png +0 -0
  57. data/lipsiadmin_generators/backend/templates/images/ext/default/slider/slider-thumb.png +0 -0
  58. data/lipsiadmin_generators/backend/templates/images/ext/default/slider/slider-v-bg.png +0 -0
  59. data/lipsiadmin_generators/backend/templates/images/ext/default/slider/slider-v-thumb.png +0 -0
  60. data/lipsiadmin_generators/backend/templates/images/ext/{slate/grid/arrow-left-white.gif → default/toolbar/more.gif} +0 -0
  61. data/lipsiadmin_generators/backend/templates/images/ext/default/toolbar/tb-xl-btn-sprite.gif +0 -0
  62. data/lipsiadmin_generators/backend/templates/images/ext/{slate/panel/left-right.gif → default/toolbar/tb-xl-sep.gif} +0 -0
  63. data/lipsiadmin_generators/backend/templates/images/ext/default/window/left-corners.png +0 -0
  64. data/lipsiadmin_generators/backend/templates/images/ext/default/window/left-right.png +0 -0
  65. data/lipsiadmin_generators/backend/templates/images/ext/default/window/left-right.psd +0 -0
  66. data/lipsiadmin_generators/backend/templates/images/ext/default/window/right-corners.png +0 -0
  67. data/lipsiadmin_generators/backend/templates/images/ext/default/window/top-bottom.png +0 -0
  68. data/lipsiadmin_generators/backend/templates/images/ext/default/window/top-bottom.psd +0 -0
  69. data/lipsiadmin_generators/backend/templates/images/ext/expressinstall.swf +0 -0
  70. data/lipsiadmin_generators/backend/templates/javascripts/ext.js +97 -76
  71. data/lipsiadmin_generators/backend/templates/javascripts/prototype.js +14 -12
  72. data/lipsiadmin_generators/backend/templates/models/notifier.rb +1 -1
  73. data/lipsiadmin_generators/backend/templates/stylesheets/backend.css +11 -2
  74. data/lipsiadmin_generators/backend/templates/stylesheets/ext.css +1070 -546
  75. data/lipsiadmin_generators/backend/templates/stylesheets/login.css +1 -0
  76. data/lipsiadmin_generators/backend/templates/views/backend/accounts/index.rjs +1 -0
  77. data/lipsiadmin_generators/backend/templates/views/backend/base/index.html.haml +7 -4
  78. data/lipsiadmin_generators/backend/templates/views/javascripts/backend.js.erb +203 -143
  79. data/lipsiadmin_generators/pdf/pdf_generator.rb +1 -4
  80. data/lipsiadmin_generators/pdf/templates/view.html.haml +11 -6
  81. data/lipsiadmin_generators/state_session/state_session_generator.rb +2 -0
  82. data/resources/javascripts/ux.js +16 -17
  83. data/resources/javascripts/ux.min.js +2 -0
  84. data/resources/pd4ml/ruby/Pd4Ruby.class +0 -0
  85. data/resources/pd4ml/ruby/Pd4Ruby.java +277 -31
  86. data/tasks/lipsiadmin_tasks.rake +18 -1
  87. metadata +32 -124
  88. data/lipsiadmin_generators/backend/templates/images/ext/default/box/tb-slate.gif +0 -0
  89. data/lipsiadmin_generators/backend/templates/images/ext/default/button/btn-arrow.gif +0 -0
  90. data/lipsiadmin_generators/backend/templates/images/ext/default/button/btn-sprite.gif +0 -0
  91. data/lipsiadmin_generators/backend/templates/images/ext/default/grid/Thumbs.db +0 -0
  92. data/lipsiadmin_generators/backend/templates/images/ext/slate/button/btn-arrow.gif +0 -0
  93. data/lipsiadmin_generators/backend/templates/images/ext/slate/button/btn-sprite.gif +0 -0
  94. data/lipsiadmin_generators/backend/templates/images/ext/slate/editor/tb-sprite.gif +0 -0
  95. data/lipsiadmin_generators/backend/templates/images/ext/slate/form/checkbox.gif +0 -0
  96. data/lipsiadmin_generators/backend/templates/images/ext/slate/form/clear-trigger.gif +0 -0
  97. data/lipsiadmin_generators/backend/templates/images/ext/slate/form/date-trigger.gif +0 -0
  98. data/lipsiadmin_generators/backend/templates/images/ext/slate/form/radio.gif +0 -0
  99. data/lipsiadmin_generators/backend/templates/images/ext/slate/form/search-trigger.gif +0 -0
  100. data/lipsiadmin_generators/backend/templates/images/ext/slate/form/trigger-tpl.gif +0 -0
  101. data/lipsiadmin_generators/backend/templates/images/ext/slate/form/trigger.gif +0 -0
  102. data/lipsiadmin_generators/backend/templates/images/ext/slate/gradient-bg.gif +0 -0
  103. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/col-move-bottom.gif +0 -0
  104. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/col-move-top.gif +0 -0
  105. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/footer-bg.gif +0 -0
  106. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/grid-blue-hd.gif +0 -0
  107. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/grid-hrow.gif +0 -0
  108. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/grid-split.gif +0 -0
  109. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/grid-vista-hd.gif +0 -0
  110. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/grid3-hd-btn.gif +0 -0
  111. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/grid3-hrow-over.gif +0 -0
  112. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/grid3-special-col-bg.gif +0 -0
  113. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/grid3-special-col-sel-bg.gif +0 -0
  114. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/group-expand-sprite.gif +0 -0
  115. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/mso-hd.gif +0 -0
  116. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/page-first-disabled.gif +0 -0
  117. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/page-first.gif +0 -0
  118. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/page-last-disabled.gif +0 -0
  119. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/page-last.gif +0 -0
  120. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/page-next-disabled.gif +0 -0
  121. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/page-next.gif +0 -0
  122. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/page-prev-disabled.gif +0 -0
  123. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/page-prev.gif +0 -0
  124. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/refresh.gif +0 -0
  125. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/row-over.gif +0 -0
  126. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/row-sel.gif +0 -0
  127. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/sort_asc.gif +0 -0
  128. data/lipsiadmin_generators/backend/templates/images/ext/slate/grid/sort_desc.gif +0 -0
  129. data/lipsiadmin_generators/backend/templates/images/ext/slate/menu/checked.gif +0 -0
  130. data/lipsiadmin_generators/backend/templates/images/ext/slate/menu/group-checked.gif +0 -0
  131. data/lipsiadmin_generators/backend/templates/images/ext/slate/menu/item-over - Copy.gif +0 -0
  132. data/lipsiadmin_generators/backend/templates/images/ext/slate/menu/item-over.gif +0 -0
  133. data/lipsiadmin_generators/backend/templates/images/ext/slate/menu/menu-parent.gif +0 -0
  134. data/lipsiadmin_generators/backend/templates/images/ext/slate/menu/menu.gif +0 -0
  135. data/lipsiadmin_generators/backend/templates/images/ext/slate/menu/unchecked.gif +0 -0
  136. data/lipsiadmin_generators/backend/templates/images/ext/slate/panel/corners-sprite.gif +0 -0
  137. data/lipsiadmin_generators/backend/templates/images/ext/slate/panel/light-hd.gif +0 -0
  138. data/lipsiadmin_generators/backend/templates/images/ext/slate/panel/tool-sprite-tpl.gif +0 -0
  139. data/lipsiadmin_generators/backend/templates/images/ext/slate/panel/tool-sprites.gif +0 -0
  140. data/lipsiadmin_generators/backend/templates/images/ext/slate/panel/tools-sprites-trans.gif +0 -0
  141. data/lipsiadmin_generators/backend/templates/images/ext/slate/panel/top-bottom.gif +0 -0
  142. data/lipsiadmin_generators/backend/templates/images/ext/slate/panel/top-bottom.png +0 -0
  143. data/lipsiadmin_generators/backend/templates/images/ext/slate/panel/white-corners-sprite.gif +0 -0
  144. data/lipsiadmin_generators/backend/templates/images/ext/slate/panel/white-left-right.gif +0 -0
  145. data/lipsiadmin_generators/backend/templates/images/ext/slate/panel/white-top-bottom.gif +0 -0
  146. data/lipsiadmin_generators/backend/templates/images/ext/slate/progress/progress-bg.gif +0 -0
  147. data/lipsiadmin_generators/backend/templates/images/ext/slate/qtip/bg.gif +0 -0
  148. data/lipsiadmin_generators/backend/templates/images/ext/slate/qtip/close.gif +0 -0
  149. data/lipsiadmin_generators/backend/templates/images/ext/slate/qtip/tip-sprite.gif +0 -0
  150. data/lipsiadmin_generators/backend/templates/images/ext/slate/s.gif +0 -0
  151. data/lipsiadmin_generators/backend/templates/images/ext/slate/shared/glass-bg.gif +0 -0
  152. data/lipsiadmin_generators/backend/templates/images/ext/slate/shared/hd-sprite.gif +0 -0
  153. data/lipsiadmin_generators/backend/templates/images/ext/slate/shared/left-btn.gif +0 -0
  154. data/lipsiadmin_generators/backend/templates/images/ext/slate/shared/right-btn.gif +0 -0
  155. data/lipsiadmin_generators/backend/templates/images/ext/slate/sizer/e-handle-dark.gif +0 -0
  156. data/lipsiadmin_generators/backend/templates/images/ext/slate/sizer/e-handle.gif +0 -0
  157. data/lipsiadmin_generators/backend/templates/images/ext/slate/sizer/ne-handle-dark.gif +0 -0
  158. data/lipsiadmin_generators/backend/templates/images/ext/slate/sizer/ne-handle.gif +0 -0
  159. data/lipsiadmin_generators/backend/templates/images/ext/slate/sizer/nw-handle-dark.gif +0 -0
  160. data/lipsiadmin_generators/backend/templates/images/ext/slate/sizer/nw-handle.gif +0 -0
  161. data/lipsiadmin_generators/backend/templates/images/ext/slate/sizer/s-handle-dark.gif +0 -0
  162. data/lipsiadmin_generators/backend/templates/images/ext/slate/sizer/s-handle.gif +0 -0
  163. data/lipsiadmin_generators/backend/templates/images/ext/slate/sizer/se-handle-dark.gif +0 -0
  164. data/lipsiadmin_generators/backend/templates/images/ext/slate/sizer/square.gif +0 -0
  165. data/lipsiadmin_generators/backend/templates/images/ext/slate/sizer/sw-handle-dark.gif +0 -0
  166. data/lipsiadmin_generators/backend/templates/images/ext/slate/sizer/sw-handle.gif +0 -0
  167. data/lipsiadmin_generators/backend/templates/images/ext/slate/slider/slider-bg.png +0 -0
  168. data/lipsiadmin_generators/backend/templates/images/ext/slate/slider/slider-thumb.png +0 -0
  169. data/lipsiadmin_generators/backend/templates/images/ext/slate/slider/slider-v-bg.png +0 -0
  170. data/lipsiadmin_generators/backend/templates/images/ext/slate/slider/slider-v-thumb.png +0 -0
  171. data/lipsiadmin_generators/backend/templates/images/ext/slate/tabs/scroll-left.gif +0 -0
  172. data/lipsiadmin_generators/backend/templates/images/ext/slate/tabs/scroll-right.gif +0 -0
  173. data/lipsiadmin_generators/backend/templates/images/ext/slate/tabs/scroller-bg.gif +0 -0
  174. data/lipsiadmin_generators/backend/templates/images/ext/slate/tabs/tab-btm-inactive-left-bg.gif +0 -0
  175. data/lipsiadmin_generators/backend/templates/images/ext/slate/tabs/tab-btm-inactive-right-bg.gif +0 -0
  176. data/lipsiadmin_generators/backend/templates/images/ext/slate/tabs/tab-btm-left-bg.gif +0 -0
  177. data/lipsiadmin_generators/backend/templates/images/ext/slate/tabs/tab-btm-right-bg.gif +0 -0
  178. data/lipsiadmin_generators/backend/templates/images/ext/slate/tabs/tab-close.gif +0 -0
  179. data/lipsiadmin_generators/backend/templates/images/ext/slate/tabs/tab-strip-bg.gif +0 -0
  180. data/lipsiadmin_generators/backend/templates/images/ext/slate/tabs/tab-strip-bg.png +0 -0
  181. data/lipsiadmin_generators/backend/templates/images/ext/slate/tabs/tab-strip-btm-bg.gif +0 -0
  182. data/lipsiadmin_generators/backend/templates/images/ext/slate/tabs/tabs-sprite.gif +0 -0
  183. data/lipsiadmin_generators/backend/templates/images/ext/slate/toolbar/bg-menu.png +0 -0
  184. data/lipsiadmin_generators/backend/templates/images/ext/slate/toolbar/bg.gif +0 -0
  185. data/lipsiadmin_generators/backend/templates/images/ext/slate/toolbar/btn-arrow-light.gif +0 -0
  186. data/lipsiadmin_generators/backend/templates/images/ext/slate/toolbar/btn-arrow.gif +0 -0
  187. data/lipsiadmin_generators/backend/templates/images/ext/slate/toolbar/btn-over-bg.gif +0 -0
  188. data/lipsiadmin_generators/backend/templates/images/ext/slate/toolbar/gray-bg.gif +0 -0
  189. data/lipsiadmin_generators/backend/templates/images/ext/slate/toolbar/tb-bg.gif +0 -0
  190. data/lipsiadmin_generators/backend/templates/images/ext/slate/toolbar/tb-btn-sprite.gif +0 -0
  191. data/lipsiadmin_generators/backend/templates/images/ext/slate/tree/arrows.gif +0 -0
  192. data/lipsiadmin_generators/backend/templates/images/ext/slate/window/icon-error.gif +0 -0
  193. data/lipsiadmin_generators/backend/templates/images/ext/slate/window/icon-info.gif +0 -0
  194. data/lipsiadmin_generators/backend/templates/images/ext/slate/window/icon-question.gif +0 -0
  195. data/lipsiadmin_generators/backend/templates/images/ext/slate/window/icon-warning.gif +0 -0
  196. data/lipsiadmin_generators/backend/templates/images/ext/slate/window/left-corners.png +0 -0
  197. data/lipsiadmin_generators/backend/templates/images/ext/slate/window/left-right.png +0 -0
  198. data/lipsiadmin_generators/backend/templates/images/ext/slate/window/right-corners.png +0 -0
  199. data/lipsiadmin_generators/backend/templates/images/ext/slate/window/top-bottom.png +0 -0
  200. data/lipsiadmin_generators/backend/templates/stylesheets/backend-slate.css +0 -105
  201. data/lipsiadmin_generators/backend/templates/stylesheets/ext-slate.css +0 -241
@@ -0,0 +1,62 @@
1
+ module Lipsiadmin
2
+ module Ext
3
+ # Generate a new Ext.Button
4
+ #
5
+ # This component is usefull for ex in toolbars
6
+ #
7
+ # # Generates:
8
+ # #{
9
+ # # buttons: [{
10
+ # # disabled: false,
11
+ # # text: Backend.locale.buttons.add,
12
+ # # id: "add",
13
+ # # cls: "x-btn-text-icon add"
14
+ # # },{
15
+ # # disabled: true,
16
+ # # text: Backend.locale.buttons.edit,
17
+ # # id: "edit",
18
+ # # cls: "x-btn-text-icon edit"
19
+ # # },{
20
+ # # disabled: true,
21
+ # # text: Backend.locale.buttons.remove,
22
+ # # id: "remove",
23
+ # # cls: "x-btn-text-icon remove"
24
+ # # },{
25
+ # # disabled: false,
26
+ # # menu: [{
27
+ # # text: "Test Me"
28
+ # # },{
29
+ # # text: "IM a sub Menu"
30
+ # # }],
31
+ # # text: Backend.locale.buttons.print,
32
+ # # id: "print",
33
+ # # cls: "x-btn-text-icon print"
34
+ # # }]
35
+ # #}
36
+ # tbar.add_button :text => "Backend.locale.buttons.add".to_l, :id => "add", :disabled => false, :cls => "x-btn-text-icon add", :handler => "add".to_l
37
+ # tbar.add_button :text => "Backend.locale.buttons.edit".to_l, :id => "edit", :disabled => true, :cls => "x-btn-text-icon edit", :handler => "edit".to_l
38
+ # tbar.add_button :text => "Backend.locale.buttons.remove".to_l, :id => "remove", :disabled => true, :cls => "x-btn-text-icon remove", :handler => "remove".to_l
39
+ # tbar.add_button :text => "Backend.locale.buttons.print".to_l, :id => "print", :disabled => false, :cls => "x-btn-text-icon print" do |menu|
40
+ # menu.add_button :text => "Test Me"
41
+ # menu.add_button :text => "IM a sub Menu"
42
+ # end
43
+ #
44
+ class Button < Component
45
+
46
+ def initialize(options={}, &block)#:nodoc:
47
+ super("Ext.Button", options)
48
+ yield self if block_given?
49
+ end
50
+
51
+ # Add new Button to the menu of this one
52
+ #
53
+ # # Generates: { handler: show, text: "Add", other: "...", icon: "..." }
54
+ # add_button :text => "Add", :handler => "show".to_l, :icon => "...", :other => "..."
55
+ #
56
+ def add_button(options, &block)
57
+ config[:menu] ||= []
58
+ config[:menu] << (options.is_a?(String) ? options : Button.new(options, &block).config)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -35,20 +35,24 @@ module Lipsiadmin
35
35
 
36
36
  # This add automatically fields from an array
37
37
  def fields(fields)
38
- fields.each { |options| add(nil, nil, options); }
38
+ fields.each { |options| add_column(nil, nil, options); }
39
39
  end
40
40
 
41
41
  # Add columns to a Ext.grid.ColumnModel
42
42
  #
43
43
  # # Generates: { header: "Created At", dataIndex: "accounts.datetime", sortable => true }
44
- # add "Created At", "accounts.datetime", :sortable => l(true)
44
+ # add "Created At", "accounts.datetime", :sortable => true
45
45
  #
46
46
  # You can pass :renderer
47
47
  #
48
48
  # # Generates: Ext.util.Format.dateRenderer()
49
+ # :render => :time_to_date # This render a datetime to a date
50
+ # # Generates: Ext.util.Format.dateRenderer()
49
51
  # :renderer => :date
50
52
  # # Generates: Ext.util.Format.dateTimeRenderer()
51
53
  # :renderer => :datetime
54
+ # # Generates: Ext.util.Format.percentage
55
+ # :renderer => :percentage
52
56
  # # Generates: Ext.util.Format.eurMoney
53
57
  # :renderer => :eur_money
54
58
  # # Generates: Ext.util.Format.usMoney
@@ -95,37 +99,39 @@ module Lipsiadmin
95
99
  # :textfield => Ext.form.TextField
96
100
  # :timefield => Ext.form.TimeField
97
101
  #
98
- def add(name=nil, data=nil, options={})
102
+ def add_column(name=nil, data=nil, options={})
99
103
  options[:header] = name if name
100
104
  options[:dataIndex] = data if data
101
105
 
102
106
  if options[:editor]
103
- xtype = options[:editor].delete(:xtype)
107
+ xtype = options[:editor][:xtype]
104
108
  case xtype
105
109
  when :checkbox then options.delete(:editor); options.merge!(:checkbox => true)
106
- when :combo then options.merge!(:editor => l("new Ext.form.ComboBox(#{Configuration.new(options[:editor]).to_s(3)})"))
107
- when :datefield then options.merge!(:editor => l("new Ext.form.DateField(#{Configuration.new(options[:editor]).to_s(3)})"))
108
- when :numberfield then options.merge!(:editor => l("new Ext.form.NumberField(#{Configuration.new(options[:editor]).to_s(3)})"))
109
- when :radio then options.merge!(:editor => l("new Ext.form.Radio(#{Configuration.new(options[:editor]).to_s(3)})"))
110
- when :textarea then options.merge!(:editor => l("new Ext.form.TextArea(#{Configuration.new(options[:editor]).to_s(3)})"))
111
- when :textfield then options.merge!(:editor => l("new Ext.form.TextField(#{Configuration.new(options[:editor]).to_s(3)})"))
112
- when :timefield then options.merge!(:editor => l("new Ext.form.TimeField(#{Configuration.new(options[:editor]).to_s(3)})"))
113
- when :datetimefield then options.merge!(:editor => l("new Ext.form.DateTimeField(#{Configuration.new(options[:editor]).to_s(3)})"))
110
+ when :combo then options.merge!(:editor => "new Ext.form.ComboBox(#{Configuration.new(options[:editor]).to_s(3)})".to_l)
111
+ when :datefield then options.merge!(:editor => "new Ext.form.DateField(#{Configuration.new(options[:editor]).to_s(3)})".to_l)
112
+ when :numberfield then options.merge!(:editor => "new Ext.form.NumberField(#{Configuration.new(options[:editor]).to_s(3)})".to_l)
113
+ when :radio then options.merge!(:editor => "new Ext.form.Radio(#{Configuration.new(options[:editor]).to_s(3)})".to_l)
114
+ when :textarea then options.merge!(:editor => "new Ext.form.TextArea(#{Configuration.new(options[:editor]).to_s(3)})".to_l)
115
+ when :textfield then options.merge!(:editor => "new Ext.form.TextField(#{Configuration.new(options[:editor]).to_s(3)})".to_l)
116
+ when :timefield then options.merge!(:editor => "new Ext.form.TimeField(#{Configuration.new(options[:editor]).to_s(3)})".to_l)
117
+ when :datetimefield then options.merge!(:editor => "new Ext.form.DateTimeField(#{Configuration.new(options[:editor]).to_s(3)})".to_l)
114
118
  end
115
119
  end
116
120
 
117
121
  case options[:renderer]
118
- when :date then options.merge!(:renderer => l("Ext.util.Format.dateRenderer()"))
119
- when :datetime then options.merge!(:renderer => l("Ext.util.Format.dateTimeRenderer()"))
120
- when :eur_money then options.merge!(:renderer => l("Ext.util.Format.eurMoney"))
121
- when :us_money then options.merge!(:renderer => l("Ext.util.Format.usMoney"))
122
- when :boolean then options.merge!(:renderer => l("Ext.util.Format.boolRenderer"))
123
- when :capitalize then options.merge!(:renderer => l("Ext.util.Format.capitalize"))
124
- when :file_size then options.merge!(:renderer => l("Ext.util.Format.fileSize"))
125
- when :downcase then options.merge!(:renderer => l("Ext.util.Format.lowercase"))
126
- when :trim then options.merge!(:renderer => l("Ext.util.Format.trim"))
127
- when :undef then options.merge!(:renderer => l("Ext.util.Format.undef"))
128
- when :upcase then options.merge!(:renderer => l("Ext.util.Format.uppercase"))
122
+ when :time_to_date then options.merge!(:renderer => "Ext.util.Format.dateRenderer()".to_l)
123
+ when :date then options.merge!(:renderer => "Ext.util.Format.dateRenderer()".to_l)
124
+ when :datetime then options.merge!(:renderer => "Ext.util.Format.dateTimeRenderer()".to_l)
125
+ when :percentage then options.merge!(:renderer => "Ext.util.Format.percentage".to_l)
126
+ when :eur_money then options.merge!(:renderer => "Ext.util.Format.eurMoney".to_l)
127
+ when :us_money then options.merge!(:renderer => "Ext.util.Format.usMoney".to_l)
128
+ when :boolean then options.merge!(:renderer => "Ext.util.Format.boolRenderer".to_l)
129
+ when :capitalize then options.merge!(:renderer => "Ext.util.Format.capitalize".to_l)
130
+ when :file_size then options.merge!(:renderer => "Ext.util.Format.fileSize".to_l)
131
+ when :downcase then options.merge!(:renderer => "Ext.util.Format.lowercase".to_l)
132
+ when :trim then options.merge!(:renderer => "Ext.util.Format.trim".to_l)
133
+ when :undef then options.merge!(:renderer => "Ext.util.Format.undef".to_l)
134
+ when :upcase then options.merge!(:renderer => "Ext.util.Format.uppercase".to_l)
129
135
  end
130
136
 
131
137
  raise ComponentError, "You must provide header and dataIndex for generate a column model" if options[:header].blank? ||
@@ -22,7 +22,7 @@ module Lipsiadmin#:nodoc:
22
22
  @var = options.delete(:var)
23
23
  @config = Configuration.new(options)
24
24
  @before, @after = [], []
25
-
25
+ @items = {}
26
26
  if self.class == Component && block_given?
27
27
  yield self
28
28
  end
@@ -47,12 +47,22 @@ module Lipsiadmin#:nodoc:
47
47
  #
48
48
  def get_var
49
49
  # I will nillify obj if they are blank
50
- @var = nil if @var == ""
51
- @config.delete(:var) if @config[:var] == ""
50
+ @var = nil if @var.blank?
51
+ @config.delete(:var) if @config[:var].blank?
52
+
52
53
  # Return a correct var
53
54
  current_var = (@var || @config[:var] || build_var)
54
55
  @prefix.to_s + current_var.to_s
55
56
  end
57
+
58
+ # Define the title of the component.
59
+ #
60
+ # Every component can have a title, because in Lipsiadmin we use it
61
+ # as a "pagetitle", but if you need it as a config you can provide global = false
62
+ #
63
+ def title(title, global=true)
64
+ global ? (before << "Backend.app.setTitle(#{title.to_json});") : config[:title] = title
65
+ end
56
66
 
57
67
  # Write the the configuration of object from an hash
58
68
  #
@@ -60,17 +70,17 @@ module Lipsiadmin#:nodoc:
60
70
  @config = Configuration.new(options)
61
71
  end
62
72
 
63
- # Read the the configuration of object from an hash
73
+ # Return the configuration hash
64
74
  #
65
75
  def config
66
76
  @config
67
77
  end
68
78
 
69
- def method_missing(method, arg=nil)#:nodoc:
70
- if method.to_s.start_with?("get_")
71
- @config[method.to_s.gsub("get_", "").to_sym]
79
+ def method_missing(method, arguments=nil, &block)#:nodoc:
80
+ if method.to_s =~ /^get_/
81
+ @config[method.to_s.gsub(/^get_/, "").to_sym]
72
82
  else
73
- add_object(method, arg)
83
+ add_object(method, arguments)
74
84
  end
75
85
  end
76
86
 
@@ -104,44 +114,53 @@ module Lipsiadmin#:nodoc:
104
114
  # # new();
105
115
  # # Ext.Msg.alert("Hello", "world");
106
116
  # # });
107
- #
108
117
  # grid.on :dblclick do |p|
109
118
  # p.call "edit"
110
119
  # p.call "new"
111
120
  # p.ext_alert "Hello", "world"
112
121
  # end
122
+ #
113
123
  def on(event, function=nil, scope=nil, &block)
114
124
  # Remove old handlers
115
- remove_listener(event)
116
- scope = ", #{l(scope)}" unless scope.blank?
125
+ un(event)
126
+ scope = ", #{scope.to_l}" unless scope.blank?
117
127
  if function
118
128
  after << "#{get_var}.on(#{event.to_json}, #{function}#{scope});"
119
129
  else
120
130
  generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(self, &block)
121
- after << "#{get_var}.on(#{event.to_json}, function() { #{generator.to_s.gsub("\n", "\n ")}\n}#{scope});"
131
+ after << "#{get_var}.on(#{event.to_json}, function() { \n #{generator.to_s.gsub("\n", "\n ")}\n}#{scope});"
122
132
  end
123
133
  end
124
- alias_method :add_listener, :on
125
134
 
126
135
  # Remove a listener
136
+ #
137
+ # Example: grid.un(:dblclick)
127
138
  #
128
- # Example: grid.remove_listener(:dblclick)
129
- def remove_listener(event)
130
- @after.delete_if { |s| s.start_with?("#{get_var}.on(#{event.to_json}") if s.is_a?(String) }
139
+ def un(event)
140
+ found = @after.delete_if { |s| s.start_with?("#{get_var}.on(#{event.to_json}") if s.is_a?(String) }
141
+ after << "#{get_var}.un(#{event.to_json})" unless found
131
142
  end
132
143
 
133
- # Generates a new Component for generate on the fly ExtJs Objects
144
+ # Generates and add new Component for generate on the fly ExtJs Objects
134
145
  #
135
146
  # Examples:
136
147
  #
137
148
  # # Generates:
138
- # # var myComponent = new MyComponent({
139
- # # default: true
140
- # # });
141
- # grid.my_component grid.new_component("MyComponent") { |p| p.default true }
149
+ # # var panel = new Ext.Panel({
150
+ # # id: 'testPanel',
151
+ # # region: 'center',
152
+ # # ...
153
+ # # })
154
+ # # mycmp.add(panel)
155
+ # #
156
+ # mycmp.add "Ext.Panel" do |panel|
157
+ # panel.id "testPanel",
158
+ # panel.region :center
159
+ # ...
160
+ # end
142
161
  #
143
- def new_component(klass, options={}, &block)
144
- Component.new(klass, options, &block)
162
+ def add(klass, options={}, &block)
163
+ add_object(Component.new(klass, options.merge(:prefix => get_var), &block))
145
164
  end
146
165
 
147
166
  # Used by ActionView::Helpers::PrototypeHelper::JavaScriptGenerator
@@ -149,31 +168,23 @@ module Lipsiadmin#:nodoc:
149
168
  yield
150
169
  end
151
170
 
152
-
153
171
  # Returns the javascript for current component
154
- #
172
+ #
155
173
  # # Generates: var rowSelectionModel = Ext.grid.RowSelectionModel();
156
- # Component.new("Ext.grid.RowSelectionModel")
174
+ # Component.new("Ext.grid.RowSelectionModel").to_s
157
175
  #
158
- def to_s
159
- script = []
160
- script << @before.uniq.compact.join("\n\n")
161
- script << "var #{get_var} = new #{@klass}(#{config.to_s});"
162
- script << @after.uniq.compact.join("\n\n")
176
+ def to_s(options={})
177
+ script = returning [] do |script|
178
+ script << @before.uniq.compact.join("\n\n")
179
+ script << "var #{get_var} = new #{@klass}(#{config.to_s});"
180
+ script << @after.uniq.compact.join("\n\n")
181
+ end
163
182
  script.delete_if { |s| s.blank? }.join("\n\n")
164
183
  end
165
184
 
166
185
  def raise_error(error)#:nodoc:
167
186
  raise ComponentError, error
168
187
  end
169
-
170
- # Returns an object whose <tt>to_json</tt> evaluates to +code+. Use this to pass a literal JavaScript
171
- # expression as an argument to another JavaScriptGenerator method.
172
- #
173
- def literal(code)
174
- ActiveSupport::JSON::Variable.new(code.to_s)
175
- end
176
- alias_method :l, :literal
177
188
 
178
189
  private
179
190
  def render_javascript(template, assigns)
@@ -187,7 +198,8 @@ module Lipsiadmin#:nodoc:
187
198
  object.prefix = get_var
188
199
  @before.delete_if { |b| b.start_with?("var #{object.get_var} = new") }
189
200
  @before << object.to_s
190
- @config[name.to_sym] = l(object.get_var)
201
+ @config[name.to_sym] = object.get_var.to_l
202
+ @items.merge!({ name.to_s.to_sym => object })
191
203
  else
192
204
  @config[name.to_sym] = object
193
205
  end
@@ -14,9 +14,10 @@ module Lipsiadmin
14
14
  # Optionally you can specify the indentation spaces.
15
15
  def to_s(indent=1)
16
16
  return if self.empty?
17
- i = (" "*indent)
17
+ i = (" "*indent)
18
18
  s = self.size > 0 ? "\n" : " "
19
- "{#{s}" + self.reject { |k,v| k.blank? || v.to_s.blank? }.collect { |k,v| "#{i*2}#{k}: #{s(v)}" if k != :var }.join(",#{s}") + "#{s}#{i}}"
19
+ r = "{#{s}" + self.collect { |k,v| "#{i*2}#{k}: #{s(v)}" if k != :var }.join(",#{s}") + "#{s}#{i if i.size > 1}}"
20
+ return r =~ /\{\s*\}/ ? "" : r
20
21
  end
21
22
 
22
23
  private
@@ -27,7 +27,7 @@ module Lipsiadmin
27
27
  # grid.base_path "/backend/posts"
28
28
  # grid.forgery_protection_token request_forgery_protection_token
29
29
  # grid.authenticity_token form_authenticity_token
30
- # grid.tbar :default
30
+ # grid.tbar :default # or [:add, :edit, :delete] or [:edit, :delete]
31
31
  # grid.store do |store|
32
32
  # store.url "/backend/posts.json"
33
33
  # store.fields @column_store.store_fields
@@ -52,20 +52,20 @@ module Lipsiadmin
52
52
  def initialize(options={}, &block)#:nodoc:
53
53
  # Call Super Class for initialize configuration
54
54
  @editable = options.delete(:editable)
55
-
56
- super("Ext.grid.#{@editable ? 'EditorGridPanel' : 'GridPanel' }", options)
55
+ super("Ext.grid.#{@editable ? 'EditorGridPanel' : 'GridPanel' }", { :plugins => [] }.merge(options))
57
56
 
58
57
  # Write default configuration if not specified
59
58
  config[:plugins] ||= []
60
59
  viewConfig :forceFit => true
61
- clicksToEdit 1
62
60
  border false
63
61
  bodyBorder false
62
+ clicksToEdit 1
64
63
  region "center"
65
64
  sm :checkbox
66
- add_plugin l("new Ext.grid.Search()")
67
65
  view :default
68
66
  render true
67
+ config[:plugins] << "new Ext.grid.Search()".to_l
68
+
69
69
  # We need to add a setTimeout because, we destroy
70
70
  # the grid before loading a new page/js.
71
71
  on(:dblclick) do |p|
@@ -88,29 +88,14 @@ module Lipsiadmin
88
88
  #
89
89
  def sm(object)
90
90
  selmodel = case object
91
- when :default then Component.new("Ext.grid.CheckboxSelectionModel")
92
- when :checkbox then Component.new("Ext.grid.CheckboxSelectionModel")
93
- when :row then Component.new("Ext.grid.RowSelectionModel")
91
+ when :default then Component.new("Ext.grid.CheckboxSelectionModel", :prefix => get_var)
92
+ when :checkbox then Component.new("Ext.grid.CheckboxSelectionModel", :prefix => get_var)
93
+ when :row then Component.new("Ext.grid.RowSelectionModel", :prefix => get_var)
94
94
  else object
95
95
  end
96
96
  add_object(:sm, selmodel)
97
97
  end
98
98
 
99
- # Define the title of the grid
100
- def title(title, global=true)
101
- global ? (before << "Backend.app.setTitle(#{title.to_json});") : config[:title] = title
102
- end
103
-
104
- # Assign plugins for the current grid
105
- def plugins(plugins)
106
- config[:plugins] = plugins
107
- end
108
-
109
- # Add a single plugin to the grid plugins
110
- def add_plugin(plugins)
111
- config[:plugins] << plugins
112
- end
113
-
114
99
  # Generate or set a new Ext.Toolbar
115
100
  # You can pass tbar :default options that will create
116
101
  # defaults buttons for add, edit and remove records, it's generate also
@@ -142,12 +127,27 @@ module Lipsiadmin
142
127
  # tbar :default
143
128
  #
144
129
  def tbar(object=nil, &block)
145
- tbar = object.is_a?(ToolBar) ? object : ToolBar.new
146
- if object == :default
147
- tbar.add l("Backend.locale.buttons.add"), :id => "add", :disabled => literal(false), :cls => "x-btn-text-icon add", :handler => l("add")
148
- tbar.add l("Backend.locale.buttons.edit"), :id => "edit", :disabled => literal(true), :cls => "x-btn-text-icon edit", :handler => l("edit")
149
- tbar.add l("Backend.locale.buttons.remove"), :id => "remove", :disabled => literal(true), :cls => "x-btn-text-icon remove", :handler => l("remove")
150
- @default_tbar = true
130
+ tbar = object.is_a?(ToolBar) ? object : ToolBar.new(:prefix => get_var)
131
+ if object == :default || object == :all
132
+ tbar.add_button :text => "Backend.locale.buttons.add".to_l, :id => "add", :disabled => false, :cls => "x-btn-text-icon add", :handler => "add".to_l
133
+ tbar.add_button :text => "Backend.locale.buttons.edit".to_l, :id => "edit", :disabled => true, :cls => "x-btn-text-icon edit", :handler => "edit".to_l
134
+ tbar.add_button :text => "Backend.locale.buttons.remove".to_l, :id => "remove", :disabled => true, :cls => "x-btn-text-icon remove", :handler => "remove".to_l
135
+ @ttbar_add, @ttbar_edit, @ttbar_delete = true, true, true
136
+ end
137
+ if object.is_a?(Array)
138
+ object.each do |button|
139
+ case button
140
+ when :add
141
+ tbar.add_button :text => "Backend.locale.buttons.add".to_l, :id => "add", :disabled => false, :cls => "x-btn-text-icon add", :handler => "add".to_l
142
+ @ttbar_add = true
143
+ when :edit
144
+ tbar.add_button :text => "Backend.locale.buttons.edit".to_l, :id => "edit", :disabled => true, :cls => "x-btn-text-icon edit", :handler => "edit".to_l
145
+ @ttbar_edit = true
146
+ when :delete
147
+ tbar.add_button :text => "Backend.locale.buttons.remove".to_l, :id => "remove", :disabled => true, :cls => "x-btn-text-icon remove", :handler => "remove".to_l
148
+ @ttbar_delete = true
149
+ end
150
+ end
151
151
  end
152
152
  yield tbar if block_given?
153
153
  add_object(:tbar, tbar)
@@ -164,7 +164,7 @@ module Lipsiadmin
164
164
  # bbar :pageSize => params[:limit], :store => store.get_var, displayInfo: true
165
165
  #
166
166
  def bbar(object=nil, &block)
167
- bbar = object.is_a?(Hash) ? Component.new("Ext.PagingToolbar", object) : object
167
+ bbar = object.is_a?(Hash) ? Component.new("Ext.PagingToolbar", object.merge(:prefix => get_var)) : object
168
168
  add_object(:bbar, bbar)
169
169
  end
170
170
 
@@ -180,8 +180,8 @@ module Lipsiadmin
180
180
  #
181
181
  def view(object=nil, &block)
182
182
  view = case object
183
- when :default then Component.new("Ext.grid.GroupingView", { :forceFit => true })
184
- when Hash then Component.new("Ext.grid.GroupingView", { :forceFit => true }.merge(object))
183
+ when :default then Component.new("Ext.grid.GroupingView", { :forceFit => true, :prefix => get_var })
184
+ when Hash then Component.new("Ext.grid.GroupingView", { :forceFit => true, :prefix => get_var }.merge(object))
185
185
  else object
186
186
  end
187
187
  add_object(:view, view)
@@ -189,7 +189,7 @@ module Lipsiadmin
189
189
 
190
190
  # Generate or set a new Ext.data.GroupingStore
191
191
  def store(object=nil, &block)
192
- store = object.is_a?(Store) ? object : Store.new(&block)
192
+ store = object.is_a?(Store) ? object : Store.new(:prefix => get_var, &block)
193
193
  add_object(:store, store)
194
194
  end
195
195
 
@@ -199,7 +199,7 @@ module Lipsiadmin
199
199
  if config[:sm] && before.find { |js| js.start_with?("var #{config[:sm]} = new Ext.grid.CheckboxSelectionModel") }
200
200
  options[:columns] << config[:sm]
201
201
  end
202
- cm = object.is_a?(ColumnModel) ? value : ColumnModel.new(options, &block)
202
+ cm = object.is_a?(ColumnModel) ? value : ColumnModel.new(options.merge(:prefix => get_var), &block)
203
203
  add_object(:cm, cm)
204
204
  end
205
205
 
@@ -255,15 +255,15 @@ module Lipsiadmin
255
255
  def get_selected(data=:id)
256
256
  raise_error "No Column Selection Model Defined" if config[:sm].blank?
257
257
  if data.to_sym == :id
258
- l("#{config[:sm]}.getSelected().id")
258
+ "#{config[:sm]}.getSelected().id".to_l
259
259
  else
260
- l("#{config[:sm]}.getSelected().data[#{data.to_json}]")
260
+ "#{config[:sm]}.getSelected().data[#{data.to_json}]"
261
261
  end
262
262
  end
263
263
 
264
264
  # Return the javascript for create a new Ext.grid.GridPanel
265
265
  def to_s
266
- if @default_tbar
266
+ if @ttbar_add || @ttbar_edit || @ttbar_delete
267
267
  raise_error "You must provide the base_path for autobuild toolbar." if @base_path.blank? && @new_path.blank? && @edit_path.blank? && @destroy_path.blank?
268
268
  raise_error "You must provide the new_path for autobuild button new of toolbar." if @base_path.blank? && @new_path.blank?
269
269
  raise_error "You must provide the edit_path for autobuild button edit of toolbar." if @base_path.blank? && @edit_path.blank?
@@ -275,9 +275,7 @@ module Lipsiadmin
275
275
  raise_error "You must provide the store." if config[:store].blank?
276
276
  end
277
277
 
278
- if @default_tbar
279
- after << render_javascript(:grid_functions, :var => get_var, :store => config[:store], :sm => config[:sm], :tbar => config[:tbar], :editable => @editable)
280
- end
278
+ after << render_javascript(:grid_functions, :var => get_var, :store => config[:store], :sm => config[:sm], :tbar => config[:tbar], :editable => @editable)
281
279
 
282
280
  if config[:store] && @render
283
281
  after << "#{config[:store]}.on('beforeload', function(){ Backend.app.mask(); });"