{"version":3,"sources":["editentry/src/EntryTypeSwitcher.js"],"names":["$","Craft","EntryTypeSwitcher","Garnish","Base","extend","$typeSelect","init","$spinner","insertAfter","parent","this","addListener","postActionRequest","ev","addClass","textStatus","cp","$primaryForm","serialize","response","trigger","tabsHtml","replaceWith","$contentHeader","$tabs","length","id","class","prependTo","appendTo","attr","html","fieldsHtml","appendFootHtml","slugGenerator","setNewSource","appendHeadHtml","headHtml","bodyHtml","checkForm","window","draftEditor","jQuery"],"mappings":"CAAA,SAACA,GAEGC,MAAAC,kBAAAC,QAAAC,KAAAC,OAAA,CACMH,YAAAA,KACFI,SAAa,KAGTC,KAAE,WACGD,KAAAA,YAAgBN,EAAA,cAChBQ,KAAAA,SAAaR,EAAA,iCAAiCS,YAAiBH,KAAAA,YAALI,UANzBC,KAAAC,YAAAD,KAAAL,YAAA,SAAA,iBActCL,aAAMY,SAAkBC,GACpBH,KAAKH,SAASO,YAAS,UAEnBC,MAAAA,kBAAJ,4BAA8Bf,MAAAgB,GAAAC,aAAAC,YAAA,CAAAC,EAAAJ,KAA9B,GACSK,KAAAA,SAAQN,SAAA,UADE,YAAfC,EAA0B,CAKtBI,KAASE,QAAU,oBAETC,MAAAA,EAAYH,EAAAA,SAEZI,GAAAA,EAAAA,SACE,GAAAC,EAAAC,OACGD,EAAAF,YAAAH,EAAAE,cACI,CACJA,MAAXE,EAA8BA,EAAAA,YAAqB,CACtDG,GAAA,iBACEC,MAAA,gBACFC,UAAD7B,EAAA,aACHA,EAAAoB,EAAAE,UAAAQ,SAAAN,GAAAO,KAAA,KAAA,aAIYC,EAAAA,mBAAcC,SAGrBC,MAAAA,GAAAA,WAGFlC,EAAOmC,WAAAA,KAAPf,EAAyBa,YACzBE,MAAcC,eAAapC,EAAA,YAC9BC,MAAAoC,eAAAjB,EAAAkB,UALDrC,MAAMiC,eAAed,EAASmB,UAU9B,oBAAmBC,eACtBL,cAAAC,aAAA,UApDbzB,KAAAU,QAAA,cAmDgBoB,OAAOC,YAAYF,kBAtDvC,CA2DGG","file":"EntryTypeSwitcher.min.js","sourcesContent":["(function($) {\n    /** global: Craft */\n    /** global: Garnish */\n    Craft.EntryTypeSwitcher = Garnish.Base.extend({\n        $typeSelect: null,\n        $spinner: null,\n\n        init: function() {\n            this.$typeSelect = $('#entryType');\n            this.$spinner = $('<div class=\"spinner hidden\"/>').insertAfter(this.$typeSelect.parent());\n\n            this.addListener(this.$typeSelect, 'change', 'onTypeChange');\n        },\n\n        onTypeChange: function(ev) {\n            this.$spinner.removeClass('hidden');\n\n            Craft.postActionRequest('entries/switch-entry-type', Craft.cp.$primaryForm.serialize(), (response, textStatus) => {\n                this.$spinner.addClass('hidden');\n\n                if (textStatus === 'success') {\n                    this.trigger('beforeTypeChange');\n\n                    const $tabs = $('#tabs');\n\n                    if (response.tabsHtml) {\n                        if ($tabs.length) {\n                            $tabs.replaceWith(response.tabsHtml);\n                        } else {\n                            const $contentHeader = $('<header/>', {\n                                id: 'content-header',\n                                class: 'pane-header',\n                            }).prependTo($('#content'));\n                            $(response.tabsHtml).appendTo($contentHeader).attr('id', 'tabs');\n                        }\n                    } else {\n                        $('#content-header').remove();\n                    }\n\n                    Craft.cp.initTabs();\n\n                    $('#fields').html(response.fieldsHtml);\n                    Craft.initUiElements($('#fields'));\n                    Craft.appendHeadHtml(response.headHtml);\n                    Craft.appendFootHtml(response.bodyHtml);\n\n                    // Update the slug generator with the new title input\n                    if (typeof slugGenerator !== 'undefined') {\n                        slugGenerator.setNewSource('#title');\n                    }\n\n                    this.trigger('typeChange');\n\n                    // Trigger an autosave with the new form data\n                    window.draftEditor.checkForm();\n                }\n            });\n        }\n    });\n})(jQuery);\n"]}