PageRenderTime 42ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/IZWebFileManager/resources/FileManagerController.js

http://izwebfilemanager.googlecode.com/
JavaScript | 341 lines | 302 code | 37 blank | 2 comment | 52 complexity | 2e4e29370ef262e8e126215327082a92 MD5 | raw file
  1. FileManagerController = function(ClientID, UniqueID, EventArgumentSplitter) {
  2. this.ClientID=ClientID;
  3. this.UniqueID=UniqueID;
  4. this.EventArgumentSplitter=EventArgumentSplitter;
  5. this.documentOnClick = new Array();
  6. this.TextBox = document.getElementById(this.ClientID + '_TextBox');
  7. this.TextBox.HideFunction = 'WFM_' + ClientID + '.HideTextBox()';
  8. this.doNotHide = false;
  9. this.doRename = false;
  10. if(document.onclick) {
  11. this.documentOnClick[this.documentOnClick.length] = document.onclick;
  12. this.documentOnClick[this.documentOnClick.length] = function(e) {eval('WFM_' + ClientID + '.HideTextBox()')};
  13. document.onclick = function(e) {
  14. eval('WFM_' + ClientID + '.evalDocumentOnClick(e)');
  15. }
  16. } else {
  17. document.onclick = function(e) {
  18. eval('WFM_' + ClientID + '.HideTextBox()');
  19. }
  20. }
  21. var mouseUp = this._onMouseUp;
  22. var keyPress = this._onKeyPress;
  23. var instance = this;
  24. this._dnd_document_onmouseup = function(e) {
  25. e = e || window.event;
  26. mouseUp.call(instance, e);
  27. }
  28. this._dnd_document_onkeypress = function(e) {
  29. e = e || window.event;
  30. keyPress.call(instance, e);
  31. }
  32. }
  33. FileManagerController.prototype.evalDocumentOnClick = function(e) {
  34. for(var i=0;i<this.documentOnClick.length;i++) {
  35. this.documentOnClick[i](e);
  36. }
  37. }
  38. FileManagerController.prototype.HideTextBox = function() {
  39. if(this.doNotHide) {
  40. this.doNotHide = false;
  41. return;
  42. }
  43. this.TextBox.style.display = "none";
  44. this.TextBox.style.visibility = "hidden";
  45. if(this.doRename) {
  46. if(''+this.TextBox.Item.Name != this.TextBox.value) {
  47. if(this.TextBox.Control.InProcess)
  48. return;
  49. this.TextBox.Control.ShowProgress();
  50. WebFileManager_InitCallback();
  51. WebFileManager_DoCallback(this.UniqueID, this.TextBox.Control.ClientID + this.EventArgumentSplitter + 'Rename' + this.EventArgumentSplitter + this.TextBox.Item.Path + this.EventArgumentSplitter + encodeURIComponent(this.TextBox.value), WebFileManager_Eval, this.TextBox.Control, WebFileManager_OnError);
  52. } else {
  53. this.TextBox.Control.SetFocus();
  54. }
  55. }
  56. this.doRename = false;
  57. }
  58. FileManagerController.prototype.OnRename = function(sender, arg) {
  59. if(sender.InProcess)
  60. return;
  61. if(sender.SelectedItems.length == 0)
  62. return;
  63. var item = null;
  64. for(i=0;i<sender.SelectedItems.length;i++) {
  65. if(sender.SelectedItems[i].CanBeRenamed) {
  66. item = sender.SelectedItems[i];
  67. break;
  68. }
  69. }
  70. if(!item)
  71. return;
  72. var name = document.getElementById(item.id+'_Name');
  73. var pos = WebForm_GetElementPosition(name);
  74. var ClientID = this.ClientID;
  75. this.doNotHide = !this.doNotHide;
  76. this.doRename = true;
  77. this.TextBox.value = item.Name;
  78. this.TextBox.className = sender.EditTextBoxStyle;
  79. this.TextBox.style.display = "inline";
  80. this.TextBox.style.visibility = "visible";
  81. this.TextBox.style.top = '' + (pos.y - sender.Element.scrollTop) + 'px';
  82. this.TextBox.style.left = '' + (pos.x - sender.Element.scrollLeft) + 'px';
  83. this.TextBox.style.width = '' + pos.width + 'px';
  84. this.TextBox.style.height = '' + pos.height + 'px';
  85. this.TextBox.focus();
  86. this.TextBox.select();
  87. this.TextBox.Item = item;
  88. this.TextBox.Control = sender;
  89. this.TextBox.onclick = function(e) {
  90. if(e == null) var e = event;
  91. e.cancelBubble = true;
  92. }
  93. this.TextBox.onkeydown = function(e) {
  94. if(e == null) var e = event;
  95. if(e.keyCode == 27) {
  96. eval('WFM_' + ClientID + '.doRename = false');
  97. eval(this.HideFunction);
  98. this.Control.SetFocus();
  99. e.cancelBubble = true;
  100. return false;
  101. }
  102. if(e.keyCode == 13) {
  103. eval(this.HideFunction);
  104. e.cancelBubble = true;
  105. return false;
  106. }
  107. }
  108. }
  109. FileManagerController.prototype.OnRefresh = function(sender, arg) {
  110. if(sender.InProcess)
  111. return;
  112. sender.ShowProgress();
  113. WebFileManager_InitCallback();
  114. WebFileManager_DoCallback(this.UniqueID, sender.ClientID + this.EventArgumentSplitter + 'Refresh' + this.EventArgumentSplitter + arg, WebFileManager_Render, sender, WebFileManager_OnError);
  115. }
  116. FileManagerController.prototype.OnExecuteCommand = function(sender, arg) {
  117. if(sender.InProcess)
  118. return;
  119. sender.ShowProgress();
  120. WebFileManager_InitCallback();
  121. WebFileManager_DoCallback(this.UniqueID, sender.ClientID + this.EventArgumentSplitter + 'ExecuteCommand' + this.EventArgumentSplitter + arg, WebFileManager_Eval, sender, WebFileManager_OnError);
  122. }
  123. FileManagerController.prototype.OnSelectedItemsDelete = function(sender, arg) {
  124. if(sender.InProcess)
  125. return;
  126. if(sender.SelectedItems.length>0 && confirm(decodeURIComponent(eval('WFM_' + this.ClientID + 'DeleteConfirm')))) {
  127. sender.ShowProgress();
  128. WebFileManager_InitCallback();
  129. WebFileManager_DoCallback(this.UniqueID, sender.ClientID + this.EventArgumentSplitter + 'SelectedItemsDelete' + this.EventArgumentSplitter + arg, WebFileManager_Eval, sender, WebFileManager_OnError);
  130. }
  131. }
  132. FileManagerController.prototype.OnSelectedItemsCopyTo = function(sender, arg) {
  133. if(sender.InProcess)
  134. return;
  135. if(sender.SelectedItems.length == 0)
  136. return;
  137. var directory = decodeURIComponent(sender.GetDirectory());
  138. arg = this.PromptDirectory(directory);
  139. this._SelectedItemsCopyTo(sender, arg);
  140. }
  141. FileManagerController.prototype._SelectedItemsCopyTo = function(sender, arg) {
  142. if(arg) {
  143. sender.ShowProgress();
  144. WebFileManager_InitCallback();
  145. WebFileManager_DoCallback(this.UniqueID, sender.ClientID + this.EventArgumentSplitter + 'SelectedItemsCopyTo' + this.EventArgumentSplitter + encodeURIComponent(arg), WebFileManager_Eval, sender, WebFileManager_OnError);
  146. }
  147. }
  148. FileManagerController.prototype.OnSelectedItemsMoveTo = function(sender, arg) {
  149. if(sender.InProcess)
  150. return;
  151. if(sender.SelectedItems.length == 0)
  152. return;
  153. var directory = decodeURIComponent(sender.GetDirectory());
  154. arg = this.PromptDirectory(directory);
  155. this._SelectedItemsMoveTo(sender, arg);
  156. }
  157. FileManagerController.prototype._SelectedItemsMoveTo = function(sender, arg) {
  158. if(arg) {
  159. sender.ShowProgress();
  160. WebFileManager_InitCallback();
  161. WebFileManager_DoCallback(this.UniqueID, sender.ClientID + this.EventArgumentSplitter + 'SelectedItemsMoveTo' + this.EventArgumentSplitter + encodeURIComponent(arg), WebFileManager_Eval, sender, WebFileManager_OnError);
  162. }
  163. }
  164. FileManagerController.prototype.PromptDirectory = function(directory) {
  165. return window.prompt(decodeURIComponent(eval('WFM_' + this.ClientID + 'SelectDestination')), directory);
  166. }
  167. FileManagerController.prototype.OnNewFolder = function(sender, arg) {
  168. if(sender.InProcess)
  169. return;
  170. sender.ShowProgress();
  171. WebFileManager_InitCallback();
  172. WebFileManager_DoCallback(this.UniqueID, sender.ClientID + this.EventArgumentSplitter + 'NewFolder' + this.EventArgumentSplitter + arg, WebFileManager_Eval, sender, WebFileManager_OnError);
  173. }
  174. FileManagerController.prototype.OnNewDocument = function(sender, arg) {
  175. if(sender.InProcess)
  176. return;
  177. sender.ShowProgress();
  178. WebFileManager_InitCallback();
  179. WebFileManager_DoCallback(this.UniqueID, sender.ClientID + this.EventArgumentSplitter + 'NewDocument' + this.EventArgumentSplitter + arg, WebFileManager_Eval, sender, WebFileManager_OnError);
  180. }
  181. FileManagerController.prototype.OnFileViewChangeView = function(sender, arg) {
  182. if(sender.InProcess)
  183. return;
  184. sender.ShowProgress();
  185. sender.SetView(arg);
  186. WebFileManager_InitCallback();
  187. WebFileManager_DoCallback(this.UniqueID, sender.ClientID + this.EventArgumentSplitter + 'FileViewChangeView' + this.EventArgumentSplitter + arg, WebFileManager_Render, sender, WebFileManager_OnError);
  188. }
  189. FileManagerController.prototype.OnFileViewShowInGroups = function(sender, arg) {
  190. if(sender.InProcess)
  191. return;
  192. sender.ShowProgress();
  193. sender.SwitchShowInGroups();
  194. WebFileManager_InitCallback();
  195. WebFileManager_DoCallback(this.UniqueID, sender.ClientID + this.EventArgumentSplitter + 'FileViewShowInGroups' + this.EventArgumentSplitter + arg, WebFileManager_Render, sender, WebFileManager_OnError);
  196. }
  197. FileManagerController.prototype.OnFileViewSort = function(sender, arg) {
  198. if(sender.InProcess)
  199. return;
  200. sender.ShowProgress();
  201. sender.SetSort(arg);
  202. WebFileManager_InitCallback();
  203. WebFileManager_DoCallback(this.UniqueID, sender.ClientID + this.EventArgumentSplitter + 'FileViewSort' + this.EventArgumentSplitter + arg, WebFileManager_Render, sender, WebFileManager_OnError);
  204. }
  205. FileManagerController.prototype.OnFileViewNavigate = function(sender, arg) {
  206. if(sender.InProcess)
  207. return;
  208. sender.ShowProgress();
  209. WebFileManager_InitCallback();
  210. WebFileManager_DoCallback(this.UniqueID, sender.ClientID + this.EventArgumentSplitter + 'FileViewNavigate' + this.EventArgumentSplitter + encodeURIComponent(arg), WebFileManager_Eval, sender, WebFileManager_OnError)
  211. }
  212. FileManagerController.prototype.getDndVisual = function() {
  213. if(this._dndVisual == null){
  214. this._dndVisual = document.createElement('div');
  215. this._dndVisual.style.visibility="hidden";
  216. this._dndVisual.style.display="none";
  217. document.body.appendChild(this._dndVisual);
  218. }
  219. return this._dndVisual;
  220. }
  221. FileManagerController.prototype._dropNotAllowedCursor = "not-allowed";
  222. FileManagerController.prototype._dropCopyCursor = 'url("<% = WebResource("IZ.WebFileManager.resources.drag_copy.cur") %>"), default';
  223. FileManagerController.prototype._dropMoveCursor = 'url("<% = WebResource("IZ.WebFileManager.resources.drag_move.cur") %>"), default';
  224. FileManagerController.prototype._isDragging = false;
  225. FileManagerController.prototype._dragSource = null;
  226. FileManagerController.prototype.startDragDrop = function(dragSource) {
  227. this._wireEvents();
  228. this._isDragging = true;
  229. this._dragSource = dragSource;
  230. }
  231. FileManagerController.prototype.stopDragDrop = function() {
  232. this._unwireEvents();
  233. this._isDragging = false;
  234. this._dragSource = null;
  235. if(this._dropTarget){
  236. this._dropTarget.onDragLeaveTarget();
  237. this._dropTarget=null;
  238. }
  239. }
  240. FileManagerController.prototype.isDragging = function() {
  241. return this._isDragging;
  242. }
  243. FileManagerController.prototype.drop = function(target, move) {
  244. var dragSource = this._dragSource;
  245. this.stopDragDrop();
  246. if(move)
  247. this._SelectedItemsMoveTo(dragSource, target.getFullPath());
  248. else
  249. this._SelectedItemsCopyTo(dragSource, target.getFullPath())
  250. }
  251. FileManagerController.prototype._wireEvents = function() {
  252. this._origin_document_onmouseup = document.onmouseup;
  253. this._origin_document_onkeypress = document.onkeypress;
  254. document.onmouseup=this._dnd_document_onmouseup;
  255. document.onkeypress=this._dnd_document_onkeypress;
  256. }
  257. FileManagerController.prototype._unwireEvents = function() {
  258. document.onmouseup = this._origin_document_onmouseup;
  259. document.onkeypress = this._origin_document_onkeypress;
  260. }
  261. FileManagerController.prototype._onMouseUp = function (e) {
  262. this.stopDragDrop();
  263. };
  264. FileManagerController.prototype._onKeyPress = function (e) {
  265. // Escape.
  266. var k = e.keyCode ? e.keyCode : e.rawEvent.keyCode;
  267. if (k == 27) {
  268. this.stopDragDrop();
  269. }
  270. };
  271. function WebFileManager_InitCallback() {
  272. __theFormPostData = "";
  273. __theFormPostCollection = new Array();
  274. WebForm_InitCallback();
  275. }
  276. function WebFileManager_Render(result, context) {
  277. var interval = window.setInterval(function() {
  278. window.clearInterval(interval);
  279. context.Element.innerHTML = result;
  280. context.Initialize();
  281. context.SetFocus();
  282. context.HidePrgress();
  283. }, 0);
  284. }
  285. function WebFileManager_Eval(result, context) {
  286. //alert(result);
  287. var interval = window.setInterval(function() {
  288. window.clearInterval(interval);
  289. context.HidePrgress();
  290. eval(result);
  291. }, 0);
  292. }
  293. function WebFileManager_OnError(result, context) {
  294. var interval = window.setInterval(function() {
  295. window.clearInterval(interval);
  296. var separatorIndex = result.lastIndexOf("|");
  297. if (separatorIndex != -1) {
  298. result = result.substring(0, separatorIndex - 1);
  299. }
  300. context.SetFocus();
  301. context.HidePrgress();
  302. alert(result.replace(/&lt;/,"<").replace(/&gt;/,">").replace(/&quot;/,'"'));
  303. }, 0);
  304. }