var AgendaEdit=function(){function e(){var e=this;this.hasChanged=!1,this.delAgendaItemStr='<a href="#" class="delAgendaItem"><span class="glyphicon glyphicon-minus-sign"></span></a>',this.$agendaform=$("#agendaEditSavingHolder");var t=$(".motionListAgenda");t.addClass("agendaListEditing"),t.nestedSortable({handle:".moveHandle",items:"li.agendaItem",toleranceElement:"> div",placeholder:"movePlaceholder",tolerance:"pointer",forcePlaceholderSize:!0,helper:"clone",axis:"y",update:function(){e.showSaver(),$("ol.motionListAgenda").trigger("antragsgruen:agenda-change")}}),t.find(".agendaItem").each(function(t,n){e.prepareAgendaItem($(n))}),this.prepareAgendaList(t),t.find("ol.agenda").each(function(t,n){e.prepareAgendaList($(n))}),t.on("click",".agendaItemAdder a",this.agendaItemAdd.bind(this)),t.on("click",".delAgendaItem",this.delAgendaItem.bind(this)),t.on("click",".editAgendaItem",this.editAgendaItem.bind(this)),t.on("submit",".agendaItemEditForm",this.submitSingleItemForm.bind(this)),this.$agendaform.submit(this.submitCompleteForm.bind(this))}return e.prototype.buildAgendaStruct=function(e){var t=this,n=[];return e.children(".agendaItem").each(function(e,a){var i=$(a),d=i.attr("id").split("_");n.push({id:d[1],code:i.find("> div > .agendaItemEditForm input[name=code]").val(),title:i.find("> div > .agendaItemEditForm input[name=title]").val(),motionTypeId:i.find("> div > .agendaItemEditForm select[name=motionType]").val(),children:t.buildAgendaStruct(i.find("> ol"))})}),n},e.prototype.submitSingleItemForm=function(e){e.preventDefault(),this.showSaver();var t=$(e.target).parents("li.agendaItem").first(),n=$(e.target),a=n.find("input[name=title]").val(),i=n.find("input[name=code]").val();t.removeClass("editing"),t.data("code",i),t.find("> div > h3 .code").text(i),t.find("> div > h3 .title").text(a),$("ol.motionListAgenda").trigger("antragsgruen:agenda-change")},e.prototype.submitCompleteForm=function(){var t=this.buildAgendaStruct($(".motionListAgenda"));this.$agendaform.find("input[name=data]").val(JSON.stringify(t)),$(window).off("beforeunload",e.onLeavePage)},e.prototype.delAgendaItem=function(e){var t=this,n=$(e.target);e.preventDefault(),bootbox.confirm(__t("admin","agendaDelEntryConfirm"),function(e){e&&(t.showSaver(),n.parents("li.agendaItem").first().remove(),$("ol.motionListAgenda").trigger("antragsgruen:agenda-change"))})},e.prototype.editAgendaItem=function(e){e.preventDefault(),this.showSaver();var t=$(e.target).parents("li.agendaItem").first();t.addClass("editing"),t.find("> div > .agendaItemEditForm input[name=code]").focus().select()},e.prototype.agendaItemAdd=function(e){e.preventDefault(),this.showSaver();var t=$($("#agendaNewElementTemplate").val());$(e.target).parents(".agendaItemAdder").first().before(t),this.prepareAgendaItem(t),this.prepareAgendaList(t.find("ol.agenda")),t.find(".editAgendaItem").trigger("click"),t.find(".agendaItemEditForm input.code").focus()},e.prototype.prepareAgendaItem=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(this.delAgendaItemStr)},e.prototype.prepareAgendaList=function(e){e.append('<li class="agendaItemAdder mjs-nestedSortable-no-nesting mjs-nestedSortable-disabled"><a href="#"><span class="glyphicon glyphicon-plus-sign"></span> '+__t("admin","agendaAddEntry")+"</a></li>")},e.prototype.showSaver=function(){$("#agendaEditSavingHolder").removeClass("hidden"),this.hasChanged=!0,$("body").hasClass("testing")||$(window).on("beforeunload",e.onLeavePage)},e.onLeavePage=function(){return __t("std","leave_changed_page")},e}();new AgendaEdit;
//# sourceMappingURL=AgendaEdit.js.map
