using tjs to load new lines instead of cloning

v1.18.x
psychobunny 10 years ago
parent 8373f7359e
commit 1998f102d6

@ -6,49 +6,54 @@ define('admin/extend/rewards', function() {
var available, var available,
active; active,
conditions,
conditionals;
rewards.init = function() { rewards.init = function() {
$(window).on('action:ajaxify.end', function() { $(window).on('action:ajaxify.end', function() {
available = JSON.parse(ajaxify.variables.get('rewards')); available = JSON.parse(ajaxify.variables.get('rewards'));
active = JSON.parse(ajaxify.variables.get('active')); active = JSON.parse(ajaxify.variables.get('active'));
conditions = JSON.parse(ajaxify.variables.get('conditions'));
conditionals = JSON.parse(ajaxify.variables.get('conditionals'));
$('[data-selected]').each(function() { $('[data-selected]').each(function() {
select($(this)); select($(this));
}).on('change', function() {
update($(this));
}); });
populateInputs(); $('#active')
.on('[data-selected]', 'change', function() {
$('.delete').on('click', function() { update($(this));
var parent = $(this).parents('[data-id]'), })
id = parent.attr('data-id'); .on('.delete', 'click', function() {
var parent = $(this).parents('[data-id]'),
socket.emit('admin.rewards.delete', {id: id}, function(err) { id = parent.attr('data-id');
if (err) {
app.alertError(err.message); socket.emit('admin.rewards.delete', {id: id}, function(err) {
} else { if (err) {
app.alertSuccess('Successfully deleted reward'); app.alertError(err.message);
} } else {
app.alertSuccess('Successfully deleted reward');
}
});
parent.remove();
return false;
})
.on('.toggle', 'click', function() {
var btn = $(this),
disabled = btn.html() === 'Enable',
id = $(this).parents('[data-id]').attr('data-id');
btn.toggleClass('btn-warning').toggleClass('btn-success').html(disabled ? 'Enable' : 'Disable');
// send disable api call
return false;
}); });
parent.remove();
return false;
});
$('.toggle').on('click', function() {
var btn = $(this),
disabled = btn.html() === 'Enable',
id = $(this).parents('[data-id]').attr('data-id');
btn.toggleClass('btn-warning').toggleClass('btn-success').html(disabled ? 'Enable' : 'Disable');
// send disable api call
return false;
});
$('#new').on('click', newReward); $('#new').on('click', newReward);
$('#save').on('click', saveRewards); $('#save').on('click', saveRewards);
populateInputs();
}); });
}; };
@ -124,16 +129,26 @@ define('admin/extend/rewards', function() {
function newReward() { function newReward() {
var ul = $('#active'), var ul = $('#active'),
li = $('#active li').last().clone(true); id = parseInt($('#active li').last().attr('data-id'), 10);
li.attr('data-id', parseInt(li.attr('data-id'), 10) + 1) var data = {
.attr('data-rid', ''); active: [{
id: id ? id + 1 : 0,
li.find('.inputs').html(''); disabled: true,
li.find('[name="rid"]').val(''); value: ''
li.find('.toggle').removeClass('btn-warning').addClass('btn-success').html('Enable'); }],
conditions: conditions,
ul.append(li); conditionals: conditionals,
rewards: available
};
var ul = $('#active');
templates.parse('admin/extend/rewards', 'active', data, function(li) {
li = $(li);
li.find('[name="rid"]').val('');
ul.append(li);
});
} }
function saveRewards() { function saveRewards() {

@ -52,6 +52,8 @@
</ul> </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}" />
<input type="hidden" template-variable="conditions" value="{function.stringify, conditions}" />
<input type="hidden" template-variable="conditionals" value="{function.stringify, conditionals}" />
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save