Files
firefly-iii/public/js/ff/rules/index.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-01-14 16:41:15 +01:00
/*
* index.js
2016-04-01 16:46:11 +02:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
2016-01-14 16:41:15 +01:00
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
2016-01-14 16:41:15 +01:00
*/
var fixHelper = function (e, tr) {
2016-01-22 07:27:49 +01:00
"use strict";
var $originals = tr.children();
var $helper = tr.clone();
$helper.children().each(function (index) {
// Set helper cell sizes to match the original sizes
$(this).width($originals.eq(index).width());
});
return $helper;
};
$(function () {
2016-01-29 17:53:49 +01:00
"use strict";
$('.rule-triggers').sortable(
{
helper: fixHelper,
stop: sortStop,
2017-02-25 05:57:01 +01:00
cursor: "move"
2016-01-29 17:53:49 +01:00
}
);
2016-01-29 17:53:49 +01:00
$('.rule-actions').sortable(
{
helper: fixHelper,
stop: sortStop,
cursor: "move"
2016-01-29 17:53:49 +01:00
}
);
}
);
function sortStop(event, ui) {
"use strict";
var current = $(ui.item);
var parent = current.parent();
var ruleId = current.parent().data('id');
var entries = [];
// who am i?
$.each(parent.children(), function (i, v) {
var trigger = $(v);
var id = trigger.data('id');
entries.push(id);
});
if (parent.hasClass('rule-triggers')) {
2017-01-02 08:30:20 +01:00
$.post('rules/trigger/order/' + ruleId, {triggers: entries}).fail(function () {
2016-01-22 07:27:49 +01:00
alert('Could not re-order rule triggers. Please refresh the page.');
});
} else {
2017-01-02 08:30:20 +01:00
$.post('rules/action/order/' + ruleId, {actions: entries}).fail(function () {
2016-01-22 07:27:49 +01:00
alert('Could not re-order rule actions. Please refresh the page.');
});
}
2016-01-22 07:27:49 +01:00
}