extjsml 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/bin/extjsmlc +70 -0
  3. data/lib/extclasses/actioncolumn.rb +11 -0
  4. data/lib/extclasses/booleancolumn.rb +34 -0
  5. data/lib/extclasses/button.rb +11 -0
  6. data/lib/extclasses/checkbox.rb +30 -0
  7. data/lib/extclasses/checkboxgroup.rb +14 -0
  8. data/lib/extclasses/checkcolumn.rb +16 -0
  9. data/lib/extclasses/combo.rb +56 -0
  10. data/lib/extclasses/compositefield.rb +11 -0
  11. data/lib/extclasses/container.rb +12 -0
  12. data/lib/extclasses/datecolumn.rb +21 -0
  13. data/lib/extclasses/datefield.rb +16 -0
  14. data/lib/extclasses/editorgrid.rb +97 -0
  15. data/lib/extclasses/fieldcontainer.rb +23 -0
  16. data/lib/extclasses/fieldset.rb +61 -0
  17. data/lib/extclasses/filefield.rb +18 -0
  18. data/lib/extclasses/form.rb +33 -0
  19. data/lib/extclasses/grid.rb +141 -0
  20. data/lib/extclasses/gridcolumn.rb +19 -0
  21. data/lib/extclasses/hidden.rb +7 -0
  22. data/lib/extclasses/htmleditor.rb +15 -0
  23. data/lib/extclasses/label.rb +10 -0
  24. data/lib/extclasses/numbercolumn.rb +30 -0
  25. data/lib/extclasses/numberfield.rb +19 -0
  26. data/lib/extclasses/paging.rb +12 -0
  27. data/lib/extclasses/panel.rb +29 -0
  28. data/lib/extclasses/passwordfield.rb +27 -0
  29. data/lib/extclasses/pivotgrid.rb +91 -0
  30. data/lib/extclasses/radio.rb +25 -0
  31. data/lib/extclasses/radiogroup.rb +14 -0
  32. data/lib/extclasses/runningcolumn.rb +9 -0
  33. data/lib/extclasses/tabpanel.rb +17 -0
  34. data/lib/extclasses/tbfill.rb +5 -0
  35. data/lib/extclasses/tbseparator.rb +5 -0
  36. data/lib/extclasses/templatecolumn.rb +11 -0
  37. data/lib/extclasses/textarea.rb +12 -0
  38. data/lib/extclasses/textfield.rb +27 -0
  39. data/lib/extclasses/timefield.rb +16 -0
  40. data/lib/extclasses/toolbar.rb +7 -0
  41. data/lib/extclasses/viewport.rb +8 -0
  42. data/lib/extclasses/window.rb +34 -0
  43. data/lib/extjsml/basenode.rb +347 -0
  44. data/lib/extjsml/ext_util.rb +232 -0
  45. data/lib/extjsml/generator.rb +578 -0
  46. data/lib/extjsml/parser.rb +35 -0
  47. data/lib/extmodules/form_field.rb +32 -0
  48. data/lib/extmodules/magic.rb +196 -0
  49. data/lib/extplugins/currency.rb +25 -0
  50. data/lib/extplugins/currencycolumn.rb +18 -0
  51. data/lib/extplugins/numeric.rb +32 -0
  52. data/lib/extplugins/pricefield.rb +36 -0
  53. data/lib/extuxs/uxaccount.rb +8 -0
  54. data/lib/extuxs/uxbroker.rb +7 -0
  55. data/lib/extuxs/uxchq.rb +8 -0
  56. data/lib/extuxs/uxreceiverinfo.rb +8 -0
  57. data/lib/extuxs/uxsettlement.rb +8 -0
  58. data/lib/test/test_parser.rb +97 -0
  59. metadata +115 -0
@@ -0,0 +1,61 @@
1
+ class ExtFieldset < ExtNode
2
+ include Magic::Title
3
+
4
+ @@ALIAS_CONFIG ={
5
+ :text => :title
6
+ }
7
+
8
+ def initialize(config, parent)
9
+ @default_config = {
10
+ layout: 'anchor',
11
+ animCollapse: true,
12
+ labelAlign: "right",
13
+ # collapsed: true,
14
+ # checkboxToggle: true,
15
+ autoHeight: true
16
+ # columnWidth: 0.5
17
+ }
18
+ super("fieldset", config, parent)
19
+ end
20
+
21
+ def to_extjs(at_deep = 0)
22
+ col_label_width = []
23
+ x = self.find_field_elements.map do |c|
24
+ [c.config[:fieldLabel], c.parent.config[:col_index], c.parent.config[:labelWidth] ]
25
+ end
26
+ self.find_field_elements.each do |c|
27
+ i = c.parent.config[:col_index] || 0
28
+ next unless i
29
+ unless col_label_width[i]
30
+ col_label_width[i] = []
31
+ end
32
+ col_label_width[i] << c.parent.config[:labelWidth]
33
+ end
34
+ max_label_width = []
35
+ col_label_width.each_with_index do |c, i|
36
+ max_label_width[i] = c.compact.max
37
+ end
38
+
39
+ # update max label within every fields container
40
+ self.find_field_elements.each do |c|
41
+ i = c.parent.config[:col_index] || 0
42
+ c.parent.config[:labelWidth] = max_label_width[i]
43
+ end
44
+
45
+ if @config[:labelWidth]
46
+ @config.merge!({ :defaults => { :labelWidth => @config[:labelWidth] } } )
47
+ # if set a button at the last child
48
+ if @childs.last.xtype == "button"
49
+ btn_style = @childs.last.config[:style]
50
+ new_btn_style = btn_style.dup if btn_style
51
+ new_btn_style ||= "{}"
52
+ fix_style = "margin-left: #{@config[:labelWidth]+5}px; margin-bottom: 0.5em; }"
53
+ new_btn_style.gsub!("}", fix_style)
54
+ @childs.last.config[:style] = new_btn_style
55
+ end
56
+ @config.delete :labelWidth
57
+ end
58
+
59
+ super(at_deep)
60
+ end
61
+ end
@@ -0,0 +1,18 @@
1
+ # depend ux
2
+ class ExtFilefield < ExtNode
3
+ include FormField
4
+
5
+ @@ALIAS_CONFIG = {
6
+ :text => :buttonText
7
+ }
8
+
9
+ def initialize(config, parent)
10
+ @default_config = {
11
+ width: 355,
12
+ labelAlign: "right",
13
+ buttonText: "Browse"
14
+ }
15
+ super('fileuploadfield',config, parent)
16
+ end
17
+ end
18
+
@@ -0,0 +1,33 @@
1
+ class ExtForm < ExtNode
2
+ # include Magic::Toolbar
3
+
4
+ def initialize(config, parent)
5
+ @default_config = {
6
+ # padding: 10,
7
+ autoHeight: true,
8
+ layout: 'anchor',
9
+ border: false
10
+ }
11
+ super('form', config, parent)
12
+ end
13
+
14
+ def to_extjs(at_deep = 0)
15
+ if @childs.last.xtype == "toolbar"
16
+ # get only item form toolbar
17
+ @config.merge! :fbar => @childs.last.to_extjs(at_deep + 1)
18
+
19
+ @childs.pop
20
+ end
21
+
22
+ if @childs.first.xtype == "toolbar"
23
+ @config.merge! :tbar => @childs.first.to_extjs(at_deep + 1)
24
+ @childs.slice!(0)
25
+ end
26
+ if find("paging",{:recursive => 1})
27
+ @config.merge! :bbar => find("paging").to_extjs(at_deep + 1)
28
+ self.remove_childs "paging"
29
+ end
30
+
31
+ super at_deep
32
+ end
33
+ end
@@ -0,0 +1,141 @@
1
+ class ExtGrid < ExtNode
2
+ include Magic::Store
3
+ include Magic::Title
4
+
5
+ @@ALIAS_CONFIG = {
6
+ :text => :title
7
+ }
8
+
9
+ def initialize(config, parent)
10
+ @default_config = {
11
+ title: "My Grid",
12
+ # enableHdMenu: false,
13
+ columnLines: true,
14
+ sm: "",
15
+ selector: "row",
16
+ # enableColumnmove: false,
17
+ viewConfig: {
18
+ forceFit: true,
19
+ emptyText: "No record"
20
+ # for expanding row to show any infomation
21
+ # enableRowBody: true
22
+ },
23
+ frame: false,
24
+ width: "auto",
25
+ loadMask: true,
26
+ # TODO dummy store
27
+ store: [],
28
+ height: 200
29
+ # columns: [
30
+ # { id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'},
31
+ # { header: 'Price', dataIndex: 'price'},
32
+ # { header: 'Change', dataIndex: 'change'},
33
+ # { header: '% Change', dataIndex: 'pctChange'},
34
+ # {
35
+ # header: 'Last Updated', width: 135, dataIndex: 'lastChange',
36
+ # xtype: 'datecolumn', format: 'M d, Y'
37
+ # }
38
+ # ]
39
+ }
40
+
41
+ super('grid',config, parent)
42
+ end
43
+
44
+ # TODO refactor
45
+ def to_extjs(at_deep = 0)
46
+ # columns
47
+ cols = []
48
+ self.childs.each do |c|
49
+ cols << c.to_extjs(at_deep) unless c.xtype.match(/column$/).nil?
50
+ end
51
+ @config.merge! :columns => cols unless cols.nil?
52
+
53
+ # rowselection type : row | rows, cell | cells, checkbox | checkboxs
54
+ #
55
+ # unless @config[:selector].nil?
56
+ # # generate random js variable name
57
+ # require "securerandom"
58
+ # var = SecureRandom.urlsafe_base64.gsub(/\d|\W/,'')
59
+ # case @config[:selector]
60
+ # when "row"
61
+ # @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.RowSelectionModel({ singleSelect: true }))</js>)"
62
+ # when "rows"
63
+ # @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.RowSelectionModel({ singleSelect: false }))</js>)"
64
+ # # TODO
65
+ # # when "cell"
66
+ # # @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.CellSelectionModel())</js>)"
67
+ # when "checkbox"
68
+ # @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.CheckboxSelectionModel({ singleSelect: true, header: '' }))</js>)"
69
+ # @config[:columns].unshift("<js>this._#{var}</js>")
70
+ # when "checkboxs"
71
+ # @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.CheckboxSelectionModel())</js>)"
72
+ # @config[:columns].unshift("<js>this._#{var}</js>")
73
+ # end
74
+ # @config.delete :selector
75
+ # end
76
+
77
+ toolbar = self.find("toolbar", {recursive: 1})
78
+ @config.merge! :tbar => toolbar.to_extjs(at_deep + 1) if toolbar
79
+
80
+ rand_store_id = nil
81
+ if @config[:store] == []
82
+
83
+ data_xtype = ExtUtil.data_xtype
84
+ data_cols = []
85
+
86
+ @config[:columns].each do |c|
87
+ if c.is_a? Hash
88
+ if data_xtype.include? c[:xtype]
89
+ data_cols << "{ name: '#{c[:dataIndex]}' }"
90
+ end
91
+ end
92
+ end
93
+
94
+ rand_store_id = ExtUtil.random_id
95
+ if @config[:restful]
96
+ @config[:url] = @config[:restful]
97
+ end
98
+
99
+ fetch_type = @config[:url] ? (@config[:restful] ? "rest" : "ajax") : "memory"
100
+ if data_cols.count > 0
101
+ @config[:store] = %Q{ <js>(
102
+ this.#{rand_store_id} = new Ext.data.JsonStore({
103
+ storeId: \"#{rand_store_id}\",
104
+ pageSize: #{@config[:pageSize] || default_page_size},
105
+ proxy: {
106
+ url: \"#{@config[:url]}\",
107
+ type: \"#{fetch_type}\",
108
+ reader: { type: \"json\", root: \"data\" }
109
+ },
110
+ fields: [#{data_cols.join(',')}]
111
+ }))
112
+ </js>}.strip
113
+
114
+ # remove internal usaged config
115
+ @config.delete :url
116
+ @config.delete :restful
117
+ end
118
+ @config.delete :pageSize
119
+ # auto create json store
120
+ end
121
+
122
+ # set paging
123
+ paging = self.find("pagingtoolbar")
124
+ if paging
125
+ paging.override_config :store => ("<js>this.#{rand_store_id}</js>" || @config[:store])
126
+ unless @config[:store] =~ /<js>/
127
+ paging.override_config :store => (rand_store_id || @config[:store])
128
+ end
129
+ @config.merge! :bbar => paging.to_extjs(at_deep + 1)
130
+ end
131
+
132
+ # grid does not allow to have items
133
+ self.childs = []
134
+
135
+ super(at_deep)
136
+ end
137
+
138
+ def default_page_size
139
+ 25
140
+ end
141
+ end
@@ -0,0 +1,19 @@
1
+ class ExtGridcolumn < ExtNode
2
+ include Magic::Column
3
+ @@ALIAS_CONFIG = {
4
+ :text => :header,
5
+ :name => :dataIndex
6
+ }
7
+ def initialize(config, parent)
8
+ @default_config = {}
9
+
10
+ super "gridcolumn", config, parent
11
+ end
12
+
13
+ def to_extjs(at_deep = 0)
14
+ if self.child_of? "editorgrid" and @config[:editor].nil?
15
+ @config.merge! :editor => { :xtype => "textfield" }
16
+ end
17
+ super at_deep
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ class ExtHidden < ExtNode
2
+ include FormField
3
+ def initialize(config, parent)
4
+ @default_config = {}
5
+ super "hidden", config, parent
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ class ExtHtmleditor < ExtNode
2
+ include FormField
3
+
4
+ @@ALIAS_CONFIG = {
5
+ :text => :fieldLabel
6
+ }
7
+
8
+ def initialize(config, parent)
9
+ @default_config = {
10
+ :labelAlign => "right"
11
+ }
12
+
13
+ super "htmleditor", config, parent
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ class ExtLabel < ExtNode
2
+ include Magic::Text
3
+ def initialize(config, parent)
4
+ @default_config = {
5
+
6
+ }
7
+ super("label", config, parent)
8
+
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ class ExtNumbercolumn < ExtNode
2
+ include Magic::Column
3
+
4
+ @@ALIAS_CONFIG = {
5
+ :text => :header,
6
+ :name => :dataIndex
7
+ }
8
+
9
+ def initialize(config, parent)
10
+
11
+ @default_config = {
12
+ :align => "right",
13
+ :sortable => true,
14
+ :format => "0,000"
15
+ }
16
+
17
+ super "numbercolumn", config, parent
18
+ end
19
+
20
+ def to_extjs(at_deep = 0)
21
+ if self.child_of? "editorgrid"
22
+ if @config[:editor].nil?
23
+ @config.merge! :editor => { :xtype => "numberfield" }
24
+ else
25
+ @config[:editor].merge! :xtype => "numberfield", :format => @config[:format] || "0,000.00"
26
+ end
27
+ end
28
+ super at_deep
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ class ExtNumberfield < ExtNode
2
+ include FormField
3
+
4
+ @@ALIAS_CONFIG = {
5
+ :text => :fieldLabel
6
+ }
7
+
8
+ def initialize(config, parent)
9
+ @default_config = {
10
+ labelAlign: "right",
11
+ decimalPrecision: 2,
12
+ decimalSeparator: '.',
13
+ allowDecimal: true,
14
+ allowNegative: false,
15
+ cls: "number"
16
+ }
17
+ super "numberfield", config, parent
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ class ExtPaging < ExtNode
2
+ def initialize(config, parent)
3
+ @default_config = {
4
+ start: 0,
5
+ limit: 20,
6
+ displayInfo: true,
7
+ dock: "bottom",
8
+ displayMsg: "Displaying {0} - {1} of {2}"
9
+ }
10
+ super('pagingtoolbar', config, parent)
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ class ExtPanel < ExtNode
2
+ include Magic::Title
3
+
4
+ @@ALIAS_CONFIG = {
5
+ :text => :title
6
+ }
7
+
8
+ def initialize(options, parent)
9
+ @default_config = {
10
+ :padding => 5,
11
+ # :height => 200,
12
+ :title => 'Title By Default',
13
+ :autoHeight => true
14
+ }
15
+ super("panel", options, parent)
16
+ end
17
+
18
+ def to_extjs(at_deep = 0)
19
+ if find("toolbar", { :recursive => 1})
20
+ @config.merge! :tbar => find("toolbar").to_extjs(at_deep + 1)
21
+ self.remove_childs "toolbar"
22
+ end
23
+ if find("paging", { :recursive => 1})
24
+ @config.merge! :bbar => find("paging").to_extjs(at_deep + 1)
25
+ self.remove_childs "paging"
26
+ end
27
+ super at_deep
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ class ExtPasswordfield < ExtNode
2
+ include FormField
3
+
4
+ @@ALIAS_CONFIG = {
5
+ :text => :fieldLabel
6
+ }
7
+
8
+ def initialize(config, parent)
9
+ @default_config = {
10
+ :width => 150,
11
+ :autoCreate => {
12
+ :tag => "input",
13
+ :type => "password",
14
+ :autocomplete => "off"
15
+ }
16
+ }
17
+ if config[:autoCreate]
18
+ @default_config.merge! config[:autoCreate]
19
+ config.delete :autoCreate
20
+ end
21
+ if config[:emptyText]
22
+ @default_config[:autoCreate][:placeholder] = config[:emptyText]
23
+ config.delete :emptyText
24
+ end
25
+ super('textfield', config, parent)
26
+ end
27
+ end
@@ -0,0 +1,91 @@
1
+ class ExtPivotgrid < ExtNode
2
+ include Magic::Store
3
+ include Magic::Title
4
+
5
+ @@ALIAS_CONFIG = {
6
+ :text => :title
7
+ }
8
+
9
+ def initialize(config, parent)
10
+ @default_config = {
11
+ title: "My Grid",
12
+ # enableHdMenu: false,
13
+ columnLines: true,
14
+ sm: "",
15
+ selector: "row",
16
+ # enableColumnmove: false,
17
+ viewConfig: {
18
+ forceFit: true,
19
+ emptyText: "No record"
20
+ # for expanding row to show any infomation
21
+ # enableRowBody: true
22
+ },
23
+ frame: true,
24
+ width: "auto",
25
+ loadMask: true,
26
+ # TODO dummy store
27
+ store: [],
28
+ height: 200
29
+ # columns: [
30
+ # { id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'},
31
+ # { header: 'Price', dataIndex: 'price'},
32
+ # { header: 'Change', dataIndex: 'change'},
33
+ # { header: '% Change', dataIndex: 'pctChange'},
34
+ # {
35
+ # header: 'Last Updated', width: 135, dataIndex: 'lastChange',
36
+ # xtype: 'datecolumn', format: 'M d, Y'
37
+ # }
38
+ # ]
39
+ }
40
+
41
+ super('pivotgrid',config, parent)
42
+ end
43
+
44
+ # TODO refactor
45
+ def to_extjs(at_deep = 0)
46
+ # columns
47
+ cols = []
48
+ self.childs.each do |c|
49
+ cols << c.to_extjs(at_deep) unless c.xtype.match(/column$/).nil?
50
+ end
51
+ @config.merge! :columns => cols unless cols.nil?
52
+
53
+ # rowselection type : row | rows, cell | cells, checkbox | checkboxs
54
+ unless @config[:selector].nil?
55
+ # generate random js variable name
56
+ require "securerandom"
57
+ var = SecureRandom.urlsafe_base64.gsub(/\d|\W/,'')
58
+ case @config[:selector]
59
+ when "row"
60
+ @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.RowSelectionModel({ singleSelect: true }))</js>)"
61
+ when "rows"
62
+ @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.RowSelectionModel({ singleSelect: false }))</js>)"
63
+ # TODO
64
+ # when "cell"
65
+ # @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.CellSelectionModel())</js>)"
66
+ when "checkbox"
67
+ @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.CheckboxSelectionModel({ singleSelect: true, header: '' }))</js>)"
68
+ @config[:columns].unshift("<js>this._#{var}</js>")
69
+ when "checkboxs"
70
+ @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.CheckboxSelectionModel())</js>)"
71
+ @config[:columns].unshift("<js>this._#{var}</js>")
72
+ end
73
+ @config.delete :selector
74
+ end
75
+
76
+ toolbar = self.find("toolbar", {recursive: 1})
77
+ @config.merge! :tbar => toolbar.to_extjs(at_deep + 1) if toolbar
78
+
79
+ paging = self.find("paging")
80
+ if paging
81
+ unless @config[:store] =~ /<js>/
82
+ paging.override_config :store => @config[:store]
83
+ end
84
+ @config.merge! :bbar => paging.to_extjs(at_deep + 1)
85
+ end
86
+
87
+ # grid not allow to have items
88
+ self.childs = []
89
+ super(at_deep)
90
+ end
91
+ end