exoskeleton 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODU4NGM1YjI0YTBjNDI4Y2M3MDFjOTQyY2U0MmNhNTljOTk1MjEzNg==
4
+ NTllOTFjMDk4Y2Y4ZmZkNGZlZjMzNzIxZTBhNDAxNTU2NDU0MmY3ZQ==
5
5
  data.tar.gz: !binary |-
6
- YzA5OTAwYWIyNzMyOWNhODNkZTgyZDNkYzcwMmRkZDkyNjk3OTZjNQ==
6
+ NzVmNDA0NzExZDE1OGFlMjA2ZWNkN2E2MGFkMWNhZmNiZDEyZWQ0Yw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDczOWU1ZDQ0NmMwMDE2MDI4NDU1NGYxOTg3ODkwNzMyYmQ1NmE0ZjFjZDYy
10
- MzQ3MzI0ZWFjY2ZhYTQ1OGFkZTI3NzEyMjYyNDRmYzY3YjJlYmZkMmQ2MmJj
11
- NTg5NjJiMWMyZGJiODAzMzY2NTUyMThkZmEyMDcxNWNkZmM3MDY=
9
+ ZWI4NTQxNTZhZTRlYmFhNTYxMzdjMzQ0ZmM3OTIxZmE1ZTllNzJhOTYwNjZm
10
+ ZDFiNWFjN2NkYjU3Y2ZkMmFhNDQ1MDU0NWMzOGIwOTE3MGNhZGNmNWY5MTk4
11
+ YjEzMWM5ZDI2Y2RiMDI0YWQ2M2ZmZDA5NWIyYzY3Njk1MzBjNWE=
12
12
  data.tar.gz: !binary |-
13
- MDc1ODY5YTNiNmRmMjZmZmNlZThiZWJiNWE1MjFhY2MxMGRiNzE4M2I1YjMw
14
- MTg0OWIwMmI3MmQ2YmVlOWY1ZjY1MGFkYTVmNzljMmQzYzgxNjEzMDhhNmY1
15
- MmI3M2RkOTU0MjE5YjdiZGRkNzhjNmUyMzkwY2EwOGMxZjIxZmU=
13
+ Mzc1ZWZjOTU4OGRmZmI2MmJkNmIyZmQ3YmM4ZmZiMmY2YTQ1N2ExNWFlZGE0
14
+ OGJiNzc1YWVjZjg2MjM5NTE2ZjBhODc3ODNiOTJkMmJhMmUxOGIyOTE2OTU1
15
+ NWJlMzI4MDlhNzY4NTg2YjMzMDZhNTk2YTlkZmM5MTAyZDc3YjI=
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  This gem builds out the basic framework to use [Backbone.js](http://backbonejs.org/) along with templating abilities
4
4
 
5
+ # Controller Prerequisite
6
+
7
+ Please review the required format for data responses coming from your controllers which can be found [here](https://github.com/agapered/exoskeleton/wiki/Using-Backbone-Collections-and-Models)
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -80,7 +84,9 @@ Navigate to the awesomness
80
84
 
81
85
  http://localhost:3000/home/index
82
86
 
83
-
87
+ ## More Detailed Usage
88
+
89
+ There are a few things to learn to use the full functionality of this gem. These items can be found on the [wiki](https://github.com/agapered/exoskeleton/wiki).
84
90
 
85
91
  ## Contributing
86
92
 
@@ -1,5 +1,45 @@
1
1
  exoskeleton.collections.base_collection = Backbone.Collection.extend({
2
2
 
3
+ __fetchStatus: new exoskeleton.models.load_status,
3
4
 
5
+ fetchStatus: function(){
6
+ return this.__fetchStatus
7
+ },
8
+
9
+ fetch: function(options){
10
+ var _this = this ;
11
+ this.__fetchStatus = new exoskeleton.models.load_status()
12
+ Backbone.Collection.prototype.fetch.call(this,{
13
+ success: function(collection, response){
14
+ if(response.success == undefined){
15
+ _this.trigger('fetch:unsuccessful', collection, null, null)
16
+ alert("Response did not come back in appropriate json format needed: {success: [true/false], data: [Your Data], message: [Custom Message]")
17
+ return
18
+ }
19
+ _this.__fetchStatus.set_completed()
20
+ _this.__fetchStatus.set_message(response.message)
21
+ if(response.success){
22
+ _this.__fetchStatus.set_successful()
23
+ _this.trigger('fetch:successful', collection, response.data, response.message)
24
+ } else {
25
+ _this.trigger('fetch:unsuccessful', collection, response.data, response.message)
26
+ }
27
+ if(options && options.success){
28
+ options.success(collection, response)
29
+ }
30
+ _this.trigger('fetch:complete', collection, response.data, response.message)
31
+ },
32
+ error: function(collection, response) {
33
+ _this.__fetchStatus.set_completed()
34
+ _this.__fetchStatus.set_message(response.message)
35
+ _this.__fetchStatus.set_system_error()
36
+ _this.trigger('fetch:error', collection, response.data, response.message)
37
+ if(options && options.error){
38
+ options.error(collection, response)
39
+ }
40
+ _this.trigger('fetch:complete', collection, response.data, response.message)
41
+ }
42
+ })
43
+ }
4
44
 
5
45
  })
@@ -1,6 +1,8 @@
1
1
  //= require ./vendor/underscore-min
2
2
  //= require ./vendor/backbone-min
3
3
  //= require ./main
4
+ //= require ./models/load_status
4
5
  //= require_tree ./models
5
6
  //= require_tree ./collections
7
+ //= require_tree ./views/mixins
6
8
  //= require_tree ./views
@@ -3,5 +3,6 @@
3
3
  exoskeleton = {
4
4
  collections: {},
5
5
  models: {},
6
- views: {}
6
+ views: {},
7
+ mixins: {}
7
8
  }
@@ -1,5 +1,47 @@
1
1
  exoskeleton.models.base_model = Backbone.Model.extend({
2
2
 
3
+ __fetchStatus: new exoskeleton.models.load_status,
4
+
5
+ fetchStatus: function(){
6
+ return this.__fetchStatus
7
+ },
8
+
9
+ parse: function(response){
10
+ var data = _.isUndefined(response.data) ? response : response.data
11
+ return data
12
+ },
13
+
14
+ fetch: function(options){
15
+ var _this = this ;
16
+ this.__fetchStatus = new exoskeleton.models.load_status()
17
+ Backbone.Model.prototype.fetch.call(this,{
18
+ success: function(model, response){
19
+ _this.__fetchStatus.set_completed()
20
+ _this.__fetchStatus.set_message(response.message)
21
+ if(response.success){
22
+ _this.__fetchStatus.set_successful()
23
+ _this._original_attributes = _.clone(model.attributes);
24
+ _this.trigger('fetch:successful', model, response.data, response.message)
25
+ } else {
26
+ _this.trigger('fetch:unsuccessful', model, response.data, response.message)
27
+ }
28
+ if(options && options.success){
29
+ options.success(model, response)
30
+ }
31
+ _this.trigger('fetch:complete', model, response.data, response.message)
32
+ },
33
+ error: function(model, response) {
34
+ _this.__fetchStatus.set_completed()
35
+ _this.__fetchStatus.set_message(response.message)
36
+ _this.__fetchStatus.set_system_error()
37
+ _this.trigger('fetch:error', model, response.data, response.message)
38
+ if(options && options.error){
39
+ options.error(model, response)
40
+ }
41
+ _this.trigger('fetch:complete', model, response.data, response.message)
42
+ }
43
+ })
44
+ },
3
45
 
4
46
 
5
47
  })
@@ -0,0 +1,40 @@
1
+ exoskeleton.models.load_status = Backbone.Model.extend( {
2
+ initialize: function(){
3
+ this.is_complete = false
4
+ this.is_successful = false
5
+ this.status_message = null
6
+ this.is_error = false
7
+ },
8
+
9
+ set_completed: function(){
10
+ this.is_complete = true
11
+ },
12
+
13
+ set_successful: function(){
14
+ this.is_successful = true
15
+ },
16
+
17
+ set_message: function(message){
18
+ this.status_message = message
19
+ },
20
+
21
+ set_system_error: function(){
22
+ this.is_error = true
23
+ },
24
+
25
+ complete: function(){
26
+ return this.is_complete
27
+ },
28
+
29
+ successful: function(){
30
+ return this.is_successful
31
+ },
32
+
33
+ message: function(){
34
+ return this.status_message
35
+ },
36
+
37
+ system_error: function(){
38
+ return this.is_error
39
+ }
40
+ })
@@ -1,4 +1,67 @@
1
1
  exoskeleton.views.base_view = Backbone.View.extend({
2
2
 
3
+ remove: function(){
4
+
5
+ if (_.isFunction(this.clean_up)){
6
+ this.clean_up()
7
+ }
8
+
9
+ _.each(this.child_views, function(child_view){
10
+ child_view.remove()
11
+ })
12
+
13
+ this.child_views = []
14
+
15
+ this.$el.children().remove()
16
+
17
+ this.undelegateEvents()
18
+ Backbone.View.prototype.remove.call(this);
19
+ },
20
+
21
+ add_subview: function(view_to_append){
22
+ if (_.isUndefined(this.child_views))
23
+ {
24
+ this.child_views = []
25
+ }
26
+ this.child_views.push(view_to_append)
27
+ },
28
+
29
+ append_view: function(view, target){
30
+ this.$(target).append(view.render().el)
31
+ this.add_subview(view)
32
+ },
33
+
34
+ set_html: function(view, target){
35
+ this.$(target).html(view.render().el)
36
+ this.add_subview(view)
37
+ },
38
+
39
+ /*postAttachment
40
+ This function executes the supplied function after the view has been attached to the DOM.
41
+ If the view is already attached to the DOM the function is executed immediately. If the
42
+ view is not attached to the DOM, it will check every eighth second for up to 30 seconds
43
+ and execute the function as soon as it is attached. If the view is not attached to the
44
+ DOM within 30 seconds, the function will never be executed. The view itself will be
45
+ passed into the function as an argument.
46
+ */
47
+ post_attachment: function(fn, count){
48
+ if ( count ){
49
+ count++
50
+ } else {
51
+ count = 0
52
+ }
53
+ if( count > 240 ){
54
+ return
55
+ }
56
+ if( $(this.el).parents('body').length > 0 ){
57
+ fn(this)
58
+ } else {
59
+ var _this = this
60
+ setTimeout(function(){
61
+ _this.post_attachment(fn, count)
62
+ }, 125)
63
+ }
64
+
65
+ }
3
66
 
4
67
  })
@@ -0,0 +1,80 @@
1
+ exoskeleton.mixins.required_elements = {
2
+ add_required_element: function(element){
3
+ if(!this.required_elements){
4
+ this.required_elements = []
5
+ }
6
+ if(_.isUndefined(this.required_element_error_shown)){
7
+ this.required_element_error_shown = false
8
+ }
9
+ var _this = this;
10
+ element.bind('fetch:complete', function(event_element){
11
+ // Prevent triggering render on sub-models and sub-collections.
12
+ if( event_element === element ){
13
+ _this.render();
14
+ }
15
+ }, this);
16
+ this.required_elements.push(element)
17
+ },
18
+ required_elements_loaded: function(){
19
+ if(!this.required_elements){
20
+ this.required_elements = []
21
+ }
22
+ var loaded = true
23
+ var successful = true
24
+ var system_error = false
25
+
26
+ for(var i=0; i<this.required_elements.length; i++){
27
+ var element = this.required_elements[i]
28
+ if(!(element.fetchStatus().is_complete)){
29
+ loaded = false
30
+ break;
31
+ }
32
+ if(!(element.fetchStatus().successful())){
33
+ successful = false
34
+ if(element.fetchStatus().system_error()){
35
+ system_error = true
36
+ }
37
+ break;
38
+ }
39
+ }
40
+
41
+ var status = {
42
+ loaded: loaded,
43
+ successful: successful,
44
+ system_error: system_error
45
+ }
46
+
47
+ return status
48
+ },
49
+ render: function(){
50
+ if(this.required_element_error_shown){
51
+ return this
52
+ }
53
+ var load_status = this.required_elements_loaded()
54
+ if(!load_status.loaded){
55
+ this.render_progress()
56
+ return this
57
+ }
58
+
59
+ if(!load_status.successful){
60
+ if(load_status.system_error){
61
+ this.system_error()
62
+ return this
63
+ }
64
+ this.required_element_error_shown = true
65
+ this.render_error()
66
+ return this
67
+ }
68
+
69
+ this.render_successful()
70
+ return this
71
+ },
72
+ system_error: function(){
73
+ //Blank method incase it is not implemented on older views
74
+ },
75
+ render_error: function(){
76
+ //Blank method incase it is not implemented on older views
77
+ }
78
+
79
+
80
+ }
@@ -1,3 +1,3 @@
1
1
  module Exoskeleton
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exoskeleton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Hopp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-14 00:00:00.000000000 Z
11
+ date: 2013-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -194,9 +194,11 @@ files:
194
194
  - app/assets/javascripts/exoskeleton/index.js
195
195
  - app/assets/javascripts/exoskeleton/main.js
196
196
  - app/assets/javascripts/exoskeleton/models/base_model.js
197
+ - app/assets/javascripts/exoskeleton/models/load_status.js
197
198
  - app/assets/javascripts/exoskeleton/vendor/backbone-min.js
198
199
  - app/assets/javascripts/exoskeleton/vendor/underscore-min.js
199
200
  - app/assets/javascripts/exoskeleton/views/base_view.js
201
+ - app/assets/javascripts/exoskeleton/views/mixins/required_elements_mixin.js
200
202
  - exoskeleton.gemspec
201
203
  - lib/exoskeleton.rb
202
204
  - lib/exoskeleton/engine.rb