-
Notifications
You must be signed in to change notification settings - Fork 12
/
backbone.hal.js
98 lines (84 loc) · 2.91 KB
/
backbone.hal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Generated by CoffeeScript 1.7.1
(function() {
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
(function(root, factory) {
if (typeof define !== "undefined" && define !== null ? define.amd : void 0) {
return define(['backbone', 'underscore'], factory);
} else {
return root.HAL = factory(Backbone, _);
}
})(this, function(Backbone, _) {
var Collection, Model;
Model = (function(_super) {
__extends(Model, _super);
function Model(attrs, options) {
Model.__super__.constructor.call(this, this.parse(_.clone(attrs)), options);
}
Model.prototype.parse = function(attrs) {
if (attrs == null) {
attrs = {};
}
this.links = attrs._links || {};
delete attrs._links;
this.embedded = attrs._embedded || {};
delete attrs._embedded;
return attrs;
};
Model.prototype.url = function() {
var _ref, _ref1;
return ((_ref = this.links) != null ? (_ref1 = _ref.self) != null ? _ref1.href : void 0 : void 0) || Model.__super__.url.call(this);
};
Model.prototype.isNew = function() {
var _ref;
return !((_ref = this.links) != null ? _ref.self : void 0);
};
return Model;
})(Backbone.Model);
Collection = (function(_super) {
__extends(Collection, _super);
function Collection(obj, options) {
if (!_.isArray(obj)) {
obj = this.parse(_.clone(obj));
}
Collection.__super__.constructor.call(this, obj, options);
}
Collection.prototype.parse = function(obj) {
var items;
if (obj == null) {
obj = {};
}
this.links = obj._links || {};
delete obj._links;
this.embedded = obj._embedded || {};
delete obj._embedded;
this.attributes = obj || {};
if (this.itemRel != null) {
items = this.embedded[this.itemRel];
} else {
items = this.embedded.items;
}
return items;
};
Collection.prototype.reset = function(obj, options) {
if (options == null) {
options = {};
}
if (!_.isArray(obj)) {
obj = this.parse(_.clone(obj));
}
options.parse = false;
return Collection.__super__.reset.call(this, obj, options);
};
Collection.prototype.url = function() {
var _ref, _ref1;
return (_ref = this.links) != null ? (_ref1 = _ref.self) != null ? _ref1.href : void 0 : void 0;
};
return Collection;
})(Backbone.Collection);
return {
Model: Model,
Collection: Collection
};
});
}).call(this);