diff --git a/backgrid/backgrid-tests.ts b/backgrid/backgrid-tests.ts new file mode 100644 index 0000000000..0c681a1d34 --- /dev/null +++ b/backgrid/backgrid-tests.ts @@ -0,0 +1,78 @@ +/// +/// +/// + + +/* + 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(); + } \ No newline at end of file diff --git a/backgrid/backgrid.d.ts b/backgrid/backgrid.d.ts new file mode 100644 index 0000000000..cf3c2ea5c4 --- /dev/null +++ b/backgrid/backgrid.d.ts @@ -0,0 +1,85 @@ +// Type definitions for Backgrid 0.2.6 +// Project: http://backgridjs.com/ +// Definitions by: Jeremy Lujan +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module Backgrid { + + interface GridOptions { + columns: Column[]; + collection: Backbone.Collection; + header: Header; + body: Body; + row: Row; + footer: Footer; + } + + class Header extends Backbone.View { + } + + class Footer extends Backbone.View { + } + + class Row extends Backbone.View { + } + + class Command { + cancel(); + moveDown(); + moveLeft(); + moveRight(); + moveUp(); + passThru(); + save(); + } + + interface ColumnAttr { + name: string; + cell: string; + headerCell: string; + label: string; + sortable: bool; + editable: bool; + renderable: bool; + formater: string; + } + + class Column extends Backbone.Model { + initialize(options?: any); + } + + class Body extends Backbone.View { + tagName: string; + + initialize(options?: any); + insertRow(model: Backbone.Model, collection: Backbone.Collection, options: any); + moveToNextCell(model: Backbone.Model, cell: Column, command: Command); + refresh(): Body; + remove(): Body; + removeRow(model: Backbone.Model, collection: Backbone.Collection, options: any); + render(): Body; + } + + class Grid extends Backbone.View { + body: Backgrid.Body; + className: string; + footer: any; + header: any; + tagName: string; + + initialize(options: any); + getSelectedModels(): Backbone.Model[]; + insertColumn(...options: any[]): Grid; + insertRow(model: Backbone.Model, collection: Backbone.Collection, options: any); + remove():Grid; + removeColumn(...options: any[]): Grid; + removeRow(model: Backbone.Model, collection: Backbone.Collection, options: any); + render():Grid; + } + + + +} +