source: pro-violet-viettel/sourcecode/assets/js/manager.js @ 682

Last change on this file since 682 was 682, checked in by quyenla, 10 years ago

tpro-violet-viettel/sourcecode/api.violet.vn/www/apps/platform/modules/space/actions/actions.class.php

File size: 38.3 KB
Line 
1if (jQuery)
2    (function ($) {
3        $.extend($.fn, {
4            violetFileManager: function (o) {
5                if (!o)
6                    var o = {};
7                if (o.tree == undefined)
8                    o.tree = null;
9                if (o.grid == undefined)
10                    o.grid = null;
11
12                if (o.maincontainer == undefined)
13                    o.maincontainer = null;
14                if (o.titlebar == undefined)
15                    o.titlebar = null;
16                if (o.toolsbar == undefined)
17                    o.toolsbar = null;
18                if (o.statusbar == undefined)
19                    o.statusbar = null;
20
21                if (o.oTree == undefined)
22                    o.oTree = null;
23                if (o.oGrid == undefined)
24                    o.oGrid = null;
25                if (o.host == undefined)
26                    o.host = 'http://localhost/';
27                if (o.hostmodule == undefined)
28                    o.hostmodule = 'privatecontent/';
29                if (o.script == undefined)
30                    o.script = 'getcontent';
31                if (o.data == undefined)
32                    o.data = null;
33                if (o.datasource == undefined)
34                    o.datasource = 'ajax';
35
36                o.host = o.host + 'ajax/';
37
38                var isDev = false;
39                var contextmenu = null;
40                var oContainer = this;
41                var tree = [];
42                var totalItem = 0;
43                var countItem = 0;
44                var maxWidth = 0;
45                var treeCurrentNode = null;
46                var self = this;
47                var oClipBoard = {items: null, act: null};
48
49                /**
50                 * Toolbar defined
51                 * */
52                var btnNewFolder = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnNewFolder');
53                var btnDel = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnDel');
54                var btnCopy = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnCopy');
55                var btnCut = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnCut');
56                var btnPaste = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnPaste');
57                var btnShare = $('#' + o.toolsbar + ' > DIV.btn-group.social > #btnShare');
58                var btnPreview = $('#' + o.toolsbar + ' > DIV.btn-group.social > #btnPreview');
59                var btnDownload = $('#' + o.toolsbar + ' > DIV.btn-group.creation > #btnDownload');
60                var btnUpload = $('#' + o.toolsbar + ' > DIV.btn-group.creation > #btnUpload');
61                var btnRefresh = $('#' + o.toolsbar + ' > DIV.btn-group.control > #btnRefresh');
62
63                var sendCommand = function (p) {
64                    if (p.postdata == undefined)
65                        p.postdata = null;
66                    if (p.script == undefined)
67                        p.script = o.script;
68                    if (p.callbackSuccess == undefined)
69                        p.callbackSuccess = null;
70                    if (p.callbackDone == undefined)
71                        p.callbackDone = null;
72                    if (p.callbackFail == undefined)
73                        p.callbackFail = null;
74                    if (p.callbackAlways == undefined)
75                        p.callbackAlways = null;
76                    if (p.parseData == undefined)
77                        p.parseData = null;
78                    if (p.self == undefined)
79                        p.self = this;
80
81                    if (p.script != null && (o.datasource == 'ajax' || isDev)) {
82                        $.post(o.host + o.hostmodule + p.script, p.postdata, function (data) {
83                            if (data) {
84                                parseData = $.parseJSON(data);
85                                p.parseData = parseData;
86                            }
87
88                            if (p.callbackSuccess != null) {
89                                if (parseInt(parseData.ERROR.errCode) === 0)
90                                    p.callbackSuccess(parseData);
91                                else {
92                                    p.callbackFail(parseData.ERROR);
93                                }
94                            }
95
96                        }).done(function () {
97                            if (p.callbackDone != null)
98                                p.callbackDone(p.parseData);
99                        }).fail(function () {
100                            if (p.callbackFail != null)
101                                p.callbackFail(this);
102                        }).always(function () {
103                            if (p.callbackAlways != null)
104                                p.callbackAlways(this);
105                        });
106                    }
107                    else if (o.datasource == 'json') {
108                        if (p.callbackSuccess != null)
109                            p.callbackSuccess(o.data);
110                        if (p.callbackDone != null)
111                            p.callbackDone(this);
112                    }
113
114                };
115
116                var getDirTreeMaxWidth = function () {
117                    var scrWidth = $(o.maincontainer).width();
118                    return parseInt(scrWidth / 2);
119                }
120
121                var layoutRender = function () {
122                    var scrWidth = $('#' + o.maincontainer).width();
123                    var scrHeght = $(window).height();
124                    var dirTreeHeight = scrHeght - $('#' + o.titlebar).height() - $('#' + o.toolsbar).height() - $('#' + o.statusbar).height() - 2;
125                    $('#' + o.tree).parent().height(dirTreeHeight);
126                    $('#' + o.grid).parent().height(dirTreeHeight);
127                    $('#' + o.grid).parent().width('calc(100% - ' + ($('#' + o.tree).parent().width() + 8) + 'px)');
128                    var scollWidth = $('#' + o.grid).parent().width();
129                    maxWidth = getDirTreeMaxWidth();
130                    $(o.tree).height(dirTreeHeight - 5);
131                }
132
133                var createFileManager = function (parseData) {
134                    o.data = parseData;
135                    totalItem = o.data.DIRECTORIES.length;
136                    o.oTree = $('#' + o.tree).violetTree({data: o.data.DIRECTORIES, manager: oContainer});
137                    o.oGrid = $('#' + o.grid).violetGrid({data: o.data, manager: oContainer});
138                };
139
140                var getAllDirChild = function (parentID, aryChild) {
141                    parentID = parentID == null ? 0 : parentID;
142                    var dirList = searchItemsByParent(parentID, 'directory');
143                    var index = aryChild.length;
144                    aryChild[index] = parentID;
145                    if (dirList.length > 0) {
146                        for (var i = 0; i < dirList.length; i++) {
147                            getAllDirChild(dirList[i].id, aryChild);
148                        }
149                    }
150                }
151
152                var buildTreeFromParent = function (dirID, node) {
153                    var aryChildFiles = [];
154                    var aryChildDirs = [];
155                    var aryChildIDs = [];
156                    var aryTmp = [];
157                    var dir = o.data.DIRECTORIES[searchItemByID(dirID, 'directory')];
158                    aryChildDirs = searchItemsByParent(dirID, 'directory');
159                    aryChildFiles = searchItemsByParent(dirID, 'file');
160
161                    node.id = dir.id;
162                    node.name = dir.name;
163                    node.type = 'directory';
164
165                    $(aryChildDirs).each(function (index) {
166                        var id = this.id;
167                        var name = this.name;
168                        var type = 'directory';
169                        var cDir = {id: id, name: name, type: type, childs: null};
170                        aryChildIDs[index] = cDir;
171                    });
172
173                    if ($(aryChildFiles).length > 0) {
174                        if (node.files == undefined)
175                            node.files = [];
176                        $(aryChildFiles).each(function (index) {
177                            var id = this.id;
178                            var name = this.name;
179                            var type = 'file';
180                            var cFile = {id: id, name: name, type: type};
181                            node.files[index] = cFile;
182                        });
183                    }
184
185                    if ($(aryChildDirs).length > 0) {
186                        if (node.childs == undefined)
187                            node.childs = [];
188                        $(aryChildIDs).each(function (index) {
189                            node.childs[index] = new Object;
190                            buildTreeFromParent(aryChildIDs[index].id, node.childs[index]);
191                        });
192                    }
193                }
194
195                var checkChildExisted = function (id) {
196                    var dirList = searchItemsByParent(id, 'directory');
197                    var fileList = searchItemsByParent(id, 'file');
198                    return (dirList.length > 0) || (fileList.length > 0);
199                }
200
201                var doneInit = function () {
202                    bindEventToToolbars();
203                    documentEventsBinding();
204                };
205
206                var failInit = function (er) {
207                    bootbox.alert(er.err);
208                }
209
210                var init = function () {
211                    layoutRender();
212                    $('#' + o.tree).parent().resizable({
213                        maxWidth: maxWidth,
214                        minWidth: 220,
215                        handles: "e",
216                        resize: function (event, ui) {
217                            layoutRender();
218                        }
219                    });
220                    $(window).resize(function () {
221                        layoutRender();
222                        $('#' + o.tree).parent().resizable({maxWidth: maxWidth});
223                    });
224                    sendCommand({postdata: null, callbackSuccess: createFileManager, callbackDone: doneInit, callbackFail: failInit});
225                };
226
227                var searchItemByID = function (id, type) {
228                    var data = {};
229                    switch (type) {
230                        case 'directory':
231                            data = o.data.DIRECTORIES;
232                            break;
233                        case 'file':
234                            data = o.data.FILES;
235                            break;
236                        default:
237                            break;
238                    }
239
240                    //for (var i = 0; i < data.length; i++) {
241                    for (var i in data) {
242                        if (data[i].id == id) {
243                            return i;
244                        }
245                    }
246                }
247
248                var searchItemsByParent = function (parentID, type) {
249                    var data = {};
250                    var aryItem = [];
251                    var index = aryItem.length;
252
253                    switch (type) {
254                        case 'directory':
255                            data = o.data.DIRECTORIES;
256                            break;
257                        case 'file':
258                            data = o.data.FILES;
259                            break;
260                        default:
261                            break;
262                    }
263
264                    for (i in data) {
265                        if (data[i].parentID == parentID) {
266                            aryItem[index] = data[i];
267                            index++;
268                        }
269                    }
270
271                    return aryItem;
272                }
273
274                /**************************
275                 * TOOLBAR EVENTS - START *
276                 **************************/
277                var btnRefreshClick = function (obj) {
278                    $(o).find('i').addClass('icon-spin');
279                    sendCommand({postdata: null,
280                        callbackSuccess: function (parseData) {
281                            o.data = parseData;
282                            self.updateData({updateAll: true});
283                            o.oTree.refeshTree();
284                        },
285                        callbackDone: function () {
286                            $(o).find('i').removeClass('icon-spin');
287                        },
288                        callbackFail: failInit
289                    });
290                }
291
292                var btnNewFolderClick = function () {
293                    createFolderStart();
294                }
295
296                var btnUploadClick = function () {
297                    uploadStart();
298                    upload_init();
299
300                }
301
302                var btnDelClick = function () {
303                    var items = o.oGrid.getHightLightItem();
304                    if ($(items).length == 0) {
305                        var dirID = $(o.oTree.getSelectedNode()).attr('id');
306                        var item = o.data.DIRECTORIES[searchItemByID(dirID, 'directory')];
307                        item.type = 'directory';
308                        items = [item];
309                    }
310                    self.deleteItem(items);
311                }
312
313                var btnCopyClick = function () {
314                    copy('copy');
315                }
316
317                var btnPasteClick = function () {
318                    paste();
319                }
320
321                var btnCutClick = function () {
322                    copy('move');
323                }
324
325                var bindEventToToolbars = function () {
326                    $(btnRefresh).click(function (e) {
327                        btnRefreshClick(this)
328                    });
329
330                    $(btnNewFolder).click(function (e) {
331                        btnNewFolderClick()
332                    });
333                    $(btnUpload).click(function (e) {
334                        btnUploadClick()
335                    });
336
337                    $(btnDel).click(function (e) {
338                        btnDelClick()
339                    });
340                    $(btnCopy).click(function (e) {
341                        btnCopyClick()
342                    });
343                    $(btnCut).click(function (e) {
344                        btnCutClick()
345                    });
346                    $(btnPaste).click(function (e) {
347                        btnPasteClick()
348                    })
349
350                    /*btnShare
351                     btnPreview
352                     btnDownload
353                     btnUpload*/
354                }
355                /************************
356                 * TOOLBAR EVENTS - END *
357                 ************************/
358
359                /***********************************
360                 * DOCUMENT EVENTS BINDING - START *
361                 ***********************************/
362                var documentEventsBinding = function () {
363                    $(document).bind('keydown', function (e) {
364                        switch (e.which) {
365                            case 113:
366                            case 27:
367                                var gridSelectedItems = o.oGrid.getHightLightItem();
368                                if ($(gridSelectedItems).length > 0) {
369                                    o.oGrid.rename(e.which);
370                                } else {
371                                    o.oTree.rename(e.which);
372                                }
373                                break;
374                            case 46:
375                                //delete
376                                btnDelClick();
377                                break;
378                            case 65:
379                                if (e.ctrlKey) {
380                                    o.oGrid.selectAllNode();
381                                }
382                                break;
383                            default:
384                                break;
385                        }
386                    });
387                }
388                /***********************************
389                 * DOCUMENT EVENTS BINDING - END *
390                 ***********************************/
391
392                /*******************************
393                 * CREATE FOLDER - START *
394                 *******************************/
395                var createFolderStart = function () {
396                    var promptOptions = {
397                        title: "Tạo thư mục mới",
398                        buttons: {
399                            confirm: {
400                                label: "Lưu"
401                            },
402                            cancel: {
403                                label: "Há»§y"
404                            }
405                        },
406                        callback: function (result) {
407                            if (result === null) {
408                            } else {
409                                createFolder(treeCurrentNode, result);
410                            }
411                        }
412                    };
413
414                    return bootbox.prompt(promptOptions);
415                }
416
417                var uploadStart = function () {
418
419                    var promptOptions = {
420                        title: "Tải lên",
421                        message: "<form id='upload' method='post' action='http://api.violet.vn/space/upload' enctype='multipart/form-data'><div id='drop'>Kéo thả tệp vào đây <a> Chọn tệp </a><input type='hidden' name='dir' value='" + self.getTreeCurrentNode() + "'/><input type='hidden' name='userid' value='33'/><input type='file' name='upload_file' multiple /></div><ul></ul></form>",
422                        buttons: {
423                            success: {
424                                label: "Tải lên",
425                                className: "btn btn-primary",
426                                callback: function (result) {
427                                 
428                                    if (result) {
429                                        var delobj = JSON.stringify(item);
430                                        var postdata = {delobj: delobj};
431                                        var script = 'delete';
432                                        sendCommand({
433                                            postdata: postdata,
434                                            script: script,
435                                            callbackSuccess: function (parseData) {
436                                                if ($(parseData.DIRECTORIES).length > 0) {
437                                                    $(parseData.DIRECTORIES).each(function (index) {
438                                                        o.oTree.deletion(this);
439                                                        o.oGrid.deletion(this, 'directory');
440                                                    });
441                                                }
442
443                                                if ($(parseData.FILES).length > 0) {
444                                                    $(parseData.FILES).each(function (index) {
445                                                        var file = o.data.FILES[searchItemByID(this, 'file')];
446                                                        o.oGrid.deletion(this, file.minetype);
447                                                    });
448                                                }
449                                            },
450                                            callbackDone: function (obj) {
451                                                if ($(parseData.DIRECTORIES).length > 0) {
452                                                    $(parseData.DIRECTORIES).each(function (index) {
453                                                        delete o.data.DIRECTORIES[searchItemByID(this, 'directory')];
454                                                    });
455                                                }
456
457                                                if ($(parseData.FILES).length > 0) {
458                                                    $(parseData.FILES).each(function (index) {
459                                                        delete o.data.FILES[searchItemByID(this, 'file')];
460                                                    });
461                                                }
462
463                                                o.oTree.setData(o.data.DIRECTORIES);
464                                                o.oGrid.setData(o.data);
465                                                self.setTreeCurrentNode(parentID);
466                                                o.oGrid.reloadGrid();
467                                            },
468                                            callbackFail: function () {
469                                            }
470                                        });
471                                    }
472                                }
473                            },
474                        }
475                    };
476
477                    return bootbox.dialog(promptOptions);
478                }
479                var upload_done = function (result) {
480                    alert(JSON.stringify(result, null, 4));
481                }
482
483                var upload_init = function () {
484                    var ul = $('#upload ul');
485
486                    $('#drop a').click(function () {
487                        $(this).parent().find('input').click();
488                    });
489                    $('#upload').fileupload({
490                        dropZone: $('#drop'),
491                        add: function (e, data) {
492
493                            var tpl = $('<li class="working"><input type="text" value="0" data-width="48" data-height="48"' +
494                                    ' data-fgColor="#0788a5" data-readOnly="1" data-bgColor="#3e4043" /><p></p><span></span></li>');
495                            tpl.find('p').text(data.files[0].name)
496                                    .append('<i>' + formatFileSize(data.files[0].size) + '</i>');
497                            data.context = tpl.appendTo(ul);
498                            tpl.find('input').knob();
499                            tpl.find('span').click(function () {
500
501                                if (tpl.hasClass('working')) {
502                                    jqXHR.abort();
503                                }
504
505                                tpl.fadeOut(function () {
506                                    tpl.remove();
507                                });
508
509                            });
510                            //alert(JSON.stringify(data, null, 4));
511                            var jqXHR = data.submit();
512                        },
513                        progress: function (e, data) {
514
515                            // Calculate the completion percentage of the upload
516                            var progress = parseInt(data.loaded / data.total * 100, 10);
517
518                            // Update the hidden input field and trigger a change
519                            // so that the jQuery knob plugin knows to update the dial
520                            data.context.find('input').val(progress).change();
521
522                            if (progress == 100) {
523                                data.context.removeClass('working');
524                            }
525                        },
526                        fail: function (e, data) {
527                            // Something has gone wrong!
528                            data.context.addClass('error');
529                        }
530
531                    });
532                    $(document).on('drop dragover', function (e) {
533                        e.preventDefault();
534                    });
535                    function formatFileSize(bytes) {
536                        if (typeof bytes !== 'number') {
537                            return '';
538                        }
539
540                        if (bytes >= 1000000000) {
541                            return (bytes / 1000000000).toFixed(2) + ' GB';
542                        }
543
544                        if (bytes >= 1000000) {
545                            return (bytes / 1000000).toFixed(2) + ' MB';
546                        }
547
548                        return (bytes / 1000).toFixed(2) + ' KB';
549                    }
550
551                };
552
553                var createFolder = function (parent, name) {
554                    var postdata = {fname: name, fparentid: parent};
555                    var script = 'createdir';
556                    /*isDev = true;*/
557                    sendCommand({
558                        postdata: postdata,
559                        script: script,
560                        callbackSuccess: function (parseData) {
561                            createFolderFinish(parseData);
562                        },
563                        callbackFail: function () {
564                        }
565                    });
566                }
567
568                var createFolderFinish = function (parseData) {
569                    /*isDev = false;*/
570                    if (parseData.ERROR.errCode == 0) {
571                        var node = {id: parseData.id, name: parseData.name, parentID: parseData.parentID};
572                        o.oTree.createNode(node);
573                        o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = node;
574                        if (o.oGrid)
575                            o.oGrid.reloadGrid();
576                    }
577                }
578                /*******************************
579                 * CREATE FOLDER - END         *
580                 *******************************/
581                /********************************
582                 * COPY & PASTE & MOVE - START  *
583                 ************=*******************/
584                var copy = function (act) {
585                    //detect selected items
586                    //push to clipboard
587                    var items = o.oGrid.getHightLightItem();
588
589                    if ($(items).length == 0) {
590                        var node = o.oTree.getSelectedNode();
591                        var itemID = $(node).attr('id');
592
593                        if (itemID == 0)
594                            return false;
595
596                        items[0] = o.data.DIRECTORIES[searchItemByID(itemID, 'directory')];
597                        items[0].type = 'directory';
598                    }
599
600                    if ($(items).length > 0) {
601                        oClipBoard.items = items;
602                        oClipBoard.act = act;
603                    }
604                    return true;
605                }
606
607                var paste = function () {
608                    if ((oClipBoard.act != 'copy'
609                            && oClipBoard.act != 'move')
610                            || oClipBoard.items == null)
611                        return;
612
613                    var items = [];
614                    var destination = self.getTreeCurrentNode();
615                    if (oClipBoard.act != 'copy') {
616                        $(oClipBoard.items).each(function (index) {
617                            var node = new Object;
618                            if (this.type == 'directory')
619                                buildTreeFromParent(this.id, node);
620                            else {
621                                node.id = this.id;
622                                node.type = 'file';
623                            }
624
625                            items[index] = node;
626                        });
627                    }
628                    else {
629                        items = oClipBoard.items;
630                    }
631
632                    var postdata = {act: oClipBoard.act, destination: destination, data: JSON.stringify(items)};
633                    var script = oClipBoard.act;
634
635                    sendCommand({
636                        postdata: postdata,
637                        script: script,
638                        callbackSuccess: function (parseData) {
639                            if (oClipBoard.act == 'copy') {
640                                $(parseData.DIRECTORIES).each(function (index) {
641                                    o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = this;
642                                });
643
644                                $(parseData.FILES).each(function (index) {
645                                    o.data.FILES[$(o.data.FILES).length] = this;
646                                });
647
648                                o.data.DIRECTORIES.sort(function (a, b) {
649                                    return a.parentID - b.parentID;
650                                });
651
652                                o.oTree.setData(o.data.DIRECTORIES);
653                                o.oGrid.setData(o.data);
654                                o.oTree.createCopyNode(parseData.DIRECTORIES);
655                                o.oGrid.reloadGrid();
656                            }
657                            else if (oClipBoard.act == 'move') {
658
659                            }
660                        }
661                    });
662
663                }
664
665                var move = function () {
666
667                }
668
669                var copyTo = function () {
670
671                }
672
673                var moveTo = function () {
674
675                }
676
677                /*****************************
678                 * COPY & PASTE & MOVE - END *
679                 *****************************/
680
681                this.deleteItem = function (item) {
682
683                    var confirmText = 'Bạn có muốn xóa ';
684
685                    if ($.isArray(item) && item.length > 1) {
686                        confirmText += 'các thư mục (và files) đã chọn?';
687                    }
688                    else if (item.length == 1) {
689                        if (item[0].id == 0)
690                            return false;
691                        confirmText += (item[0].type == 'directory') ? 'thư mục' : 'file';
692                        confirmText += ' <span style="font-weight:bold">' + item[0].name + "</span> khÃŽng?";
693                    }
694
695                    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>';
696
697                    var parentID = item[0].parentID;
698
699                    for (var i = 0; i < item.length; i++) {
700                        if (item[i].type == 'directory') {
701                            var aryChildDirTmp = [];
702                            var aryChildDirID = [];
703                            var aryChildFiles = searchItemsByParent(item[i].id, 'file');
704                            var aryChildDirs = [];
705
706                            getAllDirChild(item[i].id, aryChildDirTmp);
707                            for (var d = 1; d < aryChildDirTmp.length; d++) {
708                                aryChildDirID[d - 1] = aryChildDirTmp[d];
709                            }
710
711                            for (var j = 0; j < aryChildDirID.length; j++) {
712                                if (o.data.DIRECTORIES[searchItemByID(aryChildDirID[j], 'directory')] != undefined)
713                                    aryChildDirs[aryChildDirs.length] = o.data.DIRECTORIES[searchItemByID(aryChildDirID[j], 'directory')];
714
715                                var aryTmp = searchItemsByParent(aryChildDirID[j], 'file');
716                                if (aryTmp.length > 0)
717                                    for (var f in aryTmp) {
718                                        aryChildFiles[aryChildFiles.length] = aryTmp[f];
719                                    }
720                            }
721
722                            item[i].childDirs = aryChildDirs;
723                            item[i].childFiles = aryChildFiles;
724                        }
725                    }
726
727                    var confirmOptions = {
728                        message: confirmText,
729                        buttons: {
730                            confirm: {
731                                label: "Xóa"
732                            },
733                            cancel: {
734                                label: "KhÃŽng xóa"
735                            }
736                        },
737                        callback: function (result) {
738                            if (result) {
739                                var delobj = JSON.stringify(item);
740                                var postdata = {delobj: delobj};
741                                var script = 'delete';
742                                sendCommand({
743                                    postdata: postdata,
744                                    script: script,
745                                    callbackSuccess: function (parseData) {
746                                        if ($(parseData.DIRECTORIES).length > 0) {
747                                            $(parseData.DIRECTORIES).each(function (index) {
748                                                o.oTree.deletion(this);
749                                                o.oGrid.deletion(this, 'directory');
750                                            });
751                                        }
752
753                                        if ($(parseData.FILES).length > 0) {
754                                            $(parseData.FILES).each(function (index) {
755                                                var file = o.data.FILES[searchItemByID(this, 'file')];
756                                                o.oGrid.deletion(this, file.minetype);
757                                            });
758                                        }
759                                    },
760                                    callbackDone: function (obj) {
761                                        if ($(parseData.DIRECTORIES).length > 0) {
762                                            $(parseData.DIRECTORIES).each(function (index) {
763                                                delete o.data.DIRECTORIES[searchItemByID(this, 'directory')];
764                                            });
765                                        }
766
767                                        if ($(parseData.FILES).length > 0) {
768                                            $(parseData.FILES).each(function (index) {
769                                                delete o.data.FILES[searchItemByID(this, 'file')];
770                                            });
771                                        }
772
773                                        o.oTree.setData(o.data.DIRECTORIES);
774                                        o.oGrid.setData(o.data);
775                                        self.setTreeCurrentNode(parentID);
776                                        o.oGrid.reloadGrid();
777                                    },
778                                    callbackFail: function () {
779                                    }
780                                });
781                            }
782                        }
783                    };
784
785                    bootbox.confirm(confirmOptions);
786                }
787
788                this.setTreeCurrentNode = function (treeNode) {
789                    //fire when click a node on Tree
790                    //then fire action of Grid
791                    treeCurrentNode = treeNode;
792                    if (o.oGrid)
793                        o.oGrid.reloadGrid();
794                };
795
796                this.getTreeCurrentNode = function () {
797                    return treeCurrentNode;
798                }
799
800                this.gridNodeDblClick = function (node) {
801                    if (node.minetype == 'directory') {
802                        var treeNode = $('#' + o.tree).find('UL.vstree[rel^="node' + node.parentID + '"] > LI[rel^="folder"] > A#' + node.id);
803                        o.oTree.activeNode(treeNode);
804                    }
805                    else {
806                        //execute or preview file
807                          alert(JSON.stringify(node, null, 4));
808                    }
809                };
810
811                this.createNewFolder = function () {
812
813                }
814
815                this.updateData = function (p) {
816                    if (p.item == undefined)
817                        p.item = null;
818                    if (p.updateAll == undefined)
819                        p.updateAll = false;
820                    if (p.from == undefined)
821                        p.from = null;
822                    if (p.type == undefined)
823                        p.type = null;
824                    if (p.callback == undefined)
825                        p.callback = null;
826
827                    var obj = p.from == 'tree' ? o.oGrid : o.oTree;
828                    if (!p.updateAll) {
829                        var index = searchItemByID(p.item.id, p.type);
830                        switch (p.type) {
831                            case 'directory':
832                                o.data.DIRECTORIES[index].name = p.item.name;
833                                o.data.DIRECTORIES[index].parentID = p.item.parentID;
834                                break;
835                            case 'file':
836                                o.data.FILES[index].name = p.item.name;
837                                o.data.FILES[index].parentID = p.item.parentID;
838                                o.data.FILES[index].minetype = p.item.minetype;
839                                break;
840                            default:
841                                break;
842                        }
843                    }
844
845                    o.oTree.setData(o.data.DIRECTORIES);
846                    o.oGrid.setData(o.data);
847
848                    if (p.callback != null) {
849                        eval('obj.' + p.callback + '(p.item);')
850                    }
851
852                    //call sendCommand
853                }
854
855                this.searchItemsByParent = function (parentID, type) {
856                    return searchItemsByParent(parentID, type);
857                }
858
859                this.searchItemByID = function (parentID, type) {
860                    return searchItemByID(parentID, type);
861                }
862
863                this.initialize = function () {
864                    init();
865                    return this;
866                };
867
868                return this.initialize();
869            }
870        });
871    })(jQuery);
Note: See TracBrowser for help on using the repository browser.