require(["jquery","xwiki-meta"],function(a,b){a(document).ready(function(){var c=a("form#create");var i=c.find("input.location-name-field");var f=c.find("input.location-parent-field");var h=c.find('input[name="tocreate"]');var g=function(){var m=new XWiki.DocumentReference();if(f.length>0){var o=f.val();if(o==""){if(h.prop("checked")){return false}m=new XWiki.DocumentReference(b.wiki,i.val(),"WebHome")}else{var l=XWiki.Model.resolve(o,XWiki.EntityType.SPACE);if(h.prop("checked")){m=new XWiki.EntityReference(i.val(),XWiki.EntityType.DOCUMENT,l)}else{var n=new XWiki.EntityReference(i.val(),XWiki.EntityType.SPACE,l);m=new XWiki.EntityReference("WebHome",XWiki.EntityType.DOCUMENT,n)}}}else{if(a(".modal-popup").length>0){var l=XWiki.Model.resolve(a("#spaceReference").val(),XWiki.EntityType.SPACE);m=new XWiki.EntityReference(a("#name").val(),XWiki.EntityType.DOCUMENT,l)}else{if(h.prop("checked")){m=b.documentReference.parent}else{m=b.documentReference}}}return XWiki.Model.serialize(m.relativeTo(new XWiki.WikiReference(b.wiki)))};var k=function(l){a("#templateprovider").attr("value",l)};c.submit(function(){var o=a('input[name="type"]:checked');var n=o.attr("data-type");if(n=="blank"){k("");return true}if(n=="template"){var l=o.val();k(l);return true}if(n=="office"){if(i.length>0&&i.val().trim().length==0){return false}var m=g();if(m!=false){window.location=new XWiki.Document(new XWiki.DocumentReference(b.wiki,["XWiki"],"OfficeImporter")).getURL("view","page="+encodeURIComponent(m))}return false}});var d=function(l){var m=l.attr("data-terminal");var n=false;if(m){n=a.parseJSON(l.attr("data-terminal"))}h.prop("checked",n)};var e=false;var j=function(m){var q=f.val();var o=m.attr("data-allowed-spaces");var p=[];if(o){p=a.parseJSON(m.attr("data-allowed-spaces"))}var n=q;if(p.length>0){var l=function(u){for(var s=0;s<p.length;s++){var r=p[s];var t=r+".";if(u.indexOf(t)==0||u==r){return true}}return false};if(l(q)){n=q}else{if(l(b.space)){n=b.space;e=true}else{n=p[0];e=true}}}else{if(e){n=b.space;e=false}}if(q!=n){f.val(n);f.trigger("input")}};c.find(".xwiki-select").on("xwiki:select:updated",function(m){var l=a('input[name="type"]:checked');d(l);j(l)})})});