disabling/enabling parent will disable/enable children

v1.18.x
barisusakli 9 years ago
parent c268493d2b
commit 0ce1e666e7

@ -17,11 +17,16 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
// Enable/Disable toggle events
$('.categories').on('click', 'button[data-action="toggle"]', function() {
var rowEl = $(this).parents('li'),
cid = rowEl.attr('data-cid'),
disabled = rowEl.hasClass('disabled');
var $this = $(this),
cid = $this.attr('data-cid'),
parentEl = $this.parents('li[data-cid="' + cid + '"]'),
disabled = parentEl.hasClass('disabled');
Categories.toggle(cid, !disabled);
var children = parentEl.find('li[data-cid]').map(function() {
return $(this).attr('data-cid');
}).get();
Categories.toggle([cid].concat(children), !disabled);
return false;
});
};
@ -94,12 +99,14 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
}
};
Categories.toggle = function(cid, disabled) {
Categories.toggle = function(cids, disabled) {
var payload = {};
payload[cid] = {
disabled: disabled ? 1 : 0
};
cids.forEach(function(cid) {
payload[cid] = {
disabled: disabled ? 1 : 0
};
});
socket.emit('admin.categories.update', payload, function(err) {
if (err) {

@ -16,7 +16,7 @@
<div class="col-md-3">
<div class="clearfix pull-right text-right">
<div class="btn-group">
<button data-action="toggle" data-disabled="{categories.disabled}" class="btn <!-- IF categories.disabled -->btn-primary<!-- ELSE -->btn-danger<!-- ENDIF categories.disabled -->">
<button data-cid="{categories.cid}" data-action="toggle" data-disabled="{categories.disabled}" class="btn <!-- IF categories.disabled -->btn-primary<!-- ELSE -->btn-danger<!-- ENDIF categories.disabled -->">
<!-- IF categories.disabled -->Enable<!-- ELSE -->Disable<!-- ENDIF categories.disabled -->
</button>
<a href="./categories/{categories.cid}" class="btn btn-default">Edit</a>

Loading…
Cancel
Save