|
|
|
@ -218,34 +218,31 @@ widgets.reset = function (callback) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
widgets.resetTemplate = function (template, callback) {
|
|
|
|
|
db.getObject('widgets:' + template + '.tpl', function (err, area) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var toBeDrafted = [];
|
|
|
|
|
for (var location in area) {
|
|
|
|
|
if (area.hasOwnProperty(location)) {
|
|
|
|
|
toBeDrafted = toBeDrafted.concat(JSON.parse(area[location]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.delete('widgets:' + template + '.tpl');
|
|
|
|
|
db.getObjectField('widgets:global', 'drafts', function (err, draftWidgets) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback();
|
|
|
|
|
var toBeDrafted = [];
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
db.getObject('widgets:' + template + '.tpl', next);
|
|
|
|
|
},
|
|
|
|
|
function (area, next) {
|
|
|
|
|
for (var location in area) {
|
|
|
|
|
if (area.hasOwnProperty(location)) {
|
|
|
|
|
toBeDrafted = toBeDrafted.concat(JSON.parse(area[location]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.delete('widgets:' + template + '.tpl', next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
db.getObjectField('widgets:global', 'drafts', next);
|
|
|
|
|
},
|
|
|
|
|
function (draftWidgets, next) {
|
|
|
|
|
draftWidgets = JSON.parse(draftWidgets).concat(toBeDrafted);
|
|
|
|
|
db.setObjectField('widgets:global', 'drafts', JSON.stringify(draftWidgets), callback);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
db.setObjectField('widgets:global', 'drafts', JSON.stringify(draftWidgets), next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
widgets.resetTemplates = function (templates, callback) {
|
|
|
|
|
async.eachSeries(templates, function (template, next) {
|
|
|
|
|
widgets.resetTemplate(template, next);
|
|
|
|
|
}, callback);
|
|
|
|
|
async.eachSeries(templates, widgets.resetTemplate, callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = widgets;
|
|
|
|
|