rowModel.js
1000 Bytes
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
/**
* Model that holds our row information
*
* @package Ninja Forms Layouts
* @subpackage Fields
* @copyright (c) 2016 WP Ninjas
* @since 3.0
*/
define( ['models/cellCollection'], function( CellCollection ) {
var model = Backbone.Model.extend( {
initialize: function( models, options ) {
this.options = options;
this.set( 'cells', new CellCollection( this.get( 'cells' ), { rowModel: this } ) );
this.on( 'change:cells', this.checkEmptyCells, this );
this.set( 'order', Number( this.get( 'order' ) ) );
},
checkEmptyCells: function( model ) {
/*
* Check to see if all our cells are empty. If they are, self destruct.
*/
var remove = true;
_.each( this.get( 'cells' ).models, function( cell ) {
if ( 0 != cell.get( 'fields' ).length ) {
remove = false;
}
} );
if ( remove && 'undefined' != typeof this.collection ) {
this.collection.remove( this );
return false;
}
return true;
}
} );
return model;
} );