2015-08-12 23:26:05 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-08-04 01:48:45 +00:00
|
|
|
const messageArea = require('../core/message_area.js');
|
|
|
|
|
|
|
|
// deps
|
|
|
|
const assert = require('assert');
|
2015-08-12 23:26:05 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// A simple mixin for View Controller management
|
|
|
|
//
|
2016-08-04 01:48:45 +00:00
|
|
|
exports.ViewControllerManagement = function() {
|
2015-08-12 23:26:05 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-08-04 01:48:45 +00:00
|
|
|
exports.MessageAreaConfTempSwitcher = function() {
|
|
|
|
|
|
|
|
this.tempMessageConfAndAreaSwitch = function(messageAreaTag) {
|
|
|
|
messageAreaTag = messageAreaTag || this.messageAreaTag;
|
|
|
|
if(!messageAreaTag) {
|
|
|
|
return; // nothing to do!
|
|
|
|
}
|
|
|
|
this.prevMessageConfAndArea = {
|
|
|
|
confTag : this.client.user.properties.message_conf_tag,
|
|
|
|
areaTag : this.client.user.properties.message_area_tag,
|
|
|
|
};
|
|
|
|
if(!messageArea.tempChangeMessageConfAndArea(this.client, this.messageAreaTag)) {
|
|
|
|
this.client.log.warn( { messageAreaTag : messageArea }, 'Failed to perform temporary message area/conf switch');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.tempMessageConfAndAreaRestore = function() {
|
|
|
|
if(this.prevMessageConfAndArea) {
|
|
|
|
this.client.user.properties.message_conf_tag = this.prevMessageConfAndArea.confTag;
|
|
|
|
this.client.user.properties.message_area_tag = this.prevMessageConfAndArea.areaTag;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|