extjs-mvc 0.3.10 → 0.4.0.a
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.rdoc +5 -173
- data/Rakefile +18 -20
- data/VERSION +1 -1
- data/bin/xmvc +13 -0
- data/lib/extjs-mvc/README +20 -0
- data/lib/extjs-mvc/builder.rb +83 -0
- data/lib/extjs-mvc/builders/all_builder.rb +15 -0
- data/lib/extjs-mvc/builders/app_builder.rb +36 -0
- data/lib/extjs-mvc/builders/base.rb +138 -0
- data/lib/extjs-mvc/builders/css_builder.rb +36 -0
- data/lib/extjs-mvc/builders/docs_builder.rb +20 -0
- data/lib/extjs-mvc/builders/mvc_builder.rb +33 -0
- data/lib/extjs-mvc/builders/plugin_builder.rb +53 -0
- data/lib/extjs-mvc/cli.rb +52 -0
- data/lib/extjs-mvc/generator.rb +79 -0
- data/lib/extjs-mvc/generators/app.rb +57 -0
- data/lib/extjs-mvc/generators/base.rb +53 -0
- data/lib/extjs-mvc/generators/controller.rb +41 -0
- data/lib/extjs-mvc/generators/model.rb +41 -0
- data/lib/extjs-mvc/generators/scaffold.rb +17 -0
- data/lib/extjs-mvc/generators/templates/Controller.js +17 -0
- data/lib/extjs-mvc/generators/templates/Model.js +9 -0
- data/lib/extjs-mvc/generators/templates/ModelSpec.js +12 -0
- data/lib/extjs-mvc/generators/templates/View.js +16 -0
- data/lib/extjs-mvc/generators/templates/_Action.js +7 -0
- data/lib/extjs-mvc/generators/templates/app/README.rdoc +152 -0
- data/lib/extjs-mvc/generators/templates/app/app/App.js +64 -0
- data/lib/extjs-mvc/generators/templates/app/app/controllers/ApplicationController.js +10 -0
- data/lib/extjs-mvc/generators/templates/app/app/controllers/HomeController.js +10 -0
- data/lib/extjs-mvc/generators/templates/app/app/views/home/Index.js +17 -0
- data/lib/extjs-mvc/generators/templates/app/app/views/layout/Menu.js +23 -0
- data/lib/extjs-mvc/generators/templates/app/config/application.js +1 -0
- data/lib/extjs-mvc/generators/templates/app/config/boot.js +67 -0
- data/lib/extjs-mvc/generators/templates/app/config/build.xml +77 -0
- data/lib/extjs-mvc/generators/templates/app/config/database.js +4 -0
- data/lib/extjs-mvc/generators/templates/app/config/environment.json +58 -0
- data/lib/extjs-mvc/generators/templates/app/config/environments/development.json +1 -0
- data/lib/extjs-mvc/generators/templates/app/config/environments/production.json +4 -0
- data/lib/extjs-mvc/generators/templates/app/config/routes.js +27 -0
- data/lib/extjs-mvc/generators/templates/app/config/settings.yml +3 -0
- data/lib/extjs-mvc/generators/templates/app/public/index.html +19 -0
- data/lib/extjs-mvc/generators/templates/app/public/stylesheets/ext-mvc-all.css +49 -0
- data/{test/active_record_test.rb → lib/extjs-mvc/generators/templates/app/spec/SpecHelper.js} +0 -0
- data/lib/extjs-mvc/generators/templates/app/spec/index.html +66 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/EXAMPLE.html +68 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/LICENSE +22 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/README.markdown +307 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery-1.2.3.js +3408 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery.fn.js +29 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery.print.js +108 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.assets.js +36 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.behaviors.js +91 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.builder.js +80 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.css +90 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.events.js +42 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.matchers.js +145 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.server.js +21 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/behaviors_spec.js +178 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/matchers_spec.js +237 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/print_spec.js +119 -0
- data/{test/controller_test.rb → lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/spec_helper.js} +0 -0
- data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/suite.html +18 -0
- data/lib/extjs-mvc/generators/templates/scaffold/ScaffoldController.js +18 -0
- data/lib/extjs-mvc/generators/view.rb +29 -0
- data/lib/extjs-mvc/plugin.rb +105 -0
- data/lib/extjs-mvc/scripts.rb +15 -0
- data/lib/extjs-mvc/settings.rb +75 -0
- data/lib/extjs-mvc/setup.rb +5 -0
- data/lib/extjs-mvc/stats.rb +241 -0
- data/lib/extjs-mvc/test.rb +11 -0
- data/lib/extjs-mvc/testserver.ru +95 -0
- data/lib/extjs-mvc/ui.rb +58 -0
- data/lib/extjs-mvc/update.rb +73 -0
- data/lib/extjs-mvc.rb +70 -32
- data/lib/js/App.js +219 -0
- data/lib/js/MVC.js +260 -0
- data/lib/js/Presenter.js +52 -0
- data/lib/js/README.rdoc +69 -0
- data/lib/js/build +21 -0
- data/lib/js/controller/Controller.js +278 -0
- data/lib/js/controller/CrudController.js +460 -0
- data/lib/js/lib/Array.js +26 -0
- data/lib/js/lib/Booter.js +415 -0
- data/lib/js/lib/ClassManager.js +191 -0
- data/lib/js/lib/ControllerClassManager.js +95 -0
- data/lib/js/lib/Dependencies.js +44 -0
- data/lib/js/lib/DispatchMatcher.js +98 -0
- data/lib/js/lib/Dispatcher.js +129 -0
- data/lib/js/lib/Environment.js +43 -0
- data/lib/js/lib/Inflector.js +138 -0
- data/lib/js/lib/ModelClassManager.js +19 -0
- data/lib/js/lib/Route.js +139 -0
- data/lib/js/lib/Router.js +282 -0
- data/lib/js/lib/String.js +94 -0
- data/lib/js/lib/ViewClassManager.js +229 -0
- data/lib/js/lib/notes.txt +32 -0
- data/lib/js/model/AdapterManager.js +30 -0
- data/lib/js/model/Association.js +26 -0
- data/lib/js/model/Base.js +63 -0
- data/lib/js/model/BelongsToAssociation.js +116 -0
- data/lib/js/model/Cache.js +131 -0
- data/lib/js/model/HasManyAssociation.js +160 -0
- data/lib/js/model/Model.js +331 -0
- data/lib/js/model/UrlBuilder.js +106 -0
- data/lib/js/model/adapters/AbstractAdapter.js +296 -0
- data/lib/js/model/adapters/MemoryAdapter.js +103 -0
- data/lib/js/model/adapters/RESTAdapter.js +345 -0
- data/lib/js/model/adapters/RESTJSONAdapter.js +68 -0
- data/lib/js/model/adapters/notes.txt +42 -0
- data/lib/js/model/associations/Association.js +192 -0
- data/lib/js/model/associations/notes.txt +87 -0
- data/lib/js/model/validations/Errors.js +136 -0
- data/lib/js/model/validations/Plugin.js +139 -0
- data/lib/js/model/validations/Validations.js +276 -0
- data/lib/js/notes/Charts.graffle +0 -0
- data/lib/js/overrides/Ext.Component.js +21 -0
- data/lib/js/overrides/Ext.extend.js +142 -0
- data/lib/js/spec/Array.spec.js +15 -0
- data/lib/js/spec/ExtMVC.spec.js +65 -0
- data/lib/js/spec/Model.spec.js +370 -0
- data/lib/js/spec/OS.spec.js +83 -0
- data/lib/js/spec/Router.spec.js +99 -0
- data/lib/js/spec/SpecHelper.js +106 -0
- data/lib/js/spec/String.spec.js +83 -0
- data/lib/js/spec/model/AbstractAdapter.spec.js +49 -0
- data/lib/js/spec/model/Associations.spec.js +99 -0
- data/lib/js/spec/model/Cache.spec.js +5 -0
- data/lib/js/spec/model/RESTAdapter.spec.js +19 -0
- data/lib/js/spec/model/ValidationErrors.spec.js +64 -0
- data/lib/js/spec/model/Validations.spec.js +166 -0
- data/lib/js/spec/model/ValidationsPlugin.spec.js +108 -0
- data/lib/js/spec/suite.html +60 -0
- data/lib/js/specs-old/JSSpec.css +216 -0
- data/lib/js/specs-old/JSSpec.js +1512 -0
- data/lib/js/specs-old/all.html +66 -0
- data/lib/js/specs-old/base.js +14 -0
- data/lib/js/specs-old/controller.js +17 -0
- data/lib/js/specs-old/diff_match_patch.js +1 -0
- data/lib/js/specs-old/model.js +70 -0
- data/lib/js/specs-old/route.js +38 -0
- data/lib/js/specs-old/router.js +59 -0
- data/lib/js/specs-old/string.js +22 -0
- data/lib/js/testrunner/JSpecFormatter.js +111 -0
- data/lib/js/testrunner/TestClient.js +181 -0
- data/lib/js/testrunner/TestGrid.js +351 -0
- data/lib/js/testrunner/TestRunner.js +110 -0
- data/lib/js/testrunner/TestViewport.js +94 -0
- data/lib/js/vendor/screw-unit/EXAMPLE.html +68 -0
- data/lib/js/vendor/screw-unit/LICENSE +22 -0
- data/lib/js/vendor/screw-unit/README.markdown +307 -0
- data/lib/js/vendor/screw-unit/lib/jquery-1.2.3.js +3408 -0
- data/lib/js/vendor/screw-unit/lib/jquery.fn.js +29 -0
- data/lib/js/vendor/screw-unit/lib/jquery.print.js +108 -0
- data/lib/js/vendor/screw-unit/lib/screw.assets.js +36 -0
- data/lib/js/vendor/screw-unit/lib/screw.behaviors.js +91 -0
- data/lib/js/vendor/screw-unit/lib/screw.builder.js +80 -0
- data/lib/js/vendor/screw-unit/lib/screw.css +91 -0
- data/lib/js/vendor/screw-unit/lib/screw.events.js +42 -0
- data/lib/js/vendor/screw-unit/lib/screw.matchers.js +145 -0
- data/lib/js/vendor/screw-unit/lib/screw.server.js +21 -0
- data/lib/js/vendor/screw-unit/spec/behaviors_spec.js +178 -0
- data/lib/js/vendor/screw-unit/spec/matchers_spec.js +237 -0
- data/lib/js/vendor/screw-unit/spec/print_spec.js +119 -0
- data/{test/data_mapper_test.rb → lib/js/vendor/screw-unit/spec/spec_helper.js} +0 -0
- data/lib/js/vendor/screw-unit/spec/suite.html +18 -0
- data/lib/js/view/FormWindow.js +184 -0
- data/lib/js/view/HasManyEditorGridPanel.js +211 -0
- data/lib/js/view/scaffold/Edit.js +46 -0
- data/lib/js/view/scaffold/Index.js +561 -0
- data/lib/js/view/scaffold/New.js +20 -0
- data/lib/js/view/scaffold/ScaffoldFormPanel.js +255 -0
- data/test/helper.rb +10 -0
- data/test/test_extjs-mvc-gem.rb +7 -0
- metadata +232 -56
- data/README +0 -12
- data/lib/controller/controller.rb +0 -28
- data/lib/core_ext/array/extract_options.rb +0 -15
- data/lib/extjs/component.rb +0 -71
- data/lib/extjs/data/store.rb +0 -131
- data/lib/helpers/component.rb +0 -37
- data/lib/helpers/store.rb +0 -7
- data/lib/model/active_record.rb +0 -89
- data/lib/model/base.rb +0 -370
- data/lib/model/data_mapper.rb +0 -66
- data/lib/model/mongo_mapper.rb +0 -64
- data/lib/test/macros.rb +0 -20
- data/test/app/config/application.rb +0 -70
- data/test/app/config/database.yml +0 -3
- data/test/app/db/schema.rb +0 -75
- data/test/app/models/active_record/address.rb +0 -4
- data/test/app/models/active_record/data_type.rb +0 -3
- data/test/app/models/active_record/group.rb +0 -4
- data/test/app/models/active_record/house.rb +0 -4
- data/test/app/models/active_record/location.rb +0 -5
- data/test/app/models/active_record/person.rb +0 -4
- data/test/app/models/active_record/user.rb +0 -6
- data/test/app/models/active_record/user_group.rb +0 -4
- data/test/component_test.rb +0 -15
- data/test/debug.log +0 -2969
- data/test/model_test.rb +0 -526
- data/test/mongo_mapper_test.rb +0 -0
- data/test/store_test.rb +0 -0
- data/test/test_helper.rb +0 -32
data/lib/extjs/component.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# @class ExtJS::Component
|
3
|
-
#
|
4
|
-
class ExtJS::Component
|
5
|
-
attr_accessor :config
|
6
|
-
def initialize(params)
|
7
|
-
@config = params#params.extract_options!
|
8
|
-
@controller = @config.delete(:controller) unless @config[:controller].nil?
|
9
|
-
|
10
|
-
@config["items"] = [] if config["items"].nil?
|
11
|
-
|
12
|
-
if container = @config.delete(:container)
|
13
|
-
container.add(self)
|
14
|
-
end
|
15
|
-
@partial_config = nil
|
16
|
-
end
|
17
|
-
|
18
|
-
def apply(params)
|
19
|
-
@config.merge!(params)
|
20
|
-
end
|
21
|
-
|
22
|
-
##
|
23
|
-
# Adds a config {} or ExtJS::Component instance to this component's items collection.
|
24
|
-
# NOTE: When :partial option is used a String will of course be returned. Otherwise an ExtJS::Component
|
25
|
-
# instance will be returned.
|
26
|
-
# @return {String/ExtJS::Component}
|
27
|
-
def add(*config)
|
28
|
-
|
29
|
-
options = config.extract_options!
|
30
|
-
if !options.keys.empty?
|
31
|
-
if url = options.delete(:partial)
|
32
|
-
# rendering a partial, cache the config until partial calls #add method. @see else.
|
33
|
-
@partial_config = options
|
34
|
-
if (@controller.respond_to?(:partial))
|
35
|
-
# Merb
|
36
|
-
return @controller.partial(url, :with => self, :as => :container)
|
37
|
-
else
|
38
|
-
# Rails
|
39
|
-
return @controller.render(:partial => url, :locals => {:container => self})
|
40
|
-
end
|
41
|
-
else
|
42
|
-
options.merge!(@partial_config) unless @partial_config.nil?
|
43
|
-
options[:controller] = @controller unless @controller.nil?
|
44
|
-
cmp = ExtJS::Component.new(options)
|
45
|
-
@partial_config = nil
|
46
|
-
@config["items"] << cmp
|
47
|
-
return cmp
|
48
|
-
end
|
49
|
-
elsif !config.empty? && config.first.kind_of?(ExtJS::Component)
|
50
|
-
cmp = config.first
|
51
|
-
cmp.apply(@partial_config) unless @partial_config.nil?
|
52
|
-
@partial_config = nil
|
53
|
-
@config["items"] << cmp.config
|
54
|
-
return cmp
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def to_json
|
59
|
-
config.to_json
|
60
|
-
end
|
61
|
-
|
62
|
-
def render
|
63
|
-
@config.delete("items") if @config["items"].empty?
|
64
|
-
|
65
|
-
# If there are any listeners attached in json, we have to get rid of double-quotes in order to expose
|
66
|
-
# the javascript object.
|
67
|
-
# eg: "listeners":"SomeController.listeners.grid" -> {"listeners":SomeController.listeners.grid, ...}
|
68
|
-
json = @config.to_json.gsub(/\"(listeners|handler|scope)\":\s?\"([a-zA-Z\.\[\]\(\)]+)\"/, '"\1":\2')
|
69
|
-
"Ext.ComponentMgr.create(#{json});"
|
70
|
-
end
|
71
|
-
end
|
data/lib/extjs/data/store.rb
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# ExtJS::Data::Store
|
3
|
-
#
|
4
|
-
module ExtJS::Data
|
5
|
-
class Store
|
6
|
-
attr_accessor :id, :format, :type, :controller, :model
|
7
|
-
|
8
|
-
def initialize(*params)
|
9
|
-
options = params.extract_options!
|
10
|
-
|
11
|
-
@config = options[:config] || {}
|
12
|
-
@format = options[:format] || 'json'
|
13
|
-
@fieldset = options[:fieldset] || :default
|
14
|
-
@schema = options[:schema]
|
15
|
-
@proxy = options[:proxy] || 'http'
|
16
|
-
@writer = options[:writer]
|
17
|
-
@type = (options[:type].nil?) ? @proxy === 'direct' ? 'Ext.data.DirectStore' : "Ext.data.#{@format.capitalize}Store" : options[:type]
|
18
|
-
|
19
|
-
@controller = self.class.get_controller(options[:controller])
|
20
|
-
@model = self.class.get_model(options[:controller], options[:model])
|
21
|
-
|
22
|
-
# Merge Reader/Proxy config
|
23
|
-
@config.merge!(reader)
|
24
|
-
@config.merge!(proxy)
|
25
|
-
|
26
|
-
@config["baseParams"] = {} if @config["baseParams"].nil?
|
27
|
-
@config["baseParams"].update("fieldset" => @fieldset)
|
28
|
-
|
29
|
-
@config["format"] = @format
|
30
|
-
|
31
|
-
# Set storeId implicitly based upon Model name if not set explicitly
|
32
|
-
@id = @config["storeId"] = @model.to_s.downcase unless @config["storeId"]
|
33
|
-
end
|
34
|
-
|
35
|
-
##
|
36
|
-
# pre-load a store with data. Not yet tested. In theory, this *should* work.
|
37
|
-
#
|
38
|
-
def load(*params)
|
39
|
-
#@config["loadData"] = @model.all(params).collect {|rec| rec.to_record }
|
40
|
-
end
|
41
|
-
|
42
|
-
##
|
43
|
-
# renders the configured store
|
44
|
-
# @param {Boolean} script_tag [true] Not yet implemented. Always renders <script></script> tags.
|
45
|
-
def render(script_tag = true)
|
46
|
-
script = ''
|
47
|
-
# ugly hack for DirectProxy API. Have to add an Ext.onReady() after the Store constructor to set API
|
48
|
-
if @proxy === 'direct'
|
49
|
-
auto_load = @config.delete("autoLoad")
|
50
|
-
cname = @controller.controller_name.capitalize
|
51
|
-
script = "Ext.onReady(function() { var s = Ext.StoreMgr.get('#{@config["storeId"]}');"
|
52
|
-
if (@config["directFn"])
|
53
|
-
script += "s.proxy.directFn = #{cname}.#{@config["directFn"]};"
|
54
|
-
else
|
55
|
-
script += "s.proxy.setApi({create:#{cname}.#{@config["api"]["create"]},read:#{cname}.#{@config["api"]["read"]},update:#{cname}.#{@config["api"]["update"]},destroy:#{cname}.#{@config["api"]["destroy"]}});"
|
56
|
-
end
|
57
|
-
if auto_load
|
58
|
-
script += "s.load();"
|
59
|
-
end
|
60
|
-
script += "});"
|
61
|
-
end
|
62
|
-
|
63
|
-
if @writer # <-- ugly hack because 3.0.1 can't deal with Writer as config-param
|
64
|
-
json = @config.to_json
|
65
|
-
json[json.length-1] = ','
|
66
|
-
json += "\"writer\":new Ext.data.#{@format.capitalize}Writer(#{@writer.to_json})}"
|
67
|
-
"<script>new #{@type}(#{json});#{script}</script>"
|
68
|
-
else
|
69
|
-
"<script>new #{@type}(#{@config.to_json});#{script}</script>"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def self.get_controller(name)
|
76
|
-
begin
|
77
|
-
if (defined?(Rails))
|
78
|
-
"#{name.to_s.camelize}Controller".constantize
|
79
|
-
else
|
80
|
-
Extlib::Inflection.constantize("#{Extlib::Inflection.camelize(name)}")
|
81
|
-
end
|
82
|
-
rescue NameError
|
83
|
-
throw NameError.new("ExtJS::Store failed with an unknown controller named '#{name.to_s}'")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def self.get_model(controller, model)
|
88
|
-
unless model.class == Class
|
89
|
-
begin
|
90
|
-
if (defined?(Rails))
|
91
|
-
model = ((model) ? model : controller.singularize).camelize.constantize
|
92
|
-
else
|
93
|
-
model = Extlib::Inflection.constantize(Extlib::Inflection.camelize(((model) ? model : Extlib::Inflection.singularize(controller))))
|
94
|
-
end
|
95
|
-
rescue NameError => e
|
96
|
-
throw NameError.new("EXTJS::Store found an unknown model #{model.to_s})")
|
97
|
-
end
|
98
|
-
end
|
99
|
-
model
|
100
|
-
end
|
101
|
-
|
102
|
-
def proxy
|
103
|
-
proxy = {}
|
104
|
-
if @proxy === 'direct'
|
105
|
-
actions = ['create', 'read', 'update', 'destroy']
|
106
|
-
proxy["api"] = {}
|
107
|
-
@controller.direct_actions.each_index do |n|
|
108
|
-
proxy["api"][actions[n]] = @controller.direct_actions[n][:name]
|
109
|
-
end
|
110
|
-
else
|
111
|
-
if @config["api"]
|
112
|
-
proxy["api"] = {}
|
113
|
-
@config["api"].each {|k,v| proxy["api"][k] = "/#{@controller.controller_name}/#{v}" }
|
114
|
-
else
|
115
|
-
proxy["url"] = "/#{@controller.controller_name}.#{@format.to_s}"
|
116
|
-
end
|
117
|
-
end
|
118
|
-
proxy
|
119
|
-
end
|
120
|
-
|
121
|
-
def reader
|
122
|
-
{
|
123
|
-
"successProperty" => @controller.extjs_success_property,
|
124
|
-
"root" => @controller.extjs_root,
|
125
|
-
"messageProperty" => @controller.extjs_message_property
|
126
|
-
}.merge(@schema || @model.extjs_record(@fieldset))
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
end
|
data/lib/helpers/component.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# ExtJS::Helpers::Component
|
3
|
-
#
|
4
|
-
module ExtJS::Helpers
|
5
|
-
module Component
|
6
|
-
##
|
7
|
-
# add class-var @@extjs_on_ready
|
8
|
-
def self.included(helper)
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def extjs_component(*params)
|
13
|
-
options = params.extract_options!
|
14
|
-
options[:controller] = self
|
15
|
-
ExtJS::Component.new(options)
|
16
|
-
end
|
17
|
-
|
18
|
-
##
|
19
|
-
# Adds a script or ExtJS::Component instance to on_ready queue. The queue is emptied and rendered to
|
20
|
-
# <script></script> via #extjs_render
|
21
|
-
#
|
22
|
-
def extjs_onready(*params)
|
23
|
-
@onready_queue = [] if @onready_queue.nil?
|
24
|
-
params.each do |cmp|
|
25
|
-
@onready_queue << cmp
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
##
|
30
|
-
# Empties the on_ready queue. Renders within <script></script> tags
|
31
|
-
#
|
32
|
-
def extjs_render
|
33
|
-
@onready_queue = [] if @onready_queue.nil?
|
34
|
-
"<script>\nExt.onReady(function() {\n\t#{@onready_queue.collect {|cmp| (cmp.kind_of?(ExtJS::Component)) ? cmp.render : cmp}.join("\n\t")}\n });\n</script>"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/lib/helpers/store.rb
DELETED
data/lib/model/active_record.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# ActiveRecord adapter to ExtJS::Model mixin.
|
3
|
-
#
|
4
|
-
module ExtJS
|
5
|
-
module Model
|
6
|
-
module ClassMethods
|
7
|
-
|
8
|
-
def extjs_primary_key
|
9
|
-
self.primary_key.to_sym
|
10
|
-
end
|
11
|
-
|
12
|
-
def extjs_column_names
|
13
|
-
self.column_names.map(&:to_sym)
|
14
|
-
end
|
15
|
-
|
16
|
-
def extjs_columns_hash
|
17
|
-
self.columns_hash.symbolize_keys
|
18
|
-
end
|
19
|
-
|
20
|
-
##
|
21
|
-
# determine if supplied Column object is nullable
|
22
|
-
# @param {ActiveRecord::ConnectionAdapters::Column}
|
23
|
-
# @return {Boolean}
|
24
|
-
#
|
25
|
-
def extjs_allow_blank(col)
|
26
|
-
# if the column is the primary key always allow it to be blank.
|
27
|
-
# Otherwise we could not create new records with ExtJS because
|
28
|
-
# new records have no id and thus cannot be valid
|
29
|
-
col.name == self.primary_key || col.null
|
30
|
-
end
|
31
|
-
|
32
|
-
##
|
33
|
-
# returns the default value
|
34
|
-
# @param {ActiveRecord::ConnectionAdapters::Column}
|
35
|
-
# @return {Mixed}
|
36
|
-
#
|
37
|
-
def extjs_default(col)
|
38
|
-
col.default
|
39
|
-
end
|
40
|
-
|
41
|
-
##
|
42
|
-
# returns the corresponding column name of the type column for a polymorphic association
|
43
|
-
# @param {String/Symbol} the id column name for this association
|
44
|
-
# @return {Symbol}
|
45
|
-
def extjs_polymorphic_type(id_column_name)
|
46
|
-
id_column_name.to_s.gsub(/_id\Z/, '_type').to_sym
|
47
|
-
end
|
48
|
-
|
49
|
-
##
|
50
|
-
# determine datatype of supplied Column object
|
51
|
-
# @param {ActiveRecord::ConnectionAdapters::Column}
|
52
|
-
# @return {String}
|
53
|
-
#
|
54
|
-
def extjs_type(col)
|
55
|
-
type = col.type.to_s
|
56
|
-
case type
|
57
|
-
when "datetime", "date", "time", "timestamp"
|
58
|
-
type = "date"
|
59
|
-
when "text"
|
60
|
-
type = "string"
|
61
|
-
when "integer"
|
62
|
-
type = "int"
|
63
|
-
when "decimal"
|
64
|
-
type = "float"
|
65
|
-
end
|
66
|
-
type
|
67
|
-
end
|
68
|
-
|
69
|
-
##
|
70
|
-
# return a simple, normalized list of AR associations having the :name, :type and association class
|
71
|
-
# @return {Array}
|
72
|
-
#
|
73
|
-
def extjs_associations
|
74
|
-
@extjs_associations ||= self.reflections.inject({}) do |memo, (key, assn)|
|
75
|
-
type = (assn.macro === :has_many || assn.macro === :has_and_belongs_to_many) ? :many : assn.macro
|
76
|
-
memo[key.to_sym] = {
|
77
|
-
:name => key.to_sym,
|
78
|
-
:type => type,
|
79
|
-
:class => assn.options[:polymorphic] ? nil : assn.class_name.constantize,
|
80
|
-
:foreign_key => assn.association_foreign_key.to_sym,
|
81
|
-
:is_polymorphic => !!assn.options[:polymorphic]
|
82
|
-
}
|
83
|
-
memo
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|