Reduced post upload presenter complexity somewhat
This commit is contained in:
parent
0ca03cae60
commit
b53e2752ca
1 changed files with 48 additions and 51 deletions
|
@ -33,28 +33,28 @@ App.Presenters.PostUploadPresenter = function(
|
||||||
$el.html(template());
|
$el.html(template());
|
||||||
$messages = $el.find('.messages');
|
$messages = $el.find('.messages');
|
||||||
|
|
||||||
new App.Controls.FileDropper($el.find('[name=post-content]'), fileHandlerChanged, jQuery);
|
tagInput = new App.Controls.TagInput($el.find('form [name=tags]'), _, jQuery);
|
||||||
|
App.Controls.FileDropper($el.find('[name=post-content]'), fileHandlerChanged, jQuery);
|
||||||
|
|
||||||
$el.find('.url-handler input').keydown(urlHandlerKeyPressed);
|
$el.find('.url-handler input').keydown(urlHandlerKeyPressed);
|
||||||
$el.find('.url-handler button').click(urlHandlerButtonClicked);
|
$el.find('.url-handler button').click(urlHandlerButtonClicked);
|
||||||
$el.find('thead th.checkbox').click(postTableSelectAllCheckboxClicked);
|
$el.find('thead th.checkbox').click(postTableSelectAllCheckboxClicked);
|
||||||
|
|
||||||
mousetrap.bind('a', function(e) {
|
mousetrap.bind('a', simpleKeyPressed(selectPrevPostTableRow), 'keyup');
|
||||||
if (!e.altKey && !e.ctrlKey) {
|
mousetrap.bind('d', simpleKeyPressed(selectNextPostTableRow), 'keyup');
|
||||||
selectPrevPostInTable();
|
|
||||||
}
|
|
||||||
}, 'keyup');
|
|
||||||
mousetrap.bind('d', function(e) {
|
|
||||||
if (!e.altKey && !e.ctrlKey) {
|
|
||||||
selectNextPostInTable();
|
|
||||||
}
|
|
||||||
}, 'keyup');
|
|
||||||
|
|
||||||
$el.find('.remove').click(removeButtonClicked);
|
$el.find('.remove').click(removeButtonClicked);
|
||||||
$el.find('.move-up').click(moveUpButtonClicked);
|
$el.find('.move-up').click(moveUpButtonClicked);
|
||||||
$el.find('.move-down').click(moveDownButtonClicked);
|
$el.find('.move-down').click(moveDownButtonClicked);
|
||||||
$el.find('.submit').click(submitButtonClicked);
|
$el.find('.submit').click(submitButtonClicked);
|
||||||
|
}
|
||||||
|
|
||||||
tagInput = new App.Controls.TagInput($el.find('form [name=tags]'), _, jQuery);
|
function simpleKeyPressed(callback) {
|
||||||
|
return function(e) {
|
||||||
|
if (!e.altKey && !e.ctrlKey) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultPost() {
|
function getDefaultPost() {
|
||||||
|
@ -143,7 +143,14 @@ App.Presenters.PostUploadPresenter = function(
|
||||||
var allPosts = getAllPosts();
|
var allPosts = getAllPosts();
|
||||||
allPosts.push(post);
|
allPosts.push(post);
|
||||||
setAllPosts(allPosts);
|
setAllPosts(allPosts);
|
||||||
|
createPostTableRow(post);
|
||||||
|
}
|
||||||
|
|
||||||
|
function postChanged(post) {
|
||||||
|
updatePostTableRow(post);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createPostTableRow(post) {
|
||||||
var $table = $el.find('table');
|
var $table = $el.find('table');
|
||||||
var $row = $table.find('.template').clone(true);
|
var $row = $table.find('.template').clone(true);
|
||||||
|
|
||||||
|
@ -159,11 +166,11 @@ App.Presenters.PostUploadPresenter = function(
|
||||||
|
|
||||||
postChanged(post);
|
postChanged(post);
|
||||||
|
|
||||||
selectPostInTable(post);
|
selectPostTableRow(post);
|
||||||
showOrHidePostsTable();
|
showOrHidePostsTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
function postChanged(post) {
|
function updatePostTableRow(post) {
|
||||||
var $row = post.$tableRow;
|
var $row = post.$tableRow;
|
||||||
$row.find('.tags').text(post.tags.join(', ') || '-');
|
$row.find('.tags').text(post.tags.join(', ') || '-');
|
||||||
$row.find('.safety div').attr('class', 'safety-' + post.safety);
|
$row.find('.safety div').attr('class', 'safety-' + post.safety);
|
||||||
|
@ -373,8 +380,6 @@ App.Presenters.PostUploadPresenter = function(
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
post.tags.push(tag);
|
post.tags.push(tag);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
jQuery.each(posts, function(i, post) {
|
|
||||||
postChanged(post);
|
postChanged(post);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -385,18 +390,13 @@ App.Presenters.PostUploadPresenter = function(
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
post.tags.splice(index, 1);
|
post.tags.splice(index, 1);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
jQuery.each(posts, function(i, post) {
|
|
||||||
postChanged(post);
|
postChanged(post);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function postTableRowImageHovered(e) {
|
function postTableRowImageHovered(e) {
|
||||||
var $img = jQuery(this);
|
var $img = jQuery(this);
|
||||||
if (!$img.attr('src')) {
|
if ($img.attr('src')) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var $lightbox = jQuery('#lightbox');
|
var $lightbox = jQuery('#lightbox');
|
||||||
$lightbox.find('img').attr('src', $img.attr('src'));
|
$lightbox.find('img').attr('src', $img.attr('src'));
|
||||||
$lightbox
|
$lightbox
|
||||||
|
@ -406,13 +406,15 @@ App.Presenters.PostUploadPresenter = function(
|
||||||
top: ($img.position().top + ($img.outerHeight() - $lightbox.outerHeight()) / 2) + 'px',
|
top: ($img.position().top + ($img.outerHeight() - $lightbox.outerHeight()) / 2) + 'px',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function postTableRowImageUnhovered(e) {
|
function postTableRowImageUnhovered(e) {
|
||||||
var $lightbox = jQuery('#lightbox');
|
var $lightbox = jQuery('#lightbox');
|
||||||
$lightbox.hide();
|
$lightbox.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectPostInTable(post) {
|
function selectPostTableRow(post) {
|
||||||
|
if (post) {
|
||||||
var $table = $el.find('table');
|
var $table = $el.find('table');
|
||||||
$table.find('tbody input[type=checkbox]').prop('checked', false);
|
$table.find('tbody input[type=checkbox]').prop('checked', false);
|
||||||
$table.find('tbody tr').each(function(i, row) {
|
$table.find('tbody tr').each(function(i, row) {
|
||||||
|
@ -424,19 +426,14 @@ App.Presenters.PostUploadPresenter = function(
|
||||||
});
|
});
|
||||||
postTableCheckboxesChanged();
|
postTableCheckboxesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectPrevPostInTable() {
|
|
||||||
var prevPost = $el.find('tbody tr.selected:eq(0)').prev().data('post');
|
|
||||||
if (prevPost) {
|
|
||||||
selectPostInTable(prevPost);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectNextPostInTable() {
|
function selectPrevPostTableRow() {
|
||||||
var nextPost = $el.find('tbody tr.selected:eq(0)').next().data('post');
|
selectPostTableRow($el.find('tbody tr.selected:eq(0)').prev().data('post'));
|
||||||
if (nextPost) {
|
|
||||||
selectPostInTable(nextPost);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectNextPostTableRow() {
|
||||||
|
selectPostTableRow($el.find('tbody tr.selected:eq(0)').next().data('post'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function showOrHidePostsTable() {
|
function showOrHidePostsTable() {
|
||||||
|
|
Loading…
Reference in a new issue