* Use mixin class for ViewController management
This commit is contained in:
parent
bfdc58b90c
commit
40e1e1bea8
|
@ -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() {
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue