1 | if(jQuery) (function($){
|
---|
2 | $.extend($.fn, {
|
---|
3 | violetFileManager : function (o) {
|
---|
4 | if( !o ) var o = {};
|
---|
5 | if( o.tree == undefined ) o.tree = null;
|
---|
6 | if( o.grid == undefined ) o.grid = null;
|
---|
7 |
|
---|
8 | if( o.maincontainer == undefined ) o.maincontainer = null;
|
---|
9 | if( o.titlebar == undefined ) o.titlebar = null;
|
---|
10 | if( o.toolsbar == undefined ) o.toolsbar = null;
|
---|
11 | if( o.statusbar == undefined ) o.statusbar = null;
|
---|
12 |
|
---|
13 | if( o.oTree == undefined ) o.oTree = null;
|
---|
14 | if( o.oGrid == undefined ) o.oGrid = null;
|
---|
15 | if( o.host == undefined ) o.host = 'http://localhost/';
|
---|
16 | if( o.hostmodule == undefined ) o.hostmodule = 'privatecontent/';
|
---|
17 | if( o.script == undefined ) o.script = 'getcontent';
|
---|
18 | if( o.data == undefined ) o.data = null;
|
---|
19 | if( o.datasource == undefined ) o.datasource = 'ajax';
|
---|
20 |
|
---|
21 | o.host = o.host + 'ajax/';
|
---|
22 |
|
---|
23 | var isDev = false;
|
---|
24 | var contextmenu = null;
|
---|
25 | var oContainer = this;
|
---|
26 | var tree = [];
|
---|
27 | var totalItem = 0;
|
---|
28 | var countItem = 0;
|
---|
29 | var maxWidth = 0;
|
---|
30 | var treeCurrentNode = null;
|
---|
31 | var self = this;
|
---|
32 | var oClipBoard = {items:null, act:null};
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Toolbar defined
|
---|
36 | * */
|
---|
37 | var btnNewFolder = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnNewFolder');
|
---|
38 | var btnDel = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnDel');
|
---|
39 | var btnCopy = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnCopy');
|
---|
40 | var btnCut = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnCut');
|
---|
41 | var btnPaste = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnPaste');
|
---|
42 | var btnShare = $('#' + o.toolsbar + ' > DIV.btn-group.social > #btnShare');
|
---|
43 | var btnPreview = $('#' + o.toolsbar + ' > DIV.btn-group.social > #btnPreview');
|
---|
44 | var btnDownload = $('#' + o.toolsbar + ' > DIV.btn-group.creation > #btnDownload');
|
---|
45 | var btnUpload = $('#' + o.toolsbar + ' > DIV.btn-group.creation > #btnUpload');
|
---|
46 | var btnRefresh = $('#' + o.toolsbar + ' > DIV.btn-group.control > #btnRefresh');
|
---|
47 |
|
---|
48 | var sendCommand = function (p) {
|
---|
49 | if( p.postdata == undefined ) p.postdata = null;
|
---|
50 | if( p.script == undefined ) p.script = o.script;
|
---|
51 | if( p.callbackSuccess == undefined ) p.callbackSuccess = null;
|
---|
52 | if( p.callbackDone == undefined ) p.callbackDone = null;
|
---|
53 | if( p.callbackFail == undefined ) p.callbackFail = null;
|
---|
54 | if( p.callbackAlways == undefined ) p.callbackAlways = null;
|
---|
55 | if( p.parseData == undefined ) p.parseData = null;
|
---|
56 | if( p.self == undefined ) p.self = this;
|
---|
57 |
|
---|
58 | if (p.script != null && (o.datasource == 'ajax' || isDev)) {
|
---|
59 | $.post(o.host + o.hostmodule + p.script, p.postdata, function (data){
|
---|
60 | if (data) {
|
---|
61 | parseData = $.parseJSON(data);
|
---|
62 | p.parseData = parseData;
|
---|
63 | }
|
---|
64 |
|
---|
65 | if (p.callbackSuccess != null) {
|
---|
66 | if (parseInt(parseData.ERROR.errCode) === 0)
|
---|
67 | p.callbackSuccess(parseData);
|
---|
68 | else {
|
---|
69 | p.callbackFail(parseData.ERROR);
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | }).done(function() {if (p.callbackDone != null)p.callbackDone(p.parseData);}).fail(function() {if (p.callbackFail != null)p.callbackFail(this);}).always(function() {if (p.callbackAlways != null)p.callbackAlways(this);});
|
---|
74 | }
|
---|
75 | else if (o.datasource == 'json'){
|
---|
76 | if (p.callbackSuccess != null) p.callbackSuccess(o.data);
|
---|
77 | if (p.callbackDone != null) p.callbackDone(this);
|
---|
78 | }
|
---|
79 |
|
---|
80 | };
|
---|
81 |
|
---|
82 | var getDirTreeMaxWidth = function () {
|
---|
83 | var scrWidth = $(o.maincontainer).width();
|
---|
84 | return parseInt(scrWidth / 2);
|
---|
85 | }
|
---|
86 |
|
---|
87 | var layoutRender = function () {
|
---|
88 | var scrWidth = $('#' + o.maincontainer).width();
|
---|
89 | var scrHeght = $(window).height();
|
---|
90 | var dirTreeHeight = scrHeght - $('#' + o.titlebar).height() - $('#' + o.toolsbar).height() - $('#' + o.statusbar).height() - 2;
|
---|
91 | $('#' + o.tree).parent().height(dirTreeHeight);
|
---|
92 | $('#' + o.grid).parent().height(dirTreeHeight);
|
---|
93 | $('#' + o.grid).parent().width('calc(100% - ' + ($('#' + o.tree).parent().width() + 8) + 'px)');
|
---|
94 | var scollWidth = $('#' + o.grid).parent().width();
|
---|
95 | maxWidth = getDirTreeMaxWidth();
|
---|
96 | $(o.tree).height(dirTreeHeight - 5);
|
---|
97 | }
|
---|
98 |
|
---|
99 | var createFileManager = function (parseData) {
|
---|
100 | o.data = parseData;
|
---|
101 | totalItem = o.data.DIRECTORIES.length;
|
---|
102 | o.oTree = $('#' + o.tree).violetTree({data:o.data.DIRECTORIES,manager:oContainer});
|
---|
103 | o.oGrid = $('#' + o.grid).violetGrid({data:o.data,manager:oContainer});
|
---|
104 | };
|
---|
105 |
|
---|
106 | var getAllDirChild = function (parentID, aryChild) {
|
---|
107 | parentID = parentID == null ? 0:parentID;
|
---|
108 | var dirList = searchItemsByParent(parentID,'directory');
|
---|
109 | var index = aryChild.length;
|
---|
110 | aryChild[index] = parentID;
|
---|
111 | if (dirList.length > 0) {
|
---|
112 | for (var i = 0; i < dirList.length; i++) {
|
---|
113 | getAllDirChild(dirList[i].id, aryChild);
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | var buildTreeFromParent = function (dirID, node) {
|
---|
119 | var aryChildFiles = [];
|
---|
120 | var aryChildDirs = [];
|
---|
121 | var aryChildIDs = [];
|
---|
122 | var aryTmp = [];
|
---|
123 | var dir = o.data.DIRECTORIES[searchItemByID(dirID, 'directory')];
|
---|
124 | aryChildDirs = searchItemsByParent(dirID, 'directory');
|
---|
125 | aryChildFiles = searchItemsByParent(dirID, 'file');
|
---|
126 |
|
---|
127 | node.id = dir.id;
|
---|
128 | node.name = dir.name;
|
---|
129 | node.type = 'directory';
|
---|
130 |
|
---|
131 | $(aryChildDirs).each(function (index) {
|
---|
132 | var id = this.id;
|
---|
133 | var name = this.name;
|
---|
134 | var type = 'directory';
|
---|
135 | var cDir = {id:id, name:name, type:type, childs:null};
|
---|
136 | aryChildIDs[index] = cDir;
|
---|
137 | });
|
---|
138 |
|
---|
139 | if ($(aryChildFiles).length > 0 ) {
|
---|
140 | if (node.files == undefined) node.files = [];
|
---|
141 | $(aryChildFiles).each(function (index) {
|
---|
142 | var id = this.id;
|
---|
143 | var name = this.name;
|
---|
144 | var type = 'file';
|
---|
145 | var cFile = {id:id, name:name, type:type};
|
---|
146 | node.files[index] = cFile;
|
---|
147 | });
|
---|
148 | }
|
---|
149 |
|
---|
150 | if ($(aryChildDirs).length > 0) {
|
---|
151 | if (node.childs == undefined) node.childs = [];
|
---|
152 | $(aryChildIDs).each(function (index) {
|
---|
153 | node.childs[index] = new Object;
|
---|
154 | buildTreeFromParent(aryChildIDs[index].id, node.childs[index]);
|
---|
155 | });
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | var checkChildExisted = function (id) {
|
---|
160 | var dirList = searchItemsByParent(id,'directory');
|
---|
161 | var fileList = searchItemsByParent(id,'file');
|
---|
162 | return (dirList.length > 0) || (fileList.length > 0);
|
---|
163 | }
|
---|
164 |
|
---|
165 | var doneInit = function () {
|
---|
166 | bindEventToToolbars();
|
---|
167 | documentEventsBinding();
|
---|
168 | };
|
---|
169 |
|
---|
170 | var failInit = function (er) {
|
---|
171 | bootbox.alert(er.err);
|
---|
172 | }
|
---|
173 |
|
---|
174 | var init = function () {
|
---|
175 | layoutRender ();
|
---|
176 | $('#' + o.tree).parent().resizable({
|
---|
177 | maxWidth: maxWidth,
|
---|
178 | minWidth: 220,
|
---|
179 | handles: "e",
|
---|
180 | resize: function (event, ui) {
|
---|
181 | layoutRender ();
|
---|
182 | }
|
---|
183 | });
|
---|
184 | $(window).resize (function() {layoutRender ();$('#' + o.tree).parent().resizable({maxWidth: maxWidth});});
|
---|
185 | sendCommand ({postdata:null,callbackSuccess:createFileManager,callbackDone:doneInit,callbackFail:failInit});
|
---|
186 | };
|
---|
187 |
|
---|
188 | var searchItemByID = function (id, type) {
|
---|
189 | var data = {};
|
---|
190 | switch (type) {
|
---|
191 | case 'directory':
|
---|
192 | data = o.data.DIRECTORIES;
|
---|
193 | break;
|
---|
194 | case 'file':
|
---|
195 | data = o.data.FILES;
|
---|
196 | break;
|
---|
197 | default:
|
---|
198 | break;
|
---|
199 | }
|
---|
200 |
|
---|
201 | //for (var i = 0; i < data.length; i++) {
|
---|
202 | for (var i in data) {
|
---|
203 | if (data[i].id == id) {
|
---|
204 | return i;
|
---|
205 | }
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | var searchItemsByParent = function (parentID, type) {
|
---|
210 | var data = {};
|
---|
211 | var aryItem = [];
|
---|
212 | var index = aryItem.length;
|
---|
213 |
|
---|
214 | switch (type) {
|
---|
215 | case 'directory':
|
---|
216 | data = o.data.DIRECTORIES;
|
---|
217 | break;
|
---|
218 | case 'file':
|
---|
219 | data = o.data.FILES;
|
---|
220 | break;
|
---|
221 | default:
|
---|
222 | break;
|
---|
223 | }
|
---|
224 |
|
---|
225 | for(i in data) {
|
---|
226 | if (data[i].parentID == parentID) {
|
---|
227 | aryItem[index] = data[i];
|
---|
228 | index ++;
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|
232 | return aryItem;
|
---|
233 | }
|
---|
234 |
|
---|
235 | /**************************
|
---|
236 | * TOOLBAR EVENTS - START *
|
---|
237 | **************************/
|
---|
238 | var btnRefreshClick = function (obj) {
|
---|
239 | $(o).find('i').addClass('icon-spin');
|
---|
240 | sendCommand ({ postdata:null,
|
---|
241 | callbackSuccess:function (parseData) {
|
---|
242 | o.data = parseData;
|
---|
243 | self.updateData({updateAll:true});
|
---|
244 | o.oTree.refeshTree();
|
---|
245 | },
|
---|
246 | callbackDone:function () {$(o).find('i').removeClass('icon-spin');},
|
---|
247 | callbackFail:failInit
|
---|
248 | });
|
---|
249 | }
|
---|
250 |
|
---|
251 | var btnNewFolderClick = function () {
|
---|
252 | createFolderStart();
|
---|
253 | }
|
---|
254 |
|
---|
255 | var btnUploadClick = function () {
|
---|
256 | uploadStart();
|
---|
257 | upload_init();
|
---|
258 | }
|
---|
259 |
|
---|
260 | var btnDelClick = function () {
|
---|
261 | var items = o.oGrid.getHightLightItem();
|
---|
262 | if ($(items).length == 0){
|
---|
263 | var dirID = $(o.oTree.getSelectedNode()).attr('id');
|
---|
264 | var item = o.data.DIRECTORIES[searchItemByID(dirID,'directory')];
|
---|
265 | item.type = 'directory';
|
---|
266 | items = [item];
|
---|
267 | }
|
---|
268 | self.deleteItem(items);
|
---|
269 | }
|
---|
270 |
|
---|
271 | var btnCopyClick = function () {
|
---|
272 | copy('copy');
|
---|
273 | }
|
---|
274 |
|
---|
275 | var btnPasteClick = function () {
|
---|
276 | paste();
|
---|
277 | }
|
---|
278 |
|
---|
279 | var btnCutClick = function () {
|
---|
280 | copy('move');
|
---|
281 | }
|
---|
282 |
|
---|
283 | var bindEventToToolbars = function () {
|
---|
284 | $(btnRefresh).click(function(e){btnRefreshClick(this)});
|
---|
285 |
|
---|
286 | $(btnNewFolder).click(function(e){btnNewFolderClick()});
|
---|
287 | $(btnUpload).click(function(e){btnUploadClick()});
|
---|
288 |
|
---|
289 | $(btnDel).click(function(e){btnDelClick()});
|
---|
290 | $(btnCopy).click(function(e){btnCopyClick()});
|
---|
291 | $(btnCut).click(function(e){btnCutClick()});
|
---|
292 | $(btnPaste).click(function(e){btnPasteClick()})
|
---|
293 |
|
---|
294 | /*btnShare
|
---|
295 | btnPreview
|
---|
296 | btnDownload
|
---|
297 | btnUpload*/
|
---|
298 | }
|
---|
299 | /************************
|
---|
300 | * TOOLBAR EVENTS - END *
|
---|
301 | ************************/
|
---|
302 |
|
---|
303 | /***********************************
|
---|
304 | * DOCUMENT EVENTS BINDING - START *
|
---|
305 | ***********************************/
|
---|
306 | var documentEventsBinding = function () {
|
---|
307 | $(document).bind('keydown', function (e){
|
---|
308 | switch( e.which ) {
|
---|
309 | case 113:
|
---|
310 | case 27:
|
---|
311 | var gridSelectedItems = o.oGrid.getHightLightItem();
|
---|
312 | if ($(gridSelectedItems).length > 0) {
|
---|
313 | o.oGrid.rename(e.which);
|
---|
314 | }else {
|
---|
315 | o.oTree.rename(e.which);
|
---|
316 | }
|
---|
317 | break;
|
---|
318 | case 46:
|
---|
319 | //delete
|
---|
320 | btnDelClick();
|
---|
321 | break;
|
---|
322 | case 65:
|
---|
323 | if (e.ctrlKey) {
|
---|
324 | o.oGrid.selectAllNode();
|
---|
325 | }
|
---|
326 | break;
|
---|
327 | default:
|
---|
328 | break;
|
---|
329 | }
|
---|
330 | });
|
---|
331 | }
|
---|
332 | /***********************************
|
---|
333 | * DOCUMENT EVENTS BINDING - END *
|
---|
334 | ***********************************/
|
---|
335 |
|
---|
336 | /*******************************
|
---|
337 | * CREATE FOLDER - START *
|
---|
338 | *******************************/
|
---|
339 | var createFolderStart = function () {
|
---|
340 | var promptOptions = {
|
---|
341 | title: "Tạo thư mục má»i",
|
---|
342 | buttons: {
|
---|
343 | confirm: {
|
---|
344 | label: "Lưu"
|
---|
345 | },
|
---|
346 | cancel: {
|
---|
347 | label: "Há»§y"
|
---|
348 | }
|
---|
349 | },
|
---|
350 | callback: function(result) {
|
---|
351 | if (result === null) {
|
---|
352 |
|
---|
353 | } else {
|
---|
354 | createFolder(treeCurrentNode, result);
|
---|
355 | }
|
---|
356 | }
|
---|
357 | };
|
---|
358 |
|
---|
359 | return bootbox.prompt(promptOptions);
|
---|
360 | }
|
---|
361 |
|
---|
362 | var uploadStart = function () {
|
---|
363 | var promptOptions = {
|
---|
364 | title: "Tải lên",
|
---|
365 | message: "<form id='upload' method='post' action='upload/upload.php' enctype='multipart/form-data'><div id='drop'>Drop Here<a>Browse</a><input type='file' name='upl' multiple /></div><ul></ul></form>",
|
---|
366 | buttons: {
|
---|
367 | confirm: {
|
---|
368 | label: "Lưu"
|
---|
369 | },
|
---|
370 | cancel: {
|
---|
371 | label: "Há»§y"
|
---|
372 | }
|
---|
373 | },
|
---|
374 | callback: function(result) {
|
---|
375 | if (result === null) {
|
---|
376 |
|
---|
377 | } else {
|
---|
378 |
|
---|
379 |
|
---|
380 | createFolder(treeCurrentNode, result);
|
---|
381 | }
|
---|
382 | }
|
---|
383 | };
|
---|
384 |
|
---|
385 | return bootbox.dialog(promptOptions);
|
---|
386 | }
|
---|
387 |
|
---|
388 | var createFolder = function (parent, name) {
|
---|
389 | var postdata = {fname:name,fparentid:parent};
|
---|
390 | var script = 'createdir';
|
---|
391 | /*isDev = true;*/
|
---|
392 | sendCommand ({
|
---|
393 | postdata:postdata,
|
---|
394 | script:script,
|
---|
395 | callbackSuccess:function(parseData){createFolderFinish(parseData);},
|
---|
396 | callbackFail: function(){}
|
---|
397 | });
|
---|
398 | }
|
---|
399 |
|
---|
400 | var createFolderFinish = function (parseData) {
|
---|
401 | /*isDev = false;*/
|
---|
402 | if (parseData.ERROR.errCode == 0) {
|
---|
403 | var node = {id:parseData.id, name:parseData.name,parentID:parseData.parentID};
|
---|
404 | o.oTree.createNode(node);
|
---|
405 | o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = node;
|
---|
406 | if (o.oGrid) o.oGrid.reloadGrid();
|
---|
407 | }
|
---|
408 | }
|
---|
409 | /*******************************
|
---|
410 | * CREATE FOLDER - END *
|
---|
411 | *******************************/
|
---|
412 | /********************************
|
---|
413 | * COPY & PASTE & MOVE - START *
|
---|
414 | ************=*******************/
|
---|
415 | var copy = function (act){
|
---|
416 | //detect selected items
|
---|
417 | //push to clipboard
|
---|
418 | var items = o.oGrid.getHightLightItem();
|
---|
419 |
|
---|
420 | if ($(items).length == 0) {
|
---|
421 | var node = o.oTree.getSelectedNode();
|
---|
422 | var itemID = $(node).attr('id');
|
---|
423 |
|
---|
424 | if (itemID == 0) return false;
|
---|
425 |
|
---|
426 | items[0] = o.data.DIRECTORIES[searchItemByID(itemID, 'directory')];
|
---|
427 | items[0].type = 'directory';
|
---|
428 | }
|
---|
429 |
|
---|
430 | if ($(items).length > 0) {
|
---|
431 | oClipBoard.items = items;
|
---|
432 | oClipBoard.act = act;
|
---|
433 | }
|
---|
434 | return true;
|
---|
435 | }
|
---|
436 |
|
---|
437 | var paste = function () {
|
---|
438 | if ((oClipBoard.act != 'copy'
|
---|
439 | && oClipBoard.act != 'move')
|
---|
440 | || oClipBoard.items == null) return;
|
---|
441 |
|
---|
442 | var items = [];
|
---|
443 | var destination = self.getTreeCurrentNode();
|
---|
444 | if (oClipBoard.act != 'copy') {
|
---|
445 | $(oClipBoard.items).each(function (index) {
|
---|
446 | var node = new Object;
|
---|
447 | if (this.type == 'directory')
|
---|
448 | buildTreeFromParent(this.id, node);
|
---|
449 | else {
|
---|
450 | node.id = this.id;
|
---|
451 | node.type = 'file';
|
---|
452 | }
|
---|
453 |
|
---|
454 | items[index] = node;
|
---|
455 | });
|
---|
456 | }
|
---|
457 | else {
|
---|
458 | items = oClipBoard.items;
|
---|
459 | }
|
---|
460 |
|
---|
461 | var postdata = {act:oClipBoard.act,destination:destination,data:JSON.stringify(items)};
|
---|
462 | var script = oClipBoard.act;
|
---|
463 |
|
---|
464 | sendCommand ({
|
---|
465 | postdata:postdata,
|
---|
466 | script:script,
|
---|
467 | callbackSuccess:function(parseData){
|
---|
468 | if (oClipBoard.act == 'copy'){
|
---|
469 | $(parseData.DIRECTORIES).each(function (index) {
|
---|
470 | o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = this;
|
---|
471 | });
|
---|
472 |
|
---|
473 | $(parseData.FILES).each(function (index) {
|
---|
474 | o.data.FILES[$(o.data.FILES).length] = this;
|
---|
475 | });
|
---|
476 |
|
---|
477 | o.data.DIRECTORIES.sort(function (a,b) {
|
---|
478 | return a.parentID - b.parentID;
|
---|
479 | });
|
---|
480 |
|
---|
481 | o.oTree.setData (o.data.DIRECTORIES);
|
---|
482 | o.oGrid.setData (o.data);
|
---|
483 | o.oTree.createCopyNode(parseData.DIRECTORIES);
|
---|
484 | o.oGrid.reloadGrid();
|
---|
485 | }
|
---|
486 | else if (oClipBoard.act == 'move') {
|
---|
487 |
|
---|
488 | }
|
---|
489 | }
|
---|
490 | });
|
---|
491 |
|
---|
492 | }
|
---|
493 |
|
---|
494 | var move = function () {
|
---|
495 |
|
---|
496 | }
|
---|
497 |
|
---|
498 | var copyTo = function () {
|
---|
499 |
|
---|
500 | }
|
---|
501 |
|
---|
502 | var moveTo = function () {
|
---|
503 |
|
---|
504 | }
|
---|
505 |
|
---|
506 | /*****************************
|
---|
507 | * COPY & PASTE & MOVE - END *
|
---|
508 | *****************************/
|
---|
509 |
|
---|
510 | this.deleteItem = function (item) {
|
---|
511 |
|
---|
512 | var confirmText = 'Bạn có muá»n xóa ';
|
---|
513 |
|
---|
514 | if ($.isArray(item) && item.length > 1) {
|
---|
515 | confirmText += 'các thư mục (và files) Äã chá»n?';
|
---|
516 | }
|
---|
517 | else if (item.length == 1) {
|
---|
518 | if (item[0].id == 0) return false;
|
---|
519 | confirmText += (item[0].type == 'directory')?'thư mục':'file';
|
---|
520 | confirmText += ' <span style="font-weight:bold">' + item[0].name + "</span> khÃŽng?";
|
---|
521 | }
|
---|
522 |
|
---|
523 | confirmText += '<br /><div style="color:red">(hà nh Äá»ng nà y sẜ xóa tất cả thư mục con và các file trong các thư mục Äã chá»n)</div>';
|
---|
524 |
|
---|
525 | var parentID = item[0].parentID;
|
---|
526 |
|
---|
527 | for (var i = 0; i < item.length; i++) {
|
---|
528 | if (item[i].type == 'directory') {
|
---|
529 | var aryChildDirTmp = [];
|
---|
530 | var aryChildDirID = [];
|
---|
531 | var aryChildFiles = searchItemsByParent(item[i].id, 'file');
|
---|
532 | var aryChildDirs = [];
|
---|
533 |
|
---|
534 | getAllDirChild (item[i].id, aryChildDirTmp);
|
---|
535 | for(var d = 1; d < aryChildDirTmp.length; d++) {
|
---|
536 | aryChildDirID[d-1] = aryChildDirTmp[d];
|
---|
537 | }
|
---|
538 |
|
---|
539 | for (var j = 0; j < aryChildDirID.length; j++) {
|
---|
540 | if (o.data.DIRECTORIES[searchItemByID(aryChildDirID[j],'directory')] != undefined)
|
---|
541 | aryChildDirs[aryChildDirs.length] = o.data.DIRECTORIES[searchItemByID(aryChildDirID[j],'directory')];
|
---|
542 |
|
---|
543 | var aryTmp = searchItemsByParent(aryChildDirID[j], 'file');
|
---|
544 | if (aryTmp.length > 0)
|
---|
545 | for(var f in aryTmp) {
|
---|
546 | aryChildFiles[aryChildFiles.length] = aryTmp[f];
|
---|
547 | }
|
---|
548 | }
|
---|
549 |
|
---|
550 | item[i].childDirs = aryChildDirs;
|
---|
551 | item[i].childFiles = aryChildFiles;
|
---|
552 | }
|
---|
553 | }
|
---|
554 |
|
---|
555 | var confirmOptions = {
|
---|
556 | message:confirmText,
|
---|
557 | buttons: {
|
---|
558 | confirm: {
|
---|
559 | label: "Xóa"
|
---|
560 | },
|
---|
561 | cancel: {
|
---|
562 | label: "KhÎng xóa"
|
---|
563 | }
|
---|
564 | },
|
---|
565 | callback: function(result) {
|
---|
566 | if (result) {
|
---|
567 | var delobj = JSON.stringify(item);
|
---|
568 | var postdata = {delobj:delobj};
|
---|
569 | var script = 'delete';
|
---|
570 | sendCommand ({
|
---|
571 | postdata:postdata,
|
---|
572 | script:script,
|
---|
573 | callbackSuccess:function(parseData){
|
---|
574 | if($(parseData.DIRECTORIES).length > 0) {
|
---|
575 | $(parseData.DIRECTORIES).each (function (index) {
|
---|
576 | o.oTree.deletion(this);
|
---|
577 | o.oGrid.deletion(this, 'directory');
|
---|
578 | });
|
---|
579 | }
|
---|
580 |
|
---|
581 | if($(parseData.FILES).length > 0) {
|
---|
582 | $(parseData.FILES).each (function (index) {
|
---|
583 | var file = o.data.FILES[searchItemByID(this, 'file')];
|
---|
584 | o.oGrid.deletion(this, file.minetype);
|
---|
585 | });
|
---|
586 | }
|
---|
587 | },
|
---|
588 | callbackDone: function (obj) {
|
---|
589 | if($(parseData.DIRECTORIES).length > 0) {
|
---|
590 | $(parseData.DIRECTORIES).each(function(index){
|
---|
591 | delete o.data.DIRECTORIES[searchItemByID(this, 'directory')];
|
---|
592 | });
|
---|
593 | }
|
---|
594 |
|
---|
595 | if($(parseData.FILES).length > 0) {
|
---|
596 | $(parseData.FILES).each(function(index){
|
---|
597 | delete o.data.FILES[searchItemByID(this, 'file')];
|
---|
598 | });
|
---|
599 | }
|
---|
600 |
|
---|
601 | o.oTree.setData (o.data.DIRECTORIES);
|
---|
602 | o.oGrid.setData (o.data);
|
---|
603 | self.setTreeCurrentNode(parentID);
|
---|
604 | o.oGrid.reloadGrid();
|
---|
605 | },
|
---|
606 | callbackFail: function(){}
|
---|
607 | });
|
---|
608 | }
|
---|
609 | }
|
---|
610 | };
|
---|
611 |
|
---|
612 | bootbox.confirm(confirmOptions);
|
---|
613 | }
|
---|
614 |
|
---|
615 | this.setTreeCurrentNode = function (treeNode) {
|
---|
616 | //fire when click a node on Tree
|
---|
617 | //then fire action of Grid
|
---|
618 | treeCurrentNode = treeNode;
|
---|
619 | if (o.oGrid) o.oGrid.reloadGrid();
|
---|
620 | };
|
---|
621 |
|
---|
622 | this.getTreeCurrentNode = function () {
|
---|
623 | return treeCurrentNode;
|
---|
624 | }
|
---|
625 |
|
---|
626 | this.gridNodeDblClick = function (node) {
|
---|
627 | if (node.minetype == 'directory') {
|
---|
628 | var treeNode = $('#' + o.tree).find('UL.vstree[rel^="node' + node.parentID + '"] > LI[rel^="folder"] > A#' + node.id);
|
---|
629 | o.oTree.activeNode(treeNode);
|
---|
630 | }
|
---|
631 | else {
|
---|
632 | //execute or preview file
|
---|
633 | }
|
---|
634 | };
|
---|
635 |
|
---|
636 | this.createNewFolder = function () {
|
---|
637 |
|
---|
638 | }
|
---|
639 |
|
---|
640 | this.updateData = function (p) {
|
---|
641 | if( p.item == undefined ) p.item = null;
|
---|
642 | if( p.updateAll == undefined ) p.updateAll = false;
|
---|
643 | if( p.from == undefined ) p.from = null;
|
---|
644 | if( p.type == undefined ) p.type = null;
|
---|
645 | if( p.callback == undefined ) p.callback = null;
|
---|
646 |
|
---|
647 | var obj = p.from == 'tree' ? o.oGrid : o.oTree;
|
---|
648 | if (!p.updateAll) {
|
---|
649 | var index = searchItemByID(p.item.id, p.type);
|
---|
650 | switch (p.type) {
|
---|
651 | case 'directory':
|
---|
652 | o.data.DIRECTORIES[index].name = p.item.name;
|
---|
653 | o.data.DIRECTORIES[index].parentID = p.item.parentID;
|
---|
654 | break;
|
---|
655 | case 'file':
|
---|
656 | o.data.FILES[index].name = p.item.name;
|
---|
657 | o.data.FILES[index].parentID = p.item.parentID;
|
---|
658 | o.data.FILES[index].minetype = p.item.minetype;
|
---|
659 | break;
|
---|
660 | default:
|
---|
661 | break;
|
---|
662 | }
|
---|
663 | }
|
---|
664 |
|
---|
665 | o.oTree.setData (o.data.DIRECTORIES);
|
---|
666 | o.oGrid.setData (o.data);
|
---|
667 |
|
---|
668 | if (p.callback != null) {
|
---|
669 | eval('obj.' + p.callback + '(p.item);')
|
---|
670 | }
|
---|
671 |
|
---|
672 | //call sendCommand
|
---|
673 | }
|
---|
674 |
|
---|
675 | this.searchItemsByParent = function (parentID, type) {
|
---|
676 | return searchItemsByParent(parentID, type);
|
---|
677 | }
|
---|
678 |
|
---|
679 | this.searchItemByID = function (parentID, type) {
|
---|
680 | return searchItemByID(parentID, type);
|
---|
681 | }
|
---|
682 |
|
---|
683 | this.initialize = function () {
|
---|
684 | init();
|
---|
685 | return this;
|
---|
686 | };
|
---|
687 |
|
---|
688 | return this.initialize();
|
---|
689 | }
|
---|
690 | });
|
---|
691 | })(jQuery); |
---|