2014-03-16 14:17:43 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/* globals define, socket, app, config, ajaxify, utils, translator, templates, bootbox */
|
|
|
|
|
|
2014-06-20 14:51:01 -04:00
|
|
|
var dependencies = [
|
|
|
|
|
'taskbar',
|
|
|
|
|
'composer/controls',
|
|
|
|
|
'composer/uploads',
|
|
|
|
|
'composer/formatting',
|
|
|
|
|
'composer/drafts',
|
|
|
|
|
'composer/tags',
|
2014-06-25 17:50:06 -04:00
|
|
|
'composer/preview',
|
|
|
|
|
'composer/resize'
|
2014-06-20 14:51:01 -04:00
|
|
|
];
|
|
|
|
|
|
2014-06-25 17:50:06 -04:00
|
|
|
define('composer', dependencies, function(taskbar, controls, uploads, formatting, drafts, tags, preview, resize) {
|
2013-06-03 16:06:11 -04:00
|
|
|
var composer = {
|
2013-09-17 13:37:03 -04:00
|
|
|
active: undefined,
|
2014-06-10 15:32:08 -04:00
|
|
|
posts: {},
|
|
|
|
|
bsEnvironment: undefined
|
2014-05-18 15:09:54 -04:00
|
|
|
};
|
2014-04-30 14:22:51 -04:00
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
socket.on('event:composer.ping', function(post_uuid) {
|
|
|
|
|
if (composer.active === post_uuid) {
|
|
|
|
|
socket.emit('modules.composer.pingActive', post_uuid);
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-03-16 14:17:43 -04:00
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
$(window).off('resize', onWindowResize).on('resize', onWindowResize);
|
2014-03-01 15:46:13 -05:00
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
function onWindowResize() {
|
|
|
|
|
if (composer.active !== undefined) {
|
2014-06-25 17:50:06 -04:00
|
|
|
resize.reposition($('#cmp-uuid-' + composer.active));
|
2014-02-26 21:55:29 -05:00
|
|
|
}
|
2014-02-20 02:05:49 -05:00
|
|
|
}
|
|
|
|
|
|
2014-03-12 14:08:55 -04:00
|
|
|
function alreadyOpen(post) {
|
|
|
|
|
// If a composer for the same cid/tid/pid is already open, return the uuid, else return bool false
|
|
|
|
|
var type, id;
|
|
|
|
|
|
|
|
|
|
if (post.hasOwnProperty('cid')) {
|
|
|
|
|
type = 'cid';
|
|
|
|
|
} else if (post.hasOwnProperty('tid')) {
|
|
|
|
|
type = 'tid';
|
|
|
|
|
} else if (post.hasOwnProperty('pid')) {
|
|
|
|
|
type = 'pid';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id = post[type];
|
|
|
|
|
|
|
|
|
|
// Find a match
|
2014-03-16 14:17:43 -04:00
|
|
|
for(var uuid in composer.posts) {
|
2014-03-12 14:08:55 -04:00
|
|
|
if (composer.posts[uuid].hasOwnProperty(type) && id === composer.posts[uuid][type]) {
|
|
|
|
|
return uuid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// No matches...
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 02:05:49 -05:00
|
|
|
function push(post) {
|
2014-03-12 14:08:55 -04:00
|
|
|
var uuid = utils.generateUUID(),
|
|
|
|
|
existingUUID = alreadyOpen(post);
|
|
|
|
|
|
|
|
|
|
if (existingUUID) {
|
|
|
|
|
taskbar.updateActive(existingUUID);
|
|
|
|
|
return composer.load(existingUUID);
|
|
|
|
|
}
|
2014-02-20 02:05:49 -05:00
|
|
|
|
|
|
|
|
translator.translate('[[topic:composer.new_topic]]', function(newTopicStr) {
|
|
|
|
|
taskbar.push('composer', uuid, {
|
2014-06-13 13:57:38 -04:00
|
|
|
title: post.title ? post.title : newTopicStr
|
2014-02-20 02:05:49 -05:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2014-03-12 14:08:55 -04:00
|
|
|
// Construct a save_id
|
|
|
|
|
if (0 !== parseInt(app.uid, 10)) {
|
|
|
|
|
if (post.hasOwnProperty('cid')) {
|
|
|
|
|
post.save_id = ['composer', app.uid, 'cid', post.cid].join(':');
|
|
|
|
|
} else if (post.hasOwnProperty('tid')) {
|
|
|
|
|
post.save_id = ['composer', app.uid, 'tid', post.tid].join(':');
|
|
|
|
|
} else if (post.hasOwnProperty('pid')) {
|
|
|
|
|
post.save_id = ['composer', app.uid, 'pid', post.pid].join(':');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 02:05:49 -05:00
|
|
|
composer.posts[uuid] = post;
|
|
|
|
|
|
|
|
|
|
composer.load(uuid);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 14:12:46 -04:00
|
|
|
function composerAlert(message) {
|
2014-02-20 02:05:49 -05:00
|
|
|
$('.action-bar button').removeAttr('disabled');
|
|
|
|
|
app.alert({
|
|
|
|
|
type: 'danger',
|
2014-04-09 14:12:46 -04:00
|
|
|
timeout: 3000,
|
|
|
|
|
title: '',
|
2014-02-20 02:05:49 -05:00
|
|
|
message: message,
|
|
|
|
|
alert_id: 'post_error'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 14:14:48 -04:00
|
|
|
composer.addButton = function(iconClass, onClick) {
|
2014-05-18 15:09:54 -04:00
|
|
|
formatting.addButton(iconClass, onClick);
|
2014-04-30 14:14:48 -04:00
|
|
|
};
|
2014-04-19 15:13:57 +01:00
|
|
|
|
2013-12-22 15:15:59 -05:00
|
|
|
composer.newTopic = function(cid) {
|
2014-04-10 22:31:55 +01:00
|
|
|
push({
|
|
|
|
|
cid: cid,
|
|
|
|
|
title: '',
|
|
|
|
|
body: '',
|
|
|
|
|
modified: false,
|
|
|
|
|
isMain: true
|
|
|
|
|
});
|
2014-02-20 02:05:49 -05:00
|
|
|
};
|
2013-07-21 12:29:57 -04:00
|
|
|
|
2014-01-27 13:04:03 -05:00
|
|
|
composer.addQuote = function(tid, pid, title, username, text){
|
2014-04-10 22:31:55 +01:00
|
|
|
var uuid = composer.active;
|
|
|
|
|
|
2014-06-25 17:50:06 -04:00
|
|
|
if (uuid === undefined) {
|
2014-06-23 18:47:52 -04:00
|
|
|
composer.newReply(tid, pid, title, '[[modules:composer.user_said, ' + username + ']]' + text);
|
2014-04-10 22:31:55 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2014-06-29 16:47:11 -04:00
|
|
|
var postContainer = $('#cmp-uuid-' + uuid);
|
|
|
|
|
var bodyEl = postContainer.find('textarea');
|
2014-04-10 22:31:55 +01:00
|
|
|
var prevText = bodyEl.val();
|
|
|
|
|
if(tid !== composer.posts[uuid].tid) {
|
2014-05-20 12:35:46 -04:00
|
|
|
var link = '[' + title + '](/topic/' + tid + '#' + pid + ')';
|
|
|
|
|
translator.translate('[[modules:composer.user_said_in, ' + username + ', ' + link + ']]', onTranslated);
|
2014-04-10 22:31:55 +01:00
|
|
|
} else {
|
2014-05-20 12:35:46 -04:00
|
|
|
translator.translate('[[modules:composer.user_said, ' + username + ']]', onTranslated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onTranslated(translated) {
|
|
|
|
|
composer.posts[uuid].body = (prevText.length ? prevText + '\n\n' : '') + translated + text;
|
|
|
|
|
bodyEl.val(composer.posts[uuid].body);
|
2014-06-29 16:47:11 -04:00
|
|
|
focusElements(postContainer);
|
|
|
|
|
preview.render(postContainer);
|
2014-01-27 02:51:49 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-02-22 17:56:13 -05:00
|
|
|
composer.newReply = function(tid, pid, title, text) {
|
2014-06-23 18:47:52 -04:00
|
|
|
translator.translate(text, function(translated) {
|
|
|
|
|
push({
|
|
|
|
|
tid: tid,
|
|
|
|
|
toPid: pid,
|
|
|
|
|
title: title,
|
|
|
|
|
body: translated,
|
|
|
|
|
modified: false,
|
|
|
|
|
isMain: false
|
|
|
|
|
});
|
2014-04-10 22:31:55 +01:00
|
|
|
});
|
2014-02-20 02:05:49 -05:00
|
|
|
};
|
2013-12-22 15:15:59 -05:00
|
|
|
|
|
|
|
|
composer.editPost = function(pid) {
|
2014-04-10 22:31:55 +01:00
|
|
|
socket.emit('modules.composer.push', pid, function(err, threadData) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
push({
|
|
|
|
|
pid: pid,
|
2014-06-14 13:55:06 -04:00
|
|
|
title: $('<div/>').html(threadData.title).text(),
|
2014-04-10 22:31:55 +01:00
|
|
|
body: threadData.body,
|
|
|
|
|
modified: false,
|
2014-06-13 15:33:22 -04:00
|
|
|
isMain: threadData.isMain,
|
2014-05-21 16:13:46 -04:00
|
|
|
topic_thumb: threadData.topic_thumb,
|
|
|
|
|
tags: threadData.tags
|
2014-04-10 22:31:55 +01:00
|
|
|
});
|
|
|
|
|
});
|
2014-02-20 02:05:49 -05:00
|
|
|
};
|
2013-08-24 03:36:44 +08:00
|
|
|
|
2013-12-20 18:41:56 -05:00
|
|
|
composer.load = function(post_uuid) {
|
2014-06-25 17:50:06 -04:00
|
|
|
var postContainer = $('#cmp-uuid-' + post_uuid);
|
|
|
|
|
if (postContainer.length) {
|
|
|
|
|
activate(post_uuid);
|
|
|
|
|
resize.reposition(postContainer);
|
|
|
|
|
focusElements(postContainer);
|
2013-12-20 18:41:56 -05:00
|
|
|
} else {
|
2014-05-18 15:09:54 -04:00
|
|
|
createNewComposer(post_uuid);
|
2013-12-20 18:41:56 -05:00
|
|
|
}
|
2014-03-01 15:46:13 -05:00
|
|
|
|
2014-03-01 17:49:39 -05:00
|
|
|
var postData = composer.posts[post_uuid];
|
|
|
|
|
if (postData.tid) {
|
2014-03-01 15:46:13 -05:00
|
|
|
socket.emit('modules.composer.register', {
|
|
|
|
|
uuid: post_uuid,
|
2014-03-01 17:34:06 -05:00
|
|
|
tid: postData.tid,
|
2014-03-01 15:46:13 -05:00
|
|
|
uid: app.uid
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-02-20 02:05:49 -05:00
|
|
|
};
|
2013-07-21 12:29:57 -04:00
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
function createNewComposer(post_uuid) {
|
2014-03-28 15:35:07 -04:00
|
|
|
var allowTopicsThumbnail = config.allowTopicsThumbnail && composer.posts[post_uuid].isMain && (config.hasImageUploadPlugin || config.allowFileUploads);
|
2014-05-21 16:13:46 -04:00
|
|
|
var isTopic = composer.posts[post_uuid] ? !!composer.posts[post_uuid].cid : false;
|
|
|
|
|
var isMain = composer.posts[post_uuid] ? !!composer.posts[post_uuid].isMain : false;
|
2014-04-09 14:12:46 -04:00
|
|
|
|
2014-06-25 17:50:06 -04:00
|
|
|
composer.bsEnvironment = utils.findBootstrapEnvironment();
|
2014-06-10 15:32:08 -04:00
|
|
|
|
|
|
|
|
var template = (composer.bsEnvironment === 'xs' || composer.bsEnvironment === 'sm') ? 'composer-mobile' : 'composer';
|
2014-06-10 14:45:48 -04:00
|
|
|
|
|
|
|
|
templates.parse(template, {allowTopicsThumbnail: allowTopicsThumbnail, showTags: isTopic || isMain}, function(composerTemplate) {
|
2014-02-10 13:30:26 -05:00
|
|
|
translator.translate(composerTemplate, function(composerTemplate) {
|
|
|
|
|
composerTemplate = $(composerTemplate);
|
2013-07-21 12:29:57 -04:00
|
|
|
|
2014-02-10 13:30:26 -05:00
|
|
|
composerTemplate.attr('id', 'cmp-uuid-' + post_uuid);
|
2013-08-15 14:04:12 -04:00
|
|
|
|
2014-02-10 13:30:26 -05:00
|
|
|
$(document.body).append(composerTemplate);
|
2013-08-24 03:36:44 +08:00
|
|
|
|
2014-06-25 17:50:06 -04:00
|
|
|
var postContainer = $(composerTemplate[0]),
|
|
|
|
|
postData = composer.posts[post_uuid],
|
|
|
|
|
bodyEl = postContainer.find('textarea'),
|
|
|
|
|
draft = drafts.getDraft(postData.save_id);
|
2013-08-15 17:03:43 -04:00
|
|
|
|
2014-05-21 16:13:46 -04:00
|
|
|
tags.init(postContainer, composer.posts[post_uuid]);
|
2014-06-25 17:50:06 -04:00
|
|
|
updateTitle(postData, postContainer);
|
2014-05-21 16:13:46 -04:00
|
|
|
|
2014-06-25 17:50:06 -04:00
|
|
|
activate(post_uuid);
|
|
|
|
|
resize.reposition(postContainer);
|
2014-05-21 16:13:46 -04:00
|
|
|
|
2014-06-25 17:50:06 -04:00
|
|
|
if (config.allowFileUploads || config.hasImageUploadPlugin) {
|
2014-05-18 15:09:54 -04:00
|
|
|
uploads.initialize(post_uuid);
|
2014-02-10 13:30:26 -05:00
|
|
|
}
|
2013-08-15 16:50:00 -04:00
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
formatting.addHandler(postContainer);
|
|
|
|
|
|
|
|
|
|
if (allowTopicsThumbnail) {
|
|
|
|
|
uploads.toggleThumbEls(postContainer, composer.posts[post_uuid].topic_thumb || '');
|
2014-03-12 14:08:55 -04:00
|
|
|
}
|
2014-01-08 02:39:06 -05:00
|
|
|
|
2014-02-10 13:30:26 -05:00
|
|
|
postContainer.on('change', 'input, textarea', function() {
|
|
|
|
|
composer.posts[post_uuid].modified = true;
|
|
|
|
|
});
|
2013-07-21 12:29:57 -04:00
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
postContainer.on('click', '.action-bar button[data-action="post"]', function() {
|
|
|
|
|
$(this).attr('disabled', true);
|
|
|
|
|
post(post_uuid);
|
2014-02-20 02:05:49 -05:00
|
|
|
});
|
|
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
postContainer.on('click', '.action-bar button[data-action="discard"]', function() {
|
2014-06-23 19:15:58 -04:00
|
|
|
if (!composer.posts[post_uuid].modified) {
|
|
|
|
|
discard(post_uuid);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
translator.translate('[[modules:composer.discard]]', function(translated) {
|
|
|
|
|
bootbox.confirm(translated, function(confirm) {
|
2014-05-18 15:09:54 -04:00
|
|
|
if (confirm) {
|
|
|
|
|
discard(post_uuid);
|
2014-02-26 21:55:29 -05:00
|
|
|
}
|
2014-05-18 15:09:54 -04:00
|
|
|
});
|
2014-06-23 19:15:58 -04:00
|
|
|
});
|
2014-02-10 13:30:26 -05:00
|
|
|
});
|
2013-12-23 20:59:55 -05:00
|
|
|
|
2014-06-20 14:51:01 -04:00
|
|
|
bodyEl.on('input propertychange', function() {
|
|
|
|
|
preview.render(postContainer);
|
2014-02-10 13:30:26 -05:00
|
|
|
});
|
2014-01-17 16:16:00 -05:00
|
|
|
|
2014-06-20 19:18:13 -04:00
|
|
|
bodyEl.on('scroll', function() {
|
|
|
|
|
preview.matchScroll(postContainer);
|
2014-06-25 17:50:06 -04:00
|
|
|
});
|
2014-06-20 19:18:13 -04:00
|
|
|
|
2014-06-20 14:51:01 -04:00
|
|
|
bodyEl.val(draft ? draft : postData.body);
|
2014-06-20 19:18:13 -04:00
|
|
|
preview.render(postContainer, function() {
|
|
|
|
|
preview.matchScroll(postContainer);
|
|
|
|
|
});
|
2014-05-18 15:09:54 -04:00
|
|
|
drafts.init(postContainer, postData);
|
2014-01-31 21:27:11 -05:00
|
|
|
|
2014-06-25 17:50:06 -04:00
|
|
|
resize.handleResize(postContainer);
|
2014-02-10 17:31:51 -05:00
|
|
|
|
2014-06-24 15:49:55 -04:00
|
|
|
handleHelp(postContainer);
|
2014-02-27 14:05:31 -05:00
|
|
|
|
2014-02-10 17:31:51 -05:00
|
|
|
$(window).trigger('action:composer.loaded', {
|
|
|
|
|
post_uuid: post_uuid
|
|
|
|
|
});
|
2014-04-30 14:14:48 -04:00
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
formatting.addComposerButtons();
|
2014-06-25 17:50:06 -04:00
|
|
|
focusElements(postContainer);
|
2013-12-17 23:42:02 -05:00
|
|
|
});
|
2013-12-20 18:41:56 -05:00
|
|
|
});
|
2014-05-18 15:09:54 -04:00
|
|
|
}
|
|
|
|
|
|
2014-06-24 15:49:55 -04:00
|
|
|
function handleHelp(postContainer) {
|
|
|
|
|
var helpBtn = postContainer.find('.help');
|
|
|
|
|
socket.emit('modules.composer.renderHelp', function(err, html) {
|
|
|
|
|
if (!err && html && html.length > 0) {
|
|
|
|
|
helpBtn.removeClass('hidden');
|
|
|
|
|
helpBtn.on('click', function() {
|
|
|
|
|
bootbox.alert(html);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
function updateTitle(postData, postContainer) {
|
|
|
|
|
var titleEl = postContainer.find('.title');
|
|
|
|
|
|
|
|
|
|
if (parseInt(postData.tid, 10) > 0) {
|
|
|
|
|
translator.translate('[[topic:composer.replying_to, ' + postData.title + ']]', function(newTitle) {
|
|
|
|
|
titleEl.val(newTitle);
|
|
|
|
|
});
|
|
|
|
|
titleEl.prop('disabled', true);
|
|
|
|
|
} else if (parseInt(postData.pid, 10) > 0) {
|
|
|
|
|
titleEl.val(postData.title);
|
|
|
|
|
titleEl.prop('disabled', true);
|
|
|
|
|
socket.emit('modules.composer.editCheck', postData.pid, function(err, editCheck) {
|
|
|
|
|
if (!err && editCheck.titleEditable) {
|
|
|
|
|
titleEl.prop('disabled', false);
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-06-03 16:06:11 -04:00
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
} else {
|
|
|
|
|
titleEl.val(postData.title);
|
|
|
|
|
titleEl.prop('disabled', false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 17:50:06 -04:00
|
|
|
function activate(post_uuid) {
|
2013-12-20 18:41:56 -05:00
|
|
|
if(composer.active && composer.active !== post_uuid) {
|
|
|
|
|
composer.minimize(composer.active);
|
2013-12-18 10:03:49 -05:00
|
|
|
}
|
2013-06-04 16:20:27 -04:00
|
|
|
|
2013-07-25 13:18:55 -04:00
|
|
|
composer.active = post_uuid;
|
2014-05-21 16:13:46 -04:00
|
|
|
}
|
|
|
|
|
|
2014-06-25 17:50:06 -04:00
|
|
|
function focusElements(postContainer) {
|
|
|
|
|
var title = postContainer.find('.title'),
|
2013-12-20 18:41:56 -05:00
|
|
|
bodyEl = postContainer.find('textarea');
|
2013-12-18 23:56:59 -05:00
|
|
|
|
2014-06-25 17:50:06 -04:00
|
|
|
if (title.is(':disabled')) {
|
2014-06-29 16:47:11 -04:00
|
|
|
bodyEl.focus().putCursorAtEnd();
|
2014-06-25 17:50:06 -04:00
|
|
|
} else {
|
|
|
|
|
title.focus();
|
2013-12-18 23:56:59 -05:00
|
|
|
}
|
2014-05-18 15:09:54 -04:00
|
|
|
}
|
2014-02-20 02:05:49 -05:00
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
function post(post_uuid) {
|
2013-08-15 16:50:00 -04:00
|
|
|
var postData = composer.posts[post_uuid],
|
2013-12-20 18:41:56 -05:00
|
|
|
postContainer = $('#cmp-uuid-' + post_uuid),
|
|
|
|
|
titleEl = postContainer.find('.title'),
|
2014-02-20 02:05:49 -05:00
|
|
|
bodyEl = postContainer.find('textarea'),
|
|
|
|
|
thumbEl = postContainer.find('input#topic-thumb-url');
|
2013-08-24 03:36:44 +08:00
|
|
|
|
2013-12-20 18:41:56 -05:00
|
|
|
titleEl.val(titleEl.val().trim());
|
|
|
|
|
bodyEl.val(bodyEl.val().trim());
|
2014-06-02 17:31:09 -04:00
|
|
|
if (thumbEl.length) {
|
2014-02-22 02:01:08 -05:00
|
|
|
thumbEl.val(thumbEl.val().trim());
|
|
|
|
|
}
|
2013-08-24 03:36:44 +08:00
|
|
|
|
2014-01-22 17:23:20 -05:00
|
|
|
var checkTitle = parseInt(postData.cid, 10) || parseInt(postData.pid, 10);
|
|
|
|
|
|
2014-06-12 13:58:17 -04:00
|
|
|
if (uploads.inProgress[post_uuid] && uploads.inProgress[post_uuid].length) {
|
2014-04-09 14:12:46 -04:00
|
|
|
return composerAlert('[[error:still-uploading]]');
|
2014-01-22 17:23:20 -05:00
|
|
|
} else if (checkTitle && titleEl.val().length < parseInt(config.minimumTitleLength, 10)) {
|
2014-04-09 14:12:46 -04:00
|
|
|
return composerAlert('[[error:title-too-short, ' + config.minimumTitleLength + ']]');
|
2014-01-22 17:23:20 -05:00
|
|
|
} else if (checkTitle && titleEl.val().length > parseInt(config.maximumTitleLength, 10)) {
|
2014-04-09 14:12:46 -04:00
|
|
|
return composerAlert('[[error:title-too-long, ' + config.maximumTitleLength + ']]');
|
2014-06-02 17:31:09 -04:00
|
|
|
} else if (checkTitle && !utils.slugify(titleEl.val()).length) {
|
|
|
|
|
return composerAlert('[[error:invalid-title]]');
|
2013-12-31 14:25:26 -05:00
|
|
|
} else if (bodyEl.val().length < parseInt(config.minimumPostLength, 10)) {
|
2014-04-09 14:12:46 -04:00
|
|
|
return composerAlert('[[error:content-too-short, ' + config.minimumPostLength + ']]');
|
2013-07-17 10:45:16 -04:00
|
|
|
}
|
|
|
|
|
|
2014-01-22 17:23:20 -05:00
|
|
|
if (parseInt(postData.cid, 10) > 0) {
|
2014-01-16 15:10:37 -05:00
|
|
|
socket.emit('topics.post', {
|
2014-02-20 02:05:49 -05:00
|
|
|
title: titleEl.val(),
|
|
|
|
|
content: bodyEl.val(),
|
2014-02-22 02:01:08 -05:00
|
|
|
topic_thumb: thumbEl.val() || '',
|
2014-05-21 16:13:46 -04:00
|
|
|
category_id: postData.cid,
|
|
|
|
|
tags: tags.getTags(post_uuid)
|
2014-04-24 15:53:41 -04:00
|
|
|
}, function(err, topic) {
|
|
|
|
|
done(err);
|
|
|
|
|
if (!err) {
|
|
|
|
|
ajaxify.go('topic/' + topic.slug);
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-01-22 17:23:20 -05:00
|
|
|
} else if (parseInt(postData.tid, 10) > 0) {
|
2014-01-16 15:10:37 -05:00
|
|
|
socket.emit('posts.reply', {
|
2014-02-22 18:56:37 -05:00
|
|
|
tid: postData.tid,
|
2014-02-22 17:56:13 -05:00
|
|
|
content: bodyEl.val(),
|
|
|
|
|
toPid: postData.toPid
|
2014-01-27 20:21:14 -05:00
|
|
|
}, done);
|
2014-01-22 17:23:20 -05:00
|
|
|
} else if (parseInt(postData.pid, 10) > 0) {
|
2014-01-16 15:10:37 -05:00
|
|
|
socket.emit('posts.edit', {
|
2013-06-05 10:18:29 -04:00
|
|
|
pid: postData.pid,
|
2013-12-20 18:41:56 -05:00
|
|
|
content: bodyEl.val(),
|
2014-02-20 02:05:49 -05:00
|
|
|
title: titleEl.val(),
|
2014-05-21 16:13:46 -04:00
|
|
|
topic_thumb: thumbEl.val() || '',
|
|
|
|
|
tags: tags.getTags(post_uuid)
|
2014-01-27 20:21:14 -05:00
|
|
|
}, done);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function done(err) {
|
|
|
|
|
$('.action-bar button').removeAttr('disabled');
|
2014-04-09 14:12:46 -04:00
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
2014-01-27 20:21:14 -05:00
|
|
|
}
|
2014-04-09 14:12:46 -04:00
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
discard(post_uuid);
|
|
|
|
|
drafts.removeDraft(postData.save_id);
|
2013-06-04 16:20:27 -04:00
|
|
|
}
|
2014-05-18 15:09:54 -04:00
|
|
|
}
|
2013-12-31 14:25:26 -05:00
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
function discard(post_uuid) {
|
2013-06-04 16:20:27 -04:00
|
|
|
if (composer.posts[post_uuid]) {
|
2013-12-20 18:41:56 -05:00
|
|
|
$('#cmp-uuid-' + post_uuid).remove();
|
2014-05-18 15:09:54 -04:00
|
|
|
drafts.removeDraft(composer.posts[post_uuid].save_id);
|
2013-06-04 16:20:27 -04:00
|
|
|
delete composer.posts[post_uuid];
|
2013-12-20 18:41:56 -05:00
|
|
|
composer.active = undefined;
|
2013-06-14 15:10:22 -04:00
|
|
|
taskbar.discard('composer', post_uuid);
|
2014-01-20 16:50:39 -05:00
|
|
|
$('body').css({'margin-bottom': 0});
|
2014-01-27 20:21:14 -05:00
|
|
|
$('.action-bar button').removeAttr('disabled');
|
2014-03-01 16:53:41 -05:00
|
|
|
|
|
|
|
|
socket.emit('modules.composer.unregister', post_uuid);
|
2013-06-04 16:20:27 -04:00
|
|
|
}
|
2014-05-18 15:09:54 -04:00
|
|
|
}
|
2013-06-04 16:20:27 -04:00
|
|
|
|
2013-12-20 18:41:56 -05:00
|
|
|
composer.minimize = function(post_uuid) {
|
|
|
|
|
var postContainer = $('#cmp-uuid-' + post_uuid);
|
|
|
|
|
postContainer.css('visibility', 'hidden');
|
2013-07-25 13:18:55 -04:00
|
|
|
composer.active = undefined;
|
2013-12-20 18:41:56 -05:00
|
|
|
taskbar.minimize('composer', post_uuid);
|
2014-03-01 17:49:39 -05:00
|
|
|
|
|
|
|
|
socket.emit('modules.composer.unregister', post_uuid);
|
2014-02-20 02:05:49 -05:00
|
|
|
};
|
2014-02-13 19:41:54 -05:00
|
|
|
|
2014-05-18 15:09:54 -04:00
|
|
|
return composer;
|
2014-04-10 20:31:57 +01:00
|
|
|
});
|