define(["require","exports","../shared/AntragsgruenEditor"],function(t,i,e){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),new(function(){function t(){var t=this;this.editors=[],this.collissionEditors={},this.$form=$("#amendmentMergeForm"),this.$collissionHolder=$(".amendmentCollissionsHolder"),this.$checkCollissions=$(".checkAmendmentCollissions"),this.$affectedParagraphs=$(".affectedParagraphs > .paragraph"),this.$otherStatsFields=$(".otherAmendmentStatus input"),this.$stepWizardHolder=$("#MergeSingleWizard").find(".steps"),this.$steps={1:this.$form.find("> .step_1"),2:this.$form.find("> .step_2"),3:this.$form.find("> .step_3")},this.$checkCollissions.click(function(i){i.preventDefault(),t.loadCollissions()}),this.$steps[1].find(".goto_2").click(function(i){i.preventDefault(),t.gotoStep("2")}),this.$affectedParagraphs.each(function(i,e){t.initAffectedParagraph(e)}),this.$form.submit(this.onSubmit.bind(this)),this.gotoStep("1")}return t.prototype.gotoStep=function(t){for(var i in this.$steps)i==t?this.$steps[i].removeClass("hidden"):this.$steps[i].addClass("hidden");this.$stepWizardHolder.children().removeClass("active"),this.$stepWizardHolder.find(".goto_step"+t).addClass("active"),this.$stepWizardHolder.scrollintoview({top_offset:-50})},t.prototype.initAffectedParagraph=function(t){var i=$(t);i.find(".modifySelector input").change(function(){"1"==i.find(".modifySelector input:checked").val()?i.addClass("modified").removeClass("unmodified"):i.removeClass("modified").addClass("unmodified")}).trigger("change");var s=i.data("section-id")+"_"+i.data("paragraph-no");this.editors[s]=new e.AntragsgruenEditor(i.find(".affectedBlock > .texteditor").attr("id"))},t.prototype.loadCollissions=function(){var t=this;this.gotoStep("3");var i=this.$checkCollissions.data("url"),e={},s={};this.$affectedParagraphs.each(function(i,s){var a,o=$(s),n=o.find(".modifySelector input:checked").val(),d=o.data("section-id"),r=o.data("paragraph-no");if(n){var l=t.editors[d+"_"+r].getEditor(),c=l.getData();void 0!==l.plugins.lite?(l.plugins.lite.findPlugin(l).acceptAll(),a=l.getData(),l.setData(c)):a=l.getData()}else a=o.data("unchanged-amendment");void 0===e[o.data("section-id")]&&(e[o.data("section-id")]={}),e[o.data("section-id")][o.data("paragraph-no")]=a}),this.$otherStatsFields.each(function(t,i){var e=$(i);s[e.parents(".selectlist").data("amendment-id")]=e.val()}),$.post(i,{newSections:e,otherAmendmentsStatus:s,_csrf:this.$form.find("> input[name=_csrf]").val()},this.collissionsLoaded.bind(this))},t.prototype.collissionsLoaded=function(t){var i=this;this.collissionEditors={},this.$collissionHolder.html(t);var s=this.$collissionHolder.find(".amendmentOverrideBlock > .texteditor");s.length>0&&s.each(function(t,s){var a=$(s).attr("id");i.collissionEditors[a]=new e.AntragsgruenEditor(a)})},t.prototype.onSubmit=function(){var t=this;this.$affectedParagraphs.each(function(i,e){var s=$(e),a=s.find(".modifiedText");if("1"==s.find(".modifySelector input:checked").val()){var o=s.data("section-id")+"_"+s.data("paragraph-no"),n=t.editors[o].getEditor();void 0!==n.plugins.lite&&n.plugins.lite.findPlugin(n).acceptAll(),a.val(n.getData())}else a.val(s.data("unchanged-amendment"))});for(var i in this.collissionEditors){var e=this.collissionEditors[i].getEditor();void 0!==e.plugins.lite&&e.plugins.lite.findPlugin(e).acceptAll();var s=e.getData();$("#"+i).parents(".amendmentOverrideBlock").first().find("> textarea").val(s)}},t}())});
//# sourceMappingURL=MergeSingleAmendment.js.map
