rewards: code organization, getting ready to code saving/loading of active rewards

v1.18.x
psychobunny 10 years ago
parent 2cc6f0c507
commit 46e0fad2d8

@ -1,121 +1,133 @@
"use strict"; "use strict";
var rewards = {}; var rewards = {},
async = require('async'),
plugins = require('../plugins');
var defaults = {
conditionals: [
{
"name": ">",
"conditional": "greaterthan"
},
{
"name": ">=",
"conditional": "greaterorequalthan"
},
{
"name": "<",
"conditional": "lesserthan"
},
{
"name": "<=",
"conditional": "lesserorequalthan"
},
{
"name": "string:",
"conditional": "string"
}
]
};
rewards.get = function(callback) { rewards.get = function(callback) {
callback(false, { async.parallel({
conditions: [ active: getActiveRewards,
{ conditions: function(next) {
"name": "Reputation", plugins.fireHook('filter:rewards.conditions', [
"condition": "reputation" {
}, "name": "Reputation",
{ "condition": "reputation"
"name": "Post Count",
"condition": "postcount"
},
{
"name": "Last Logged in Time",
"condition": "lastLoggedIn"
}
],
conditionals: [
{
"name": ">",
"conditional": "greaterthan"
},
{
"name": ">=",
"conditional": "greaterorequalthan"
},
{
"name": "<",
"conditional": "lesserthan"
},
{
"name": "<=",
"conditional": "lesserorequalthan"
},
{
"name": "string:",
"conditional": "string"
}
],
active: [
{
"rewardID": 1,
"condition": "postcount",
"conditional": "greaterthan",
"rewards": {
"title": "Here is a title",
"message": "here is a message"
}, },
"value": 100, {
"disabled": false "name": "Post Count",
}, "condition": "postcount"
{
"rewardID": 0,
"condition": "lastLoggedIn",
"conditional": "lesserthan",
"rewards": {
"groupname": "group2"
}, },
"value": 10, {
"disabled": true "name": "Last Logged in Time",
} "condition": "lastLoggedIn"
], }
rewards: [ ], next);
{ },
"rewardID": 0, conditionals: function(next) {
"name": "Add to Group", plugins.fireHook('filter:rewards.conditionals', defaults.conditionals, next);
"inputs": [ },
{ rewards: function(next) {
"type": "select", plugins.fireHook('filter:rewards.rewards', [
"name": "groupname", {
"label": "Group Name:", "rewardID": 0,
"values": [ "name": "Add to Group",
{ "inputs": [
"name": "Group 1", {
"value": "group1" "type": "select",
}, "name": "groupname",
{ "label": "Group Name:",
"name": "Group 2", "values": [
"value": "group2" {
}, "name": "Group 1",
{ "value": "group1"
"name": "Group 3", },
"value": "group3" {
} "name": "Group 2",
], "value": "group2"
} },
] {
}, "name": "Group 3",
{ "value": "group3"
"rewardID": 1, }
"name": "Send alert message", ],
"inputs": [ }
{ ]
"type": "text", },
"name": "title", {
"label": "Title:" "rewardID": 1,
}, "name": "Send alert message",
{ "inputs": [
"type": "text", {
"name": "message", "type": "text",
"label": "Message:" "name": "title",
} "label": "Title:"
] },
} {
] "type": "text",
}); "name": "message",
"label": "Message:"
}
]
}
], next);
}
}, callback);
}; };
function getConditions() { function getConditions() {
} }
function getRewards() { function getActiveRewards(callback) {
callback(false, [
{
"rewardID": 1,
"condition": "postcount",
"conditional": "greaterthan",
"rewards": {
"title": "Here is a title",
"message": "here is a message"
},
"value": 100,
"disabled": false
},
{
"rewardID": 0,
"condition": "lastLoggedIn",
"conditional": "lesserthan",
"rewards": {
"groupname": "group2"
},
"value": 10,
"disabled": true
}
]);
} }
module.exports = rewards; module.exports = rewards;
Loading…
Cancel
Save