aboutsummaryrefslogtreecommitdiffstats
path: root/admin/themes/default/template/include/add_album.inc.tpl
blob: acbdc948a8123a3fe512653473a1301bfcd5356c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{footer_script}{literal}
jQuery(document).ready(function(){
  jQuery(".addAlbumOpen").colorbox({
    inline: true,
    href: "#addAlbumForm",
    onComplete: function() {
      jQuery("input[name=category_name]").focus();
      
      jQuery("#category_parent").html('<option value="0">------------</option>')
        .append(jQuery("#albumSelect").html())
        .val(jQuery("#albumSelect").val());
    }
  });

  jQuery("#addAlbumForm form").submit(function() {
      jQuery("#categoryNameError").text("");
      
      var parent_id = jQuery("select[name=category_parent] option:selected").val(),
          name = jQuery("input[name=category_name]").val();

      jQuery.ajax({
        url: "ws.php",
        dataType: 'json',
        data: {
          format: 'json',
          method: 'pwg.categories.add',
          parent: parent_id,
          name: name
        },
        beforeSend: function() {
          jQuery("#albumCreationLoading").show();
        },
        success: function(data) {
          jQuery("#albumCreationLoading").hide();
          jQuery(".addAlbumOpen").colorbox.close();

          var newAlbum = data.result.id,
              newAlbum_name = '';
              
          if (parent_id!=0) {
            newAlbum_name = jQuery("#category_parent").find("option[value="+ parent_id +"]").text() +' / ';
          }
          newAlbum_name+= name;
          
          var new_option = jQuery("<option/>")
              .attr("value", newAlbum)
              .attr("selected", "selected")
              .text(newAlbum_name);
              
          jQuery("#albumSelect").find("option").removeAttr('selected');
          
          if (parent_id==0) {
            jQuery("#albumSelect").prepend(new_option);
          }
          else {
            jQuery("#albumSelect").find("option[value="+ parent_id +"]").after(new_option);
          }

          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}

<div style="display:none">
  <div id="addAlbumForm" style="text-align:left;padding:1em;">
    <form>
      {'Parent album'|@translate}<br>
      <select id="category_parent" name="category_parent">
      </select>
      <br><br>
      
      {'Album name'|@translate}<br>
      <input name="category_name" type="text" maxlength="255"> <span id="categoryNameError"></span>
      <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>
    </form>
  </div>
</div>