elfinder.callback.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // $Id: elfinder.callback.js 106 2011-02-26 08:19:56Z ph0enix $
  2. (function($) {
  3. /**
  4. * @class elFinder command "search"
  5. * Find files
  6. *
  7. * @author Dmitry (dio) Levashov
  8. **/
  9. elFinder.prototype.commands.search = function() {
  10. this.title = 'Find files';
  11. this.options = {ui : 'searchbutton'}
  12. this.alwaysEnabled = true;
  13. this.updateOnSelect = false;
  14. /**
  15. * Return command status.
  16. * Search does not support old api.
  17. *
  18. * @return Number
  19. **/
  20. this.getstate = function() {
  21. return 0;
  22. }
  23. /**
  24. * Send search request to backend.
  25. *
  26. * @param String search string
  27. * @return $.Deferred
  28. **/
  29. this.exec = function(q) {
  30. var fm = this.fm;
  31. if (typeof(q) == 'string' && q) {
  32. return fm.request({
  33. data : {cmd : 'search', elfinder_search_q : q},
  34. notify : {type : 'search', cnt : 1, hideCnt : true}
  35. });
  36. }
  37. fm.getUI('toolbar').find('.'+fm.res('class', 'searchbtn')+' :text').focus();
  38. return $.Deferred().reject();
  39. }
  40. }
  41. elFinder.prototype.commands.test134 = function() {
  42. this.title = 'Test Command';
  43. //this.options = {ui : 'uploadbutton'}
  44. this.alwaysEnabled = true;
  45. this.updateOnSelect = false;
  46. this.state = 0;
  47. this.getstate = function() {
  48. return 0;
  49. }
  50. /**
  51. * Send search request to backend.
  52. *
  53. * @param String search string
  54. * @return $.Deferred
  55. **/
  56. this.exec = function(q) {
  57. var fm = this.fm;
  58. alert(Drupal.t('test command. arg=') + q);
  59. return $.Deferred().reject();
  60. }
  61. }
  62. $().ready(function() {
  63. var uiopts = elFinder.prototype._options.uiOptions.toolbar;
  64. var newOpts = new Array();
  65. var disabledCommands = Drupal.settings.elfinder.disabledCommands;
  66. for (var i in uiopts) {
  67. var optsGroup = uiopts[i];
  68. var newOptsGroup = Array();
  69. for (var j in optsGroup) {
  70. var found = false;
  71. for (var k in disabledCommands) {
  72. if (disabledCommands[k] == optsGroup[j]) {
  73. found = true;
  74. }
  75. }
  76. if (found == false) {
  77. newOptsGroup.push(optsGroup[j]);
  78. }
  79. }
  80. if (i == 0) {
  81. newOptsGroup.push('up');
  82. }
  83. if (newOptsGroup.length >= 1) {
  84. newOpts.push(newOptsGroup);
  85. }
  86. }
  87. var contextMenuCwd = elFinder.prototype._options.contextmenu.cwd;
  88. var contextMenuFiles = elFinder.prototype._options.contextmenu.files;
  89. var contextMenuNavbar = elFinder.prototype._options.contextmenu.navbar;
  90. var newContextMenuCwd = Array();
  91. var newContextMenuFiles = Array();
  92. var newContextMenuNavbar = Array();
  93. for (var i in contextMenuCwd) {
  94. var found = false;
  95. for (var k in disabledCommands) {
  96. if (disabledCommands[k] == contextMenuCwd[i]) {
  97. found = true;
  98. }
  99. }
  100. if (found == false && contextMenuCwd[i] != '|') {
  101. newContextMenuCwd.push(contextMenuCwd[i]);
  102. }
  103. }
  104. for (var i in contextMenuFiles) {
  105. var found = false;
  106. for (var k in disabledCommands) {
  107. if (disabledCommands[k] == contextMenuFiles[i]) {
  108. found = true;
  109. }
  110. }
  111. if (found == false && contextMenuFiles[i] != '|') {
  112. newContextMenuFiles.push(contextMenuFiles[i]);
  113. }
  114. }
  115. for (var i in contextMenuNavbar) {
  116. var found = false;
  117. for (var k in disabledCommands) {
  118. if (disabledCommands[k] == contextMenuNavbar[i]) {
  119. found = true;
  120. }
  121. }
  122. if (found == false && contextMenuNavbar[i] != '|') {
  123. newContextMenuNavbar.push(contextMenuNavbar[i]);
  124. }
  125. }
  126. elFinder.prototype._options.uiOptions.toolbar = newOpts;
  127. elFinder.prototype._options.contextmenu.cwd = newContextMenuCwd;
  128. elFinder.prototype._options.contextmenu.files = newContextMenuFiles;
  129. elFinder.prototype._options.contextmenu.navbar = newContextMenuNavbar;
  130. });
  131. $().ready(function() {
  132. if (Drupal.settings.elfinder) {
  133. var editorApp = Drupal.settings.elfinder.editorApp;
  134. var elfinderOpts = {
  135. url : Drupal.settings.elfinder.connectorUrl,
  136. lang : Drupal.settings.elfinder.langCode,
  137. rememberLastDir : Drupal.settings.elfinder.rememberLastDir,
  138. closeOnEditorCallback : false,
  139. customData : {token: Drupal.settings.elfinder.token}
  140. }
  141. /* Pushing all settings to elFinder */
  142. $.extend(elfinderOpts, Drupal.settings.elfinder);
  143. if (editorApp && typeof window[Drupal.settings.elfinder.editorCallback] == 'function') {
  144. elfinderOpts.editorCallback = window[Drupal.settings.elfinder.editorCallback];
  145. }
  146. if (editorApp && typeof window[Drupal.settings.elfinder.editorCallback] == 'function') {
  147. elfinderOpts.getFileCallback = window[Drupal.settings.elfinder.editorCallback];
  148. }
  149. if (elfinderOpts.api21) {
  150. //alert('api21');
  151. console.log('2.1 api');
  152. elfinderOpts['commandsOptions'] = {
  153. info: {
  154. // Key is the same as your command name
  155. desc : {
  156. // Field label
  157. label : 'Description1',
  158. // HTML Template
  159. tpl : '<div class="elfinder-info-desc"><span class="elfinder-info-spinner"></span></div>',
  160. // Action that sends the request to the server and get the description
  161. action : function(file, filemanager, dialog) {
  162. // Use the @filemanager object to issue a request
  163. filemanager.request({
  164. // Issuing the custom 'desc' command, targetting the selected file
  165. data : { cmd: 'desc', target: file.hash, },
  166. preventDefault: true,
  167. })
  168. // If the request fails, populate the field with 'Unknown'
  169. .fail(function() {
  170. dialog.find('.elfinder-info-desc').html(filemanager.i18n('unknown'));
  171. })
  172. // When the request is successful, show the description
  173. .done(function(data) {
  174. dialog.find('.elfinder-info-desc').html(data.desc);
  175. });
  176. },
  177. },
  178. }
  179. };
  180. }
  181. $('#finder').elfinder(elfinderOpts);
  182. if(elfinderOpts.browserMode != 'backend') {
  183. // If this is a popup, add an event so that elfinder fills the window.
  184. $(window).resize(function() {
  185. var h = ($(window).height());
  186. if($('#finder').height() != h) {
  187. $('#finder').height(h).resize();
  188. }
  189. });
  190. }
  191. }
  192. });
  193. })(jQuery);