diff --git a/core/fse--class.js b/core/fse--class.js index 86e2bbd6..2cf5b648 100644 --- a/core/fse--class.js +++ b/core/fse--class.js @@ -40,13 +40,7 @@ function FullScreenEditor(options) { this.editorMode = 'edit'; // view | edit | editMenu | - // :TODO: viewControllers management should be a mixin that can be thrown in here, menu_module.js, etc. - this.viewControllers = {}; - this.addViewController = function(name, vc) { - assert(!self.viewControllers[name]); - self.viewControllers[name] = vc; - return vc; - } + this.initViewControllers(); this.getFooterName = function(editorMode) { editorMode = editorMode || this.editorMode; @@ -133,8 +127,9 @@ function FullScreenEditor(options) { }, function displayFooter(callback) { // we have to treat the footer special - self.redrawFooter( { clear : false, footerName : self.getFooterName() }, function footerDisplayed(err) { - if(self.initMci) { + var footerName = self.getFooterName(); + self.redrawFooter( { clear : false, footerName : footerName }, function footerDisplayed(err, artData) { + if(options.initMci) { self.mciData[footerName] = artData; } callback(err); @@ -271,6 +266,7 @@ function FullScreenEditor(options) { } require('util').inherits(FullScreenEditor, events.EventEmitter); +require('./mod_mixins.js').ViewControllerManagement.call(FullScreenEditor.prototype); FullScreenEditor.prototype.enter = function() { diff --git a/core/menu_module.js b/core/menu_module.js index b9511991..0dd98e73 100644 --- a/core/menu_module.js +++ b/core/menu_module.js @@ -24,7 +24,8 @@ function MenuModule(options) { this.menuConfig = options.menuConfig; this.menuConfig.options = options.menuConfig.options || {}; this.menuMethods = {}; // methods called from @method's - this.viewControllers = {}; // name->vc + + this.initViewControllers(); this.initSequence = function() { var mciData = { }; @@ -142,6 +143,8 @@ function MenuModule(options) { require('util').inherits(MenuModule, PluginModule); +require('./mod_mixins.js').ViewControllerManagement.call(MenuModule.prototype); + MenuModule.prototype.enter = function(client) { this.client = client; assert(_.isObject(client)); @@ -150,16 +153,7 @@ MenuModule.prototype.enter = function(client) { }; MenuModule.prototype.leave = function() { - var self = this; - Object.keys(this.viewControllers).forEach(function entry(name) { - self.viewControllers[name].detachClientEvents(); - }); -}; - -MenuModule.prototype.addViewController = function(name, vc) { - assert(!this.viewControllers[name]); - this.viewControllers[name] = vc; - return vc; + this.detachViewControllers(); }; MenuModule.prototype.beforeArt = function() { diff --git a/core/mod_mixins.js b/core/mod_mixins.js new file mode 100644 index 00000000..f035b6f1 --- /dev/null +++ b/core/mod_mixins.js @@ -0,0 +1,30 @@ +/* jslint node: true */ +'use strict'; + +var assert = require('assert'); + +// +// A simple mixin for View Controller management +// +var ViewControllerManagement = function() { + this.initViewControllers = function() { + this.viewControllers = {}; + }; + + this.detachViewControllers = function() { + var self = this; + Object.keys(this.viewControllers).forEach(function vc(name) { + self.viewControllers[name].detachClientEvents(); + }); + }; + + this.addViewController = function(name, vc) { + assert(this.viewControllers, 'initViewControllers() has not been called!'); + assert(!this.viewControllers[name], 'ViewController by the name of \'' + name + '\' already exists!'); + + this.viewControllers[name] = vc; + return vc; + }; +}; + +exports.ViewControllerManagement = ViewControllerManagement; \ No newline at end of file