if(typeof(XWiki)=="undefined"){XWiki=new Object()
}if(typeof(XWiki.editors)=="undefined"){XWiki.editors=new Object()
}XWiki.editors.XDataEditors=Class.create({initialize:function(){this.classDocument=$$("meta[name=document]")[0].content;
this.classDocumentName=$$("meta[name=page]")[0].content;
this.classDocumentSpace=$$("meta[name=space]")[0].content;
this.urlEditTemplate="$xwiki.getURL('__space__.__page__', 'edit')".replace("__space__",this.classDocumentSpace).replace("__page__",this.classDocumentName);
this.urlAddPropertyTemplate="$xwiki.getURL('__space__.__page__', 'propadd')".replace("__space__",this.classDocumentSpace).replace("__page__",this.classDocumentName);
$$(".xclass").each(function(a){this.enhanceClassUX(a)
}.bind(this));
this.ajaxObjectAdd($("add_xobject"));
this.ajaxPropertyAdd();
this.makeSortable($("xwikiclassproperties"));
this.classSwitcherBehavior();
this.ajaxRemoveDeprecatedProperties($("body"),".syncAllProperties")
},enhanceClassUX:function(a){this.expandCollapseClass(a);
a.select(".xobject").each(function(b){this.enhanceObjectUX(b)
}.bind(this));
a.select(".xproperty").each(function(b){this.expandCollapseMetaProperty(b);
this.ajaxPropertyDeletion(b);
this.makeDisableVisible(b)
}.bind(this));
this.ajaxObjectAdd(a)
},enhanceObjectUX:function(a){this.ajaxObjectDeletion(a);
this.editButtonBehavior(a);
this.expandCollapseObject(a);
this.ajaxRemoveDeprecatedProperties(a,".syncProperties")
},ajaxObjectAdd:function(a){if(!a){return
}a.select(".xobject-add-control").each(function(b){b.observe("click",function(g){b.blur();
g.stop();
var d,e,f;
if(b.href){d=b.href.replace(/[?&]xredirect=[^&]*/,"");
e=true
}else{var c=a.down("select");
if(c&&c.selectedIndex>=0){f=c.options[c.selectedIndex].value
}e=f&&f!="-";
d=this.urlEditTemplate+"?xpage=editobject&xaction=addObject&className="+f
}if(!b.disabled&&e){new Ajax.Request(d,{onCreate:function(){b.disabled=true;
b.notification=new XWiki.widgets.Notification("$msg.get('core.editors.object.add.inProgress')","inprogress")
},onSuccess:function(h){var i=b.up(".add_xobject");
if(i){var k;
if(i.up(".xclass")){i.insert({before:h.responseText});
k=i.previous()
}else{i.insert({after:h.responseText});
k=i.next()
}if(k){var m;
if(k.hasClassName("xclass")){this.enhanceClassUX(k);
m=k.down(".xobject")
}else{if(k.hasClassName("xobject")){this.enhanceObjectUX(k);
var j=k.id.replace(/^xobject_/,"xclass_").replace(/_\d+$/,"");
var l=$(j);
if(l){l.down(".add_xobject").insert({before:k});
this.updateXObjectCount(l)
}m=k
}}m.removeClassName("collapsed");
m.up(".xclass").removeClassName("collapsed")
}}b.notification.replace(new XWiki.widgets.Notification("$msg.get('core.editors.object.add.done')","done"))
}.bind(this),onFailure:function(h){var i=h.statusText;
if(h.statusText==""||h.status==12031){i="Server not responding"
}b.notification.replace(new XWiki.widgets.Notification("$msg.get('core.editors.object.add.failed')"+i,"error"))
},onComplete:function(){b.disabled=false
},on1223:function(h){h.request.options.onSuccess(h)
},on0:function(h){h.request.options.onFailure(h)
}})
}}.bindAsEventListener(this))
}.bind(this))
},ajaxObjectDeletion:function(a){var b=a.down("a.delete");
b.observe("click",function(c){b.blur();
c.stop();
if(!b.disabled){new XWiki.widgets.ConfirmedAjaxRequest(b.href,{onCreate:function(){b.disabled=true
},onSuccess:function(){var d=b.up(".xobject");
var e=d.up(".xclass");
d.remove();
this.updateXObjectCount(e)
}.bind(this),onComplete:function(){b.disabled=false
}},{confirmationText:"$msg.get('core.editors.object.delete.confirm')",progressMessageText:"$msg.get('core.editors.object.delete.inProgress')",successMessageText:"$msg.get('core.editors.object.delete.done')",failureMessageText:"$msg.get('core.editors.object.delete.failed')"})
}}.bindAsEventListener(this))
},ajaxRemoveDeprecatedProperties:function(a,b){a.select(b).each(function(c){c.observe("click",function(d){c.blur();
d.stop();
if(!c.disabled){new Ajax.Request(c.href,{onCreate:function(){c.disabled=true;
c.notification=new XWiki.widgets.Notification("$msg.get('core.editors.object.removeDeprecatedProperties.inProgress')","inprogress")
},onSuccess:function(e){a.select(".deprecatedProperties").invoke("remove");
c.notification.replace(new XWiki.widgets.Notification("$msg.get('core.editors.object.removeDeprecatedProperties.done')","done"))
},onFailure:function(e){var f=e.statusText;
if(e.statusText==""||e.status==12031){f="Server not responding"
}c.notification.replace(new XWiki.widgets.Notification("$msg.get('core.editors.object.removeDeprecatedProperties.failed')"+f,"error"))
},onComplete:function(){c.disabled=false
},on1223:function(e){e.request.options.onSuccess(e)
},on0:function(e){e.request.options.onFailure(e)
}})
}})
})
},ajaxPropertyAdd:function(){$$("input[name=action_propadd]").each(function(b){b._x_propnameElt=$("propname");
b._x_proptypeElt=$("proptype");
b._x_form_tokenElt=$("form_token");
var a=b._x_form_tokenElt?b._x_form_tokenElt.value:"";
b.observe("click",function(d){b.blur();
d.stop();
if(!b.disabled&&b._x_propnameElt.value!=""&&b._x_proptypeElt.selectedIndex>=0){var c=this.urlAddPropertyTemplate+"?propname="+b._x_propnameElt.value+"&proptype="+b._x_proptypeElt.options[b._x_proptypeElt.selectedIndex].value+"&xredirect="+encodeURIComponent(this.urlEditTemplate+"?xpage=editclass&xaction=displayProperty&propName="+b._x_propnameElt.value)+"&form_token="+b._x_form_tokenElt.value;
new Ajax.Request(c,{onCreate:function(){b.disabled=true;
b.notification=new XWiki.widgets.Notification("$msg.get('core.editors.class.addProperty.inProgress')","inprogress")
},onSuccess:function(e){$("xclassContent").insert({bottom:e.responseText});
var f=$("xclassContent").lastChild;
this.expandCollapseMetaProperty(f);
this.makeSortable(f);
this.ajaxPropertyDeletion(f);
this.makeDisableVisible(f);
b.notification.replace(new XWiki.widgets.Notification("$msg.get('core.editors.class.addProperty.done')","done"))
}.bind(this),onFailure:function(e){var f=e.statusText;
if(e.statusText==""||e.status==12031){f="Server not responding"
}b.notification.replace(new XWiki.widgets.Notification("$msg.get('core.editors.class.addProperty.failed')"+f,"error"))
},onComplete:function(){b.disabled=false
},on1223:function(e){e.request.options.onSuccess(e)
},on0:function(e){e.request.options.onFailure(e)
}})
}}.bindAsEventListener(this))
}.bind(this))
},ajaxPropertyDeletion:function(b){var a=b.down("a.delete");
a.observe("click",function(c){a.blur();
c.stop();
if(!a.disabled){new XWiki.widgets.ConfirmedAjaxRequest(a.href,{onCreate:function(){a.disabled=true
},onSuccess:function(){b.remove()
},onComplete:function(){a.disabled=false
}},{confirmationText:"$msg.get('core.editors.class.deleteProperty.confirm')",progressMessageText:"$msg.get('core.editors.class.deleteProperty.inProgress')",successMessageText:"$msg.get('core.editors.class.deleteProperty.done')",failureMessageText:"$msg.get('core.editors.class.deleteProperty.failed')"})
}})
},makeDisableVisible:function(a){a.down(".disabletool input").observe("click",function(b){a.toggleClassName("disabled")
})
},editButtonBehavior:function(a){var b=a.down("a.edit");
if(!b){return
}b.observe("click",function(c){b.blur();
c.stop();
window.location=b.href
}.bindAsEventListener())
},updateXObjectCount:function(c){var b=c.select(".xobject").size();
if(b==0){c.remove()
}else{var a=c.down(".xclass_xobject_nb");
if(typeof(a)!="undefined"){a.update("("+b+")")
}}},expandCollapseObject:function(b){totalItems=$$("#xwikiobjects .xobject").size();
b.addClassName("collapsable");
if(totalItems>1){b.toggleClassName("collapsed")
}var a=b.down(".xobject-title");
a.observe("click",function(c){a.up().toggleClassName("collapsed")
}.bindAsEventListener());
b.select(".xobject-content dt").each(function(d){if(!d.down("input[type=checkbox]")){d.addClassName("collapsable");
var c=new Element("span",{"class":"collapser"});
c.observe("click",function(e){this.up("dt").next("dd").toggle();
this.toggleClassName("collapsed")
}.bindAsEventListener(c));
d.insert({top:c})
}else{d.addClassName("uncollapsable")
}});
b.select(".xobject-content dt label").each(function(c){c.observe("click",function(d){if(c.up("dt").down("span").hasClassName("collapsed")){c.up("dt").next("dd").toggle();
c.up("dt").down("span").toggleClassName("collapsed")
}}.bindAsEventListener())
})
},expandCollapseClass:function(b){b.addClassName("collapsable");
var a=b.down(".xclass-title");
a.observe("click",function(c){a.up().toggleClassName("collapsed")
}.bindAsEventListener())
},expandCollapseMetaProperty:function(b){b.addClassName("collapsable");
b.addClassName("collapsed");
var a=b.down(".xproperty-title");
a.observe("click",function(c){a.up().toggleClassName("collapsed")
}.bindAsEventListener());
b.select(".xproperty-content dt").each(function(d){if(!d.down("input[type=checkbox]")){d.addClassName("collapsable");
var c=new Element("span",{"class":"collapser"});
c.observe("click",function(e){this.up("dt").next("dd").toggle();
this.toggleClassName("collapsed")
}.bindAsEventListener(c));
d.insert({top:c})
}else{d.addClassName("uncollapsable")
}});
b.select(".xproperty-content dt label").each(function(c){c.observe("click",function(d){if(c.up("dt").down("span").hasClassName("collapsed")){c.up("dt").next("dd").toggle();
c.up("dt").down("span").toggleClassName("collapsed")
}}.bindAsEventListener())
})
},classSwitcherBehavior:function(){var a=$$("#switch-xclass #classname");
if(a.size()>0){a=a[0];
a.observe("change",function(){var b=this.options[this.selectedIndex].value;
if(b!="-"){new XWiki.widgets.ConfirmationBox({onYes:function(){document.fire("xwiki:actions:save",{"continue":true,form:$("propupdate")});
document.observe("xwiki:document:saved",function(){window.self.location=b
})
},onNo:function(){window.self.location=b
}},{confirmationText:"$msg.get('core.editors.class.switchClass.confirm')"})
}}.bindAsEventListener(a));
a.up("form").down("input[type='submit']").hide();
a.up("form").down(".warningmessage").hide()
}},makeSortable:function(a){if(!a){return
}a.select(".xproperty-content").each(function(b){b.select("input").each(function(c){if(c.id.endsWith("_number")){b.numberProperty=c;
c.up().hide();
if(c.up().previous("dt")){c.up().previous("dt").hide()
}}})
});
a.select(".xproperty-title .tools").each(function(c){var b=new Element("span",{"class":"tool move",title:"Drag and drop to change the order"}).update("move");
c.makePositioned();
c.appendChild(b);
b.observe("click",function(d){d.stop()
}.bindAsEventListener())
});
Sortable.create("xclassContent",{tag:"div",only:"xproperty",handle:"move",starteffect:this.startDrag.bind(this),endeffect:this.endDrag.bind(this),onUpdate:this.updateOrder.bind(this)})
},updateOrder:function(a){var c=a.childElements();
for(var b=0;
b<c.size();
++b){var d=c[b].down(".xproperty-content");
d.numberProperty.value=b+1
}},startDrag:function(a){a.addClassName("dragged");
$("xclassContent").childElements().each(function(b){b._expandedBeforeDrag=!b.hasClassName("collapsed");
b.addClassName("collapsed")
})
},endDrag:function(a){a.removeClassName("dragged");
$("xclassContent").childElements().each(function(b){if(b._expandedBeforeDrag){b.removeClassName("collapsed")
}})
}});
document.observe("xwiki:dom:loaded",function(){new XWiki.editors.XDataEditors()
});