define("editableProperty",["jquery","xwiki-meta"],function(a,b){a.fn.editableProperty=function(){return this.each(f)};var f=function(){if(a(this).find(".editableProperty-edit").length===0){var k=a('<a href="#editProperty" class="editableProperty-edit"></a>');k.attr("title","Edit");k.html("<span class=\"fa fa-pencil\"></span>");var j=a('<a href="#cancelProperty" class="editableProperty-cancel"></a>');j.attr("title","Cancel");j.hide().html("<span class=\"fa fa-times\"></span>");var m=a('<a href="#saveProperty" class="editableProperty-save"></a>');m.attr("title","Save");m.hide().html("<span class=\"fa fa-check\"></span>");a(this).find("label").after(k,j,m)}var l=a(this).next("dd").addClass("editableProperty-viewer");a('<dd class="editableProperty-editor"/>').hide().insertAfter(l)};a(document).on("click.editProperty",".editableProperty-edit",function(k){k.preventDefault();var j=a(this);if(!j.hasClass("disabled")){e(j.closest(".editableProperty"))}});a(document).on("click.saveProperty",".editableProperty-save",function(j){j.preventDefault();var k=a(this);if(!k.hasClass("disabled")){h(k.closest(".editableProperty"))}});a(document).on("click.cancelProperty",".editableProperty-cancel",function(k){k.preventDefault();var j=a(this);if(!j.hasClass("disabled")){g(j.closest(".editableProperty"))}});var e=function(k){var j=k.find(".editableProperty-edit").addClass("disabled");return a.get(XWiki.currentDocument.getURL("get"),{xpage:"display",mode:"edit",property:k.data("property"),type:k.data("propertyType"),language:b.locale}).done(function(l,o,n){i(n.getResponseHeader("X-XWIKI-HTML-HEAD"));j.hide();k.find(".editableProperty-save, .editableProperty-cancel").show();var m=k.next(".editableProperty-viewer").hide().next(".editableProperty-editor");m.html(l).show();a(document).trigger("xwiki:dom:updated",{elements:m.toArray()});m.find(":input").filter(":visible").focus()}).fail(function(){new XWiki.widgets.Notification("Failed to edit property.","error")}).always(function(){j.removeClass("disabled")})};var g=function(j){j.next(".editableProperty-viewer").show().next(".editableProperty-editor").hide();j.find(".editableProperty-save, .editableProperty-cancel").hide();j.find(".editableProperty-edit").show()};var c=function(m){m.find(".editableProperty-save, .editableProperty-cancel").addClass("disabled");var j=m.next(".editableProperty-viewer").next(".editableProperty-editor");j.trigger("xwiki:actions:beforeSave");var k=j.find(":input").serializeArray();k.push({name:"language",value:b.locale});k.push({name:"comment",value:"Update property "+m.data("property")});k.push({name:"minorEdit",value:true});k.push({name:"form_token",value:b.form_token});k.push({name:"ajax",value:true});var l=new XWiki.widgets.Notification("Saving...","inprogress");return a.post(XWiki.currentDocument.getURL("save"),k).done(function(){j.trigger("xwiki:document:saved");l.replace(new XWiki.widgets.Notification("Saved","done"))}).fail(function(n){j.trigger("xwiki:document:saveFailed");l.replace(new XWiki.widgets.Notification("Failed to save the page. Reason: <span id=\"saveFailureReason\"/>","error"));a("#saveFailureReason").text(n.statusText)}).always(function(){m.find(".editableProperty-save, .editableProperty-cancel").removeClass("disabled")})};var d=function(j){return a.get(XWiki.currentDocument.getURL("get"),{xpage:"display",property:j.data("property"),type:j.data("propertyType"),language:b.locale}).done(function(k,n,l){i(l.getResponseHeader("X-XWIKI-HTML-HEAD"));g(j);var m=j.next(".editableProperty-viewer").html(k);a(document).trigger("xwiki:dom:updated",{elements:m.toArray()})}).fail(function(){new XWiki.widgets.Notification("Failed to view property.","error")})};var h=function(j){return c(j).then(a.proxy(d,null,j))};var i=function(l){var j;var k=function(){return a("link, script").map(function(){return a(this).attr("href")||a(this).attr("src")}).get()};a("<div/>").html(l).find("link, script").filter(function(){if(!j){j=k()}var m=a(this).attr("href")||a(this).attr("src");return j.indexOf(m)<0}).appendTo("head")}});require(["jquery","editableProperty","xwiki-events-bridge"],function(a){var b=function(d,e){var c=a((e&&e.elements)||document);c.find("dt.editableProperty").editableProperty()};a(document).on("xwiki:dom:updated",b);XWiki.domIsLoaded&&b()});