Commit d2965f7e authored by Amanda Ghassaei's avatar Amanda Ghassaei

events timing

parent 3bc775d1
......@@ -32,8 +32,21 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
this._checkURL();
this.listenTo(this, "change:partType", this._updatePartType);
this.listenTo(this, "change:cellType change:connectionType change:latticeType", function(){
this._updateLatticeConfig();//pass no params
this.listenTo(this, "change:cellType", function(){
this._cellTypeChanged();
this._reloadCells();
});
this.listenTo(this, "change:connectionType", function(){
this._connectionTypeChanged();
this._reloadCells();
});
this.listenTo(this, "change:latticeType", function(){
this._latticeTypeChanged();
this._reloadCells();
});
this.listenTo(this, "change:aspectRatio", function(){
this._reloadCells();
});
this.listenTo(appState, "change:currentNav", this._navChanged);
......@@ -41,7 +54,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
this.updateThreeViewTarget();
});
this._updateLatticeConfig();
this._latticeTypeChanged();
this._reloadCells();
},
_checkURL: function(){
......@@ -57,25 +71,22 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
//latticeType
_setToDefaultsSilently: function(){
var newCellType = this.get("cellType");
var newConnectionType = this.get("connectionType");
var newLatticeType = this.get("latticeType");
if (this.previous("cellType") !== undefined && newCellType != this.previous("cellType")){
newConnectionType = _.keys(plist.allLattices[newCellType].connection)[0];
this.set("connectionType", newConnectionType, {silent:true});
}
if (this.previous("connectionType") !== undefined && newConnectionType != this.previous("connectionType")){
newLatticeType = _.keys(plist.allLattices[newCellType].connection[newConnectionType].type)[0];
this.set("latticeType", newLatticeType, {silent:true});
}
_cellTypeChanged: function(){
var cellType = this.get("cellType");
var connectionType = _.keys(plist.allLattices[cellType].connection)[0];
this.set("connectionType", connectionType, {silent:true});
this._connectionTypeChanged();
},
this._updateLatticeType();
_connectionTypeChanged: function(){
var cellType = this.get("cellType");
var connectionType = this.get("connectionType");
var latticeType = _.keys(plist.allLattices[cellType].connection[connectionType].type)[0];
this.set("latticeType", latticeType, {silent:true});
this._latticeTypeChanged();
},
_updateLatticeType: function(){
_latticeTypeChanged: function(){
var latticeData = this._getLatticePlistData();
this.set("aspectRatio", latticeData.aspectRatio.clone(), {silent:true});
......@@ -254,7 +265,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
self.compositeEditor = new CompositeEditorLattice(_.extend({id:id}, _.omit(data, "sparseCells")), null, function(_self){
var cells = null;
if (data) cells = data.sparseCells;
_self._updateLatticeConfig(cells, self._getSubclassForLatticeType());
_self._reloadCells(cells, self._getSubclassForLatticeType());
appState.set("currentNav", "navComposite");
});
......
......@@ -45,12 +45,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
return plist.allLattices[this.get("cellType")].connection[this.get("connectionType")].type[this.get("latticeType")];
},
_updateLatticeConfig: function(cells, subclass){//do not clear cells if loading from file (cells array contains important metadata)
_reloadCells: function(cells, subclass){
if (!cells) {
if (this._setToDefaultsSilently) this._setToDefaultsSilently();
cells = JSON.parse(JSON.stringify(this.sparseCells));
}
if (!cells) cells = JSON.parse(JSON.stringify(this.sparseCells));
if (this._setDefaultCellMode) this._setDefaultCellMode();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment