spine-rails 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore
CHANGED
@@ -25,6 +25,12 @@
|
|
25
25
|
}
|
26
26
|
return this;
|
27
27
|
},
|
28
|
+
one: function(ev, callback) {
|
29
|
+
return this.bind(ev, function() {
|
30
|
+
this.unbind(ev, arguments.callee);
|
31
|
+
return callback.apply(this, arguments);
|
32
|
+
});
|
33
|
+
},
|
28
34
|
trigger: function() {
|
29
35
|
var args, callback, ev, list, _i, _len, _ref;
|
30
36
|
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
@@ -176,21 +182,24 @@
|
|
176
182
|
}
|
177
183
|
};
|
178
184
|
Model.refresh = function(values, options) {
|
179
|
-
var record, _i, _len
|
185
|
+
var record, records, _i, _len;
|
180
186
|
if (options == null) {
|
181
187
|
options = {};
|
182
188
|
}
|
183
189
|
if (options.clear) {
|
184
190
|
this.records = {};
|
185
191
|
}
|
186
|
-
|
187
|
-
|
188
|
-
|
192
|
+
records = this.fromJSON(values);
|
193
|
+
if (!isArray(records)) {
|
194
|
+
records = [records];
|
195
|
+
}
|
196
|
+
for (_i = 0, _len = records.length; _i < _len; _i++) {
|
197
|
+
record = records[_i];
|
189
198
|
record.newRecord = false;
|
190
199
|
record.id || (record.id = guid());
|
191
200
|
this.records[record.id] = record;
|
192
201
|
}
|
193
|
-
this.trigger('refresh');
|
202
|
+
this.trigger('refresh', !options.clear && records);
|
194
203
|
return this;
|
195
204
|
};
|
196
205
|
Model.select = function(callback) {
|
@@ -389,16 +398,16 @@
|
|
389
398
|
var error;
|
390
399
|
error = this.validate();
|
391
400
|
if (error) {
|
392
|
-
this.trigger('error',
|
401
|
+
this.trigger('error', error);
|
393
402
|
return false;
|
394
403
|
}
|
395
|
-
this.trigger('beforeSave'
|
404
|
+
this.trigger('beforeSave');
|
396
405
|
if (this.newRecord) {
|
397
406
|
this.create();
|
398
407
|
} else {
|
399
408
|
this.update();
|
400
409
|
}
|
401
|
-
this.trigger('save'
|
410
|
+
this.trigger('save');
|
402
411
|
return this;
|
403
412
|
};
|
404
413
|
Model.prototype.updateAttribute = function(name, value) {
|
@@ -419,11 +428,11 @@
|
|
419
428
|
return this.save();
|
420
429
|
};
|
421
430
|
Model.prototype.destroy = function() {
|
422
|
-
this.trigger('beforeDestroy'
|
431
|
+
this.trigger('beforeDestroy');
|
423
432
|
delete this.constructor.records[this.id];
|
424
433
|
this.destroyed = true;
|
425
|
-
this.trigger('destroy'
|
426
|
-
this.trigger('change',
|
434
|
+
this.trigger('destroy');
|
435
|
+
this.trigger('change', 'destroy');
|
427
436
|
this.unbind();
|
428
437
|
return this;
|
429
438
|
};
|
@@ -460,16 +469,16 @@
|
|
460
469
|
};
|
461
470
|
Model.prototype.update = function() {
|
462
471
|
var clone, records;
|
463
|
-
this.trigger('beforeUpdate'
|
472
|
+
this.trigger('beforeUpdate');
|
464
473
|
records = this.constructor.records;
|
465
474
|
records[this.id].load(this.attributes());
|
466
475
|
clone = records[this.id].clone();
|
467
|
-
|
468
|
-
return
|
476
|
+
clone.trigger('update');
|
477
|
+
return clone.trigger('change', 'update');
|
469
478
|
};
|
470
479
|
Model.prototype.create = function() {
|
471
480
|
var clone, records;
|
472
|
-
this.trigger('beforeCreate'
|
481
|
+
this.trigger('beforeCreate');
|
473
482
|
if (!this.id) {
|
474
483
|
this.id = guid();
|
475
484
|
}
|
@@ -477,8 +486,8 @@
|
|
477
486
|
records = this.constructor.records;
|
478
487
|
records[this.id] = this.dup(false);
|
479
488
|
clone = records[this.id].clone();
|
480
|
-
|
481
|
-
return
|
489
|
+
clone.trigger('create');
|
490
|
+
return clone.trigger('change', 'create');
|
482
491
|
};
|
483
492
|
Model.prototype.bind = function(events, callback) {
|
484
493
|
var binder, unbinder;
|
@@ -496,11 +505,13 @@
|
|
496
505
|
return binder;
|
497
506
|
};
|
498
507
|
Model.prototype.trigger = function() {
|
499
|
-
var _ref;
|
500
|
-
|
508
|
+
var args, _ref;
|
509
|
+
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
510
|
+
args.splice(1, 0, this);
|
511
|
+
return (_ref = this.constructor).trigger.apply(_ref, args);
|
501
512
|
};
|
502
513
|
Model.prototype.unbind = function() {
|
503
|
-
return this.trigger('unbind'
|
514
|
+
return this.trigger('unbind');
|
504
515
|
};
|
505
516
|
return Model;
|
506
517
|
})();
|
@@ -508,7 +519,7 @@
|
|
508
519
|
__extends(Controller, Module);
|
509
520
|
Controller.include(Events);
|
510
521
|
Controller.include(Log);
|
511
|
-
Controller.prototype.eventSplitter = /^(\
|
522
|
+
Controller.prototype.eventSplitter = /^(\S+)\s*(.*)$/;
|
512
523
|
Controller.prototype.tag = 'div';
|
513
524
|
function Controller(options) {
|
514
525
|
this.release = __bind(this.release, this);
|
@@ -722,5 +733,4 @@
|
|
722
733
|
return new this(a1, a2, a3, a4, a5);
|
723
734
|
};
|
724
735
|
Spine.Class = Module;
|
725
|
-
Spine.App = new Controller;
|
726
736
|
}).call(this);
|
@@ -74,16 +74,37 @@
|
|
74
74
|
this.errorResponse = __bind(this.errorResponse, this);
|
75
75
|
this.recordsResponse = __bind(this.recordsResponse, this);
|
76
76
|
}
|
77
|
-
Collection.prototype.
|
77
|
+
Collection.prototype.find = function(id, params) {
|
78
|
+
var record;
|
79
|
+
record = new this.model({
|
80
|
+
id: id
|
81
|
+
});
|
82
|
+
return this.ajax(params, {
|
83
|
+
type: 'GET',
|
84
|
+
url: Ajax.getURL(record)
|
85
|
+
}).success(this.recordsResponse).error(this.errorResponse);
|
86
|
+
};
|
87
|
+
Collection.prototype.all = function(params) {
|
78
88
|
return this.ajax(params, {
|
79
89
|
type: 'GET',
|
80
90
|
url: Ajax.getURL(this.model)
|
81
91
|
}).success(this.recordsResponse).error(this.errorResponse);
|
82
92
|
};
|
83
93
|
Collection.prototype.fetch = function(params) {
|
84
|
-
|
85
|
-
|
86
|
-
|
94
|
+
var id;
|
95
|
+
if (params == null) {
|
96
|
+
params = {};
|
97
|
+
}
|
98
|
+
if (id = params.id) {
|
99
|
+
delete params.id;
|
100
|
+
return this.find(id, params).success(__bind(function(record) {
|
101
|
+
return this.model.refresh(record);
|
102
|
+
}, this));
|
103
|
+
} else {
|
104
|
+
return this.all(params).success(__bind(function(records) {
|
105
|
+
return this.model.refresh(records);
|
106
|
+
}, this));
|
107
|
+
}
|
87
108
|
};
|
88
109
|
Collection.prototype.recordsResponse = function(data, status, xhr) {
|
89
110
|
return this.model.trigger('ajaxSuccess', null, status, xhr);
|
@@ -102,11 +123,13 @@
|
|
102
123
|
this.recordResponse = __bind(this.recordResponse, this);
|
103
124
|
this.model = this.record.constructor;
|
104
125
|
}
|
105
|
-
Singleton.prototype.
|
106
|
-
return this.
|
107
|
-
|
108
|
-
|
109
|
-
|
126
|
+
Singleton.prototype.reload = function(params) {
|
127
|
+
return this.queue(__bind(function() {
|
128
|
+
return this.ajax(params, {
|
129
|
+
type: 'GET',
|
130
|
+
url: Ajax.getURL(this.record)
|
131
|
+
}).success(this.recordResponse).error(this.errorResponse);
|
132
|
+
}, this));
|
110
133
|
};
|
111
134
|
Singleton.prototype.create = function(params) {
|
112
135
|
return this.queue(__bind(function() {
|
@@ -135,7 +158,7 @@
|
|
135
158
|
}, this));
|
136
159
|
};
|
137
160
|
Singleton.prototype.recordResponse = function(data, status, xhr) {
|
138
|
-
this.record.trigger('ajaxSuccess',
|
161
|
+
this.record.trigger('ajaxSuccess', status, xhr);
|
139
162
|
if (Spine.isBlank(data)) {
|
140
163
|
return;
|
141
164
|
}
|
@@ -148,10 +171,10 @@
|
|
148
171
|
}, this));
|
149
172
|
};
|
150
173
|
Singleton.prototype.blankResponse = function(data, status, xhr) {
|
151
|
-
return this.record.trigger('ajaxSuccess',
|
174
|
+
return this.record.trigger('ajaxSuccess', status, xhr);
|
152
175
|
};
|
153
176
|
Singleton.prototype.errorResponse = function(xhr, statusText, error) {
|
154
|
-
return this.record.trigger('ajaxError',
|
177
|
+
return this.record.trigger('ajaxError', xhr, statusText, error);
|
155
178
|
};
|
156
179
|
return Singleton;
|
157
180
|
})();
|
@@ -17,8 +17,8 @@
|
|
17
17
|
Manager.include(Spine.Events);
|
18
18
|
function Manager() {
|
19
19
|
this.controllers = [];
|
20
|
-
this.add.apply(this, arguments);
|
21
20
|
this.bind('change', this.change);
|
21
|
+
this.add.apply(this, arguments);
|
22
22
|
}
|
23
23
|
Manager.prototype.add = function() {
|
24
24
|
var cont, controllers, _i, _len, _results;
|
@@ -34,18 +34,19 @@
|
|
34
34
|
controller.bind('active', __bind(function() {
|
35
35
|
var args;
|
36
36
|
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
37
|
-
return this.trigger('change', controller
|
37
|
+
return this.trigger.apply(this, ['change', controller].concat(__slice.call(args)));
|
38
38
|
}, this));
|
39
|
-
controller.bind('
|
39
|
+
controller.bind('release', __bind(function() {
|
40
40
|
return this.controllers.splice(this.controllers.indexOf(controller), 1);
|
41
41
|
}, this));
|
42
42
|
return this.controllers.push(controller);
|
43
43
|
};
|
44
44
|
Manager.prototype.deactivate = function() {
|
45
|
-
return this.trigger('change', false
|
45
|
+
return this.trigger.apply(this, ['change', false].concat(__slice.call(arguments)));
|
46
46
|
};
|
47
|
-
Manager.prototype.change = function(
|
48
|
-
var cont, _i, _len, _ref, _results;
|
47
|
+
Manager.prototype.change = function() {
|
48
|
+
var args, cont, current, _i, _len, _ref, _results;
|
49
|
+
current = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
49
50
|
_ref = this.controllers;
|
50
51
|
_results = [];
|
51
52
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
(function() {
|
2
|
-
var Collection, Instance, Singleton,
|
2
|
+
var Collection, Instance, Singleton, singularize, underscore;
|
3
3
|
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
|
4
4
|
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
|
5
5
|
function ctor() { this.constructor = child; }
|
data/lib/spine/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spine-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-17 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70334460548580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70334460548580
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70334460548120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70334460548120
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &70334460547660 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '3.0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70334460547660
|
47
47
|
description: This gem provides Spine for your Rails 3 application.
|
48
48
|
email:
|
49
49
|
- info@eribium.org
|