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