var AgendaEdit=function(){function e(){var e="agendaItemAdder mjs-nestedSortable-no-nesting mjs-nestedSortable-disabled",n='<li class="'+e+'"><a href="#"><span class="glyphicon glyphicon-plus-sign"></span> '+__t("admin","agendaAddEntry")+"</a></li>",a=function(e){e.find("> div").prepend('<span class="glyphicon glyphicon-resize-vertical moveHandle"></span>'),e.find("> div > h3").append('<a href="#" class="editAgendaItem"><span class="glyphicon glyphicon-pencil"></span></a>'),e.find("> div > h3").append('<a href="#" class="delAgendaItem"><span class="glyphicon glyphicon-minus-sign"></span></a>')},i=function(e){e.append(n)},t=function(){$("#agendaEditSavingHolder").removeClass("hidden")},d=function(e){var n=[];return e.children(".agendaItem").each(function(){var e=$(this),a=e.attr("id").split("_");n.push({id:a[1],code:e.find("> div > .agendaItemEditForm input[name=code]").val(),title:e.find("> div > .agendaItemEditForm input[name=title]").val(),motionTypeId:e.find("> div > .agendaItemEditForm select[name=motionType]").val(),children:d(e.find("> ol"))})}),n},o=$(".motionListAgenda");o.addClass("agendaListEditing"),o.nestedSortable({handle:".moveHandle",items:"li.agendaItem",toleranceElement:"> div",placeholder:"movePlaceholder",tolerance:"pointer",forcePlaceholderSize:!0,helper:"clone",axis:"y",update:function(){t(),$("ol.motionListAgenda").trigger("antragsgruen:agenda-change")}}),o.find(".agendaItem").each(function(){a($(this))}),i(o),o.find("ol.agenda").each(function(){i($(this))}),o.on("click",".agendaItemAdder a",function(e){e.preventDefault();var n=$($("#agendaNewElementTemplate").val()),d=$(this).parents(".agendaItemAdder").first();d.before(n),a(n),i(n.find("ol.agenda")),n.find(".editAgendaItem").trigger("click"),n.find(".agendaItemEditForm input.code").focus(),t()}),o.on("click",".delAgendaItem",function(e){var n=$(this);e.preventDefault(),bootbox.confirm(__t("admin","agendaDelEntryConfirm"),function(e){e&&(t(),n.parents("li.agendaItem").first().remove(),$("ol.motionListAgenda").trigger("antragsgruen:agenda-change"))})}),o.on("click",".editAgendaItem",function(e){t(),e.preventDefault();var n=$(this).parents("li.agendaItem").first();n.addClass("editing"),n.find("> div > .agendaItemEditForm input[name=code]").focus().select()}),o.on("submit",".agendaItemEditForm",function(e){t();var n=$(this).parents("li.agendaItem").first(),a=$(this),i=a.find("input[name=title]").val(),d=a.find("input[name=code]").val();e.preventDefault(),n.removeClass("editing"),n.data("code",d),n.find("> div > h3 .code").text(d),n.find("> div > h3 .title").text(i),$("ol.motionListAgenda").trigger("antragsgruen:agenda-change")}),$("#agendaEditSavingHolder").submit(function(){var e=d($(".motionListAgenda"));$(this).find("input[name=data]").val(JSON.stringify(e))})}return e}();new AgendaEdit;
//# sourceMappingURL=AgendaEdit.js.map
