'+
'');
// make source list sortable
$( "ul.sortable-src").sortable({
connectWith: "ul.sortable-dest",
placeholder: "ui-state-highlight",
receive: function(event, ui) { FW_sortableSrcListSort(); },
stop: function(event, ui) { FW_sortableSrcListSort(); }
});
// make destination list sortable
$("ul.sortable-dest").sortable({
connectWith: "ul.sortable-dest",
placeholder: "ui-state-highlight",
stop: function(event, ui) { FW_sortableUpdateLinks(); },
create: function(event, ui) { FW_sortableUpdateLinks(); },
receive: function(event, ui) { FW_sortableUpdateLinks(); }
});
// add click handler for item removal in destination list
$('ul.sortable-dest').on("click", "a.sort-item-delete", function(event) {
var el = $(this).parents("li");
if(el.attr("key") !== undefined) {
el.appendTo("ul.sortable-src");
el.html(el.attr("value"));
}
else el.remove();
FW_sortableSrcListSort();
FW_sortableUpdateLinks();
return false;
});
// add click handler for quick add by click on list item in source list
$('ul.sortable-src').on("click", "li.sortable-item", function(event) {
$(this).appendTo("ul.sortable-dest");
FW_sortableUpdateLinks();
});
// add click handler for inserting a new custom value to destination list
$('a#sort_add_new_item').click(function () {
var new_val = $('input#sort_new_item').val().split(',');
$.each(new_val, function(index,value) {
var v = value.trim();
if(v.length)
{
$('ul.sortable-dest').append('
'+v+'
');
$('input#sort_new_item').val('');
FW_sortableUpdateLinks();
}
});
return false;
});
// create the dialog
$('#sortdlg').dialog(
{ modal:true, closeOnEscape:false, maxHeight:$(window).height()*3/4, width:'auto', height:'auto',
buttons:[
{ text:"Cancel", click:function(){ $('#sortdlg').remove(); } },
{ text:"OK", click:function(){
var res=[];
$("#sortdlg ul.sortable-dest li.sortable-item").each(function(){
res.push($(this).attr("value"));
});
$('#sortdlg').remove();
$(newEl).val(res.join(","));
if(cmd)
cmd(res.join(","));
}}]}).focus();
});
return newEl;
}
// sort all items in source list according to their original given order
function
FW_sortableSrcListSort()
{
$('ul.sortable-src li.sortable-item').sort(function (a, b) {
return (($(a).attr("key") < $(b).attr("key")) ? -1 : ($(a).attr("key") > $(b).attr("key")) ? 1 : 0);
}).appendTo("ul.sortable-src");
}
// add index number and deletion link to all items in destination list
function
FW_sortableUpdateLinks()
{
$("ul.sortable-dest li.sortable-item").each(function () {
$(this).html(($(this).index() + 1)+'. '+$(this).attr("value")+($(this).attr("deletable") == "false" ? '' : ''));
});
}
// create the inital html output
function
FW_sortableCreateTable(elements, selected)
{
var table = '