{footer_script}{literal} jQuery(document).ready(function(){ function fillCategoryListbox(selectId, selectedValue) { jQuery.getJSON( "ws.php?format=json&method=pwg.categories.getList", { recursive: true, fullname: true, format: "json", }, function(data) { jQuery.each( data.result.categories, function(i,category) { var selected = null; if (category.id == selectedValue) { selected = "selected"; } jQuery("") .attr("value", category.id) .attr("selected", selected) .text(category.name) .appendTo("#"+selectId) ; } ); } ); } jQuery(".addAlbumOpen").colorbox({ inline:true, href:"#addAlbumForm", onComplete:function(){ jQuery("input[name=category_name]").focus(); } }); jQuery("#addAlbumForm form").submit(function(){ jQuery("#categoryNameError").text(""); jQuery.ajax({ url: "ws.php?format=json&method=pwg.categories.add", data: { parent: jQuery("select[name=category_parent] option:selected").val(), name: jQuery("input[name=category_name]").val(), }, beforeSend: function() { jQuery("#albumCreationLoading").show(); }, success:function(html) { jQuery("#albumCreationLoading").hide(); var newAlbum = jQuery.parseJSON(html).result.id; jQuery(".addAlbumOpen").colorbox.close(); jQuery("#albumSelect").find("option").remove(); fillCategoryListbox("albumSelect", newAlbum); /* we refresh the album creation form, in case the user wants to create another album */ jQuery("#category_parent").find("option").remove(); jQuery("") .attr("value", 0) .text("------------") .appendTo("#category_parent") ; fillCategoryListbox("category_parent", newAlbum); jQuery("#addAlbumForm form input[name=category_name]").val(''); jQuery("#albumSelection").show(); return true; }, error:function(XMLHttpRequest, textStatus, errorThrows) { jQuery("#albumCreationLoading").hide(); jQuery("#categoryNameError").text(errorThrows).css("color", "red"); } }); return false; }); }); {/literal}{/footer_script}