luca 0.6.6
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.
- 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,110 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
|
|
3
|
+
_.mixin(_.string);
|
|
4
|
+
|
|
5
|
+
window.Luca = {
|
|
6
|
+
VERSION: "0.6.1",
|
|
7
|
+
core: {},
|
|
8
|
+
containers: {},
|
|
9
|
+
components: {},
|
|
10
|
+
modules: {},
|
|
11
|
+
fields: {},
|
|
12
|
+
util: {},
|
|
13
|
+
registry: {
|
|
14
|
+
classes: {},
|
|
15
|
+
namespaces: ["Luca.containers", "Luca.components"]
|
|
16
|
+
},
|
|
17
|
+
component_cache: {
|
|
18
|
+
cid_index: {},
|
|
19
|
+
name_index: {}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
Luca.enableBootstrap = true;
|
|
24
|
+
|
|
25
|
+
Luca.registry.addNamespace = function(identifier) {
|
|
26
|
+
Luca.registry.namespaces.push(identifier);
|
|
27
|
+
return Luca.registry.namespaces = _(Luca.registry.namespaces).uniq();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
Luca.cache = function(needle, component) {
|
|
31
|
+
var lookup_id;
|
|
32
|
+
if (component != null) Luca.component_cache.cid_index[needle] = component;
|
|
33
|
+
component = Luca.component_cache.cid_index[needle];
|
|
34
|
+
if ((component != null ? component.component_name : void 0) != null) {
|
|
35
|
+
Luca.component_cache.name_index[component.component_name] = component.cid;
|
|
36
|
+
} else if ((component != null ? component.name : void 0) != null) {
|
|
37
|
+
Luca.component_cache.name_index[component.name] = component.cid;
|
|
38
|
+
}
|
|
39
|
+
if (component != null) return component;
|
|
40
|
+
lookup_id = Luca.component_cache.name_index[needle];
|
|
41
|
+
return Luca.component_cache.cid_index[lookup_id];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
Luca.util.nestedValue = function(accessor, source_object) {
|
|
45
|
+
return _(accessor.split(/\./)).inject(function(obj, key) {
|
|
46
|
+
return obj = obj != null ? obj[key] : void 0;
|
|
47
|
+
}, source_object);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
Luca.registry.lookup = function(ctype) {
|
|
51
|
+
var c, className, parents;
|
|
52
|
+
c = Luca.registry.classes[ctype];
|
|
53
|
+
if (c != null) return c;
|
|
54
|
+
className = _.camelize(_.capitalize(ctype));
|
|
55
|
+
parents = _(Luca.registry.namespaces).map(function(namespace) {
|
|
56
|
+
return Luca.util.nestedValue(namespace, window || global);
|
|
57
|
+
});
|
|
58
|
+
return _.first(_.compact(_(parents).map(function(parent) {
|
|
59
|
+
return parent[className];
|
|
60
|
+
})));
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
Luca.util.lazyComponent = function(config) {
|
|
64
|
+
var componentClass, constructor, ctype;
|
|
65
|
+
ctype = config.ctype;
|
|
66
|
+
componentClass = Luca.registry.lookup(ctype);
|
|
67
|
+
if (!componentClass) {
|
|
68
|
+
throw "Invalid Component Type: " + ctype + ". Did you forget to register it?";
|
|
69
|
+
}
|
|
70
|
+
constructor = eval(componentClass);
|
|
71
|
+
return new constructor(config);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
Luca.register = function(component, constructor_class) {
|
|
75
|
+
var exists;
|
|
76
|
+
exists = Luca.registry.classes[component];
|
|
77
|
+
if (exists != null) {
|
|
78
|
+
throw "Can not register component with the signature " + component + ". Already exists";
|
|
79
|
+
} else {
|
|
80
|
+
return Luca.registry.classes[component] = constructor_class;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
Luca.available_templates = function(filter) {
|
|
85
|
+
var available;
|
|
86
|
+
if (filter == null) filter = "";
|
|
87
|
+
available = _(Luca.templates).keys();
|
|
88
|
+
if (filter.length > 0) {
|
|
89
|
+
return _(available).select(function(tmpl) {
|
|
90
|
+
return tmpl.match(filter);
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
return available;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
Luca.util.isIE = function() {
|
|
98
|
+
try {
|
|
99
|
+
Object.defineProperty({}, '', {});
|
|
100
|
+
return false;
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
$((function() {
|
|
107
|
+
return $('body').addClass('luca-ui-enabled');
|
|
108
|
+
})());
|
|
109
|
+
|
|
110
|
+
}).call(this);
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
var instances;
|
|
3
|
+
|
|
4
|
+
instances = [];
|
|
5
|
+
|
|
6
|
+
Luca.CollectionManager = (function() {
|
|
7
|
+
|
|
8
|
+
CollectionManager.prototype.__collections = {};
|
|
9
|
+
|
|
10
|
+
function CollectionManager(options) {
|
|
11
|
+
this.options = options != null ? options : {};
|
|
12
|
+
_.extend(this, this.options);
|
|
13
|
+
_.extend(this, Backbone.Events);
|
|
14
|
+
instances.push(this);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
CollectionManager.prototype.add = function(key, collection) {
|
|
18
|
+
return this.currentScope()[key] = collection;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
CollectionManager.prototype.allCollections = function() {
|
|
22
|
+
return _(this.currentScope()).values();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
CollectionManager.prototype.create = function(key, collectionOptions, initialModels, private) {
|
|
26
|
+
var CollectionClass, collection;
|
|
27
|
+
if (collectionOptions == null) collectionOptions = {};
|
|
28
|
+
if (initialModels == null) initialModels = [];
|
|
29
|
+
if (private == null) private = false;
|
|
30
|
+
CollectionClass = collectionOptions.base;
|
|
31
|
+
CollectionClass || (CollectionClass = this.guessCollectionClass(key));
|
|
32
|
+
if (private || collectionOptions.private) {
|
|
33
|
+
collectionOptions.registerWith = "";
|
|
34
|
+
}
|
|
35
|
+
collection = new CollectionClass(initialModels, collectionOptions);
|
|
36
|
+
this.add(key, collection);
|
|
37
|
+
return collection;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
CollectionManager.prototype.collectionNamespace = Luca.Collection.namespace;
|
|
41
|
+
|
|
42
|
+
CollectionManager.prototype.currentScope = function() {
|
|
43
|
+
var current_scope, _base;
|
|
44
|
+
if (current_scope = this.getScope()) {
|
|
45
|
+
return (_base = this.__collections)[current_scope] || (_base[current_scope] = {});
|
|
46
|
+
} else {
|
|
47
|
+
return this.__collections;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
CollectionManager.prototype.each = function(fn) {
|
|
52
|
+
return _(this.all()).each(fn);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
CollectionManager.prototype.get = function(key) {
|
|
56
|
+
return this.currentScope()[key];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
CollectionManager.prototype.getScope = function() {
|
|
60
|
+
return;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
CollectionManager.prototype.getOrCreate = function(key, collectionOptions, initialModels) {
|
|
64
|
+
if (collectionOptions == null) collectionOptions = {};
|
|
65
|
+
if (initialModels == null) initialModels = [];
|
|
66
|
+
return this.get(key) || this.create(key, collectionOptions, initialModels, false);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
CollectionManager.prototype.guessCollectionClass = function(key) {
|
|
70
|
+
var classified, guess;
|
|
71
|
+
classified = _(key).chain().capitalize().camelize().value();
|
|
72
|
+
guess = (this.collectionNamespace || (window || global))[classified];
|
|
73
|
+
return guess;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
CollectionManager.prototype.private = function(key, collectionOptions, initialModels) {
|
|
77
|
+
if (collectionOptions == null) collectionOptions = {};
|
|
78
|
+
if (initialModels == null) initialModels = [];
|
|
79
|
+
return this.create(key, collectionOptions, initialModels, true);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return CollectionManager;
|
|
83
|
+
|
|
84
|
+
})();
|
|
85
|
+
|
|
86
|
+
Luca.CollectionManager.destroyAll = function() {
|
|
87
|
+
return instances = [];
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
Luca.CollectionManager.instances = function() {
|
|
91
|
+
return instances;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
Luca.CollectionManager.get = function() {
|
|
95
|
+
return _(instances).last();
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
}).call(this);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
|
|
3
|
+
Luca.SocketManager = (function() {
|
|
4
|
+
|
|
5
|
+
function SocketManager(options) {
|
|
6
|
+
this.options = options != null ? options : {};
|
|
7
|
+
_.extend(Backbone.Events);
|
|
8
|
+
this.loadTransport();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
SocketManager.prototype.connect = function() {
|
|
12
|
+
switch (this.options.provider) {
|
|
13
|
+
case "socket.io":
|
|
14
|
+
return this.socket = io.connect(this.options.socket_host);
|
|
15
|
+
case "faye.js":
|
|
16
|
+
return this.socket = new Faye.Client(this.options.socket_host);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
SocketManager.prototype.transportLoaded = function() {
|
|
21
|
+
return this.connect();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
SocketManager.prototype.transport_script = function() {
|
|
25
|
+
switch (this.options.provider) {
|
|
26
|
+
case "socket.io":
|
|
27
|
+
return "" + this.options.transport_host + "/socket.io/socket.io.js";
|
|
28
|
+
case "faye.js":
|
|
29
|
+
return "" + this.options.transport_host + "/faye.js";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
SocketManager.prototype.loadTransport = function() {
|
|
34
|
+
var script,
|
|
35
|
+
_this = this;
|
|
36
|
+
script = document.createElement('script');
|
|
37
|
+
script.setAttribute("type", "text/javascript");
|
|
38
|
+
script.setAttribute("src", this.transport_script());
|
|
39
|
+
script.onload = this.transportLoaded;
|
|
40
|
+
if (Luca.util.isIE()) {
|
|
41
|
+
script.onreadystatechange = function() {
|
|
42
|
+
if (script.readyState === "loaded") return _this.transportLoaded();
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return document.getElementsByTagName('head')[0].appendChild(script);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return SocketManager;
|
|
49
|
+
|
|
50
|
+
})();
|
|
51
|
+
|
|
52
|
+
}).call(this);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
|
|
3
|
+
Luca.modules.Deferrable = {
|
|
4
|
+
configure_collection: function(setAsDeferrable) {
|
|
5
|
+
var collectionManager, _ref, _ref2;
|
|
6
|
+
if (setAsDeferrable == null) setAsDeferrable = true;
|
|
7
|
+
if (!this.collection) return;
|
|
8
|
+
if (_.isString(this.collection) && (collectionManager = (_ref = Luca.CollectionManager) != null ? _ref.get() : void 0)) {
|
|
9
|
+
this.collection = collectionManager.getOrCreate(this.collection);
|
|
10
|
+
}
|
|
11
|
+
if (!(this.collection && _.isFunction(this.collection.fetch) && _.isFunction(this.collection.reset))) {
|
|
12
|
+
this.collection = new Luca.Collection(this.collection.initial_set, this.collection);
|
|
13
|
+
}
|
|
14
|
+
if ((_ref2 = this.collection) != null ? _ref2.deferrable_trigger : void 0) {
|
|
15
|
+
this.deferrable_trigger = this.collection.deferrable_trigger;
|
|
16
|
+
}
|
|
17
|
+
if (setAsDeferrable) return this.deferrable = this.collection;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
}).call(this);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
|
|
3
|
+
Luca.LocalStore = (function() {
|
|
4
|
+
|
|
5
|
+
function LocalStore(name) {
|
|
6
|
+
var store;
|
|
7
|
+
this.name = name;
|
|
8
|
+
store = localStorage.getItem(this.name);
|
|
9
|
+
this.data = (store && JSON.parse(store)) || {};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
LocalStore.prototype.guid = function() {
|
|
13
|
+
var S4;
|
|
14
|
+
S4 = function() {
|
|
15
|
+
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
16
|
+
};
|
|
17
|
+
return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
LocalStore.prototype.save = function() {
|
|
21
|
+
return localStorage.setItem(this.name, JSON.stringify(this.data));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
LocalStore.prototype.create = function(model) {
|
|
25
|
+
if (!model.id) model.id = model.attribtues.id = this.guid();
|
|
26
|
+
this.data[model.id] = model;
|
|
27
|
+
this.save();
|
|
28
|
+
return model;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
LocalStore.prototype.update = function(model) {
|
|
32
|
+
this.data[model.id] = model;
|
|
33
|
+
this.save();
|
|
34
|
+
return model;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
LocalStore.prototype.find = function(model) {
|
|
38
|
+
return this.data[model.id];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
LocalStore.prototype.findAll = function() {
|
|
42
|
+
return _.values(this.data);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
LocalStore.prototype.destroy = function(model) {
|
|
46
|
+
delete this.data[model.id];
|
|
47
|
+
this.save();
|
|
48
|
+
return model;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return LocalStore;
|
|
52
|
+
|
|
53
|
+
})();
|
|
54
|
+
|
|
55
|
+
Backbone.LocalSync = function(method, model, options) {
|
|
56
|
+
var resp, store;
|
|
57
|
+
store = model.localStorage || model.collection.localStorage;
|
|
58
|
+
resp = (function() {
|
|
59
|
+
switch (method) {
|
|
60
|
+
case "read":
|
|
61
|
+
if (model.id) {
|
|
62
|
+
return store.find(model);
|
|
63
|
+
} else {
|
|
64
|
+
return store.findAll();
|
|
65
|
+
}
|
|
66
|
+
case "create":
|
|
67
|
+
return store.create(model);
|
|
68
|
+
case "update":
|
|
69
|
+
return store.update(model);
|
|
70
|
+
case "delete":
|
|
71
|
+
return store.destroy(model);
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
74
|
+
if (resp) {
|
|
75
|
+
return options.success(resp);
|
|
76
|
+
} else {
|
|
77
|
+
return options.error("Record not found");
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
}).call(this);
|