2015-08-14 20:49:06 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var FullScreenEditorModule = require('../core/fse.js').FullScreenEditorModule;
|
2015-08-16 19:35:34 +00:00
|
|
|
var Message = require('../core/message.js').Message;
|
2015-08-20 04:10:18 +00:00
|
|
|
var user = require('../core/user.js');
|
2015-08-16 19:35:34 +00:00
|
|
|
|
|
|
|
var _ = require('lodash');
|
2015-08-20 04:10:18 +00:00
|
|
|
var async = require('async');
|
2015-08-14 20:49:06 +00:00
|
|
|
|
|
|
|
exports.getModule = AreaPostFSEModule;
|
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'Message Area Post',
|
2015-09-01 05:18:46 +00:00
|
|
|
desc : 'Module for posting a new message to an area',
|
2015-08-14 20:49:06 +00:00
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
|
|
|
function AreaPostFSEModule(options) {
|
|
|
|
FullScreenEditorModule.call(this, options);
|
|
|
|
|
2015-08-16 19:35:34 +00:00
|
|
|
var self = this;
|
|
|
|
|
2015-08-14 20:49:06 +00:00
|
|
|
// we're posting, so always start with 'edit' mode
|
|
|
|
this.editorMode = 'edit';
|
|
|
|
|
2015-08-16 19:35:34 +00:00
|
|
|
this.menuMethods.editModeMenuSave = function(formData, extraArgs) {
|
2015-08-20 04:10:18 +00:00
|
|
|
|
2015-09-21 01:10:09 +00:00
|
|
|
var msg;
|
2015-08-20 04:10:18 +00:00
|
|
|
async.series(
|
|
|
|
[
|
2015-09-21 01:10:09 +00:00
|
|
|
function getMessageObject(callback) {
|
|
|
|
self.getMessage(function gotMsg(err, msgObj) {
|
|
|
|
msg = msgObj;
|
|
|
|
callback(err);
|
|
|
|
});
|
2015-08-20 04:10:18 +00:00
|
|
|
},
|
|
|
|
function saveMessage(callback) {
|
|
|
|
msg.persist(function persisted(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
if(err) {
|
|
|
|
// :TODO:... sooooo now what?
|
|
|
|
} else {
|
|
|
|
console.log(msg);
|
|
|
|
}
|
|
|
|
|
2015-09-24 05:55:13 +00:00
|
|
|
self.client.fallbackMenuModule( { }, function result(err) {
|
|
|
|
// :TODO: how to best handle this??? fallbackMenuModule should prob inspect options & cb to be optional. gotoMenuModule() already has default cb
|
|
|
|
});
|
2015-09-20 07:29:07 +00:00
|
|
|
//self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
|
2015-08-20 04:10:18 +00:00
|
|
|
}
|
|
|
|
);
|
2015-08-16 19:35:34 +00:00
|
|
|
};
|
2015-08-14 20:49:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require('util').inherits(AreaPostFSEModule, FullScreenEditorModule);
|
|
|
|
|
2015-08-18 03:45:11 +00:00
|
|
|
AreaPostFSEModule.prototype.enter = function(client) {
|
|
|
|
|
2015-08-20 23:00:35 +00:00
|
|
|
if(_.isString(client.user.properties.message_area_name)) {
|
|
|
|
this.messageAreaName = client.user.properties.message_area_name;
|
|
|
|
}
|
|
|
|
|
2015-08-18 03:45:11 +00:00
|
|
|
AreaPostFSEModule.super_.prototype.enter.call(this, client);
|
2015-08-20 04:10:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AreaPostFSEModule.prototype.validateToUserName = function(un, cb) {
|
|
|
|
var self = this;
|
|
|
|
|
2015-09-20 04:55:09 +00:00
|
|
|
if(!un) {
|
|
|
|
cb(new Error('Username must be supplied!'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-20 04:10:18 +00:00
|
|
|
if(!self.isLocalEmail()) {
|
|
|
|
cb(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
user.getUserIdAndName(un, function uidAndName(err, userId, userName) {
|
|
|
|
self.toUserId = userId;
|
|
|
|
cb(err);
|
|
|
|
});
|
2015-08-18 03:45:11 +00:00
|
|
|
};
|