Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Navigator and move there components status update
- Loading branch information
Showing
4 changed files
with
52 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,54 @@ | ||
function Navigator(collection, c) { | ||
var config = c, | ||
defaults = require('./config/config'), | ||
ItemsView = require('./view/ItemsView'); | ||
|
||
// Set default options | ||
for (var name in defaults) { | ||
if (!(name in config)) | ||
config[name] = defaults[name]; | ||
} | ||
module.exports = () => { | ||
let itemsView; | ||
let config = {}; | ||
const defaults = require('./config/config'); | ||
const ItemsView = require('./view/ItemsView'); | ||
|
||
return { | ||
init(collection, opts) { | ||
config = opts || config; | ||
const em = config.em; | ||
|
||
// Set default options | ||
for (var name in defaults) { | ||
if (!(name in config)) | ||
config[name] = defaults[name]; | ||
} | ||
|
||
itemsView = new ItemsView({ | ||
collection, | ||
config, | ||
opened: opts.opened || {} | ||
}); | ||
em && em.on('change:selectedComponent', this.componentChanged); | ||
this.componentChanged(); | ||
|
||
return this; | ||
}, | ||
|
||
/** | ||
* Triggered when the selected component is changed | ||
* @private | ||
*/ | ||
componentChanged() { | ||
const em = config.em; | ||
const opened = em.get('opened'); | ||
const model = em.get('selectedComponent'); | ||
let parent = model && model.collection ? model.collection.parent : null; | ||
|
||
var obj = { | ||
collection, | ||
config, | ||
opened: c.opened || {} | ||
}; | ||
for (let cid in opened) { | ||
opened[cid].set('open', 0); | ||
} | ||
|
||
this.ItemsView = new ItemsView(obj); | ||
} | ||
while (parent) { | ||
parent.set('open', 1); | ||
opened[parent.cid] = parent; | ||
parent = parent.collection ? parent.collection.parent : null; | ||
} | ||
}, | ||
|
||
Navigator.prototype = { | ||
render() { | ||
return this.ItemsView.render().$el; | ||
return itemsView.render().$el; | ||
}, | ||
} | ||
}; | ||
|
||
module.exports = Navigator; |