forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackgrid-tests.ts
78 lines (55 loc) · 1.88 KB
/
backgrid-tests.ts
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
/// <reference path="backgrid.d.ts" />
/// <reference path="../backbone/backbone.d.ts" />
/// <reference path="../jquery/jquery.d.ts" />
/*
Uses getters and setters and requires ES >= 5
$ tsc --target ES5 backgrid-tests.ts
*/
class TestModel extends Backbone.Model {
get Id(): number { return this.get('id'); }
set Id(value: number) { this.set('id', value); }
get FirstName(): string { return this.get('FirstName'); }
set FirstName(value: string) { this.set('FirstName', value); }
set LastName(value: string) { this.set('LastName', value); }
get LastName(): string { return this.get('LastName'); }
set EMail(value: string) { this.set('EMail', value); }
get EMail(): string { return this.get('EMail'); }
}
class TestCollection extends Backbone.Collection {
constructor(models?: any, options?: any) {
this.model = TestModel;
super(models, options);
}
initialize() {
this.on("change", this.modelChanged, this)
}
modelChanged(model: Backbone.Model, val: any, options: any){
model.save();
}
}
class TestView extends Backbone.View {
gridView: Backgrid.Grid;
testCollection: TestCollection;
constructor(viewOptions?: Backbone.ViewOptions) {
this.testCollection = new TestCollection();
this.gridView = new Backgrid.Grid({
columns: [new Backgrid.Column({name: "FirstName", cell: "string", label: "First Name"}),
new Backgrid.Column({name: "LastName", cell: "string", label: "Last Name"}),
new Backgrid.Column({name: "EMail", cell: "string", label: "E-Mail"})],
collection:this.testCollection,
});
super(viewOptions);
}
initialize() {
}
render() {
this.$el.empty();
this.$el.append(this.gridView.render().$el);
//this.testCollection.fetch();
return this;
}
}
function test_grid() {
var view = new TestView();
view.render();
}