luca 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +77 -0
- data/Guardfile +22 -0
- data/README.md +291 -0
- data/Rakefile +28 -0
- data/app.rb +46 -0
- data/assets/images/glyphicons-halflings-white.png +0 -0
- data/assets/images/glyphicons-halflings.png +0 -0
- data/assets/javascripts/dependencies/backbone-min.js +37 -0
- data/assets/javascripts/dependencies/backbone-query.min.js +1 -0
- data/assets/javascripts/dependencies/bootstrap.min.js +1 -0
- data/assets/javascripts/dependencies/jasmine-html.js +190 -0
- data/assets/javascripts/dependencies/jasmine.js +2476 -0
- data/assets/javascripts/dependencies/jquery.js +4 -0
- data/assets/javascripts/dependencies/modal.js +698 -0
- data/assets/javascripts/dependencies/modernizr.min.js +30 -0
- data/assets/javascripts/dependencies/prettify.js +28 -0
- data/assets/javascripts/dependencies/sinon.js +3469 -0
- data/assets/javascripts/dependencies/spin-min.js +2 -0
- data/assets/javascripts/dependencies/underscore-min.js +31 -0
- data/assets/javascripts/dependencies/underscore-string.min.js +14 -0
- data/assets/javascripts/dependencies.coffee +7 -0
- data/assets/javascripts/luca-ui-base.coffee +12 -0
- data/assets/javascripts/luca-ui-spec.coffee +2 -0
- data/assets/javascripts/luca-ui.coffee +3 -0
- data/assets/javascripts/sandbox/collections/sample.coffee +0 -0
- data/assets/javascripts/sandbox/config.coffee +7 -0
- data/assets/javascripts/sandbox/sandbox.coffee +16 -0
- data/assets/javascripts/sandbox/templates/features/collection_helpers.luca +33 -0
- data/assets/javascripts/sandbox/templates/features/form_demo_code.luca +48 -0
- data/assets/javascripts/sandbox/templates/features/grid_demo_code.luca +24 -0
- data/assets/javascripts/sandbox/templates/features/introduction.luca +11 -0
- data/assets/javascripts/sandbox/templates/features/view_helpers.luca +43 -0
- data/assets/javascripts/sandbox/templates/navigation.luca +8 -0
- data/assets/javascripts/sandbox/views/form_demo.coffee +47 -0
- data/assets/javascripts/sandbox/views/grid_demo.coffee +23 -0
- data/assets/javascripts/sandbox/views/pages/collection_events_sample.coffee +1 -0
- data/assets/javascripts/sandbox/views/pages/pages_controller.coffee +28 -0
- data/assets/javascripts/sandbox.coffee +4 -0
- data/assets/javascripts/spec-dependencies.coffee +4 -0
- data/assets/stylesheets/bootstrap-responsive.min.css +3 -0
- data/assets/stylesheets/bootstrap.min.css +610 -0
- data/assets/stylesheets/jasmine.css +166 -0
- data/assets/stylesheets/luca-ui-bootstrap.css +5 -0
- data/assets/stylesheets/luca-ui-spec.css +3 -0
- data/assets/stylesheets/luca-ui.css +3 -0
- data/assets/stylesheets/prettify.css +40 -0
- data/assets/stylesheets/sandbox/sandbox.scss +4 -0
- data/assets/stylesheets/sandbox.css +3 -0
- data/config.ru +11 -0
- data/lib/luca/command_line.rb +69 -0
- data/lib/luca/rails/engine.rb +12 -0
- data/lib/luca/rails/version.rb +6 -0
- data/lib/luca/rails.rb +9 -0
- data/lib/luca/template.rb +51 -0
- data/lib/luca/test_harness.rb +106 -0
- data/lib/luca.rb +1 -0
- data/lib/sprockets/luca_template.rb +49 -0
- data/lib/templates/spec_manifest_javascripts.erb +7 -0
- data/lib/templates/spec_manifest_stylesheets.erb +11 -0
- data/luca.gemspec +26 -0
- data/public/jasmine/index.html +26 -0
- data/public/sandbox/api.js +1 -0
- data/spec/components/application_spec.coffee +0 -0
- data/spec/components/collection_loader_view_spec.coffee +0 -0
- data/spec/components/controller_spec.coffee +0 -0
- data/spec/components/form_view_spec.coffee +13 -0
- data/spec/components/grid_view_spec.coffee +0 -0
- data/spec/components/record_manager_spec.coffee +0 -0
- data/spec/components/template_spec.coffee +0 -0
- data/spec/containers/card_view_spec.coffee +1 -0
- data/spec/containers/column_view_spec.coffee +0 -0
- data/spec/containers/modal_view_spec.coffee +0 -0
- data/spec/containers/panel_view_spec.coffee +0 -0
- data/spec/containers/split_view_spec.coffee +0 -0
- data/spec/containers/tab_view_spec.coffee +0 -0
- data/spec/containers/viewport_spec.coffee +0 -0
- data/spec/core/collection_spec.coffee +215 -0
- data/spec/core/container_spec.coffee +0 -0
- data/spec/core/field_spec.coffee +0 -0
- data/spec/core/observer_spec.coffee +0 -0
- data/spec/core/view_spec.coffee +87 -0
- data/spec/framework_spec.coffee +48 -0
- data/spec/helper.coffee +120 -0
- data/spec/managers/collection_manager_spec.coffee +95 -0
- data/spec/managers/socket_manager_spec.coffee +0 -0
- data/src/components/application.coffee +83 -0
- data/src/components/base_toolbar.coffee +16 -0
- data/src/components/collection_loader_view.coffee +37 -0
- data/src/components/controller.coffee +41 -0
- data/src/components/fields/button_field.coffee +40 -0
- data/src/components/fields/checkbox_field.coffee +41 -0
- data/src/components/fields/file_upload_field.coffee +15 -0
- data/src/components/fields/hidden_field.coffee +18 -0
- data/src/components/fields/select_field.coffee +100 -0
- data/src/components/fields/text_area_field.coffee +43 -0
- data/src/components/fields/text_field.coffee +42 -0
- data/src/components/fields/type_ahead_field.coffee +10 -0
- data/src/components/form_button_toolbar.coffee +26 -0
- data/src/components/form_view.coffee +205 -0
- data/src/components/grid_view.coffee +208 -0
- data/src/components/record_manager.coffee +215 -0
- data/src/components/router.coffee +34 -0
- data/src/components/template.coffee +19 -0
- data/src/containers/card_view.coffee +89 -0
- data/src/containers/column_view.coffee +48 -0
- data/src/containers/modal_view.coffee +85 -0
- data/src/containers/panel_view.coffee +24 -0
- data/src/containers/split_view.coffee +12 -0
- data/src/containers/tab_view.coffee +77 -0
- data/src/containers/viewport.coffee +16 -0
- data/src/core/collection.coffee +319 -0
- data/src/core/container.coffee +256 -0
- data/src/core/field.coffee +68 -0
- data/src/core/observer.coffee +17 -0
- data/src/core/view.coffee +190 -0
- data/src/framework.coffee +110 -0
- data/src/index.coffee +255 -0
- data/src/managers/collection_manager.coffee +168 -0
- data/src/managers/socket_manager.coffee +54 -0
- data/src/modules/deferrable.coffee +18 -0
- data/src/modules/local_storage.coffee +50 -0
- data/src/stylesheets/base.scss +78 -0
- data/src/stylesheets/components/form_view.scss +54 -0
- data/src/stylesheets/components/grid_view.scss +111 -0
- data/src/stylesheets/components/toolbar.scss +15 -0
- data/src/stylesheets/containers/container.scss +7 -0
- data/src/stylesheets/containers/modal_view.scss +0 -0
- data/src/stylesheets/containers/tab_view.scss +33 -0
- data/src/stylesheets/normalize.scss +430 -0
- data/src/templates/components/bootstrap_form_controls.luca +7 -0
- data/src/templates/components/collection_loader_view.luca +5 -0
- data/src/templates/components/form_view.luca +15 -0
- data/src/templates/components/grid_view.luca +9 -0
- data/src/templates/components/grid_view_empty_text.luca +3 -0
- data/src/templates/containers/basic.luca +1 -0
- data/src/templates/containers/tab_selector_container.luca +8 -0
- data/src/templates/containers/tab_view.luca +1 -0
- data/src/templates/containers/toolbar_wrapper.luca +1 -0
- data/src/templates/fields/button_field.luca +2 -0
- data/src/templates/fields/button_field_link.luca +5 -0
- data/src/templates/fields/checkbox_field.luca +9 -0
- data/src/templates/fields/file_upload_field.luca +8 -0
- data/src/templates/fields/hidden_field.luca +1 -0
- data/src/templates/fields/select_field.luca +7 -0
- data/src/templates/fields/text_area_field.luca +8 -0
- data/src/templates/fields/text_field.luca +13 -0
- data/src/templates/sample/contents.luca +1 -0
- data/src/templates/sample/welcome.luca +1 -0
- data/vendor/assets/images/glyphicons-halflings-white.png +0 -0
- data/vendor/assets/images/glyphicons-halflings.png +0 -0
- data/vendor/assets/javascripts/luca-spec-dependencies.js +6135 -0
- data/vendor/assets/javascripts/luca-ui-base.js +1527 -0
- data/vendor/assets/javascripts/luca-ui-spec.js +3654 -0
- data/vendor/assets/javascripts/luca-ui.js +2763 -0
- data/vendor/assets/luca-ui/base.css +85 -0
- data/vendor/assets/luca-ui/components/application.js +91 -0
- data/vendor/assets/luca-ui/components/base_toolbar.js +23 -0
- data/vendor/assets/luca-ui/components/controller.js +38 -0
- data/vendor/assets/luca-ui/components/fields/button_field.js +45 -0
- data/vendor/assets/luca-ui/components/fields/checkbox_field.js +43 -0
- data/vendor/assets/luca-ui/components/fields/file_upload_field.js +20 -0
- data/vendor/assets/luca-ui/components/fields/hidden_field.js +20 -0
- data/vendor/assets/luca-ui/components/fields/select_field.js +97 -0
- data/vendor/assets/luca-ui/components/fields/text_area_field.js +48 -0
- data/vendor/assets/luca-ui/components/fields/text_field.js +46 -0
- data/vendor/assets/luca-ui/components/fields/type_ahead_field.js +13 -0
- data/vendor/assets/luca-ui/components/form_button_toolbar.js +32 -0
- data/vendor/assets/luca-ui/components/form_view.css +32 -0
- data/vendor/assets/luca-ui/components/form_view.js +207 -0
- data/vendor/assets/luca-ui/components/grid_view.css +76 -0
- data/vendor/assets/luca-ui/components/grid_view.js +202 -0
- data/vendor/assets/luca-ui/components/record_manager.js +207 -0
- data/vendor/assets/luca-ui/components/router.js +36 -0
- data/vendor/assets/luca-ui/components/template.js +26 -0
- data/vendor/assets/luca-ui/components/toolbar.css +11 -0
- data/vendor/assets/luca-ui/containers/card_view.js +98 -0
- data/vendor/assets/luca-ui/containers/column_view.js +52 -0
- data/vendor/assets/luca-ui/containers/container.css +3 -0
- data/vendor/assets/luca-ui/containers/modal_view.css +0 -0
- data/vendor/assets/luca-ui/containers/modal_view.js +87 -0
- data/vendor/assets/luca-ui/containers/panel_view.js +34 -0
- data/vendor/assets/luca-ui/containers/split_view.js +13 -0
- data/vendor/assets/luca-ui/containers/tab_view.css +16 -0
- data/vendor/assets/luca-ui/containers/tab_view.js +80 -0
- data/vendor/assets/luca-ui/containers/viewport.js +18 -0
- data/vendor/assets/luca-ui/core/collection.js +221 -0
- data/vendor/assets/luca-ui/core/container.js +205 -0
- data/vendor/assets/luca-ui/core/field.js +59 -0
- data/vendor/assets/luca-ui/core/observer.js +42 -0
- data/vendor/assets/luca-ui/core/view.js +127 -0
- data/vendor/assets/luca-ui/framework.js +110 -0
- data/vendor/assets/luca-ui/index.js +5 -0
- data/vendor/assets/luca-ui/managers/collection_manager.js +98 -0
- data/vendor/assets/luca-ui/managers/socket_manager.js +52 -0
- data/vendor/assets/luca-ui/modules/deferrable.js +21 -0
- data/vendor/assets/luca-ui/modules/local_storage.js +81 -0
- data/vendor/assets/luca-ui/normalize.css +359 -0
- data/vendor/assets/luca-ui/stylesheets/base.css +85 -0
- data/vendor/assets/luca-ui/stylesheets/components/form_view.css +32 -0
- data/vendor/assets/luca-ui/stylesheets/components/grid_view.css +76 -0
- data/vendor/assets/luca-ui/stylesheets/components/toolbar.css +11 -0
- data/vendor/assets/luca-ui/stylesheets/containers/container.css +3 -0
- data/vendor/assets/luca-ui/stylesheets/containers/modal_view.css +0 -0
- data/vendor/assets/luca-ui/stylesheets/containers/tab_view.css +16 -0
- data/vendor/assets/luca-ui/stylesheets/normalize.css +359 -0
- data/vendor/assets/luca-ui/templates/components/bootstrap_form_controls.js +4 -0
- data/vendor/assets/luca-ui/templates/components/form_view.js +4 -0
- data/vendor/assets/luca-ui/templates/components/grid_view.js +4 -0
- data/vendor/assets/luca-ui/templates/components/grid_view_empty_text.js +4 -0
- data/vendor/assets/luca-ui/templates/containers/basic.js +4 -0
- data/vendor/assets/luca-ui/templates/containers/tab_selector_container.js +4 -0
- data/vendor/assets/luca-ui/templates/containers/tab_view.js +4 -0
- data/vendor/assets/luca-ui/templates/containers/toolbar_wrapper.js +4 -0
- data/vendor/assets/luca-ui/templates/fields/button_field.js +4 -0
- data/vendor/assets/luca-ui/templates/fields/button_field_link.js +4 -0
- data/vendor/assets/luca-ui/templates/fields/checkbox_field.js +4 -0
- data/vendor/assets/luca-ui/templates/fields/file_upload_field.js +4 -0
- data/vendor/assets/luca-ui/templates/fields/hidden_field.js +4 -0
- data/vendor/assets/luca-ui/templates/fields/select_field.js +4 -0
- data/vendor/assets/luca-ui/templates/fields/text_area_field.js +4 -0
- data/vendor/assets/luca-ui/templates/fields/text_field.js +4 -0
- data/vendor/assets/luca-ui/templates/sample/contents.js +4 -0
- data/vendor/assets/luca-ui/templates/sample/welcome.js +4 -0
- data/vendor/assets/stylesheets/luca-spec-dependencies.css +166 -0
- data/vendor/assets/stylesheets/luca-ui-bootstrap.css +1201 -0
- data/vendor/assets/stylesheets/luca-ui-spec.css +586 -0
- data/vendor/assets/stylesheets/luca-ui.css +586 -0
- data/views/index.erb +20 -0
- data/views/jasmine.erb +22 -0
- data/views/spec_harness.erb +29 -0
- metadata +361 -0
@@ -0,0 +1,221 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
Luca.Collection = (Backbone.QueryCollection || Backbone.Collection).extend({
|
4
|
+
initialize: function(models, options) {
|
5
|
+
var table,
|
6
|
+
_this = this;
|
7
|
+
if (models == null) models = [];
|
8
|
+
this.options = options;
|
9
|
+
_.extend(this, this.options);
|
10
|
+
if (this.cached) {
|
11
|
+
this.bootstrap_cache_key = _.isFunction(this.cached) ? this.cached() : this.cached;
|
12
|
+
}
|
13
|
+
if (this.registerAs || this.registerWith) {
|
14
|
+
console.log("This configuration API is deprecated. use @name and @manager properties instead");
|
15
|
+
}
|
16
|
+
this.name || (this.name = this.registerAs);
|
17
|
+
this.manager || (this.manager = this.registerWith);
|
18
|
+
if (this.name && !this.manager) this.manager = Luca.CollectionManager.get();
|
19
|
+
if (this.manager) {
|
20
|
+
this.name || (this.name = this.cached());
|
21
|
+
this.name = _.isFunction(this.name) ? this.name() : this.name;
|
22
|
+
this.bind("after:initialize", function() {
|
23
|
+
return _this.register(_this.manager, _this.name, _this);
|
24
|
+
});
|
25
|
+
}
|
26
|
+
if (this.useLocalStorage === true && (window.localStorage != null)) {
|
27
|
+
table = this.bootstrap_cache_key || this.name;
|
28
|
+
throw "Must specify either a cached or registerAs property to use localStorage";
|
29
|
+
this.localStorage = new Luca.LocalStore(table);
|
30
|
+
}
|
31
|
+
if (_.isArray(this.data) && this.data.length > 0) {
|
32
|
+
this.memoryCollection = true;
|
33
|
+
}
|
34
|
+
if (this.useNormalUrl !== true) this.__wrapUrl();
|
35
|
+
Backbone.Collection.prototype.initialize.apply(this, [models, this.options]);
|
36
|
+
return this.trigger("after:initialize");
|
37
|
+
},
|
38
|
+
__wrapUrl: function() {
|
39
|
+
var params, url,
|
40
|
+
_this = this;
|
41
|
+
if (_.isFunction(this.url)) {
|
42
|
+
return this.url = _.wrap(this.url, function(fn) {
|
43
|
+
var existing_params, new_val, parts, queryString, val;
|
44
|
+
val = fn.apply(_this);
|
45
|
+
parts = val.split('?');
|
46
|
+
if (parts.length > 1) existing_params = _.last(parts);
|
47
|
+
queryString = _this.queryString();
|
48
|
+
if (existing_params && val.match(existing_params)) {
|
49
|
+
queryString = queryString.replace(existing_params, '');
|
50
|
+
}
|
51
|
+
new_val = "" + val + "?" + queryString;
|
52
|
+
if (new_val.match(/\?$/)) new_val = new_val.replace(/\?$/, '');
|
53
|
+
return new_val;
|
54
|
+
});
|
55
|
+
} else {
|
56
|
+
url = this.url;
|
57
|
+
params = this.queryString();
|
58
|
+
return this.url = _([url, params]).compact().join("?");
|
59
|
+
}
|
60
|
+
},
|
61
|
+
queryString: function() {
|
62
|
+
var parts,
|
63
|
+
_this = this;
|
64
|
+
parts = _(this.base_params || (this.base_params = Luca.Collection.baseParams())).inject(function(memo, value, key) {
|
65
|
+
var str;
|
66
|
+
str = "" + key + "=" + value;
|
67
|
+
memo.push(str);
|
68
|
+
return memo;
|
69
|
+
}, []);
|
70
|
+
return _.uniq(parts).join("&");
|
71
|
+
},
|
72
|
+
resetFilter: function() {
|
73
|
+
this.base_params = Luca.Collection.baseParams();
|
74
|
+
return this;
|
75
|
+
},
|
76
|
+
applyFilter: function(filter, options) {
|
77
|
+
if (filter == null) filter = {};
|
78
|
+
if (options == null) options = {};
|
79
|
+
this.applyParams(filter);
|
80
|
+
return this.fetch(_.extend(options, {
|
81
|
+
refresh: true
|
82
|
+
}));
|
83
|
+
},
|
84
|
+
applyParams: function(params) {
|
85
|
+
this.base_params || (this.base_params = Luca.Collection.baseParams());
|
86
|
+
return _.extend(this.base_params, params);
|
87
|
+
},
|
88
|
+
register: function(collectionManager, key, collection) {
|
89
|
+
if (collectionManager == null) {
|
90
|
+
collectionManager = Luca.CollectionManager.get();
|
91
|
+
}
|
92
|
+
if (key == null) key = "";
|
93
|
+
if (!(key.length >= 1)) {
|
94
|
+
throw "Can not register with a collection manager without a key";
|
95
|
+
}
|
96
|
+
if (collectionManager == null) {
|
97
|
+
throw "Can not register with a collection manager without a valid collection manager";
|
98
|
+
}
|
99
|
+
if (_.isString(collectionManager)) {
|
100
|
+
collectionManager = Luca.util.nestedValue(collectionManager, window || global);
|
101
|
+
}
|
102
|
+
if (!collectionManager) throw "Could not register with collection manager";
|
103
|
+
if (_.isFunction(collectionManager.add)) {
|
104
|
+
return collectionManager.add(key, collection);
|
105
|
+
}
|
106
|
+
if (_.isObject(collectionManager)) {
|
107
|
+
return collectionManager[key] = collection;
|
108
|
+
}
|
109
|
+
},
|
110
|
+
loadFromBootstrap: function() {
|
111
|
+
if (!this.bootstrap_cache_key) return;
|
112
|
+
this.reset(this.cached_models());
|
113
|
+
return this.trigger("bootstrapped", this);
|
114
|
+
},
|
115
|
+
bootstrap: function() {
|
116
|
+
return this.loadFromBootstrap();
|
117
|
+
},
|
118
|
+
cached_models: function() {
|
119
|
+
return Luca.Collection.cache(this.bootstrap_cache_key);
|
120
|
+
},
|
121
|
+
fetch: function(options) {
|
122
|
+
var url;
|
123
|
+
if (options == null) options = {};
|
124
|
+
this.trigger("before:fetch", this);
|
125
|
+
if (this.memoryCollection === true) return this.reset(this.data);
|
126
|
+
if (this.cached_models().length && !options.refresh) return this.bootstrap();
|
127
|
+
url = _.isFunction(this.url) ? this.url() : this.url;
|
128
|
+
if (!((url && url.length > 1) || this.localStorage)) return true;
|
129
|
+
this.fetching = true;
|
130
|
+
try {
|
131
|
+
return Backbone.Collection.prototype.fetch.apply(this, arguments);
|
132
|
+
} catch (e) {
|
133
|
+
console.log("Error in Collection.fetch", e);
|
134
|
+
throw e;
|
135
|
+
}
|
136
|
+
},
|
137
|
+
onceLoaded: function(fn, options) {
|
138
|
+
var wrapped,
|
139
|
+
_this = this;
|
140
|
+
if (options == null) {
|
141
|
+
options = {
|
142
|
+
autoFetch: true
|
143
|
+
};
|
144
|
+
}
|
145
|
+
if (this.length > 0 && !this.fetching) {
|
146
|
+
fn.apply(this, [this]);
|
147
|
+
return;
|
148
|
+
}
|
149
|
+
wrapped = function() {
|
150
|
+
return fn.apply(_this, [_this]);
|
151
|
+
};
|
152
|
+
this.bind("reset", function() {
|
153
|
+
wrapped();
|
154
|
+
return this.unbind("reset", this);
|
155
|
+
});
|
156
|
+
if (!(this.fetching || !options.autoFetch)) return this.fetch();
|
157
|
+
},
|
158
|
+
ifLoaded: function(fn, options) {
|
159
|
+
var scope,
|
160
|
+
_this = this;
|
161
|
+
if (options == null) {
|
162
|
+
options = {
|
163
|
+
scope: this,
|
164
|
+
autoFetch: true
|
165
|
+
};
|
166
|
+
}
|
167
|
+
scope = options.scope || this;
|
168
|
+
if (this.length > 0 && !this.fetching) fn.apply(scope, [this]);
|
169
|
+
this.bind("reset", function(collection) {
|
170
|
+
return fn.apply(scope, [collection]);
|
171
|
+
});
|
172
|
+
if (!(this.fetching === true || !options.autoFetch || this.length > 0)) {
|
173
|
+
return this.fetch();
|
174
|
+
}
|
175
|
+
},
|
176
|
+
parse: function(response) {
|
177
|
+
var models;
|
178
|
+
this.fetching = false;
|
179
|
+
this.trigger("after:response", response);
|
180
|
+
models = this.root != null ? response[this.root] : response;
|
181
|
+
if (this.bootstrap_cache_key) {
|
182
|
+
Luca.Collection.cache(this.bootstrap_cache_key, models);
|
183
|
+
}
|
184
|
+
return models;
|
185
|
+
}
|
186
|
+
});
|
187
|
+
|
188
|
+
_.extend(Luca.Collection.prototype, {
|
189
|
+
trigger: function() {
|
190
|
+
if (Luca.enableGlobalObserver) {
|
191
|
+
Luca.CollectionObserver || (Luca.CollectionObserver = new Luca.Observer({
|
192
|
+
type: "collection"
|
193
|
+
}));
|
194
|
+
Luca.CollectionObserver.relay(this, arguments);
|
195
|
+
}
|
196
|
+
return Backbone.View.prototype.trigger.apply(this, arguments);
|
197
|
+
}
|
198
|
+
});
|
199
|
+
|
200
|
+
Luca.Collection.baseParams = function(obj) {
|
201
|
+
if (obj) return Luca.Collection._baseParams = obj;
|
202
|
+
if (_.isFunction(Luca.Collection._baseParams)) {
|
203
|
+
return Luca.Collection._baseParams.call();
|
204
|
+
}
|
205
|
+
if (_.isObject(Luca.Collection._baseParams)) {
|
206
|
+
return Luca.Collection._baseParams;
|
207
|
+
}
|
208
|
+
};
|
209
|
+
|
210
|
+
Luca.Collection._bootstrapped_models = {};
|
211
|
+
|
212
|
+
Luca.Collection.bootstrap = function(obj) {
|
213
|
+
return _.extend(Luca.Collection._bootstrapped_models, obj);
|
214
|
+
};
|
215
|
+
|
216
|
+
Luca.Collection.cache = function(key, models) {
|
217
|
+
if (models) return Luca.Collection._bootstrapped_models[key] = models;
|
218
|
+
return Luca.Collection._bootstrapped_models[key] || [];
|
219
|
+
};
|
220
|
+
|
221
|
+
}).call(this);
|
@@ -0,0 +1,205 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
Luca.core.Container = Luca.View.extend({
|
4
|
+
className: 'luca-ui-container',
|
5
|
+
componentClass: 'luca-ui-panel',
|
6
|
+
isContainer: true,
|
7
|
+
hooks: ["before:components", "before:layout", "after:components", "after:layout", "first:activation"],
|
8
|
+
rendered: false,
|
9
|
+
components: [],
|
10
|
+
initialize: function(options) {
|
11
|
+
this.options = options != null ? options : {};
|
12
|
+
_.extend(this, this.options);
|
13
|
+
this.setupHooks(Luca.core.Container.prototype.hooks);
|
14
|
+
return Luca.View.prototype.initialize.apply(this, arguments);
|
15
|
+
},
|
16
|
+
beforeRender: function() {
|
17
|
+
this.debug("container before render");
|
18
|
+
this.doLayout();
|
19
|
+
return this.doComponents();
|
20
|
+
},
|
21
|
+
doLayout: function() {
|
22
|
+
this.debug("container do layout");
|
23
|
+
this.trigger("before:layout", this);
|
24
|
+
this.prepareLayout();
|
25
|
+
return this.trigger("after:layout", this);
|
26
|
+
},
|
27
|
+
doComponents: function() {
|
28
|
+
this.debug("container do components");
|
29
|
+
this.trigger("before:components", this, this.components);
|
30
|
+
this.prepareComponents();
|
31
|
+
this.createComponents();
|
32
|
+
this.renderComponents();
|
33
|
+
return this.trigger("after:components", this, this.components);
|
34
|
+
},
|
35
|
+
applyPanelConfig: function(panel, panelIndex) {
|
36
|
+
var config, style_declarations;
|
37
|
+
style_declarations = [];
|
38
|
+
if (panel.height) {
|
39
|
+
style_declarations.push("height: " + (_.isNumber(panel.height) ? panel.height + 'px' : panel.height));
|
40
|
+
}
|
41
|
+
if (panel.width) {
|
42
|
+
style_declarations.push("width: " + (_.isNumber(panel.width) ? panel.width + 'px' : panel.width));
|
43
|
+
}
|
44
|
+
if (panel.float) style_declarations.push("float: " + panel.float);
|
45
|
+
return config = {
|
46
|
+
classes: (panel != null ? panel.classes : void 0) || this.componentClass,
|
47
|
+
id: "" + this.cid + "-" + panelIndex,
|
48
|
+
style: style_declarations.join(';')
|
49
|
+
};
|
50
|
+
},
|
51
|
+
prepareLayout: function() {
|
52
|
+
var _this = this;
|
53
|
+
this.debug("container prepare layout");
|
54
|
+
this.componentContainers = _(this.components).map(function(component, index) {
|
55
|
+
return _this.applyPanelConfig.apply(_this, [component, index]);
|
56
|
+
});
|
57
|
+
if (this.appendContainers) {
|
58
|
+
return _(this.componentContainers).each(function(container) {
|
59
|
+
return _this.$el.append(Luca.templates["containers/basic"](container));
|
60
|
+
});
|
61
|
+
}
|
62
|
+
},
|
63
|
+
prepareComponents: function() {
|
64
|
+
var _this = this;
|
65
|
+
this.debug("container prepare components");
|
66
|
+
return this.components = _(this.components).map(function(object, index) {
|
67
|
+
var panel;
|
68
|
+
panel = _this.componentContainers[index];
|
69
|
+
object.container = _this.appendContainers ? "#" + panel.id : _this.el;
|
70
|
+
return object;
|
71
|
+
});
|
72
|
+
},
|
73
|
+
createComponents: function() {
|
74
|
+
var map,
|
75
|
+
_this = this;
|
76
|
+
this.debug("container create components");
|
77
|
+
map = this.componentIndex = {
|
78
|
+
name_index: {},
|
79
|
+
cid_index: {}
|
80
|
+
};
|
81
|
+
this.components = _(this.components).map(function(object, index) {
|
82
|
+
var component;
|
83
|
+
component = _.isObject(object) && object.render && object.trigger ? object : (object.ctype || (object.ctype = Luca.defaultComponentType || "template"), Luca.util.lazyComponent(object));
|
84
|
+
if (!component.container && component.options.container) {
|
85
|
+
component.container = component.options.container;
|
86
|
+
}
|
87
|
+
if (map && (component.cid != null)) map.cid_index[component.cid] = index;
|
88
|
+
if (map && (component.name != null)) {
|
89
|
+
map.name_index[component.name] = index;
|
90
|
+
}
|
91
|
+
return component;
|
92
|
+
});
|
93
|
+
return this.debug("components created", this.components);
|
94
|
+
},
|
95
|
+
renderComponents: function(debugMode) {
|
96
|
+
var _this = this;
|
97
|
+
this.debugMode = debugMode != null ? debugMode : "";
|
98
|
+
this.debug("container render components");
|
99
|
+
return _(this.components).each(function(component) {
|
100
|
+
component.getParent = function() {
|
101
|
+
return _this;
|
102
|
+
};
|
103
|
+
$(component.container).append($(component.el));
|
104
|
+
try {
|
105
|
+
return component.render();
|
106
|
+
} catch (e) {
|
107
|
+
console.log("Error Rendering Component " + (component.name || component.cid), component);
|
108
|
+
console.log(e.message);
|
109
|
+
return console.log(e.stack);
|
110
|
+
}
|
111
|
+
});
|
112
|
+
},
|
113
|
+
firstActivation: function() {
|
114
|
+
var _this = this;
|
115
|
+
return _(this.components).each(function(component) {
|
116
|
+
var activator, _ref;
|
117
|
+
activator = _this;
|
118
|
+
if ((component != null ? component.previously_activated : void 0) !== true) {
|
119
|
+
if (component != null) {
|
120
|
+
if ((_ref = component.trigger) != null) {
|
121
|
+
_ref.apply(component, ["first:activation", [component, activator]]);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
return component.previously_activated = true;
|
125
|
+
}
|
126
|
+
});
|
127
|
+
},
|
128
|
+
select: function(attribute, value, deep) {
|
129
|
+
var components;
|
130
|
+
if (deep == null) deep = false;
|
131
|
+
components = _(this.components).map(function(component) {
|
132
|
+
var matches, test;
|
133
|
+
matches = [];
|
134
|
+
test = component[attribute];
|
135
|
+
if (test === value) matches.push(component);
|
136
|
+
if (deep === true && component.isContainer === true) {
|
137
|
+
matches.push(component.select(attribute, value, true));
|
138
|
+
}
|
139
|
+
return _.compact(matches);
|
140
|
+
});
|
141
|
+
return _.flatten(components);
|
142
|
+
},
|
143
|
+
findComponentByName: function(name, deep) {
|
144
|
+
if (deep == null) deep = false;
|
145
|
+
return this.findComponent(name, "name_index", deep);
|
146
|
+
},
|
147
|
+
findComponentById: function(id, deep) {
|
148
|
+
if (deep == null) deep = false;
|
149
|
+
return this.findComponent(id, "cid_index", deep);
|
150
|
+
},
|
151
|
+
findComponent: function(needle, haystack, deep) {
|
152
|
+
var component, position, sub_container, _ref, _ref2;
|
153
|
+
if (haystack == null) haystack = "name";
|
154
|
+
if (deep == null) deep = false;
|
155
|
+
position = (_ref = this.componentIndex) != null ? _ref[haystack][needle] : void 0;
|
156
|
+
component = (_ref2 = this.components) != null ? _ref2[position] : void 0;
|
157
|
+
if (component) return component;
|
158
|
+
if (deep === true) {
|
159
|
+
sub_container = _(this.components).detect(function(component) {
|
160
|
+
return component != null ? typeof component.findComponent === "function" ? component.findComponent(needle, haystack, true) : void 0 : void 0;
|
161
|
+
});
|
162
|
+
return sub_container != null ? typeof sub_container.findComponent === "function" ? sub_container.findComponent(needle, haystack, true) : void 0 : void 0;
|
163
|
+
}
|
164
|
+
},
|
165
|
+
eachComponent: function(fn, deep) {
|
166
|
+
var _this = this;
|
167
|
+
if (deep == null) deep = true;
|
168
|
+
return _(this.components).each(function(component) {
|
169
|
+
var _ref;
|
170
|
+
fn.apply(component, [component]);
|
171
|
+
if (deep) {
|
172
|
+
return component != null ? (_ref = component.eachComponent) != null ? _ref.apply(component, [fn, deep]) : void 0 : void 0;
|
173
|
+
}
|
174
|
+
});
|
175
|
+
},
|
176
|
+
indexOf: function(name) {
|
177
|
+
var names;
|
178
|
+
names = _(this.components).pluck('name');
|
179
|
+
return _(names).indexOf(name);
|
180
|
+
},
|
181
|
+
activeComponent: function() {
|
182
|
+
if (!this.activeItem) return this;
|
183
|
+
return this.components[this.activeItem];
|
184
|
+
},
|
185
|
+
componentElements: function() {
|
186
|
+
return $("." + this.componentClass, this.el);
|
187
|
+
},
|
188
|
+
getComponent: function(needle) {
|
189
|
+
return this.components[needle];
|
190
|
+
},
|
191
|
+
rootComponent: function() {
|
192
|
+
return !(this.getParent != null);
|
193
|
+
},
|
194
|
+
getRootComponent: function() {
|
195
|
+
if (this.rootComponent()) {
|
196
|
+
return this;
|
197
|
+
} else {
|
198
|
+
return this.getParent().getRootComponent();
|
199
|
+
}
|
200
|
+
}
|
201
|
+
});
|
202
|
+
|
203
|
+
Luca.register("container", "Luca.core.Container");
|
204
|
+
|
205
|
+
}).call(this);
|
@@ -0,0 +1,59 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
Luca.core.Field = Luca.View.extend({
|
4
|
+
className: 'luca-ui-text-field luca-ui-field',
|
5
|
+
isField: true,
|
6
|
+
template: 'fields/text_field',
|
7
|
+
labelAlign: 'top',
|
8
|
+
hooks: ["before:validation", "after:validation", "on:change"],
|
9
|
+
statuses: ["warning", "error", "success"],
|
10
|
+
initialize: function(options) {
|
11
|
+
var _ref;
|
12
|
+
this.options = options != null ? options : {};
|
13
|
+
_.extend(this, this.options);
|
14
|
+
Luca.View.prototype.initialize.apply(this, arguments);
|
15
|
+
this.input_id || (this.input_id = _.uniqueId('field'));
|
16
|
+
this.input_name || (this.input_name = this.name);
|
17
|
+
this.helperText || (this.helperText = "");
|
18
|
+
if (this.required && !((_ref = this.label) != null ? _ref.match(/^\*/) : void 0)) {
|
19
|
+
this.label || (this.label = "*" + this.label);
|
20
|
+
}
|
21
|
+
this.inputStyles || (this.inputStyles = "");
|
22
|
+
if (this.disabled) this.disable();
|
23
|
+
this.updateState(this.state);
|
24
|
+
return this.placeHolder || (this.placeHolder = "");
|
25
|
+
},
|
26
|
+
beforeRender: function() {
|
27
|
+
if (Luca.enableBootstrap) this.$el.addClass('control-group');
|
28
|
+
if (this.required) this.$el.addClass('required');
|
29
|
+
this.$el.html(Luca.templates[this.template](this));
|
30
|
+
return this.input = $('input', this.el);
|
31
|
+
},
|
32
|
+
change_handler: function(e) {
|
33
|
+
return this.trigger("on:change", this, e);
|
34
|
+
},
|
35
|
+
disable: function() {
|
36
|
+
return $("input", this.el).attr('disabled', true);
|
37
|
+
},
|
38
|
+
enable: function() {
|
39
|
+
return $("input", this.el).attr('disabled', false);
|
40
|
+
},
|
41
|
+
getValue: function() {
|
42
|
+
return this.input.attr('value');
|
43
|
+
},
|
44
|
+
render: function() {
|
45
|
+
return $(this.container).append(this.$el);
|
46
|
+
},
|
47
|
+
setValue: function(value) {
|
48
|
+
return this.input.attr('value', value);
|
49
|
+
},
|
50
|
+
updateState: function(state) {
|
51
|
+
var _this = this;
|
52
|
+
return _(this.statuses).each(function(cls) {
|
53
|
+
_this.$el.removeClass(cls);
|
54
|
+
return _this.$el.addClass(state);
|
55
|
+
});
|
56
|
+
}
|
57
|
+
});
|
58
|
+
|
59
|
+
}).call(this);
|
@@ -0,0 +1,42 @@
|
|
1
|
+
(function() {
|
2
|
+
var __slice = Array.prototype.slice;
|
3
|
+
|
4
|
+
Luca.Observer = (function() {
|
5
|
+
|
6
|
+
function Observer(options) {
|
7
|
+
var _this = this;
|
8
|
+
this.options = options != null ? options : {};
|
9
|
+
_.extend(this, Backbone.Events);
|
10
|
+
this.type = this.options.type;
|
11
|
+
if (this.options.debugAll) {
|
12
|
+
this.bind("event", function() {
|
13
|
+
var args, t;
|
14
|
+
t = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
15
|
+
return console.log("Observed " + _this.type + " " + (t.name || t.id || t.cid), t, _(args).flatten());
|
16
|
+
});
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
Observer.prototype.relay = function() {
|
21
|
+
var args, triggerer;
|
22
|
+
triggerer = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
23
|
+
this.trigger("event", triggerer, args);
|
24
|
+
return this.trigger("event:" + args[0], triggerer, args.slice(1));
|
25
|
+
};
|
26
|
+
|
27
|
+
return Observer;
|
28
|
+
|
29
|
+
})();
|
30
|
+
|
31
|
+
Luca.Observer.enableObservers = function(options) {
|
32
|
+
if (options == null) options = {};
|
33
|
+
Luca.enableGlobalObserver = true;
|
34
|
+
Luca.ViewObserver = new Luca.Observer(_.extend(options, {
|
35
|
+
type: "view"
|
36
|
+
}));
|
37
|
+
return Luca.CollectionObserver = new Luca.Observer(_.extend(options, {
|
38
|
+
type: "collection"
|
39
|
+
}));
|
40
|
+
};
|
41
|
+
|
42
|
+
}).call(this);
|
@@ -0,0 +1,127 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
Luca.View = Backbone.View.extend({
|
4
|
+
base: 'Luca.View'
|
5
|
+
});
|
6
|
+
|
7
|
+
Luca.View.originalExtend = Backbone.View.extend;
|
8
|
+
|
9
|
+
Luca.View.extend = function(definition) {
|
10
|
+
var _base;
|
11
|
+
_base = definition.render;
|
12
|
+
_base || (_base = function() {
|
13
|
+
var container;
|
14
|
+
container = _.isFunction(this.container) ? this.container() : this.container;
|
15
|
+
if (!($(container) && this.$el)) return this;
|
16
|
+
$(container).append(this.$el);
|
17
|
+
return this;
|
18
|
+
});
|
19
|
+
definition.render = function() {
|
20
|
+
var _this = this;
|
21
|
+
if (this.deferrable) {
|
22
|
+
this.trigger("before:render", this);
|
23
|
+
this.deferrable.bind(this.deferrable_event, _.once(function() {
|
24
|
+
_base.apply(_this, arguments);
|
25
|
+
return _this.trigger("after:render", _this);
|
26
|
+
}));
|
27
|
+
if (!this.deferrable_trigger) this.immediate_trigger = true;
|
28
|
+
if (this.immediate_trigger === true) {
|
29
|
+
return this.deferrable.fetch();
|
30
|
+
} else {
|
31
|
+
return this.bind(this.deferrable_trigger, _.once(function() {
|
32
|
+
return _this.deferrable.fetch();
|
33
|
+
}));
|
34
|
+
}
|
35
|
+
} else {
|
36
|
+
this.trigger("before:render", this);
|
37
|
+
_base.apply(this, arguments);
|
38
|
+
return this.trigger("after:render", this);
|
39
|
+
}
|
40
|
+
};
|
41
|
+
return Luca.View.originalExtend.apply(this, [definition]);
|
42
|
+
};
|
43
|
+
|
44
|
+
_.extend(Luca.View.prototype, {
|
45
|
+
debug: function() {
|
46
|
+
var message, _i, _len, _results;
|
47
|
+
if (!(this.debugMode || (window.LucaDebugMode != null))) return;
|
48
|
+
_results = [];
|
49
|
+
for (_i = 0, _len = arguments.length; _i < _len; _i++) {
|
50
|
+
message = arguments[_i];
|
51
|
+
_results.push(console.log([this.name || this.cid, message]));
|
52
|
+
}
|
53
|
+
return _results;
|
54
|
+
},
|
55
|
+
trigger: function() {
|
56
|
+
if (Luca.enableGlobalObserver) {
|
57
|
+
Luca.ViewObserver || (Luca.ViewObserver = new Luca.Observer({
|
58
|
+
type: "view"
|
59
|
+
}));
|
60
|
+
Luca.ViewObserver.relay(this, arguments);
|
61
|
+
}
|
62
|
+
return Backbone.View.prototype.trigger.apply(this, arguments);
|
63
|
+
},
|
64
|
+
hooks: ["after:initialize", "before:render", "after:render", "first:activation", "activation", "deactivation"],
|
65
|
+
deferrable_event: "reset",
|
66
|
+
initialize: function(options) {
|
67
|
+
var unique,
|
68
|
+
_this = this;
|
69
|
+
this.options = options != null ? options : {};
|
70
|
+
_.extend(this, this.options);
|
71
|
+
if (this.name != null) this.cid = _.uniqueId(this.name);
|
72
|
+
Luca.cache(this.cid, this);
|
73
|
+
unique = _(Luca.View.prototype.hooks.concat(this.hooks)).uniq();
|
74
|
+
this.setupHooks(unique);
|
75
|
+
if (this.autoBindEventHandlers === true) {
|
76
|
+
_(this.events).each(function(handler, event) {
|
77
|
+
if (_.isString(handler)) return _.bindAll(_this, handler);
|
78
|
+
});
|
79
|
+
}
|
80
|
+
this.trigger("after:initialize", this);
|
81
|
+
return this.registerCollectionEvents();
|
82
|
+
},
|
83
|
+
$container: function() {
|
84
|
+
return $(this.container);
|
85
|
+
},
|
86
|
+
setupHooks: function(set) {
|
87
|
+
var _this = this;
|
88
|
+
set || (set = this.hooks);
|
89
|
+
return _(set).each(function(event) {
|
90
|
+
var fn, parts, prefix;
|
91
|
+
parts = event.split(':');
|
92
|
+
prefix = parts.shift();
|
93
|
+
parts = _(parts).map(function(p) {
|
94
|
+
return _.capitalize(p);
|
95
|
+
});
|
96
|
+
fn = prefix + parts.join('');
|
97
|
+
return _this.bind(event, function() {
|
98
|
+
if (_this[fn]) return _this[fn].apply(_this, arguments);
|
99
|
+
});
|
100
|
+
});
|
101
|
+
},
|
102
|
+
getCollectionManager: function() {
|
103
|
+
var _ref;
|
104
|
+
return this.collectionManager || ((_ref = Luca.CollectionManager.get) != null ? _ref.call() : void 0);
|
105
|
+
},
|
106
|
+
registerCollectionEvents: function() {
|
107
|
+
var manager,
|
108
|
+
_this = this;
|
109
|
+
manager = this.getCollectionManager();
|
110
|
+
return _(this.collectionEvents).each(function(handler, signature) {
|
111
|
+
var collection, event, key, _ref;
|
112
|
+
_ref = signature.split(" "), key = _ref[0], event = _ref[1];
|
113
|
+
collection = _this["" + key + "Collection"] = manager.getOrCreate(key);
|
114
|
+
if (!collection) throw "Could not find collection specified by " + key;
|
115
|
+
if (_.isString(handler)) handler = _this[handler];
|
116
|
+
if (!_.isFunction(handler)) throw "invalid collectionEvents configuration";
|
117
|
+
try {
|
118
|
+
return collection.bind(event, handler);
|
119
|
+
} catch (e) {
|
120
|
+
console.log("Error Binding To Collection in registerCollectionEvents", _this);
|
121
|
+
throw e;
|
122
|
+
}
|
123
|
+
});
|
124
|
+
}
|
125
|
+
});
|
126
|
+
|
127
|
+
}).call(this);
|