passing in values for saving rewards

v1.18.x
psychobunny 10 years ago
parent 91c02d4e29
commit cd26f5d06d

@ -41,13 +41,14 @@ define('admin/extend/rewards', function() {
});
$('#new').on('click', newReward);
$('#save').on('click', saveRewards);
});
};
function select(el) {
el.val(el.attr('data-selected'));
switch (el.attr('name')) {
case 'reward':
case 'id':
selectReward(el);
break;
}
@ -56,7 +57,7 @@ define('admin/extend/rewards', function() {
function update(el) {
el.attr('data-selected', el.val());
switch (el.attr('name')) {
case 'reward':
case 'id':
selectReward(el);
break;
}
@ -130,5 +131,26 @@ define('admin/extend/rewards', function() {
ul.append(li);
}
function saveRewards() {
var activeRewards = [];
$('#active li').each(function() {
var data = $(this).find('form.main').serializeArray();
data.rewards = $(this).find('form.rewards').serializeArray();
data.disabled = $(this).find('.toggle').html() === 'Enable';
activeRewards.push(data);
});
socket.emit('admin.rewards.save', activeRewards, function(err) {
if (err) {
app.alertError(err.message);
} else {
app.alertSuccess('Successfully saved rewards');
}
});
}
return rewards;
});

@ -25,6 +25,7 @@ var async = require('async'),
categories: require('./admin/categories'),
groups: require('./admin/groups'),
tags: require('./admin/tags'),
rewards: require('./admin/rewards'),
themes: {},
plugins: {},
widgets: {},

@ -0,0 +1,13 @@
"use strict";
var rewards = require('../../rewards'),
rewards = {};
rewards.save = function(socket, data, callback) {
console.log(data);
callback(new Error('derp'));
//callback(err ? err.message : null);
};
module.exports = rewards;

@ -3,10 +3,10 @@
<div class="panel panel-default">
<div class="panel-heading">Rewards</div>
<div class="panel-body">
<form>
<ul id="active">
<!-- BEGIN active -->
<li data-id="{active.id}" data-index="@index">
<form class="main">
<div class="well inline-block">
<label for="condition">If User's</label><br />
<select name="condition" data-selected="{active.condition}">
@ -22,17 +22,22 @@
<option value="{conditionals.conditional}">{conditionals.name}</option>
<!-- END conditionals -->
</select>
<input type="text" value="{active.value}" />
<input type="text" name="value" value="{active.value}" />
</div>
<div class="well inline-block">
<label for="condition">Then:</label><br />
<select name="reward" data-selected="{active.id}">
<select name="id" data-selected="{active.id}">
<!-- BEGIN rewards -->
<option value="{rewards.id}">{rewards.name}</option>
<!-- END rewards -->
</select>
</div>
</form>
<form class="rewards">
<div class="inputs well inline-block"></div>
</form>
<div class="well inline-block pull-right">
<button class="btn btn-danger delete">Delete</button>
<!-- IF active.disabled -->
@ -45,7 +50,6 @@
</li>
<!-- END active -->
</ul>
</form>
<input type="hidden" template-variable="rewards" value="{function.stringify, rewards}" />
<input type="hidden" template-variable="active" value="{function.stringify, active}" />
</div>

Loading…
Cancel
Save