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); $('#new').on('click', newReward);
$('#save').on('click', saveRewards);
}); });
}; };
function select(el) { function select(el) {
el.val(el.attr('data-selected')); el.val(el.attr('data-selected'));
switch (el.attr('name')) { switch (el.attr('name')) {
case 'reward': case 'id':
selectReward(el); selectReward(el);
break; break;
} }
@ -56,7 +57,7 @@ define('admin/extend/rewards', function() {
function update(el) { function update(el) {
el.attr('data-selected', el.val()); el.attr('data-selected', el.val());
switch (el.attr('name')) { switch (el.attr('name')) {
case 'reward': case 'id':
selectReward(el); selectReward(el);
break; break;
} }
@ -130,5 +131,26 @@ define('admin/extend/rewards', function() {
ul.append(li); 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; return rewards;
}); });

@ -25,6 +25,7 @@ var async = require('async'),
categories: require('./admin/categories'), categories: require('./admin/categories'),
groups: require('./admin/groups'), groups: require('./admin/groups'),
tags: require('./admin/tags'), tags: require('./admin/tags'),
rewards: require('./admin/rewards'),
themes: {}, themes: {},
plugins: {}, plugins: {},
widgets: {}, 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 panel-default">
<div class="panel-heading">Rewards</div> <div class="panel-heading">Rewards</div>
<div class="panel-body"> <div class="panel-body">
<form> <ul id="active">
<ul id="active"> <!-- BEGIN active -->
<!-- BEGIN active --> <li data-id="{active.id}" data-index="@index">
<li data-id="{active.id}" data-index="@index"> <form class="main">
<div class="well inline-block"> <div class="well inline-block">
<label for="condition">If User's</label><br /> <label for="condition">If User's</label><br />
<select name="condition" data-selected="{active.condition}"> <select name="condition" data-selected="{active.condition}">
@ -22,30 +22,34 @@
<option value="{conditionals.conditional}">{conditionals.name}</option> <option value="{conditionals.conditional}">{conditionals.name}</option>
<!-- END conditionals --> <!-- END conditionals -->
</select> </select>
<input type="text" value="{active.value}" /> <input type="text" name="value" value="{active.value}" />
</div> </div>
<div class="well inline-block"> <div class="well inline-block">
<label for="condition">Then:</label><br /> <label for="condition">Then:</label><br />
<select name="reward" data-selected="{active.id}"> <select name="id" data-selected="{active.id}">
<!-- BEGIN rewards --> <!-- BEGIN rewards -->
<option value="{rewards.id}">{rewards.name}</option> <option value="{rewards.id}">{rewards.name}</option>
<!-- END rewards --> <!-- END rewards -->
</select> </select>
</div> </div>
</form>
<form class="rewards">
<div class="inputs well inline-block"></div> <div class="inputs well inline-block"></div>
<div class="well inline-block pull-right"> </form>
<button class="btn btn-danger delete">Delete</button>
<!-- IF active.disabled --> <div class="well inline-block pull-right">
<button class="btn btn-success toggle">Enable</button> <button class="btn btn-danger delete">Delete</button>
<!-- ELSE --> <!-- IF active.disabled -->
<button class="btn btn-warning toggle">Disable</button> <button class="btn btn-success toggle">Enable</button>
<!-- ENDIF active.disabled --> <!-- ELSE -->
</div> <button class="btn btn-warning toggle">Disable</button>
<div class="clearfix"></div> <!-- ENDIF active.disabled -->
</li> </div>
<!-- END active --> <div class="clearfix"></div>
</ul> </li>
</form> <!-- END active -->
</ul>
<input type="hidden" template-variable="rewards" value="{function.stringify, rewards}" /> <input type="hidden" template-variable="rewards" value="{function.stringify, rewards}" />
<input type="hidden" template-variable="active" value="{function.stringify, active}" /> <input type="hidden" template-variable="active" value="{function.stringify, active}" />
</div> </div>

Loading…
Cancel
Save