!function(){var t;t=jQuery,Craft.QuickPostWidget=Garnish.Base.extend({params:null,initFields:null,formHtml:null,$widget:null,$form:null,$saveBtn:null,$errorList:null,loading:!1,init:function(i,e,r,n){this.params=e,this.initFields=r,this.formHtml=n,this.$widget=t("#widget"+i),this.initForm(this.$widget.find("form:first"))},initForm:function(t){var i=this;this.$form=t,this.$saveBtn=this.$form.find("button[type=submit]"),this.initFields();var e=this.$form.find("> .buttons > .btngroup > .menubtn").data("trigger").$container.find("> ul > li > a");this.addListener(this.$form,"submit","handleFormSubmit"),this.addListener(e,"click","saveAndContinueEditing"),this.addListener(e,"keydown",(function(t){t.keyCode!==Garnish.SPACE_KEY&&t.keyCode!==Garnish.RETURN_KEY||(t.preventDefault(),i.saveAndContinueEditing())}))},handleFormSubmit:function(t){t.preventDefault(),this.save(this.onSave.bind(this))},saveAndContinueEditing:function(){this.save(this.gotoEntry.bind(this))},save:function(i){var e=this;if(!this.loading){this.loading=!0,this.$saveBtn.addClass("loading");var r=Garnish.getPostData(this.$form),n=t.extend({enabled:1},r,this.params);Craft.postActionRequest("entries/save-entry",n,(function(r,n){if(e.loading=!1,e.$saveBtn.removeClass("loading"),e.$errorList&&e.$errorList.children().remove(),"success"===n)Craft.cp.displaySuccess(Craft.t("app","Entry saved."),{details:r.elementHtml}),i(r);else if(Craft.cp.displayError(Craft.t("app","Couldn’t save entry.")),r&&r.errors)for(var s in e.$errorList||(e.$errorList=t('<ul class="errors"/>').insertAfter(e.$form)),r.errors)if(r.errors.hasOwnProperty(s))for(var a=0;a<r.errors[s].length;a++){var o=r.errors[s][a];t("<li/>",{text:o}).appendTo(e.$errorList)}}))}},onSave:function(i){var e=t(this.formHtml);if(this.$form.replaceWith(e),Craft.initUiElements(e),this.initForm(e),void 0!==Craft.RecentEntriesWidget)for(var r=0;r<Craft.RecentEntriesWidget.instances.length;r++){var n=Craft.RecentEntriesWidget.instances[r];n.params.sectionId&&n.params.sectionId!=this.params.sectionId||n.addEntry({url:i.cpEditUrl,title:i.title,dateCreated:i.dateCreated,username:i.authorUsername})}},gotoEntry:function(t){Craft.redirectTo(t.cpEditUrl)}})}();
//# sourceMappingURL=QuickPostWidget.js.map