r96939 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96938‎ | r96939 | r96940 >
Date:02:31, 13 September 2011
Author:inez
Status:deferred
Tags:
Comment:
Added support for tables in synth demo
Modified paths:
  • /trunk/parsers/wikidom/demos/synth/index.html (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.TableBlockCellModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.TableBlockModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.TableBlockRowModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js (added) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js (added) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js (added) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/synth/models/es.TableBlockCellModel.js
@@ -9,6 +9,7 @@
1010 * @property attributes {Object}
1111 */
1212 es.TableBlockCellModel = function( documentModel, attributes ) {
 13+ es.ModelContainerItem.call( this, 'row' );
1314 this.documentModel = documentModel || null;
1415 this.attributes = attributes || {};
1516 };
@@ -21,9 +22,9 @@
2223 * @param obj {Object}
2324 */
2425 es.TableBlockCellModel.newFromPlainObject = function( obj ) {
25 - return new es.TableBlockRowModel(
 26+ return new es.TableBlockCellModel(
2627 // 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 ),
2829 // Attributes - if given, make a deep copy of attributes
2930 !$.isPlainObject( obj.attributes ) ? {} : $.extend( true, {}, obj.attributes )
3031 );
@@ -32,12 +33,19 @@
3334 /* Methods */
3435
3536 /**
 37+ * Creates a view for this model
 38+ */
 39+es.TableBlockCellModel.prototype.createView = function() {
 40+ return new es.TableBlockCellView( this );
 41+};
 42+
 43+/**
3644 * Gets the length of all content.
3745 *
3846 * @method
3947 * @returns {Integer} Length of all content
4048 */
41 -es.TableBlockRowModel.prototype.getContentLength = function() {
 49+es.TableBlockCellModel.prototype.getContentLength = function() {
4250 return this.cells.getContentLength();
4351 };
4452
@@ -47,7 +55,8 @@
4856 * @method
4957 * @returns obj {Object}
5058 */
51 -es.TableBlockRowModel.prototype.getPlainObject = function() {
 59+es.TableBlockCellModel.prototype.getPlainObject = function() {
 60+ /*
5261 var obj = {};
5362 if ( this.documentModel ) {
5463 obj.document = this.documentModel;
@@ -56,4 +65,9 @@
5766 obj.attributes = $.extend( true, {}, this.attributes );
5867 }
5968 return obj;
 69+ */
6070 };
 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 @@
1111 */
1212 es.TableBlockModel = function( rows, attributes ) {
1313 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+
1522 this.attributes = attributes || {};
1623 };
1724
@@ -60,6 +67,7 @@
6168 * @returns obj {Object}
6269 */
6370 es.TableBlockModel.prototype.getPlainObject = function() {
 71+ /*
6472 var obj = { 'type': 'table' };
6573 if ( this.rows.length ) {
6674 obj.rows = $.map( this.rows, function( row ) {
@@ -70,11 +78,13 @@
7179 obj.attributes = $.extend( true, {}, this.attributes );
7280 }
7381 return obj;
 82+ */
7483 };
7584
7685 // Register constructor
77 -es.BlockModel.constructors['table'] = es.TableBlockModel;
 86+es.BlockModel.constructors['table'] = es.TableBlockModel.newFromPlainObject;
7887
7988 /* Inheritance */
8089
8190 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 @@
4848 * Creates a view for this model
4949 */
5050 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 );
5253 };
5354
5455 /**
Index: trunk/parsers/wikidom/lib/synth/models/es.TableBlockRowModel.js
@@ -9,7 +9,15 @@
1010 * @property attributes {Object}
1111 */
1212 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+
1422 this.attributes = attributes || {};
1523 };
1624
@@ -35,6 +43,13 @@
3644 /* Methods */
3745
3846 /**
 47+ * Creates a view for this model
 48+ */
 49+es.TableBlockRowModel.prototype.createView = function() {
 50+ return new es.TableBlockRowView( this );
 51+};
 52+
 53+/**
3954 * Gets the length of all content.
4055 *
4156 * @method
@@ -51,6 +66,7 @@
5267 * @returns obj {Object}
5368 */
5469 es.TableBlockRowModel.prototype.getPlainObject = function() {
 70+ /*
5571 var obj = {};
5672 if ( this.cells.length ) {
5773 obj.cells = $.map( this.cells, function( cell ) {
@@ -61,4 +77,10 @@
6278 obj.attributes = $.extend( true, {}, this.attributes );
6379 }
6480 return obj;
 81+ */
6582 };
 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 @@
6464 <script src="../../lib/synth/bases/es.ModelContainerItem.js"></script>
6565 <script src="../../lib/synth/bases/es.ViewContainer.js"></script>
6666 <script src="../../lib/synth/bases/es.ViewContainerItem.js"></script>
 67+
6768 <script src="../../lib/synth/models/es.SurfaceModel.js"></script>
6869 <script src="../../lib/synth/models/es.DocumentModel.js"></script>
6970 <script src="../../lib/synth/models/es.BlockModel.js"></script>
@@ -70,6 +71,10 @@
7172 <script src="../../lib/synth/models/es.ListBlockItemModel.js"></script>
7273 <script src="../../lib/synth/models/es.ListBlockModel.js"></script>
7374 <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+
7479 <script src="../../lib/synth/views/es.BlockView.js"></script>
7580 <script src="../../lib/synth/views/es.ContentView.js"></script>
7681 <script src="../../lib/synth/views/es.DocumentView.js"></script>
@@ -77,6 +82,9 @@
7883 <script src="../../lib/synth/views/es.ListBlockView.js"></script>
7984 <script src="../../lib/synth/views/es.ParagraphBlockView.js"></script>
8085 <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>
8189
8290 <!-- Demo -->
8391 <script src="es.js"></script>

Status & tagging log