This repository was archived by the owner on Apr 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinit.js
More file actions
executable file
·1094 lines (1032 loc) · 41.8 KB
/
init.js
File metadata and controls
executable file
·1094 lines (1032 loc) · 41.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) Codiad & Andr3as, distributed
* as-is and without warranty under the MIT License.
* See [root]/license.md for more information. This information must remain intact.
*/
(function(global, $){
var codiad = global.codiad,
scripts = document.getElementsByTagName('script'),
path = scripts[scripts.length-1].src.split('?')[0],
curpath = path.split('/').slice(0, -1).join('/')+'/';
$(function() {
codiad.CodeTransfer.init();
});
codiad.CodeTransfer = {
path : curpath,
controller : curpath + "controller.php",
cBase : "",
cDir : "",
sBase : "/",
sDir : "/",
localSel : [],
serverSel : [],
mode : "ftp",
hided : false,
mirrorEnabled : false,
editLocal : [],
init: function() {
var _this = this;
amplify.subscribe('active.onSave', function(path){
//Upload locally edited files
path = path || codiad.active.getPath();
if (typeof(_this.editLocal[path]) != 'undefined') {
setTimeout(function() {
_this.editFileLocallySave(path);
}, 500);
}
});
amplify.subscribe('active.onClose', function(path){
//Delete locally edited files
if (typeof(_this.editLocal[path]) != 'undefined') {
setTimeout(function() {
_this.editFileLocallyClose(path);
}, 500);
}
});
},
showSwitchDialog: function() {
if (this.hided) {
this.showDialog(this.mode);
} else {
codiad.modal.load(300,this.path+'dialog.php?action=switch');
}
},
setMode: function(mode) {
this.mode = mode;
$.getJSON(this.controller+"?action=setMode&mode="+mode, function(data){
if (data.status == "error") {
alert(data.message);
}
});
},
showDialog: function(mode) {
var _this = this;
this.mirrorEnabled = false;
codiad.modal.load(1000,this.path+'dialog.php?action='+mode);
$('#transfer_form').ready(function(){
//Hide Loading
_this.hideLoadingAnimation();
//List Local Files
_this.cBase = $('#project-root').attr('data-path');
_this.cDir = _this.cBase;
_this.updateLocalFiles(_this.cDir);
$('#close-handle').click(function() {
_this.closeDialog();
});
if (_this.hided) {
_this.updateServerFiles(_this.sDir);
} else {
_this.setMode(mode);
}
});
},
closeDialog: function() {
//Disconnect ftp connection
this.disconnect();
codiad.modal.unload();
},
//////////////////////////////////////////////////////////
//
// Add an Entry to the Log
//
// Parameters:
//
// entry - {String} - String or HTML-Code (Table) to add to the Log
//
//////////////////////////////////////////////////////////
addLogEntry: function(entry) {
var last = $('#transfer_log').html().replace("<tbody>", "").replace("</tbody>", "");
entry = "<tr><td>" + entry + "</td></tr>" + last;
$('#transfer_log').html(entry);
},
//////////////////////////////////////////////////////////
//
// Add files and directory to the lists
//
// Parameters:
//
// index - {Array} - Index of the directory: [0] {name,type}
// id - {String} - Selector of the list to update it
// dot - {String} - Path of the current directory
//
//////////////////////////////////////////////////////////
updateList: function(index, id, dot) {
//Add upper dir
dot = this.getParentDir(dot);
if (dot === "") {
dot = "/";
}
var insert = '<li class="directory open" data-path="'+dot+'" data-type="directory">..</li>';
if (index !== null) {
var buf, name, path, icon, type, ext, mode;
for (var i = 0; i < index.length; i++) {
buf = index[i].name;
name = buf.substring(buf.lastIndexOf("/")+1);
path = buf;
if (index[i].type == "file") {
ext = name.substring(name.lastIndexOf(".")+1);
icon = "file ext-"+ext;
type = "file";
} else {
icon = "directory close";
type = "directory";
}
insert += '<li class="'+icon+'" data-path="'+path+'" data-type="'+type+'">'+name+'</li>';
}
}
$(id).html(insert);
if ("#transfer_localList" == id) {
this.updateLocalClick();
$('#local_path').text(this.cDir);
} else if ("#transfer_serverList" == id) {
this.updateServerClick();
$('#server_path').text(this.sDir);
}
//Set max-height absolute
$('.file_list_div').css('max-height', function(){
return 0.4*window.innerHeight + "px";
});
},
//////////////////////////////////////////////////////////
//
// Update the displayed files of the remote server
//
// Parameters:
//
// path - {String} - Path of the current directory
//
//////////////////////////////////////////////////////////
updateServerFiles: function(path, mirror) {
var _this = this;
this.showLoadingAnimation();
mirror = mirror || false;
if(this.mirrorEnabled && !mirror) {
//Check if folder exists on server
var update = false;
if (this.directoryExists('#transfer_localList', this.getName(path))) {
this.cDir = this.cDir + '/' + this.getName(path);
update = true;
} else if ($('#transfer_serverList li[data-path="' + path + '"]').text() == "..") {
if (this.getName($('#transfer_localList li:first').attr('data-path')) == this.getName(path)) {
this.cDir = $('#transfer_localList li:first').attr('data-path');
update = true;
}
}
if (update) {
this.updateLocalFiles(this.cDir, true);
}
}
$.getJSON(this.controller+"?action=getServerFiles&path="+path, function(data) {
_this.hideLoadingAnimation();
if (data.status == 'error') {
_this.addLogEntry(data.message);
} else {
_this.updateList(data.files, "#transfer_serverList", _this.sDir);
}
});
},
//////////////////////////////////////////////////////////
//
// Update the displayed files of the Codiad server
//
// Parameters:
//
// path - {String} - Path of the current Directory
//
//////////////////////////////////////////////////////////
updateLocalFiles: function(path, mirror) {
var _this = this;
_this.showLoadingAnimation();
mirror = mirror || false;
if(this.mirrorEnabled && !mirror) {
//Check if folder exists local
var update = false;
if (this.directoryExists('#transfer_serverList', this.getName(path))) {
this.sDir = this.sDir + '/' + this.getName(path);
update = true;
} else if ($('#transfer_localList li[data-path="' + path + '"]').text() == "..") {
if (this.getName($('#transfer_serverList li:first').attr('data-path')) == this.getName(path)) {
this.sDir = $('#transfer_serverList li:first').attr('data-path');
update = true;
}
}
if (update) {
this.updateServerFiles(this.sDir, true);
}
}
$.getJSON("components/filemanager/controller.php?action=index&path="+path,
function(data) {
_this.hideLoadingAnimation();
codiad.filemanager.rescan(_this.cBase);
_this.updateList(data.data.index, '#transfer_localList', _this.cDir);
});
},
//////////////////////////////////////////////////////////
//
// Transfer file to remote server
//
// Parameters:
//
// cPath - {String} - Path of the file on the Codiad server with filename
// sPath - {String} - Directory on the remote server without filename
// fName - {String} - Name of the file
// mode - {String} - FTP-Transfermode / either FTP_ASCII or FTP_BINARY
//
//////////////////////////////////////////////////////////
transferFileToServer: function(cPath, sPath, file, mode) {
var _this = this;
this.showLoadingAnimation();
$.getJSON(this.controller+"?action=transferFileToServer&cPath="+cPath+"&sPath="+sPath+"&fName="+file+"&path="+this.sDir+"&mode="+mode,
function(data) {
_this.hideLoadingAnimation();
if (data.status != 'error') {
_this.updateServerFiles(_this.sDir);
}
_this.addLogEntry(data.message);
});
},
//////////////////////////////////////////////////////////
//
// Transfer file to Codiad Server
//
// Parameters:
//
// cPath - {String} - Path of the file on the Codiad server with filename
// sPath - {String} - Directory on the remote server without filename
// fName - {String} - Name of the file
// mode - {String} - FTP-Transfermode / either FTP_ASCII or FTP_BINARY
//
//////////////////////////////////////////////////////////
transferFileToClient: function(cPath, sPath, file, mode) {
var _this = this;
this.showLoadingAnimation();
$.getJSON(this.controller+"?action=transferFileToClient&cPath="+cPath+"&sPath="+sPath+"&fName="+file+"&path="+this.sDir+"&mode="+mode,
function(data) {
_this.hideLoadingAnimation();
if (data.status != 'error') {
_this.updateLocalFiles(_this.cDir);
codiad.filemanager.rescan(_this.cBase);
}
_this.addLogEntry(data.message);
});
},
//////////////////////////////////////////////////////////
//
// Update click listener of filelist of the Codiad server
//
//////////////////////////////////////////////////////////
updateLocalClick: function() {
var _this = this;
//Remove old selections
$('#transfer_localList li').removeClass("selected");
this.localSel = [];
//Add new listener
$('#transfer_localList li').click(function(e){
_this.handleSelection(this, e, 'localSel', '#transfer_localList li');
});
$('#transfer_localList li').dblclick(function(){
var path = $(this).attr('data-path');
if ($(this).attr('data-type') == 'directory') {
//Open dir
if (path == "/") {
path = path.replace("/", _this.cBase);
}
_this.cDir = path;
_this.updateLocalFiles(path);
_this.addLogEntry('Directory Changed');
} else {
//Transfer file
var file = $(this).text();
var mode = $('#transfer_mode').val();
_this.transferFileToServer(path, _this.sDir, file, mode);
}
});
},
//////////////////////////////////////////////////////////
//
// Update click listener of filelist of the remote server
//
//////////////////////////////////////////////////////////
updateServerClick: function() {
var _this = this;
//Remove old selections
$('#transfer_serverList li').removeClass("selected");
this.serverSel = [];
//Add new listener
$('#transfer_serverList li').click(function(e){
_this.handleSelection(this, e, 'serverSel', '#transfer_serverList li');
});
$('#transfer_serverList li').dblclick(function(){
var path = $(this).attr('data-path');
if ($(this).attr('data-type') == 'directory') {
//Open dir
if (path === "") {
path = "/";
}
_this.sDir = path;
_this.updateServerFiles(path);
_this.addLogEntry('Directory changed');
} else {
var file = $(this).text();
var mode = $('#transfer_mode').val();
_this.transferFileToClient(_this.cDir+'/'+file, _this.sDir, file, mode);
}
});
},
//////////////////////////////////////////////////////////
//
// Handle click event of selection
//
// Parameters:
//
// item - {jQuery Object} - Clicked dom element
// e - {jQuery eventObject} - EvenObject of the jQuery
// click handler
// selArr - {String} - Name of the array which contains
// all selected elements
// serverSel or localSel
// listSel - {String} - jQuery file list item selector
// "transfer_localList li" or
// "transfer_serverList li"
//
//////////////////////////////////////////////////////////
handleSelection: function(item, e, selArr, listSel) {
//Catch ..
if ($(item).text == "..") {
return;
}
//Unselect if already selected
if ($(item).hasClass("selected")) {
$(item).removeClass("selected");
//Check if multiselection
if (this[selArr].length > 1) {
//Multiselection
if (e.shiftKey) {
//Shift pressed -> keep other selected, remove only item one
var index = this[selArr].indexOf(item);
this[selArr] = this[selArr].splice(index, 1);
} else {
//Remove all selected, keep only item
$(listSel).removeClass("selected");
$(item).addClass("selected");
this[selArr][0] = $.makeArray(item);
}
} else {
this[selArr] = [];
return;
}
return;
}
//Remove old selections
$(listSel).removeClass("selected");
//Shift pressed
if (e.shiftKey) {
if (this[selArr] == []) {
this[selArr][0] = $.makeArray(item);
} else {
this[selArr].push($.makeArray(item));
}
} else {
//New single click
this[selArr] = [];
this[selArr][0] = $.makeArray(item);
}
//Mark selection
var arr;
for (var i = 0; i < this[selArr].length; i++) {
$(this[selArr][i].reverse()).addClass("selected");
}
$(item).addClass("selected");
},
//////////////////////////////////////////////////////////
//
// Create folder
//
// Parameters:
//
// selArr - {String} - Name of the array which contains
// all selected elements
// serverSel or localSel
//
//////////////////////////////////////////////////////////
createFolder: function(selArr) {
var _this = this;
var name = prompt("Directory:");
var path = "";
if (name === null) {
return false;
}
if ((this[selArr].length == 1) && ($(this[selArr][0].reverse()).attr('data-type') == 'directory') ) {
//Only one selection
if ($(this[selArr][0].reverse()).text() == "..") {
//Create Directory in upper Directory
alert("Not Allowed!");
return;
}
path = $(this[selArr][0].reverse()).attr('data-path');
} else {
if (selArr == "localSel") {
path = this.cDir;
} else {
path = this.sDir;
}
}
//Create folder in the current dir
selArr = selArr.replace("Sel", "");
selArr = selArr.substring(0,1).toUpperCase() + selArr.substring(1);
if (path == "/") {
path = path + name;
} else {
path = path + "/" + name;
}
this.showLoadingAnimation();
$.getJSON(this.controller+"?action=create"+selArr+"Directory&path="+path, function(data){
_this.hideLoadingAnimation();
if (data.status != "error") {
if (selArr == "Local") {
_this.updateLocalFiles(_this.cDir);
codiad.filemanager.rescan(_this.cBase);
} else {
_this.updateServerFiles(_this.sDir);
}
}
_this.addLogEntry(data.message);
});
},
//////////////////////////////////////////////////////////
//
// Delete all selected elements
//
// Parameters:
//
// selArr - {String} - Name of the array which contains
// all selected elements
// serverSel or localSel
//
//////////////////////////////////////////////////////////
deleteSel: function(selArr) {
var result = confirm('Really Delete?');
if (result) {
for (var i = 0; i < this[selArr].length; i++) {
this.deleteObject(this[selArr][i], selArr);
}
//Delete Selection
this.unselect(selArr);
}
},
//////////////////////////////////////////////////////////
//
// Delete object on Codiad or remote server
// either file or directory
//
// Parameters:
//
// obj - {Array of a jQuery object} - Array of the clicked
// dom element
// selArr - {String} - Name of the array which contains
// all selected elements
// serverSel or localSel
//
//////////////////////////////////////////////////////////
deleteObject: function(obj, selArr) {
var _this = this;
selArr = selArr.replace("Sel", "");
selArr = selArr.substring(0,1).toUpperCase() + selArr.substring(1);
var path = $(obj.reverse()).attr('data-path');
var type = $(obj.reverse()).attr('data-type');
type = type.substring(0,1).toUpperCase() + type.substring(1);
this.showLoadingAnimation();
$.getJSON(this.controller+"?action=remove"+selArr+type+"&path="+path, function(data){
_this.hideLoadingAnimation();
_this.addLogEntry(data.message);
});
},
//////////////////////////////////////////////////////////
//
// Display info of selected elements on the remote server
//
//////////////////////////////////////////////////////////
serverInfo: function() {
var _this = this;
var buf = [];
var obj, data;
for (var i = 0; i < this.serverSel.length; i++) {
obj = this.serverSel[i].reverse();
data = $(obj).attr('data-path');
if (buf == []) {
buf[0] = data;
} else {
buf.push(data);
}
}
this.showLoadingAnimation();
$.getJSON(this.controller+"?action=getServerFiles&path="+this.sDir, function(data) {
_this.hideLoadingAnimation();
var index = data.files;
var info = [];
var item = [];
var name;
for (var j = 0; j < index.length; j++) {
if (buf.indexOf(index[j].name) != -1) {
name = index[j].name.substring(index[j].name.lastIndexOf("/")+1);
item.name = name;
item.type = index[j].type;
item.permissions = index[j].permissions;
item.owner = index[j].owner;
item.group = index[j].group;
item.size = index[j].size;
item.date = index[j].day +" "+ index[j].month + " - " + index[j].time;
if (info == []) {
info[0] = item;
} else {
info.push(item);
}
item = [];
}
}
_this.createInfoTable(info);
});
},
//////////////////////////////////////////////////////////
//
// Display info of selected elements on the local server
//
//////////////////////////////////////////////////////////
localInfo: function() {
var _this = this;
var buf = [];
var obj, data, files;
for (var i = 0; i < this.localSel.length; i++) {
obj = this.localSel[i].reverse();
data = $(obj).attr('data-path');
if (buf == []) {
buf[0] = data;
} else {
buf.push(data);
}
}
files = JSON.stringify(buf);
this.showLoadingAnimation();
$.post(this.controller+"?action=getLocalInfo", { "files":files}, function(data){
_this.hideLoadingAnimation();
data = JSON.parse(data);
if (data.status == "error") {
_this.addLogEntry(data.message);
} else {
_this.createInfoTable(data.info);
}
});
},
//////////////////////////////////////////////////////////
//
// Create Table of informations
//
// Parameters:
//
// info - {Array} - File informations
// name - file name
// size - file size in bytes
// type - type of the file (File or Directory)
// date - Date of the last modification
// permissions - Permissions of the file
// owner - Owner of the file
// group - Group of the file
//
//////////////////////////////////////////////////////////
createInfoTable: function(info) {
var alertText = '<table><tr><td>Name</td><td><abbr title="Size in Bytes">Size</abbr></td>';
alertText += '<td>Type</td><td>Date</td><td>Permissions</td><td>Owner/Group</td></tr>';
for (var i = 0; i < info.length; i++) {
alertText += "<tr>";
alertText += "<td>"+info[i].name+"</td>";
alertText += "<td>"+info[i].size+"</td>";
alertText += "<td>"+info[i].type+"</td>";
alertText += "<td>"+info[i].date+"</td>";
alertText += "<td>"+info[i].permissions+"</td>";
alertText += "<td>"+info[i].owner+"/"+info[i].group+"</td>";
alertText += "</tr>";
}
alertText += "</table>";
this.addLogEntry(alertText);
},
//////////////////////////////////////////////////////////
//
// Change permissions of selection
//
// Parameters:
//
// selArr - {String} - Name of the array which contains
// all selected elements
// serverSel or localSel
//
//////////////////////////////////////////////////////////
fileModeSel: function(selArr) {
var obj, path;
var mode = prompt("Permissions: (Octal Value)");
if (mode === null) {
return false;
}
var type = selArr.replace("Sel", "");
type = type.substring(0,1).toUpperCase() + type.substring(1);
for (var i = 0; i < this[selArr].length; i++) {
obj = this[selArr][i].reverse();
if (this.mode == "ftp") {
if ($(obj).attr('data-type') == 'file') {
path = $(obj).attr('data-path');
this.changeFileMode(path, type, mode);
}
} else {
path = $(obj).attr('data-path');
this.changeFileMode(path, type, mode);
}
}
},
//////////////////////////////////////////////////////////
//
// Change permissions of file on remote server
//
// Parameters:
//
// path - {String} - Path of the file with filename
// type - {String} - Location of the file
// either Server or Local
// mode - {String} - New permissions of the file as an
// octal value
//
//////////////////////////////////////////////////////////
changeFileMode: function(path, type, mode) {
var _this = this;
this.showLoadingAnimation();
$.getJSON(this.controller+"?action=change"+type+"FileMode&path="+path+"&mode="+mode, function(data) {
_this.hideLoadingAnimation();
_this.addLogEntry(data.message);
});
},
//////////////////////////////////////////////////////////
//
// Rename selected files and directory
//
// Parameters:
//
// selArr - {String} - Name of the array which contains
// all selected elements
// serverSel or localSel
//
//////////////////////////////////////////////////////////
renameSel: function(selArr) {
var obj, path, newName, old;
var type = selArr.replace("Sel", "");
type = type.substring(0,1).toUpperCase() + type.substring(1);
for (var i = 0; i < this[selArr].length; i++) {
obj = this[selArr][i].reverse();
old = $(obj).text();
newName = prompt("Rename:", old);
if (newName !== null) {
path = $(obj).attr('data-path');
this.rename(path, type, newName);
}
}
},
//////////////////////////////////////////////////////////
//
// Rename file or directory local or on remote server
//
// Parameters:
//
// path - {String} - Path of the file with filename
// type - {String} - Location of the file
// either Server or Local
// newName - {String} - New name of the file or directory
//
//////////////////////////////////////////////////////////
rename: function(path, type, newName) {
var _this = this;
var old = path.substring(path.lastIndexOf("/")+1);
path = this.getParentDir(path);
this.showLoadingAnimation();
$.getJSON(this.controller+"?action=rename"+type+"&path="+path+"&old="+old+"&new="+newName, function(data) {
_this.hideLoadingAnimation();
_this.addLogEntry(data.message);
});
},
//////////////////////////////////////////////////////////
//
// Change group of selected files and directory
//
// Parameters:
//
// selArr - {String} - Name of the array which contains
// all selected elements
// serverSel or localSel
//
//////////////////////////////////////////////////////////
changeGroupSel: function(selArr) {
var obj, path, newGroup, name;
newGroup = prompt("Change group:");
if (newGroup === null) {
return false;
}
var type = selArr.replace("Sel", "");
type = type.substring(0,1).toUpperCase() + type.substring(1);
for (var i = 0; i < this[selArr].length; i++) {
obj = this[selArr][i].reverse();
name = $(obj).text();
path = $(obj).attr('data-path');
this.changeGroup(path, type, newGroup);
}
},
//////////////////////////////////////////////////////////
//
// Change group local or on remote server
//
// Parameters:
//
// path - {String} - Path of the file with filename
// type - {String} - Location of the file
// either Server or Local
// newGroup - {String} - New name of the new group
//
//////////////////////////////////////////////////////////
changeGroup: function(path, type, newGroup) {
var _this = this;
this.showLoadingAnimation();
$.getJSON(this.controller+"?action=change"+type+"Group&path="+path+"&grpName="+newGroup, function(data) {
_this.hideLoadingAnimation();
_this.addLogEntry(data.message);
});
},
//////////////////////////////////////////////////////////
//
// Get current directory of remote server
//
// Parameters:
//
// isBase - {Boolean} - Set current directory as server
// base directory
// update - {Boolean} - Update the value of the form
//
//////////////////////////////////////////////////////////
getServerDirectory: function(isBase, update) {
var _this = this;
$.getJSON(this.controller+"?action=getSeverDirectory", function(data){
if (data.status != 'error') {
_this.sDir = data.dir;
if (isBase) {
_this.sBase = data.dir;
}
if (update) {
$('#server_path').text(_this.sDir);
}
}
});
},
//////////////////////////////////////////////////////////
//
// Transfer selection
//
// Parameters:
//
// selArr - {String} - Name of the array which contains
// all selected elements
// serverSel or localSel
//
//////////////////////////////////////////////////////////
transferSel: function(selArr) {
var mode = $('#transfer_mode').val();
var source = selArr.replace("Sel", "");
var obj, path, file;
for (var i = 0; i < this[selArr].length; i++) {
obj = this[selArr][i].reverse();
file = $(obj).text();
path = $(obj).attr("data-path");
if (source == "local") {
//TransferFileToServer
this.transferFileToServer(path, this.sDir, file, mode);
} else {
//TransferFileToClient
this.transferFileToClient(this.cDir+"/"+file, this.sDir, file, mode);
}
}
this.unselect(selArr);
},
//////////////////////////////////////////////////////////
//
// Edit selection locally
//
// Parameters:
//
// selArr - {String} - Name of the array which contains
// all selected elements
// serverSel or localSel
//
//////////////////////////////////////////////////////////
editSel: function(selArr) {
var mode = $('#transfer_mode').val();
var source = selArr.replace("Sel", "");
var obj, path, file;
for (var i = 0; i < this[selArr].length; i++) {
obj = this[selArr][i].reverse();
file = $(obj).text();
path = $(obj).attr("data-path");
this.editFileLocally(this.sDir, file, mode);
}
this.unselect(selArr);
},
//////////////////////////////////////////////////////////
//
// Transfer file to Codiad Server
//
// Parameters:
//
// sPath - {String} - Directory on the remote server without filename
// fName - {String} - Name of the file
// mode - {String} - FTP-Transfermode / either FTP_ASCII or FTP_BINARY
//
//////////////////////////////////////////////////////////
editFileLocally: function(sPath, file, mode) {
var _this = this;
this.showLoadingAnimation();
$.getJSON(this.controller+"?action=editFileLocally&cBase="+this.cBase+"&sPath="+sPath+"&fName="+file+"&path="+this.sDir+"&mode="+mode,
function(data) {
_this.hideLoadingAnimation();
if (data.status != 'error') {
codiad.filemanager.openFile(data.file);
_this.editLocal[data.file] = {cPath: data.file, cBase: _this.cBase, sPath: sPath, fName: file, sDir: _this.sDir, mode: mode};
_this.hide();
}
codiad.message[data.status](data.message);
});
},
//////////////////////////////////////////////////////////
//
// Delete locally edited file
//
// Parameters:
//
// path - {String} - Path of local file
//
//////////////////////////////////////////////////////////
editFileLocallyClose: function(path) {
if (typeof(this.editLocal[path]) == 'undefined') {
return false;
} else {
var file = this.editLocal[path];
this.editLocal[path] = undefined;
}
$.getJSON(this.controller+"?action=editFileLocallyClose&cPath="+file.cPath+"&cBase", function(data) {
if (data.status == 'error') {
codiad.message[data.status](data.message);
}
});
},
//////////////////////////////////////////////////////////
//
// Save locally edited file
//
// Parameters:
//
// path - {String} - Path of local file
//
//////////////////////////////////////////////////////////
editFileLocallySave: function(path) {
if (typeof(this.editLocal[path]) == 'undefined') {
return false;
} else {
var file = this.editLocal[path];
}
$.getJSON(this.controller+"?action=transferFileToServer&cPath="+file.cPath+"&sPath="+file.sPath+"&fName="+file.fName+"&path="+file.sDir+"&mode="+file.mode, function(data) {
codiad.message[data.status](data.message);
});
},
//////////////////////////////////////////////////////////
//
// Delete selection
//
// Parameters:
//
// selArr - {String} - Name of the array which contains
// all selected elements
// serverSel or localSel
//
//////////////////////////////////////////////////////////
unselect: function(selArr) {
selList = selArr.replace("Sel", "List");
this[selArr] = [];
$('#transfer_'+selList+" li").removeClass("selected");
},
//////////////////////////////////////////////////////////
//
// Display loading circle
//
//////////////////////////////////////////////////////////
showLoadingAnimation: function() {
$('.drops').show();
},
//////////////////////////////////////////////////////////
//
// Hide loading circle
//
//////////////////////////////////////////////////////////
hideLoadingAnimation: function() {
$('.drops').hide();
},
//////////////////////////////////////////////////////////
//
// Get parent directory
//
// Parameters:
//
// path - {String} - Path of file or directory to get
// parent directory
//
//////////////////////////////////////////////////////////
getParentDir: function(path) {
return path.substring(0,path.lastIndexOf("/"));
},