[13063] | 1 | {footer_script}{literal} |
---|
| 2 | jQuery(document).ready(function(){ |
---|
| 3 | jQuery(".addAlbumOpen").colorbox({ |
---|
[23944] | 4 | inline: true, |
---|
| 5 | href: "#addAlbumForm", |
---|
| 6 | onComplete: function() { |
---|
[13063] | 7 | jQuery("input[name=category_name]").focus(); |
---|
[23944] | 8 | |
---|
| 9 | jQuery("#category_parent").html('<option value="0">------------</option>') |
---|
| 10 | .append(jQuery("#albumSelect").html()) |
---|
| 11 | .val(jQuery("#albumSelect").val()); |
---|
[13063] | 12 | } |
---|
| 13 | }); |
---|
| 14 | |
---|
[23944] | 15 | jQuery("#addAlbumForm form").submit(function() { |
---|
[13063] | 16 | jQuery("#categoryNameError").text(""); |
---|
[23944] | 17 | |
---|
| 18 | var parent_id = jQuery("select[name=category_parent] option:selected").val(), |
---|
| 19 | name = jQuery("input[name=category_name]").val(); |
---|
[13063] | 20 | |
---|
| 21 | jQuery.ajax({ |
---|
[23944] | 22 | url: "ws.php", |
---|
| 23 | dataType: 'json', |
---|
[13063] | 24 | data: { |
---|
[23944] | 25 | format: 'json', |
---|
| 26 | method: 'pwg.categories.add', |
---|
| 27 | parent: parent_id, |
---|
| 28 | name: name |
---|
[13063] | 29 | }, |
---|
| 30 | beforeSend: function() { |
---|
| 31 | jQuery("#albumCreationLoading").show(); |
---|
| 32 | }, |
---|
[23944] | 33 | success: function(data) { |
---|
[13063] | 34 | jQuery("#albumCreationLoading").hide(); |
---|
| 35 | jQuery(".addAlbumOpen").colorbox.close(); |
---|
| 36 | |
---|
[23944] | 37 | var newAlbum = data.result.id, |
---|
| 38 | newAlbum_name = ''; |
---|
| 39 | |
---|
| 40 | if (parent_id!=0) { |
---|
| 41 | newAlbum_name = jQuery("#category_parent").find("option[value="+ parent_id +"]").text() +' / '; |
---|
| 42 | } |
---|
| 43 | newAlbum_name+= name; |
---|
| 44 | |
---|
| 45 | var new_option = jQuery("<option/>") |
---|
| 46 | .attr("value", newAlbum) |
---|
| 47 | .attr("selected", "selected") |
---|
| 48 | .text(newAlbum_name); |
---|
| 49 | |
---|
| 50 | jQuery("#albumSelect").find("option").removeAttr('selected'); |
---|
| 51 | |
---|
| 52 | if (parent_id==0) { |
---|
[23952] | 53 | jQuery("#albumSelect").prepend(new_option); |
---|
[23944] | 54 | } |
---|
| 55 | else { |
---|
| 56 | jQuery("#albumSelect").find("option[value="+ parent_id +"]").after(new_option); |
---|
| 57 | } |
---|
[13063] | 58 | |
---|
| 59 | jQuery("#addAlbumForm form input[name=category_name]").val(''); |
---|
| 60 | jQuery("#albumSelection").show(); |
---|
| 61 | |
---|
| 62 | return true; |
---|
| 63 | }, |
---|
[23944] | 64 | error: function(XMLHttpRequest, textStatus, errorThrows) { |
---|
[13063] | 65 | jQuery("#albumCreationLoading").hide(); |
---|
| 66 | jQuery("#categoryNameError").text(errorThrows).css("color", "red"); |
---|
| 67 | } |
---|
| 68 | }); |
---|
| 69 | |
---|
| 70 | return false; |
---|
| 71 | }); |
---|
| 72 | }); |
---|
| 73 | {/literal}{/footer_script} |
---|
| 74 | |
---|
| 75 | <div style="display:none"> |
---|
| 76 | <div id="addAlbumForm" style="text-align:left;padding:1em;"> |
---|
| 77 | <form> |
---|
| 78 | {'Parent album'|@translate}<br> |
---|
[23944] | 79 | <select id="category_parent" name="category_parent"> |
---|
[13063] | 80 | </select> |
---|
[23944] | 81 | <br><br> |
---|
| 82 | |
---|
| 83 | {'Album name'|@translate}<br> |
---|
| 84 | <input name="category_name" type="text" maxlength="255"> <span id="categoryNameError"></span> |
---|
| 85 | <br><br><br> |
---|
| 86 | |
---|
| 87 | <input type="submit" value="{'Create'|@translate}"> |
---|
| 88 | <span id="albumCreationLoading" style="display:none"><img src="themes/default/images/ajax-loader-small.gif"></span> |
---|
[13063] | 89 | </form> |
---|
| 90 | </div> |
---|
| 91 | </div> |
---|