Index: trunk/parsers/wikidom/lib/synth/models/es.TableBlockCellModel.js |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | * @property attributes {Object} |
11 | 11 | */ |
12 | 12 | es.TableBlockCellModel = function( documentModel, attributes ) { |
| 13 | + es.ModelContainerItem.call( this, 'row' ); |
13 | 14 | this.documentModel = documentModel || null; |
14 | 15 | this.attributes = attributes || {}; |
15 | 16 | }; |
— | — | @@ -21,9 +22,9 @@ |
22 | 23 | * @param obj {Object} |
23 | 24 | */ |
24 | 25 | es.TableBlockCellModel.newFromPlainObject = function( obj ) { |
25 | | - return new es.TableBlockRowModel( |
| 26 | + return new es.TableBlockCellModel( |
26 | 27 | // Cells - if given, convert plain document object to es.DocumentModel objects |
27 | | - !$.isArray( obj.document ) ? null : es.DocumentModel.newFromPlainObject( obj.document ), |
| 28 | + !$.isPlainObject( obj.document ) ? null : es.DocumentModel.newFromPlainObject( obj.document ), |
28 | 29 | // Attributes - if given, make a deep copy of attributes |
29 | 30 | !$.isPlainObject( obj.attributes ) ? {} : $.extend( true, {}, obj.attributes ) |
30 | 31 | ); |
— | — | @@ -32,12 +33,19 @@ |
33 | 34 | /* Methods */ |
34 | 35 | |
35 | 36 | /** |
| 37 | + * Creates a view for this model |
| 38 | + */ |
| 39 | +es.TableBlockCellModel.prototype.createView = function() { |
| 40 | + return new es.TableBlockCellView( this ); |
| 41 | +}; |
| 42 | + |
| 43 | +/** |
36 | 44 | * Gets the length of all content. |
37 | 45 | * |
38 | 46 | * @method |
39 | 47 | * @returns {Integer} Length of all content |
40 | 48 | */ |
41 | | -es.TableBlockRowModel.prototype.getContentLength = function() { |
| 49 | +es.TableBlockCellModel.prototype.getContentLength = function() { |
42 | 50 | return this.cells.getContentLength(); |
43 | 51 | }; |
44 | 52 | |
— | — | @@ -47,7 +55,8 @@ |
48 | 56 | * @method |
49 | 57 | * @returns obj {Object} |
50 | 58 | */ |
51 | | -es.TableBlockRowModel.prototype.getPlainObject = function() { |
| 59 | +es.TableBlockCellModel.prototype.getPlainObject = function() { |
| 60 | + /* |
52 | 61 | var obj = {}; |
53 | 62 | if ( this.documentModel ) { |
54 | 63 | obj.document = this.documentModel; |
— | — | @@ -56,4 +65,9 @@ |
57 | 66 | obj.attributes = $.extend( true, {}, this.attributes ); |
58 | 67 | } |
59 | 68 | return obj; |
| 69 | + */ |
60 | 70 | }; |
| 71 | + |
| 72 | +/* Inheritance */ |
| 73 | + |
| 74 | +es.extend( es.TableBlockCellModel, es.ModelContainerItem ); |
\ No newline at end of file |
Index: trunk/parsers/wikidom/lib/synth/models/es.TableBlockModel.js |
— | — | @@ -10,7 +10,14 @@ |
11 | 11 | */ |
12 | 12 | es.TableBlockModel = function( rows, attributes ) { |
13 | 13 | es.BlockModel.call( this, ['isDocumentContainer', 'isAggregate'] ); |
14 | | - this.rows = new es.ContentSeries( rows || [] ); |
| 14 | + es.ModelContainer.call( this ); |
| 15 | + |
| 16 | + if ( $.isArray( rows ) ) { |
| 17 | + for ( var i = 0; i < rows.length; i++ ) { |
| 18 | + this.append( rows[i] ); |
| 19 | + } |
| 20 | + } |
| 21 | + |
15 | 22 | this.attributes = attributes || {}; |
16 | 23 | }; |
17 | 24 | |
— | — | @@ -60,6 +67,7 @@ |
61 | 68 | * @returns obj {Object} |
62 | 69 | */ |
63 | 70 | es.TableBlockModel.prototype.getPlainObject = function() { |
| 71 | + /* |
64 | 72 | var obj = { 'type': 'table' }; |
65 | 73 | if ( this.rows.length ) { |
66 | 74 | obj.rows = $.map( this.rows, function( row ) { |
— | — | @@ -70,11 +78,13 @@ |
71 | 79 | obj.attributes = $.extend( true, {}, this.attributes ); |
72 | 80 | } |
73 | 81 | return obj; |
| 82 | + */ |
74 | 83 | }; |
75 | 84 | |
76 | 85 | // Register constructor |
77 | | -es.BlockModel.constructors['table'] = es.TableBlockModel; |
| 86 | +es.BlockModel.constructors['table'] = es.TableBlockModel.newFromPlainObject; |
78 | 87 | |
79 | 88 | /* Inheritance */ |
80 | 89 | |
81 | 90 | es.extend( es.TableBlockModel, es.BlockModel ); |
| 91 | +es.extend( es.TableBlockModel, es.ModelContainer ); |
Index: trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js |
— | — | @@ -47,7 +47,8 @@ |
48 | 48 | * Creates a view for this model |
49 | 49 | */ |
50 | 50 | es.BlockModel.prototype.createView = function() { |
51 | | - return new es.BlockView( this ); |
| 51 | + throw 'BlockModel.createView not implemented in this subclass.'; |
| 52 | + //return new es.BlockView( this ); |
52 | 53 | }; |
53 | 54 | |
54 | 55 | /** |
Index: trunk/parsers/wikidom/lib/synth/models/es.TableBlockRowModel.js |
— | — | @@ -9,7 +9,15 @@ |
10 | 10 | * @property attributes {Object} |
11 | 11 | */ |
12 | 12 | es.TableBlockRowModel = function( cells, attributes ) { |
13 | | - this.cells = new es.ContentSeries( cells || [] ); |
| 13 | + es.ModelContainerItem.call( this, 'table' ); |
| 14 | + es.ModelContainer.call( this ); |
| 15 | + |
| 16 | + if ( $.isArray( cells ) ) { |
| 17 | + for ( var i = 0; i < cells.length; i++ ) { |
| 18 | + this.append( cells[i] ); |
| 19 | + } |
| 20 | + } |
| 21 | + |
14 | 22 | this.attributes = attributes || {}; |
15 | 23 | }; |
16 | 24 | |
— | — | @@ -35,6 +43,13 @@ |
36 | 44 | /* Methods */ |
37 | 45 | |
38 | 46 | /** |
| 47 | + * Creates a view for this model |
| 48 | + */ |
| 49 | +es.TableBlockRowModel.prototype.createView = function() { |
| 50 | + return new es.TableBlockRowView( this ); |
| 51 | +}; |
| 52 | + |
| 53 | +/** |
39 | 54 | * Gets the length of all content. |
40 | 55 | * |
41 | 56 | * @method |
— | — | @@ -51,6 +66,7 @@ |
52 | 67 | * @returns obj {Object} |
53 | 68 | */ |
54 | 69 | es.TableBlockRowModel.prototype.getPlainObject = function() { |
| 70 | + /* |
55 | 71 | var obj = {}; |
56 | 72 | if ( this.cells.length ) { |
57 | 73 | obj.cells = $.map( this.cells, function( cell ) { |
— | — | @@ -61,4 +77,10 @@ |
62 | 78 | obj.attributes = $.extend( true, {}, this.attributes ); |
63 | 79 | } |
64 | 80 | return obj; |
| 81 | + */ |
65 | 82 | }; |
| 83 | + |
| 84 | +/* Inheritance */ |
| 85 | + |
| 86 | +es.extend( es.TableBlockRowModel, es.ModelContainerItem ); |
| 87 | +es.extend( es.TableBlockRowModel, es.ModelContainer ); |
\ No newline at end of file |
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js |
— | — | @@ -0,0 +1,25 @@ |
| 2 | +/** |
| 3 | + * Creates an es.ParagraphBlockView object. |
| 4 | + */ |
| 5 | +es.TableBlockRowView = function( model ) { |
| 6 | + es.ViewContainer.call( this, model, 'row', 'tr' ) |
| 7 | + es.ViewContainerItem.call( this, model, 'tr' ); |
| 8 | + |
| 9 | + var classes = this.$.attr('class'); |
| 10 | + for ( var name in this.model.attributes ) { |
| 11 | + this.$.attr( name, this.model.attributes[name] ); |
| 12 | + } |
| 13 | + this.$.addClass(classes); |
| 14 | +}; |
| 15 | + |
| 16 | +/** |
| 17 | + * Render content. |
| 18 | + */ |
| 19 | +es.TableBlockRowView.prototype.renderContent = function() { |
| 20 | + for ( var i = 0; i < this.views.length; i++ ) { |
| 21 | + this.views[i].renderContent(); |
| 22 | + } |
| 23 | +}; |
| 24 | + |
| 25 | +es.extend( es.TableBlockRowView, es.ViewContainer ); |
| 26 | +es.extend( es.TableBlockRowView, es.ViewContainerItem ); |
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js |
— | — | @@ -0,0 +1,25 @@ |
| 2 | +/** |
| 3 | + * Creates an es.ParagraphBlockView object. |
| 4 | + */ |
| 5 | +es.TableBlockCellView = function( model ) { |
| 6 | + es.ViewContainerItem.call( this, model, 'cell', 'td' ); |
| 7 | + |
| 8 | + this.documentView = new es.DocumentView( this.model.documentModel ); |
| 9 | + this.$.append( this.documentView.$ ); |
| 10 | + |
| 11 | + var classes = this.$.attr('class'); |
| 12 | + for ( var name in this.model.attributes ) { |
| 13 | + this.$.attr( name, this.model.attributes[name] ); |
| 14 | + } |
| 15 | + this.$.addClass(classes); |
| 16 | +}; |
| 17 | + |
| 18 | +/** |
| 19 | + * Render content. |
| 20 | + */ |
| 21 | +es.TableBlockCellView.prototype.renderContent = function() { |
| 22 | + //debugger; |
| 23 | + this.documentView.renderContent(); |
| 24 | +}; |
| 25 | + |
| 26 | +es.extend( es.TableBlockCellView, es.ViewContainerItem ); |
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js |
— | — | @@ -0,0 +1,25 @@ |
| 2 | +/** |
| 3 | + * Creates an es.ParagraphBlockView object. |
| 4 | + */ |
| 5 | +es.TableBlockView = function( model ) { |
| 6 | + es.ViewContainer.call( this, model, 'table', 'table' ); |
| 7 | + es.BlockView.call( this, model, 'table', 'table' ); |
| 8 | + |
| 9 | + var classes = this.$.attr('class'); |
| 10 | + for ( var name in this.model.attributes ) { |
| 11 | + this.$.attr( name, this.model.attributes[name] ); |
| 12 | + } |
| 13 | + this.$.addClass(classes); |
| 14 | +}; |
| 15 | + |
| 16 | +/** |
| 17 | + * Render content. |
| 18 | + */ |
| 19 | +es.TableBlockView.prototype.renderContent = function() { |
| 20 | + for ( var i = 0; i < this.views.length; i++ ) { |
| 21 | + this.views[i].renderContent(); |
| 22 | + } |
| 23 | +}; |
| 24 | + |
| 25 | +es.extend( es.TableBlockView, es.ViewContainer ); |
| 26 | +es.extend( es.TableBlockView, es.BlockView ); |
Index: trunk/parsers/wikidom/demos/synth/index.html |
— | — | @@ -63,6 +63,7 @@ |
64 | 64 | <script src="../../lib/synth/bases/es.ModelContainerItem.js"></script> |
65 | 65 | <script src="../../lib/synth/bases/es.ViewContainer.js"></script> |
66 | 66 | <script src="../../lib/synth/bases/es.ViewContainerItem.js"></script> |
| 67 | + |
67 | 68 | <script src="../../lib/synth/models/es.SurfaceModel.js"></script> |
68 | 69 | <script src="../../lib/synth/models/es.DocumentModel.js"></script> |
69 | 70 | <script src="../../lib/synth/models/es.BlockModel.js"></script> |
— | — | @@ -70,6 +71,10 @@ |
71 | 72 | <script src="../../lib/synth/models/es.ListBlockItemModel.js"></script> |
72 | 73 | <script src="../../lib/synth/models/es.ListBlockModel.js"></script> |
73 | 74 | <script src="../../lib/synth/models/es.ParagraphBlockModel.js"></script> |
| 75 | + <script src="../../lib/synth/models/es.TableBlockModel.js"></script> |
| 76 | + <script src="../../lib/synth/models/es.TableBlockRowModel.js"></script> |
| 77 | + <script src="../../lib/synth/models/es.TableBlockCellModel.js"></script> |
| 78 | + |
74 | 79 | <script src="../../lib/synth/views/es.BlockView.js"></script> |
75 | 80 | <script src="../../lib/synth/views/es.ContentView.js"></script> |
76 | 81 | <script src="../../lib/synth/views/es.DocumentView.js"></script> |
— | — | @@ -77,6 +82,9 @@ |
78 | 83 | <script src="../../lib/synth/views/es.ListBlockView.js"></script> |
79 | 84 | <script src="../../lib/synth/views/es.ParagraphBlockView.js"></script> |
80 | 85 | <script src="../../lib/synth/views/es.SurfaceView.js"></script> |
| 86 | + <script src="../../lib/synth/views/es.TableBlockView.js"></script> |
| 87 | + <script src="../../lib/synth/views/es.TableBlockRowView.js"></script> |
| 88 | + <script src="../../lib/synth/views/es.TableBlockCellView.js"></script> |
81 | 89 | |
82 | 90 | <!-- Demo --> |
83 | 91 | <script src="es.js"></script> |