Baris Soner Usakli 11 years ago
commit 859ca8dd18

@ -5,13 +5,21 @@ define(['forum/accountheader'], function(header) {
header.init();
$('#submitBtn').on('click', function() {
var settings = {};
var settings = {
showemail: $('#showemailCheckBox').is(':checked') ? 1 : 0,
usePagination: $('#usePaginationCheckBox').is(':checked') ? 1 : 0,
topicsPerPage: $('#topicsPerPage').val(),
postsPerPage: $('#postsPerPage').val()
};
$('.account input, .account textarea').each(function(id, input) {
input = $(input);
switch (input.attr('type')) {
case 'text' :
case 'textarea' :
settings[input.attr('data-property')] = input.val();
break;
case 'checkbox' :
settings[input.attr('data-property')] = input.is(':checked') ? 1 : 0;
break;
}
});
socket.emit('user.saveSettings', settings, function(err) {
if (err) {
@ -19,8 +27,27 @@ define(['forum/accountheader'], function(header) {
}
app.alertSuccess('Settings saved!');
});
return false;
});
socket.emit('user.getSettings', function(err, settings) {
for (var setting in settings) {
if (settings.hasOwnProperty(setting)) {
var input = $('.account input[data-property="' + setting + '"]');
switch (input.attr('type')) {
case 'text' :
case 'textarea' :
input.val(settings[setting]);
break;
case 'checkbox' :
input.prop('checked', !!settings[setting]);
break;
}
}
}
});
};
return AccountSettings;

@ -5,7 +5,7 @@
<div class="well">
<div class="checkbox">
<label>
<input id="showemailCheckBox" type="checkbox" <!-- IF settings.showemail -->checked<!-- ENDIF settings.showemail --> > <strong>[[user:show_email]]</strong>
<input type="checkbox" data-property="showemail" /> <strong>[[user:show_email]]</strong>
</label>
</div>
</div>
@ -13,13 +13,20 @@
<div class="well">
<div class="checkbox">
<label>
<input id="usePaginationCheckBox" type="checkbox" <!-- IF settings.usePagination -->checked<!-- ENDIF settings.usePagination -->> <strong>[[user:paginate_description]]</strong>
<input type="checkbox" data-property="usePagination"> <strong>[[user:paginate_description]]</strong>
</label>
</div>
<strong>[[user:topics_per_page]]</strong><br /> <input id="topicsPerPage" type="text" class="form-control" value="{settings.topicsPerPage}"><br />
<strong>[[user:posts_per_page]]</strong><br /> <input id="postsPerPage" type="text" class="form-control" value="{settings.postsPerPage}"><br />
<strong>[[user:topics_per_page]]</strong><br /> <input type="text" class="form-control" data-property="topicsPerPage"><br />
<strong>[[user:posts_per_page]]</strong><br /> <input type="text" class="form-control" data-property="postsPerPage"><br />
</div>
<!-- BEGIN settings -->
<h4>{settings.title}</h4>
<div class="well">
{settings.content}
</div>
<!-- END settings -->
</div>
</div>

@ -266,10 +266,10 @@ var fs = require('fs'),
});
});
app.get('/api/user/:userslug/settings', function (req, res, next) {
app.get('/api/user/:userslug/settings', function(req, res, next) {
var callerUID = req.user ? req.user.uid : '0';
user.getUidByUserslug(req.params.userslug, function (err, uid) {
user.getUidByUserslug(req.params.userslug, function(err, uid) {
if (err) {
return next(err);
}
@ -286,26 +286,27 @@ var fs = require('fs'),
});
}
user.getUserFields(uid, ['username', 'userslug'], function (err, userData) {
plugins.fireHook('filter:user.settings', [], function(err, settings) {
if (err) {
return next(err);
}
if(!userData) {
return res.json(404, {
error: 'User not found!'
});
}
user.getSettings(uid, function(err, settings) {
if(err) {
user.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
if (err) {
return next(err);
}
if(!userData) {
return res.json(404, {
error: 'User not found!'
});
}
userData.settings = settings;
res.json(userData);
});
});
});
});

@ -133,6 +133,12 @@ SocketUser.unfollow = function(socket, data, callback) {
}
};
SocketUser.getSettings = function(socket, data, callback) {
if (socket.uid) {
user.getSettings(socket.uid, callback);
}
};
SocketUser.saveSettings = function(socket, data, callback) {
if (socket.uid && data) {
user.saveSettings(socket.uid, data, callback);

@ -204,29 +204,23 @@ var bcrypt = require('bcryptjs'),
}
if(!settings) {
return sendDefaultSettings();
settings = {}
}
settings.showemail = parseInt(settings.showemail, 10) !== 0;
settings.usePagination = parseInt(settings.usePagination, 10) !== 0;
settings.topicsPerPage = parseInt(settings.topicsPerPage, 10);
settings.postsPerPage = parseInt(settings.postsPerPage, 10);
settings.showemail = settings.showemail ? parseInt(settings.showemail, 10) !== 0 : parseInt(meta.config.usePagination, 10) !== 0;
settings.usePagination = settings.usePagination ? parseInt(settings.usePagination, 10) !== 0 : parseInt(meta.config.usePagination, 10) !== 0;
settings.topicsPerPage = settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : parseInt(meta.config.topicsPerPage, 10) || 20;
settings.postsPerPage = settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : parseInt(meta.config.postsPerPage, 10) || 10;
callback(null, settings);
});
}
User.saveSettings = function(uid, data, callback) {
db.setObject('user:' + uid + ':settings', {
showemail: data.showemail || 0,
usePagination: data.usePagination || 0,
topicsPerPage: data.topicsPerPage || 20,
postsPerPage: data.postsPerPage || 10
}, callback);
db.setObject('user:' + uid + ':settings', data, callback);
}
User.updateProfile = function(uid, data, callback) {
var fields = ['username', 'email', 'fullname', 'website', 'location', 'birthday', 'signature'];
var returnData = {
success: false

Loading…
Cancel
Save