source: extensions/pbase2piwigo/admin/template/import.init_import.tpl @ 17314

Last change on this file since 17314 was 17314, checked in by mistic100, 8 years ago
  • many small improvements
  • protect "generic" functions
  • complete localization
File size: 4.9 KB
Line 
1{combine_script id='jquery.ajaxmanager' load='footer' path='themes/default/js/plugins/jquery.ajaxmanager.js'}
2{combine_script id='jquery.jgrowl' load='footer' require='jquery' path='themes/default/js/plugins/jquery.jgrowl_minimized.js'}
3{combine_script id='MultiGetSet' load='header' path=$PBASE_PATH|cat:'admin/template/MultiGetSet.js'}
4{combine_css path="admin/themes/default/uploadify.jGrowl.css"}
5
6{footer_script require='jquery.ajaxmanager,jquery.jgrowl'}
7var errorHead   = '{'ERROR'|@translate|@escape:'javascript'}';
8var errorMsg    = '{'an error happened'|@translate|@escape:'javascript'}';
9var successHead = '{'Success'|@translate|@escape:'javascript'}';
10var errors_final_msg = '{'%1$d errors occured. %2$d albums and %3$d photos added.'|@translate}';
11
12{literal}
13// custom classe for counters listening
14var MyClass = function(){
15  var public = this;
16  var private = {};
17 
18  private.lenght = 0;
19  private.errors = 0;
20  private.categories = 0;
21  private.pictures = 0;
22 
23  MultiGetSet({
24    public: public,
25    private: private,
26    handler: Observable
27  });
28};
29
30var queue = new MyClass();
31
32queue.listen("lenght", function(opt){
33  if (opt.newValue == 0) {
34    $(".loading").css('display', 'none');
35    if (queue.get("errors") == 0) {
36      $(".infos").css('display', 'block');
37    } else {
38      errors_final_msg = errors_final_msg.replace('%1$d', queue.get("errors"));
39      errors_final_msg = errors_final_msg.replace('%2$d', queue.get("categories"));
40      errors_final_msg = errors_final_msg.replace('%3$d', queue.get("pictures"));
41     
42      $(".warnings").css('display', '').html('<ul><li>'+ errors_final_msg +'</li></ul>');
43    }
44  }
45});
46queue.listen("categories", function(opt) {
47  $(".nb_categories").html(opt.newValue);
48});
49queue.listen("pictures", function(opt) {
50  $(".nb_pictures").html(opt.newValue);
51});
52queue.listen("errors", function(opt) {
53  $(".nb_errors").html(opt.newValue);
54});
55
56
57var queuedManager = jQuery.manageAjax.create('queued', {
58  queue: true, 
59  maxRequests: 1
60});
61
62function add_cat_to_add_queue(path, parent_id, recursive, fills) {
63  queuedManager.add({
64    type: 'POST',
65    dataType: 'json',
66    url: 'ws.php?format=json',
67    data: { method: 'pwg.pBase.addCat', path: path, parent_id: parent_id, recursive: recursive },
68    success: function(data) {
69      if (data['stat'] == 'ok') {
70        data = data['result'];
71       
72        for (i in data['pictures']) {
73          queue.increment("lenght");
74          add_picture_to_add_queue(data['pictures'][i], data['category_id'], fills);
75        }
76        if (recursive) {
77          for (i in data['categories']) {
78            queue.increment("lenght");
79            add_cat_to_add_queue(data['categories'][i], data['category_id'], recursive, fills);
80          }
81        }
82       
83        jQuery.jGrowl(data['message'], { theme: 'success', header: successHead, life: 2000, sticky: false });
84        queue.increment("categories");
85      } else {
86        jQuery.jGrowl(data['result'], { theme: 'error', header: errorHead, sticky: true });
87        queue.increment("errors");
88      }
89     
90      queue.decrement("lenght");
91    },
92    error: function () {
93      jQuery.jGrowl(errorMsg, { theme: 'error', header: errorHead, sticky: true });
94      queue.increment("errors");
95    }
96  });
97}
98
99function add_picture_to_add_queue(url, cat_id, fills) {
100  queuedManager.add({
101    type: 'POST',
102    dataType: 'json',
103    url: 'ws.php?format=json',
104    data: { method: 'pwg.pBase.addImage', url: url, category: cat_id, fills: fills },
105    success: function(data) {
106      if (data['stat'] == 'ok') {
107        jQuery.jGrowl(data['result'], { theme: 'success', header: successHead, life: 2000, sticky: false });
108        queue.increment("pictures");
109      } else {
110        jQuery.jGrowl(data['result'], { theme: 'error', header: errorHead, sticky: true });
111        queue.increment("errors");
112      }
113     
114      queue.decrement("lenght");
115    },
116    error: function () {
117      jQuery.jGrowl(errorMsg, { theme: 'error', header: errorHead, sticky: true });
118      queue.increment("errors");
119    }
120  });
121}
122{/literal}
123
124{foreach from=$categories item=cat}
125add_cat_to_add_queue('{$cat}', {$PARENT_CATEGORY}, {$RECURSIVE}, '{$FILLS}');
126{/foreach}
127
128queue.set("lenght", {$categories|@count});
129{/footer_script}
130
131
132<div class="infos" style="display:none;">
133  <ul>
134    <li>{'Completed. %1$d albums and %2$d photos added.'|@translate|sprintf:$nb_categories:$nb_pictures}</li>
135  </ul>
136</div>
137<div class="warnings" style="display:none;">
138  <ul>
139    <li>null</li>
140  </ul>
141</div>
142
143<p>
144  <b>{'Nb albums'|@translate}</b>: <span class="nb_categories">0</span>/{$nb_categories}<br>
145  <b>{'Nb photos'|@translate}</b>: <span class="nb_pictures">0</span>/{$nb_pictures}<br>
146  <b>{'Errors'|@translate}</b>: <span class="nb_errors">0</span><br>
147  <br>
148  <img class="loading" src="{$PBASE_PATH}admin/template/loader-{$themeconf.name}.gif">
149</p>
150
151{* <a href="{$MANAGE_LINK}">{'Manage this set of %d photos'|@translate|sprintf:$nb_pictures}</a> *}
Note: See TracBrowser for help on using the repository browser.