[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/kcfinder/js/browser/ -> clipboard.js (source)

   1  <?php
   2  
   3  /** This file is part of KCFinder project
   4    *
   5    *      @desc Clipboard functionality
   6    *   @package KCFinder
   7    *   @version 2.21
   8    *    @author Pavel Tzonkov <[email protected]>
   9    * @copyright 2010 KCFinder Project
  10    *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
  11    *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
  12    *      @link http://kcfinder.sunhater.com
  13    */?>
  14  
  15  browser.initClipboard = function() {
  16      if (!this.clipboard || !this.clipboard.length) return;
  17      var size = 0;
  18      $.each(this.clipboard, function(i, val) {
  19          size += parseInt(val.size);
  20      });
  21      size = this.humanSize(size);
  22      $('#clipboard').html('<div title="' + this.label("Clipboard") + ' (' + this.clipboard.length + ' ' + this.label("files") + ', ' + size + ')" onclick="browser.openClipboard()"></div>');
  23      var resize = function() {
  24          $('#clipboard').css('left', $(window).width() - $('#clipboard').outerWidth() + 'px');
  25          $('#clipboard').css('top', $(window).height() - $('#clipboard').outerHeight() + 'px');
  26      };
  27      resize();
  28      $('#clipboard').css('display', 'block');
  29      $(window).unbind();
  30      $(window).resize(function() {
  31          browser.resize();
  32          resize();
  33      });
  34  };
  35  
  36  browser.openClipboard = function() {
  37      if (!this.clipboard || !this.clipboard.length) return;
  38      if ($('.menu a[href="kcact:cpcbd"]').html()) {
  39          $('#clipboard').removeClass('selected');
  40          this.hideDialog();
  41          return;
  42      }
  43      var html = '<div class="menu"><div class="list">';
  44      $.each(this.clipboard, function(i, val) {
  45          icon = _.getFileExtension(val.name);
  46          if (val.thumb)
  47              icon = ".image";
  48          else if (!val.smallIcon || !icon.length)
  49              icon = ".";
  50          var icon = 'themes/' + browser.theme + '/img/files/small/' + icon + '.png';
  51          html += '<a style="background-image:url(' + _.escapeDirs(icon) + ')" title="' + browser.label("Click to remove from the Clipboard") + '" onclick="browser.removeFromClipboard(' + i + ')">' + _.htmlData(_.basename(val.name)) + '</a>';
  52      });
  53      html += '</div><div class="delimiter"></div>';
  54      if (this.support.zip) html+=
  55          '<a href="kcact:download">' + this.label("Download files") + '</a>' +
  56          '<div class="delimiter"></div>';
  57      html +=
  58          '<a href="kcact:cpcbd"' + (!browser.dirWritable ? ' class="denied"' : '') + '>' + this.label("Copy files here") + '</a>' +
  59          '<a href="kcact:mvcbd"' + (!browser.dirWritable ? ' class="denied"' : '') + '>' + this.label("Move files here") + '</a>' +
  60          '<a href="kcact:rmcbd">' + this.label("Delete files") + '</a>' +
  61          '<div class="delimiter"></div>' +
  62          '<a href="kcact:clrcbd">' + this.label("Clear the Clipboard") + '</a>' +
  63      '</div>';
  64  
  65      setTimeout(function() {
  66          $('#clipboard').addClass('selected');
  67          $('#dialog').html(html);
  68          $('.menu a[href="kcact:download"]').click(function() {
  69              browser.hideDialog();
  70              browser.downloadClipboard();
  71              return false;
  72          });
  73          $('.menu a[href="kcact:cpcbd"]').click(function() {
  74              if (!browser.dirWritable) return false;
  75              browser.hideDialog();
  76              browser.copyClipboard(browser.dir);
  77              return false;
  78          });
  79          $('.menu a[href="kcact:mvcbd"]').click(function() {
  80              if (!browser.dirWritable) return false;
  81              browser.hideDialog();
  82              browser.moveClipboard(browser.dir);
  83              return false;
  84          });
  85          $('.menu a[href="kcact:rmcbd"]').click(function() {
  86              browser.hideDialog();
  87              if (confirm(browser.label("Are you sure you want to delete all files in the Clipboard?")))
  88                  browser.deleteClipboard();
  89              return false;
  90          });
  91          $('.menu a[href="kcact:clrcbd"]').click(function() {
  92              browser.hideDialog();
  93              browser.clearClipboard();
  94              return false;
  95          });
  96  
  97          var left = $(window).width() - $('#dialog').outerWidth();
  98          var top = $(window).height() - $('#dialog').outerHeight() - $('#clipboard').outerHeight();
  99          var lheight = top + _.outerTopSpace('#dialog');
 100          $('.menu .list').css('max-height', lheight + 'px');
 101          var top = $(window).height() - $('#dialog').outerHeight() - $('#clipboard').outerHeight();
 102          $('#dialog').css('left', (left - 4) + 'px');
 103          $('#dialog').css('top', top + 'px');
 104          $('#dialog').fadeIn();
 105      }, 1);
 106  };
 107  
 108  browser.removeFromClipboard = function(i) {
 109      if (!this.clipboard || !this.clipboard[i]) return false;
 110      if (this.clipboard.length == 1) {
 111          this.clearClipboard();
 112          this.hideDialog();
 113          return;
 114      }
 115  
 116      if (i < this.clipboard.length - 1) {
 117          var last = this.clipboard.slice(i + 1);
 118          this.clipboard = this.clipboard.slice(0, i);
 119          this.clipboard = this.clipboard.concat(last);
 120      } else
 121          this.clipboard.pop();
 122  
 123      this.initClipboard();
 124      this.hideDialog();
 125      this.openClipboard();
 126      return true;
 127  };
 128  
 129  browser.copyClipboard = function(dir) {
 130      if (!this.clipboard || !this.clipboard.length) return;
 131      var files = [];
 132      var failed = 0;
 133      for (i = 0; i < this.clipboard.length; i++)
 134          if (this.clipboard[i].readable)
 135              files[i] = this.clipboard[i].dir + "/" + this.clipboard[i].name;
 136          else
 137              failed++;
 138      if (this.clipboard.length == failed) {
 139          alert(this.label("The files in the Clipboard are not readable."))
 140          return;
 141      }
 142      if (failed && !confirm(browser.label("{count} files in the Clipboard are not readable. Do you want to copy the rest?", {count:failed})))
 143          return;
 144      if (dir == browser.dir)
 145          this.fadeFiles();
 146      $.ajax({
 147          type: 'POST',
 148          url: browser.baseGetData('cp_cbd'),
 149          data: {dir:dir, files:files},
 150          async: false,
 151          success: function(xml) {
 152              browser.errors(xml);
 153              browser.clearClipboard();
 154              if (dir == browser.dir)
 155                  browser.refresh();
 156          },
 157          error: function(request, error) {
 158              $('#files > div').css('opacity', '');
 159              $('#files > div').css('filter', '');
 160              alert(browser.label("Unknown error."));
 161          }
 162      });
 163  };
 164  
 165  browser.moveClipboard = function(dir) {
 166      if (!this.clipboard || !this.clipboard.length) return;
 167      var files = [];
 168      var failed = 0;
 169      for (i = 0; i < this.clipboard.length; i++)
 170          if (this.clipboard[i].readable && this.clipboard[i].writable)
 171              files[i] = this.clipboard[i].dir + "/" + this.clipboard[i].name;
 172          else
 173              failed++;
 174      if (this.clipboard.length == failed) {
 175          alert(this.label("The files in the Clipboard are not movable."))
 176          return;
 177      }
 178      if (failed && !confirm(browser.label("{count} files in the Clipboard are not movable. Do you want to move the rest?", {count: failed})))
 179          return;
 180      this.fadeFiles();
 181      $.ajax({
 182          type: 'POST',
 183          url: browser.baseGetData('mv_cbd'),
 184          data: {dir:dir, files:files},
 185          async: false,
 186          success: function(xml) {
 187              browser.errors(xml);
 188              browser.clearClipboard();
 189              browser.refresh();
 190          },
 191          error: function(request, error) {
 192              $('#files > div').css('opacity', '');
 193              $('#files > div').css('filter', '');
 194              alert(browser.label("Unknown error."));
 195          }
 196      });
 197  };
 198  
 199  browser.deleteClipboard = function() {
 200      if (!this.clipboard || !this.clipboard.length) return;
 201      var files = [];
 202      var failed = 0;
 203      for (i = 0; i < this.clipboard.length; i++)
 204          if (this.clipboard[i].readable && this.clipboard[i].writable)
 205              files[i] = this.clipboard[i].dir + "/" + this.clipboard[i].name;
 206          else
 207              failed++;
 208      if (this.clipboard.length == failed) {
 209          alert(this.label("The files in the Clipboard are not removable."))
 210          return;
 211      }
 212      if (failed && !confirm(browser.label("{count} files in the Clipboard are not removable. Do you want to delete the rest?", {count: failed})))
 213          return;
 214      this.fadeFiles();
 215      $.ajax({
 216          type: 'POST',
 217          url: browser.baseGetData('rm_cbd'),
 218          data: {files:files},
 219          async: false,
 220          success: function(xml) {
 221              browser.errors(xml);
 222              browser.clearClipboard();
 223              browser.refresh();
 224          },
 225          error: function(request, error) {
 226              $('#files > div').css({opacity:'', filter:''});
 227              alert(browser.label("Unknown error."));
 228          }
 229      });
 230  };
 231  
 232  browser.downloadClipboard = function() {
 233      if (!this.clipboard || !this.clipboard.length) return;
 234      var files = [];
 235      for (i = 0; i < this.clipboard.length; i++)
 236          if (this.clipboard[i].readable)
 237              files[i] = this.clipboard[i].dir + "/" + this.clipboard[i].name;
 238      if (files.length)
 239          this.post(this.baseGetData('downloadClipboard'), {files:files});
 240  };
 241  
 242  browser.clearClipboard = function() {
 243      $('#clipboard').html('');
 244      this.clipboard = [];
 245  };


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1