pbw 0.0.1 → 0.0.2
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.
- checksums.yaml +8 -8
- data/Rakefile +3 -1
- data/app/controllers/pbw/application_controller.rb +22 -0
- data/app/controllers/pbw/roles_controller.rb +43 -0
- data/app/models/pbw/ability.rb +13 -0
- data/app/models/pbw/permission.rb +12 -0
- data/app/models/pbw/role.rb +25 -0
- data/app/models/pbw/user.rb +54 -0
- data/config/initializers/devise.rb +5 -0
- data/config/routes.rb +4 -0
- data/lib/generators/pbw/install/USAGE +5 -0
- data/lib/generators/pbw/install/install_generator.rb +38 -0
- data/lib/generators/pbw/install/templates/app.coffee +11 -0
- data/lib/generators/pbw/resource_helpers.rb +55 -0
- data/lib/pbw/engine.rb +7 -1
- data/lib/pbw/version.rb +1 -1
- data/lib/pbw.rb +2 -0
- data/vendor/assets/javascripts/backbone.js +1571 -0
- data/vendor/assets/javascripts/backbone_datalink.js +0 -0
- data/vendor/assets/javascripts/backbone_rails_sync.js +81 -0
- data/vendor/assets/javascripts/underscore.js +1246 -0
- metadata +28 -13
File without changes
|
@@ -0,0 +1,81 @@
|
|
1
|
+
(function($) {
|
2
|
+
var methodMap = {
|
3
|
+
'create': 'POST',
|
4
|
+
'update': 'PUT',
|
5
|
+
'delete': 'DELETE',
|
6
|
+
'read' : 'GET'
|
7
|
+
};
|
8
|
+
|
9
|
+
var getUrl = function(object) {
|
10
|
+
if (!(object && object.url)) return null;
|
11
|
+
return _.isFunction(object.url) ? object.url() : object.url;
|
12
|
+
};
|
13
|
+
|
14
|
+
var urlError = function() {
|
15
|
+
throw new Error("A 'url' property or function must be specified");
|
16
|
+
};
|
17
|
+
|
18
|
+
Backbone.sync = function(method, model, options) {
|
19
|
+
var type = methodMap[method];
|
20
|
+
|
21
|
+
// Default JSON-request options.
|
22
|
+
var params = _.extend({
|
23
|
+
type: type,
|
24
|
+
dataType: 'json',
|
25
|
+
beforeSend: function( xhr ) {
|
26
|
+
if (!options.noCSRF) {
|
27
|
+
var token = $('meta[name="csrf-token"]').attr('content');
|
28
|
+
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
|
29
|
+
}
|
30
|
+
model.trigger('sync:start');
|
31
|
+
}
|
32
|
+
}, options);
|
33
|
+
|
34
|
+
if (!params.url) {
|
35
|
+
params.url = getUrl(model) || urlError();
|
36
|
+
}
|
37
|
+
|
38
|
+
// Ensure that we have the appropriate request data.
|
39
|
+
if (!params.data && model && (method == 'create' || method == 'update')) {
|
40
|
+
params.contentType = 'application/json';
|
41
|
+
|
42
|
+
var data = {}
|
43
|
+
|
44
|
+
if(model.paramRoot) {
|
45
|
+
data[model.paramRoot] = model.toJSON();
|
46
|
+
} else {
|
47
|
+
data = model.toJSON();
|
48
|
+
}
|
49
|
+
|
50
|
+
params.data = JSON.stringify(data)
|
51
|
+
}
|
52
|
+
|
53
|
+
// Don't process data on a non-GET request.
|
54
|
+
if (params.type !== 'GET') {
|
55
|
+
params.processData = false;
|
56
|
+
}
|
57
|
+
|
58
|
+
// Trigger the sync end event
|
59
|
+
var complete = options.complete;
|
60
|
+
params.complete = function(jqXHR, textStatus) {
|
61
|
+
model.trigger('sync:end');
|
62
|
+
if (complete) complete(jqXHR, textStatus);
|
63
|
+
};
|
64
|
+
|
65
|
+
var success = options.success;
|
66
|
+
params.success = function(resp) {
|
67
|
+
if (success) success(model, resp, options);
|
68
|
+
model.trigger('sync', model, resp, options);
|
69
|
+
};
|
70
|
+
|
71
|
+
var error = options.error;
|
72
|
+
params.error = function(xhr) {
|
73
|
+
if (error) error(model, xhr, options);
|
74
|
+
model.trigger('error', model, xhr, options);
|
75
|
+
};
|
76
|
+
|
77
|
+
// Make the request.
|
78
|
+
return $.ajax(params);
|
79
|
+
}
|
80
|
+
|
81
|
+
})(jQuery);
|