Composer: simplify code with early returns

v1.18.x
Micheil Smith 11 years ago
parent 9dc0a4b115
commit 78e1e4fbac

@ -415,65 +415,76 @@ define(['taskbar'], function(taskbar) {
} }
composer.newTopic = function(cid) { composer.newTopic = function(cid) {
if(allowed()) { if(!allowed()) {
push({ return;
cid: cid,
title: '',
body: '',
modified: false,
isMain: true
});
} }
push({
cid: cid,
title: '',
body: '',
modified: false,
isMain: true
});
}; };
composer.addQuote = function(tid, pid, title, username, text){ composer.addQuote = function(tid, pid, title, username, text){
if (allowed()) { if (!allowed()) {
var uuid = composer.active; return;
if(uuid !== undefined){ }
var bodyEl = $('#cmp-uuid-'+uuid).find('textarea');
var prevText = bodyEl.val(); var uuid = composer.active;
if(tid !== composer.posts[uuid].tid) {
text = username + ' said in ['+title+'](/topic/'+tid+'#'+pid+'):\n'+text; if(uuid === undefined){
} else { composer.newReply(tid, pid, title, username + ' said:\n' + text);
text = username + ' said:\n' + text; return;
} }
composer.posts[uuid].body = (prevText.length ? prevText + '\n\n' : '') + text;
bodyEl.val(composer.posts[uuid].body); var bodyEl = $('#cmp-uuid-'+uuid).find('textarea');
} else { var prevText = bodyEl.val();
composer.newReply(tid, pid, title, username + ' said:\n' + text); if(tid !== composer.posts[uuid].tid) {
} text = username + ' said in ['+title+'](/topic/'+tid+'#'+pid+'):\n'+text;
} else {
text = username + ' said:\n' + text;
} }
composer.posts[uuid].body = (prevText.length ? prevText + '\n\n' : '') + text;
bodyEl.val(composer.posts[uuid].body);
}; };
composer.newReply = function(tid, pid, title, text) { composer.newReply = function(tid, pid, title, text) {
if(allowed()) { if(!allowed()) {
push({ return;
tid: tid,
toPid: pid,
title: title,
body: text,
modified: false,
isMain: false
});
} }
push({
tid: tid,
toPid: pid,
title: title,
body: text,
modified: false,
isMain: false
});
}; };
composer.editPost = function(pid) { composer.editPost = function(pid) {
if(allowed()) { if(!allowed()) {
socket.emit('modules.composer.push', pid, function(err, threadData) { return;
if(err) {
return app.alertError(err.message);
}
push({
pid: pid,
title: threadData.title,
body: threadData.body,
modified: false,
isMain: !threadData.index,
topic_thumb: threadData.topic_thumb
});
});
} }
socket.emit('modules.composer.push', pid, function(err, threadData) {
if(err) {
return app.alertError(err.message);
}
push({
pid: pid,
title: threadData.title,
body: threadData.body,
modified: false,
isMain: !threadData.index,
topic_thumb: threadData.topic_thumb
});
});
}; };
composer.load = function(post_uuid) { composer.load = function(post_uuid) {

Loading…
Cancel
Save