using tjs to load new lines instead of cloning

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

@ -6,22 +6,26 @@ define('admin/extend/rewards', function() {
var available,
active;
active,
conditions,
conditionals;
rewards.init = function() {
$(window).on('action:ajaxify.end', function() {
available = JSON.parse(ajaxify.variables.get('rewards'));
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() {
select($(this));
}).on('change', function() {
update($(this));
});
populateInputs();
$('.delete').on('click', function() {
$('#active')
.on('[data-selected]', 'change', function() {
update($(this));
})
.on('.delete', 'click', function() {
var parent = $(this).parents('[data-id]'),
id = parent.attr('data-id');
@ -35,9 +39,8 @@ define('admin/extend/rewards', function() {
parent.remove();
return false;
});
$('.toggle').on('click', function() {
})
.on('.toggle', 'click', function() {
var btn = $(this),
disabled = btn.html() === 'Enable',
id = $(this).parents('[data-id]').attr('data-id');
@ -49,6 +52,8 @@ define('admin/extend/rewards', function() {
$('#new').on('click', newReward);
$('#save').on('click', saveRewards);
populateInputs();
});
};
@ -124,16 +129,26 @@ define('admin/extend/rewards', function() {
function newReward() {
var ul = $('#active'),
li = $('#active li').last().clone(true);
id = parseInt($('#active li').last().attr('data-id'), 10);
var data = {
active: [{
id: id ? id + 1 : 0,
disabled: true,
value: ''
}],
conditions: conditions,
conditionals: conditionals,
rewards: available
};
li.attr('data-id', parseInt(li.attr('data-id'), 10) + 1)
.attr('data-rid', '');
var ul = $('#active');
li.find('.inputs').html('');
templates.parse('admin/extend/rewards', 'active', data, function(li) {
li = $(li);
li.find('[name="rid"]').val('');
li.find('.toggle').removeClass('btn-warning').addClass('btn-success').html('Enable');
ul.append(li);
});
}
function saveRewards() {

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

Loading…
Cancel
Save