Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 11 years ago
commit 6a649f9b9a

@ -407,7 +407,7 @@ var socket,
return;
}
if (!app.username) {
if (!app.uid) {
app.alert({
type: 'danger',
title: 'Not Logged In',

@ -14,7 +14,20 @@ define(['uploader'], function(uploader) {
function save() {
if(Object.keys(modified_categories).length) {
socket.emit('admin.categories.update', modified_categories);
socket.emit('admin.categories.update', modified_categories, function(err, result) {
if (err) {
return app.alertError(err.message);
}
if (result && result.length) {
app.alert({
title: 'Updated Categories',
message: 'Category IDs ' + result.join(', ') + ' was successfully updated.',
type: 'success',
timeout: 2000
});
}
});
modified_categories = {};
}
return false;

@ -3,27 +3,22 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
loadingMoreTopics = false;
Category.init = function() {
var cid = templates.get('category_id'),
categoryName = templates.get('category_name'),
categoryUrl = encodeURIComponent(window.location.href),
twitterUrl = "https://twitter.com/intent/tweet?url=" + categoryUrl + "&text=" + encodeURIComponent(categoryName),
facebookUrl = "https://www.facebook.com/sharer/sharer.php?u=" + categoryUrl,
googleUrl = "https://plus.google.com/share?url=" + categoryUrl;
var cid = templates.get('category_id');
app.enterRoom('category_' + cid);
$('#twitter-share').on('click', function () {
window.open(twitterUrl, '_blank', 'width=550,height=420,scrollbars=no,status=no');
window.open('https://twitter.com/intent/tweet?url=' + encodeURIComponent(window.location.href) + '&text=' + encodeURIComponent(templates.get('category_name')), '_blank', 'width=550,height=420,scrollbars=no,status=no');
return false;
});
$('#facebook-share').on('click', function () {
window.open(facebookUrl, '_blank', 'width=626,height=436,scrollbars=no,status=no');
window.open('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(window.location.href), '_blank', 'width=626,height=436,scrollbars=no,status=no');
return false;
});
$('#google-share').on('click', function () {
window.open(googleUrl, '_blank', 'width=500,height=570,scrollbars=no,status=no');
window.open('https://plus.google.com/share?url=' + encodeURIComponent(window.location.href), '_blank', 'width=500,height=570,scrollbars=no,status=no');
return false;
});
@ -43,9 +38,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
var clickedTid = $(this).parents('li.category-item[data-tid]').attr('data-tid');
$('#topics-container li.category-item').each(function(index, el) {
if($(el).offset().top - $(window).scrollTop() > 0) {
tid = $(el).attr('data-tid');
localStorage.setItem('category:bookmark', tid);
localStorage.setItem('category:bookmark', $(el).attr('data-tid'));
localStorage.setItem('category:bookmark:clicked', clickedTid);
return false;
}
@ -138,8 +131,9 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
if(!loadingMoreTopics && $('#topics-container').children().length) {
var after = 0;
var el = null;
var after = 0,
offset = 0,
el = null;
if(direction > 0) {
el = $('#topics-container .category-item[data-tid]').last();
@ -151,10 +145,9 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
if(after < 0) {
after = 0;
}
offset = el.offset().top - $('#header-menu').offset().top + $('#header-menu').height();
}
var offset = el.offset().top - $('#header-menu').offset().top + $('#header-menu').height();
Category.loadMoreTopics(templates.get('category_id'), after, function() {
if(direction < 0 && el) {
Category.scrollToTopic(el.attr('data-tid'), null, 0, offset);
@ -204,7 +197,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
pagination.recreatePaginationLinks(newPageCount);
});
$('#topics-container span.timeago').timeago();
topic.find('span.timeago').timeago();
app.createUserTooltips();
$(window).trigger('action:categories.new_topic.loaded');
@ -269,7 +262,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
}
}
$('#topics-container span.timeago').timeago();
html.find('span.timeago').timeago();
app.createUserTooltips();
app.makeNumbersHumanReadable(html.find('.human-readable-number'));

@ -1,35 +1,45 @@
var db = require('./../database'),
'use strict';
var async = require('async'),
db = require('./../database'),
utils = require('./../../public/src/utils'),
categories = require('./../categories');
(function(CategoriesAdmin) {
CategoriesAdmin.update = function(modified, socket) {
var updated = [];
CategoriesAdmin.update = function(modified, socket, callback) {
for (var cid in modified) {
function updateCategory(cid, next) {
var category = modified[cid];
var fields = Object.keys(category);
for (var key in category) {
db.setObjectField('category:' + cid, key, category[key]);
async.each(fields, function(key, next) {
updateCategoryField(cid, key, category[key], next);
}, next);
}
function updateCategoryField(cid, key, value, next) {
db.setObjectField('category:' + cid, key, value, function(err) {
if(err) {
return next(err);
}
if (key === 'name') {
// reset slugs if name is updated
var slug = cid + '/' + utils.slugify(category[key]);
db.setObjectField('category:' + cid, 'slug', slug);
var slug = cid + '/' + utils.slugify(value);
db.setObjectField('category:' + cid, 'slug', slug, next);
} else if (key === 'order') {
db.sortedSetAdd('categories:cid', category[key], cid);
db.sortedSetAdd('categories:cid', value, cid, next);
} else {
next();
}
}
updated.push(cid);
});
}
socket.emit('event:alert', {
title: 'Updated Categories',
message: 'Category IDs ' + updated.join(', ') + ' was successfully updated.',
type: 'success',
timeout: 2000
var cids = Object.keys(modified);
async.each(cids, updateCategory, function(err) {
callback(err, cids);
});
};

@ -118,12 +118,12 @@ SocketAdmin.categories.create = function(socket, data, callback) {
categories.create(data, callback);
};
SocketAdmin.categories.update = function(socket, data) {
SocketAdmin.categories.update = function(socket, data, callback) {
if(!data) {
throw new Error('invalid data');
return callback(new Error('invalid data'));
}
admin.categories.update(data, socket);
admin.categories.update(data, socket, callback);
};
SocketAdmin.categories.search = function(socket, data, callback) {

Loading…
Cancel
Save