if(typeof(XWiki)=="undefined"){XWiki=new Object()}if(typeof(XWiki.blog)=="undefined"){XWiki.blog=new Object()}XWiki.blog.Categories=Class.create({categoriesSelector:".blog-category-level",activeForm:false,initialize:function(){if($$(".blog-categories-list")){this.addDeleteListener();this.addAddSubcategoryListener();this.addAddCategoryListener();this.addRenameListener()}},activateForm:function(a){if(this.activeForm){this.activeForm.hide()}a.show();this.activeForm=a;a.down("input[type=text]").focus()},addRenameListener:function(){$$(".blog-category-level").each(function(a){a=a.down("a.rename");if(!a){return}a.observe("click",function(b){a.blur();b.stop();if(a.disabled){return}else{this.createRenameForm(a)}}.bindAsEventListener(this))}.bind(this))},createRenameForm:function(b){var a=b.up(".blog-categories-list");if(!a._x_rename_form){if(!a.disabled){new Ajax.Request("/en/Blog/ManageCategories?xpage=plain&display=renameForm&ajax=1",{onCreate:function(){a.disabled=true;a.notification=new XWiki.widgets.Notification("Fetching form...","inprogress")},onSuccess:function(d){var c=new Element("div");c.update(d.responseText);a._x_rename_form=c.down("form");this.ajaxifyRenameForm(a._x_rename_form);this.insertRenameForm(b,a._x_rename_form)}.bind(this),onFailure:function(c){new XWiki.widgets.Notification(c.responseText||"Server not responding","error")},on0:function(c){c.request.options.onFailure(c)},onComplete:function(){a.disabled=false;a.notification.hide()}})}}else{this.insertRenameForm(b,a._x_rename_form)}},insertRenameForm:function(c,b){b._x_item=c;c.up(".blog-category-tools").insert({after:b});var a=b.down("input[name=category]");a.value=decodeURIComponent(c.href.substring(c.href.indexOf("category=")+9).replace(/\+/g," "));this.activateForm(b)},ajaxifyRenameForm:function(a){a.setAttribute("autocomplete","off");a.down("input[type=text]").setAttribute("autocomplete","off");a.down("input[type=text]").setAttribute("autocomplete","off");a.observe("submit",function(b){b.stop();a.down("input[type=text]").focus();if(a.newCategoryName.value!=""){new Ajax.Request(a.action+"?ajax=1&xpage=plain&display=list&"+a.serialize(),{onCreate:function(){a.disable();a.notification=new XWiki.widgets.Notification("Renaming category...","inprogress")},onSuccess:function(c){$$(".blog-categories-list").first().replace(c.responseText);this.initialize();a.reset()}.bind(this),onFailure:function(c){new XWiki.widgets.Notification(c.responseText||"Server not responding","error")},onComplete:function(){a.enable();a.notification.hide()},on403:function(c){new XWiki.widgets.Notification("You are not allowed to create the target page","error")},on404:function(c){new XWiki.widgets.Notification("Invalid category, please refresh the page to update the category tree","error")},on409:function(c){new XWiki.widgets.Notification("Target page already exists, please choose a different name","error")},on0:function(c){c.request.options.onFailure(c)}})}}.bindAsEventListener(this));a.down("a").observe("click",function(b){this.reset();b.stop()}.bindAsEventListener(a));a.observe("reset",function(){a.hide()})},addAddSubcategoryListener:function(){$$(".blog-category-level").each(function(a){a=a.down("a.add-subcategory");if(!a){return}a.observe("click",function(b){a.blur();b.stop();if(a.disabled){return}else{this.createAddSubcategoryForm(a)}}.bindAsEventListener(this))}.bind(this))},addAddCategoryListener:function(){$$(".blog-add-category-label a").each(function(a){a.observe("click",function(b){a.blur();b.stop();this.createAddSubcategoryForm(a)}.bindAsEventListener(this))}.bind(this))},createAddSubcategoryForm:function(f){var d=f.up(".blog-categories-list");var g={};var a=f.getAttribute("href").toQueryParams();var e=a.entry;if(e&&e!=""){g.entry=e}var c=a.entryObjNb;if(c&&c!=""){g.entryObjNb=c}var h=a.categoriesSpace;if(h&&h!=""){g.categoriesSpace=h}var b=a.parentCategory;if(b&&b!=""){g.categoryParent=b}if(!d._x_add_form){if(!d.disabled){new Ajax.Request("/en/Blog/ManageCategories?xpage=plain&display=addForm&ajax=1",{parameters:g,onCreate:function(){d.disabled=true;d.notification=new XWiki.widgets.Notification("Fetching form...","inprogress")},onSuccess:function(j){var i=new Element("div");i.update(j.responseText);d._x_add_form=i.down("form");this.ajaxifyAddForm(d._x_add_form);this.insertAddForm(f,d._x_add_form)}.bind(this),onFailure:function(i){new XWiki.widgets.Notification(i.responseText||"Server not responding","error")},on0:function(i){i.request.options.onFailure(i)},onComplete:function(){d.disabled=false;d.notification.hide()}})}}else{this.insertAddForm(f,d._x_add_form)}},insertAddForm:function(e,d){d._x_item=e;var b=d.down("select");b.selectedIndex=0;if(e.hasClassName("tool")){var a="option[value='"+decodeURIComponent(e.href.substring(e.href.indexOf("parentCategory=")+15).replace(/\+/g," ")).replace(/\\/g,"\\\\").replace(/'/g,"\\'")+"']";var c=b.down(a);if(c){b.selectedIndex=c.index}b.up("label").hide();e.up(".blog-category-tools").insert({after:d})}else{e.up("ul").insert({after:d});b.up("label").show()}this.activateForm(d)},ajaxifyAddForm:function(a){var c="ajax=1&xpage=plain&";var b="?";if(a.action.toQueryParams().entry){b="&"}c=b+c;a.setAttribute("autocomplete","off");a.down("input[type=text]").setAttribute("autocomplete","off");a.down("input[type=text]").setAttribute("autocomplete","off");a.observe("submit",function(d){d.stop();a.down("input[type=text]").focus();if(a.newCategoryName.value!=""){new Ajax.Request(a.action+c+"mode=select&"+a.serialize(),{onCreate:function(){a.disable();a.notification=new XWiki.widgets.Notification("Adding category...","inprogress")},onSuccess:function(e){var f=[];$$(".blog-categories-list").each(function(g){g.select("input[type=checkbox]").each(function(h){if(h.checked){f.push(h.value)}})});$$(".blog-categories-list").first().replace(e.responseText);this.initialize();a.reset();$$(".blog-categories-list").each(function(g){g.select("input[type=checkbox]").each(function(h){h.checked=false;if(!h.checked&&f.contains(h.value)){h.checked=true}})})}.bind(this),onFailure:function(e){new XWiki.widgets.Notification(e.responseText||"Server not responding","error")},onComplete:function(){a.enable();a.notification.hide()},on401:function(e){new XWiki.widgets.Notification("You have been logged out, please refresh and log in","error")},on403:function(e){new XWiki.widgets.Notification("You are not allowed to create the target page","error")},on409:function(e){new XWiki.widgets.Notification("Target page already exists, please choose a different name","error")},on0:function(e){e.request.options.onFailure(e)}})}}.bindAsEventListener(this));a.down("a").observe("click",function(d){this.reset();d.stop()}.bindAsEventListener(a));a.observe("reset",function(){a.hide()})},addDeleteListener:function(){$$(".blog-category-level").each(function(a){a=a.down("a.delete");if(!a){return}a.observe("click",function(b){a.blur();b.stop();if(a.disabled){return}else{new XWiki.widgets.ConfirmedAjaxRequest(a.href+"&display=list&xpage=plain&ajax=1",{onCreate:function(){a.disabled=true},onSuccess:function(c){$$(".blog-categories-list").first().replace(c.responseText);this.initialize()}.bind(this),onComplete:function(){a.disabled=false}},{confirmationText:"Are you sure you want to delete this category? This action is not reversible.",progressMessageText:"Deleting category...",successMessageText:"Deleted",failureMessageText:"Failed to delete category"})}}.bindAsEventListener(this))}.bind(this))}});document.observe("xwiki:dom:loaded",function(){new XWiki.blog.Categories();$$(".blog-categories-list.subcategories").each(function(a){var d='<span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span>';var e='<span class="glyphicon glyphicon-chevron-up" aria-hidden="true"></span>';var c=new Element("a",{"class":"subcat-toggle-link"}).update(d);var b=a.down("div",1);c.observe("click",function(){b.toggle();c.update(b.visible()?e:d)});a.down("strong").insert({after:c});a.down("strong").insert({after:"&nbsp;&nbsp;"});b.toggle()})});