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