Skip to content

Commit 31e9844

Browse files
committed
add/remove switch conditionals preserve cssOrder, and put new ones at top. Fixes #82
1 parent e8314be commit 31e9844

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

switchboard/admin/index.tpl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@
373373
</script>
374374

375375
<script type="text/x-handlebars-template" id="switchData">
376-
<div id="id_{{key}}" class="switch" data-switch-key="{{key}}" data-switch-label="{{label}}" data-switch-description="{{description}}" data-switch-status="{{status}}">
376+
<div id="id_{{key}}" class="switch" data-switch-key="{{key}}" data-switch-label="{{label}}" data-switch-description="{{description}}" data-switch-status="{{status}}" style="order:{{ cssOrder }}">
377377
<div class="status">
378378
<label for="status_{{key}}">Status</label>
379379
<select name="status_{{key}}">
@@ -724,9 +724,9 @@
724724
$('.switches', $sb).on('submit', '.conditions-form form', function(e) {
725725
e.preventDefault();
726726
var $form = $(this);
727-
727+
var $switch = $form.parents('.switch:first');
728728
var data = {
729-
key: $form.parents('.switch:first').attr('data-switch-key'),
729+
key: $switch.attr('data-switch-key'),
730730
id: $form.attr('data-switch'),
731731
field: $form.attr('data-field')
732732
};
@@ -744,6 +744,7 @@
744744
});
745745
746746
api(SWITCHBOARD.addCondition, data, function (swtch) {
747+
swtch.cssOrder = $switch.css('order');
747748
var result = templates.switchData(swtch);
748749
$('.switches .switch[data-switch-key="' + data.key + '"]', $sb).replaceWith(result);
749750
});
@@ -753,15 +754,16 @@
753754
e.preventDefault();
754755
755756
var $el = $(this).parents('span:first');
756-
757+
var $switch = $el.parents('.switch:first');
757758
var data = {
758-
key: $el.parents('.switch:first').attr('data-switch-key'),
759+
key: $switch.attr('data-switch-key'),
759760
id: $el.attr('data-switch'),
760761
field: $el.attr('data-field'),
761762
value: $el.attr('data-value')
762763
};
763764
764765
api(SWITCHBOARD.delCondition, data, function (swtch) {
766+
swtch.cssOrder = $switch.css('order');
765767
var result = templates.switchData(swtch);
766768
$('.switches .switch[data-switch-key="' + data.key + '"]').replaceWith(result);
767769
});
@@ -814,6 +816,7 @@
814816
},
815817
816818
function (swtch) {
819+
swtch.cssOrder = -999999;
817820
var result = templates.switchData(swtch);
818821
819822
if (action === 'add') {

0 commit comments

Comments
 (0)