// Copyright Zikula Foundation 2010 - license GNU/LGPLv3 (or at your option, any later version).
var appendItemBeforeResponse=true;var removeItemBeforeResponse=true;var cloneDraggedItem=true;function bindSubscriberAreaToProviderArea(a,b){subscriberAreaToggle(a,b)}function unbindProviderAreaFromSubscriberArea(c,a,d,b){if(removeItemBeforeResponse){removeProviderAreaFromSubscriberArea(c,d)}subscriberAreaToggle(a,b)}function subscriberAreaToggle(a,c){var b={subscriberarea:a,providerarea:c};new Zikula.Ajax.Request("ajax.php?module=Extensions&func=togglesubscriberareastatus",{parameters:b,onComplete:togglesubscriberareastatus_response})}function togglesubscriberareastatus_response(a){if(!a.isSuccess()){Zikula.showajaxerror(a.getMessage());return}var b=a.getData();if(b.action=="bind"){if(!appendItemBeforeResponse){appendProviderAreaToSubscriberArea(b.subscriberarea_id,b.subscriberarea,b.providerarea_id)}}else{if(b.action=="unbind"){if(!removeItemBeforeResponse){removeProviderAreaFromSubscriberArea(b.subscriberarea_id,b.providerarea_id)}}}}function appendProviderAreaToSubscriberArea(f,a,g){var c=$("availablearea_"+g+"-::sarea_identifier::");var d=$("sarea_"+f+"_list");var b=$("sarea_empty_"+f);if(cloneDraggedItem){var e=c.cloneNode(true)}else{var e=c}e.id=e.id.replace("availablearea_","attachedarea_");e.id=e.id.replace("::sarea_identifier::",f);e.innerHTML=e.innerHTML.replace(new RegExp("availablearea_","g"),"attachedarea_");e.innerHTML=e.innerHTML.replace(new RegExp("::sarea_identifier::","g"),f);e.innerHTML=e.innerHTML.replace(" z-hide","");e.innerHTML=e.innerHTML.replace("##id",f);e.innerHTML=e.innerHTML.replace("##name",a);e.removeClassName("z-draggable");e.removeClassName("z-itemdragleft");e.addClassName("z-sortable");e.addClassName("z-itemsort");e.style.opacity=1;e.style.top=0;e.style.left=0;if(!b.hasClassName("z-hide")){b.addClassName("z-hide")}d.appendChild(e);createSortable("sarea_"+f);createDroppable("sarea_"+f);Zikula.recolor(d.id,"z-itemheader")}function removeProviderAreaFromSubscriberArea(c,e){var d=$("attachedarea_"+e+"-"+c);d.remove();var a=0;var b=$("sarea_"+c);$$("#"+b.id+" li.z-sortable").each(function(f){a++});if(a==0){$("sarea_empty_"+c).removeClassName("z-hide")}Zikula.recolor(b.id,"z-itemheader")}function initAreasSortables(){$A(document.getElementsByClassName("z-sortable")).each(function(b){Element.addClassName(b.id,"z-itemsort")});for(var a=0;a<subscriber_areas.length;a++){createSortable(subscriber_areas[a])}}function createSortable(a){var b=a+"_list";Sortable.create(b,{dropOnEmpty:true,only:"z-sortable",containment:[b],onUpdate:changeAttachedAreaOrder})}function changeAttachedAreaOrder(){var d=this.element.id;var a=$(d.replace("_list","_a")).value;var c="";$$("#"+d+" li.z-sortable").each(function(e){c+="&providerarea[]="+$(e.id+"_a").value});var b="ol_id="+d+"&subscriberarea="+a+c;new Zikula.Ajax.Request("ajax.php?module=Extensions&func=changeproviderareaorder",{parameters:b,onComplete:changeproviderareaorder_response})}function changeproviderareaorder_response(a){if(!a.isSuccess()){Zikula.showajaxerror(a.getMessage());return}var b=a.getData();Zikula.recolor(b.ol_id,$(b.ol_id).down(0).id)}function initAreasDraggables(){$$("ol li.z-draggable").each(function(a){Element.addClassName(a.id,"z-itemdragleft");new Draggable(a.id,{revert:true,ghosting:false})})}function initAreasDroppables(){for(var a=0;a<subscriber_areas.length;a++){createDroppable(subscriber_areas[a])}}function createDroppable(a){Droppables.add(a,{accept:"z-draggable",hoverclass:"z-hook-droppable-active",onHover:function(b,d,c){subscriber_panel.expand(d.retrieve("panelIndex"),false)},onDrop:function(b,g,d){var c={category:$(g.id+"_c").value,area:$(g.id+"_a").value,identifier:$(g.id+"_i").value};var f={category:$(b.id+"_c").value,area:$(b.id+"_a").value,identifier:$(b.id+"_i").value};if(f.category!=c.category){return}var e=false;$$("#"+g.id+" li.z-sortable").each(function(h){if(h.id.split("_")[1].split("-")[0]==f.identifier){e=true;throw $break}});if(e){return}bindSubscriberAreaToProviderArea(c.area,f.area);if(appendItemBeforeResponse){appendProviderAreaToSubscriberArea(c.identifier,c.area,f.identifier)}}})};