source: trunk/admin/themes/default/template/include/add_album.inc.tpl @ 13063

Last change on this file since 13063 was 13063, checked in by plg, 12 years ago

feature 2470 added: ability to create a new album "on the fly" on the
"associate to album" action of the Batch Manager. The code was moved
from the upload form and is now used by the upload form + Batch Manager.

File size: 3.1 KB
Line 
1{footer_script}{literal}
2jQuery(document).ready(function(){
3  function fillCategoryListbox(selectId, selectedValue) {
4    jQuery.getJSON(
5      "ws.php?format=json&method=pwg.categories.getList",
6      {
7        recursive: true,
8        fullname: true,
9        format: "json",
10      },
11      function(data) {
12        jQuery.each(
13          data.result.categories,
14          function(i,category) {
15            var selected = null;
16            if (category.id == selectedValue) {
17              selected = "selected";
18            }
19           
20            jQuery("<option/>")
21              .attr("value", category.id)
22              .attr("selected", selected)
23              .text(category.name)
24              .appendTo("#"+selectId)
25              ;
26          }
27        );
28      }
29    );
30  }
31
32  jQuery(".addAlbumOpen").colorbox({
33    inline:true,
34    href:"#addAlbumForm",
35    onComplete:function(){
36      jQuery("input[name=category_name]").focus();
37    }
38  });
39
40  jQuery("#addAlbumForm form").submit(function(){
41      jQuery("#categoryNameError").text("");
42
43      jQuery.ajax({
44        url: "ws.php?format=json&method=pwg.categories.add",
45        data: {
46          parent: jQuery("select[name=category_parent] option:selected").val(),
47          name: jQuery("input[name=category_name]").val(),
48        },
49        beforeSend: function() {
50          jQuery("#albumCreationLoading").show();
51        },
52        success:function(html) {
53          jQuery("#albumCreationLoading").hide();
54
55          var newAlbum = jQuery.parseJSON(html).result.id;
56          jQuery(".addAlbumOpen").colorbox.close();
57
58          jQuery("#albumSelect").find("option").remove();
59          fillCategoryListbox("albumSelect", newAlbum);
60
61          /* we refresh the album creation form, in case the user wants to create another album */
62          jQuery("#category_parent").find("option").remove();
63
64          jQuery("<option/>")
65            .attr("value", 0)
66            .text("------------")
67            .appendTo("#category_parent")
68          ;
69
70          fillCategoryListbox("category_parent", newAlbum);
71
72          jQuery("#addAlbumForm form input[name=category_name]").val('');
73
74          jQuery("#albumSelection").show();
75
76          return true;
77        },
78        error:function(XMLHttpRequest, textStatus, errorThrows) {
79            jQuery("#albumCreationLoading").hide();
80            jQuery("#categoryNameError").text(errorThrows).css("color", "red");
81        }
82      });
83
84      return false;
85  });
86});
87{/literal}{/footer_script}
88
89<div style="display:none">
90  <div id="addAlbumForm" style="text-align:left;padding:1em;">
91    <form>
92      {'Parent album'|@translate}<br>
93      <select id ="category_parent" name="category_parent">
94        <option value="0">------------</option>
95        {html_options options=$category_parent_options selected=$category_parent_options_selected}
96      </select>
97
98      <br><br>{'Album name'|@translate}<br><input name="category_name" type="text"> <span id="categoryNameError"></span>
99      <br><br><br><input type="submit" value="{'Create'|@translate}"> <span id="albumCreationLoading" style="display:none"><img src="themes/default/images/ajax-loader-small.gif"></span>
100    </form>
101  </div>
102</div>
Note: See TracBrowser for help on using the repository browser.