-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel.js
More file actions
75 lines (56 loc) · 1.92 KB
/
model.js
File metadata and controls
75 lines (56 loc) · 1.92 KB
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
// Generated by CoffeeScript 1.4.0
(function() {
var Database, Record,
__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; };
Record = (function(_super) {
__extends(Record, _super);
function Record() {
return Record.__super__.constructor.apply(this, arguments);
}
Record.prototype.initialize = function() {
if (!this.get('title')) {
return this.set('title', 'New record');
}
};
return Record;
})(Backbone.Model);
Database = (function(_super) {
__extends(Database, _super);
function Database() {
return Database.__super__.constructor.apply(this, arguments);
}
Database.prototype.localStorage = new Backbone.LocalStorage("Database");
Database.prototype.model = Record;
Database.prototype.processURL = function(url) {
return url.split(/[?#]/)[0];
};
Database.prototype.createRecord = function(events) {
var model, record, url;
if (events.length === 0) {
return false;
}
url = this.processURL(events[0].url);
record = {
events: events,
size: events.length,
url: url
};
console.log('Saving record...');
console.log(record);
model = this.create(record);
return this.updateHash(record.url, model.id);
};
Database.prototype.updateHash = function(url, id) {
var ids, key, val;
key = "HT-" + url;
val = localStorage[key] || "";
ids = val.split(/[, ]+/);
ids.push(id);
return localStorage[key] = ids.join(', ');
};
return Database;
})(Backbone.Collection);
window.Record = Record;
window.Database = new Database;
}).call(this);