Merge remote-tracking branch 'origin/master' into webserver.js-refactor

v1.18.x
psychobunny 11 years ago
commit e73f8d6f37

@ -46,7 +46,8 @@
"nodebb-theme-cerulean": "~0.0.13",
"nodebb-theme-lavender": "~0.0.22",
"less": "^1.6.3",
"daemon": "~1.1.0"
"daemon": "~1.1.0",
"underscore": "^1.6.0"
},
"optionalDependencies": {
"redis": "0.8.3",

@ -218,9 +218,10 @@ var socket,
$('#' + params.location).prepend(alert.fadeIn('100'));
if(typeof params.closefn === 'function') {
alert.find('button').on('click', function () {
alert.find('button').on('click', function() {
params.closefn();
fadeOut();
return false;
});
}
});
@ -407,7 +408,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);
});
};

@ -174,7 +174,7 @@ var fs = require('fs'),
(function(staticDir) {
fs.exists(staticDir, function(exists) {
if (exists) {
Plugins.staticDirs[mappedPath] = staticDir;
Plugins.staticDirs[path.join(pluginData.id, mappedPath)] = staticDir;
} else {
winston.warn('[plugins/' + pluginData.id + '] Mapped path \'' + mappedPath + ' => ' + staticDir + '\' not found.');
}

@ -4,6 +4,8 @@ var nconf = require('nconf'),
path = require('path'),
fs = require('fs'),
validator = require('validator'),
_ = require('underscore'),
async = require('async'),
plugins = require('../plugins'),
PluginRoutes = function(app) {
@ -31,16 +33,34 @@ var nconf = require('nconf'),
// Static Assets
app.get('/plugins/:id/*', function(req, res) {
var relPath = req._parsedUrl.pathname.replace(nconf.get('relative_path') + '/plugins/' + req.params.id, '');
var relPath = req._parsedUrl.pathname.replace(nconf.get('relative_path') + '/plugins/', ''),
matches = _.map(plugins.staticDirs, function(realPath, mappedPath) {
if (relPath.match(mappedPath)) {
return mappedPath;
} else {
return null;
}
}).filter(function(a) { return a; });
if (matches) {
async.map(matches, function(mappedPath, next) {
var filePath = path.join(plugins.staticDirs[mappedPath], relPath.slice(mappedPath.length));
if (plugins.staticDirs[req.params.id]) {
var fullPath = path.join(plugins.staticDirs[req.params.id], decodeURIComponent(relPath));
fs.exists(filePath, function(exists) {
if (exists) {
next(null, filePath);
} else {
next();
}
});
}, function(err, matches) {
// Filter out the nulls
matches = matches.filter(function(a) {
return a;
});
fs.exists(fullPath, function(exists) {
if (exists) {
res.sendfile(fullPath, {
maxAge: app.enabled('cache') ? 5184000000 : 0
});
if (matches.length) {
res.sendfile(matches[0]);
} else {
res.redirect('/404');
}

@ -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