source: pro-violet-viettel/www/deploy/20150304/assets/js/manager.js @ 854

Last change on this file since 854 was 854, checked in by dungnv, 10 years ago
File size: 39.7 KB
RevLine 
[780]1if (jQuery)
[846]2        (function($) {
3                $
4                                .extend(
5                                                $.fn,
6                                                {
7                                                        violetFileManager : function(o) {
8                                                                if (!o)
9                                                                        var o = {};
10                                                                if (o.tree == undefined)
11                                                                        o.tree = null;
12                                                                if (o.grid == undefined)
13                                                                        o.grid = null;
[780]14
[846]15                                                                if (o.maincontainer == undefined)
16                                                                        o.maincontainer = null;
17                                                                if (o.titlebar == undefined)
18                                                                        o.titlebar = null;
19                                                                if (o.toolsbar == undefined)
20                                                                        o.toolsbar = null;
21                                                                if (o.statusbar == undefined)
22                                                                        o.statusbar = null;
23                                                                if (o.navigationbar == undefined)
24                                                                        o.navigationbar = null;
[780]25
[846]26                                                                if (o.oTree == undefined)
27                                                                        o.oTree = null;
28                                                                if (o.oGrid == undefined)
29                                                                        o.oGrid = null;
30                                                                if (o.host == undefined)
31                                                                        o.host = 'http://localhost/';
32                                                                if (o.hostmodule == undefined)
33                                                                        o.hostmodule = 'privatecontent/';
34                                                                if (o.script == undefined)
35                                                                        o.script = 'getcontent';
36                                                                if (o.data == undefined)
37                                                                        o.data = null;
38                                                                if (o.datasource == undefined)
39                                                                        o.datasource = 'ajax';
[780]40
[846]41                                                                if (o.filehosting == undefined)
42                                                                        o.filehosting = 'http://sbgapi.violet.vn/';
[780]43
[846]44                                                                if (o.invisibledButtons == undefined)
45                                                                        o.invisibledButtons = null;
[780]46
[846]47                                                                o.host = o.host + 'ajax/';
[780]48
[846]49                                                                var isDev = false;
50                                                                var contextmenu = null;
51                                                                var oContainer = this;
52                                                                var tree = [];
53                                                                var totalItem = 0;
54                                                                var countItem = 0;
55                                                                var maxWidth = 0;
56                                                                var treeCurrentNode = null;
57                                                                var self = this;
58                                                                var oClipBoard = {
59                                                                        items : null,
60                                                                        act : null
61                                                                };
[780]62
[846]63                                                                /**
64                                                                 * Toolbar defined
65                                                                 */
66                                                                var btnNewFolder = $('#'
67                                                                                + o.toolsbar
68                                                                                + ' > DIV.btn-group.basic > #btnNewFolder');
69                                                                var btnDel = $('#' + o.toolsbar
70                                                                                + ' > DIV.btn-group.basic > #btnDel');
71                                                                var btnCopy = $('#' + o.toolsbar
72                                                                                + ' > DIV.btn-group.basic > #btnCopy');
73                                                                var btnCut = $('#' + o.toolsbar
74                                                                                + ' > DIV.btn-group.basic > #btnCut');
75                                                                var btnPaste = $('#' + o.toolsbar
76                                                                                + ' > DIV.btn-group.basic > #btnPaste');
77                                                                var btnShare = $('#' + o.toolsbar
78                                                                                + ' > DIV.btn-group.social > #btnShare');
79                                                                var btnPreview = $('#'
80                                                                                + o.toolsbar
81                                                                                + ' > DIV.btn-group.social > #btnPreview');
82                                                                var btnDownload = $('#'
83                                                                                + o.toolsbar
84                                                                                + ' > DIV.btn-group.creation > #btnDownload');
85                                                                var btnUpload = $('#'
86                                                                                + o.toolsbar
87                                                                                + ' > DIV.btn-group.creation > #btnUpload');
88                                                                var btnRefresh = $('#'
89                                                                                + o.toolsbar
90                                                                                + ' > DIV.btn-group.control > #btnRefresh');
[780]91
[846]92                                                                var toolbarButtons = [ btnNewFolder, btnDel,
93                                                                                btnCopy, btnCut, btnPaste, btnShare,
94                                                                                btnPreview, btnDownload, btnUpload,
95                                                                                btnRefresh ];
96                                                                var statusbar = $('DIV#' + o.statusbar);
[780]97
[846]98                                                                var sendCommand = function(p) {
99                                                                        if (p.postdata == undefined)
100                                                                                p.postdata = null;
101                                                                        if (p.script == undefined)
102                                                                                p.script = o.script;
103                                                                        if (p.callbackSuccess == undefined)
104                                                                                p.callbackSuccess = null;
105                                                                        if (p.callbackDone == undefined)
106                                                                                p.callbackDone = null;
107                                                                        if (p.callbackFail == undefined)
108                                                                                p.callbackFail = null;
109                                                                        if (p.callbackAlways == undefined)
110                                                                                p.callbackAlways = null;
111                                                                        if (p.parseData == undefined)
112                                                                                p.parseData = null;
113                                                                        if (p.self == undefined)
114                                                                                p.self = this;
[780]115
[846]116                                                                        if (p.script != null
117                                                                                        && (o.datasource == 'ajax' || isDev)) {
118                                                                                $
119                                                                                                .post(
120                                                                                                                o.host + o.hostmodule
121                                                                                                                                + p.script,
122                                                                                                                p.postdata,
123                                                                                                                function(data) {
124                                                                                                                        if (data) {
125                                                                                                                                parseData = $
126                                                                                                                                                .parseJSON(data);
127                                                                                                                                p.parseData = parseData;
128                                                                                                                        }
[780]129
[846]130                                                                                                                        if (p.callbackSuccess != null) {
131                                                                                                                                if (parseInt(parseData.ERROR.errCode) === 0)
132                                                                                                                                        p
133                                                                                                                                                        .callbackSuccess(parseData);
134                                                                                                                                else {
135                                                                                                                                        p
136                                                                                                                                                        .callbackFail(parseData.ERROR);
137                                                                                                                                }
138                                                                                                                        }
[780]139
[846]140                                                                                                                })
141                                                                                                .done(
142                                                                                                                function() {
143                                                                                                                        if (p.callbackDone != null)
144                                                                                                                                p
145                                                                                                                                                .callbackDone(p.parseData);
146                                                                                                                })
147                                                                                                .fail(function() {
148                                                                                                        if (p.callbackFail != null)
149                                                                                                                p.callbackFail(this);
150                                                                                                })
151                                                                                                .always(
152                                                                                                                function() {
153                                                                                                                        if (p.callbackAlways != null)
154                                                                                                                                p
155                                                                                                                                                .callbackAlways(this);
156                                                                                                                });
157                                                                        } else if (o.datasource == 'json') {
158                                                                                if (p.callbackSuccess != null)
159                                                                                        p.callbackSuccess(o.data);
160                                                                                if (p.callbackDone != null)
161                                                                                        p.callbackDone(this);
162                                                                        }
[780]163
[846]164                                                                };
[780]165
[846]166                                                                var getDirTreeMaxWidth = function() {
167                                                                        var scrWidth = $(o.maincontainer).width();
168                                                                        return parseInt(scrWidth / 2);
169                                                                }
[780]170
[846]171                                                                var layoutRender = function() {
172                                                                        var scrWidth = $('#' + o.maincontainer)
173                                                                                        .width();
174                                                                        var scrHeght = $(window).innerHeight();
175                                                                        var dirTreeHeight = scrHeght
176                                                                                        - $('#' + o.titlebar).height()
177                                                                                        - $('#' + o.toolsbar).height()
178                                                                                        - $('#' + o.statusbar).height() - 5;
179                                                                        $('#' + o.tree).parent().height(
180                                                                                        dirTreeHeight);
181                                                                        $('#' + o.grid).parent().height(
182                                                                                        dirTreeHeight);
183                                                                        $('#' + o.grid).parent().width(
184                                                                                        'calc(100% - '
185                                                                                                        + ($('#' + o.tree).parent()
186                                                                                                                        .width() + 8)
187                                                                                                        + 'px)');
188                                                                        var scollWidth = $('#' + o.grid).parent()
189                                                                                        .width();
190                                                                        maxWidth = getDirTreeMaxWidth();
191                                                                        $(o.tree).height(dirTreeHeight - 5);
[780]192
[846]193                                                                        if (o.invisibledButtons != null) {
194                                                                                for ( var i = 0; i < o.invisibledButtons.length; i++) {
195                                                                                        $('#' + o.invisibledButtons[i])
196                                                                                                        .hide();
197                                                                                }
198                                                                        }
199                                                                }
[780]200
[846]201                                                                var createFileManager = function(parseData) {
202                                                                        o.data = parseData;
203                                                                        totalItem = o.data.DIRECTORIES.length;
204                                                                        o.oTree = $('#' + o.tree).violetTree({
205                                                                                data : o.data.DIRECTORIES,
206                                                                                manager : oContainer
207                                                                        });
208                                                                        o.oGrid = $('#' + o.grid).violetGrid({
209                                                                                data : o.data,
210                                                                                manager : oContainer
211                                                                        });
212                                                                        self.refreshStatusBar();
213                                                                };
[780]214
[846]215                                                                var getAllDirChild = function(parentID,
216                                                                                aryChild) {
217                                                                        parentID = parentID == null ? 0 : parentID;
218                                                                        var dirList = searchItemsByParent(parentID,
219                                                                                        'directory');
220                                                                        var index = aryChild.length;
221                                                                        aryChild[index] = parentID;
222                                                                        if (dirList.length > 0) {
223                                                                                for ( var i = 0; i < dirList.length; i++) {
224                                                                                        getAllDirChild(dirList[i].id,
225                                                                                                        aryChild);
226                                                                                }
227                                                                        }
228                                                                }
[780]229
[846]230                                                                var buildTreeFromParent = function(dirID, node) {
231                                                                        var aryChildFiles = [];
232                                                                        var aryChildDirs = [];
233                                                                        var aryChildIDs = [];
234                                                                        var aryTmp = [];
235                                                                        var dir = o.data.DIRECTORIES[searchItemByID(
236                                                                                        dirID, 'directory')];
237                                                                        aryChildDirs = searchItemsByParent(dirID,
238                                                                                        'directory');
239                                                                        aryChildFiles = searchItemsByParent(dirID,
240                                                                                        'file');
[780]241
[846]242                                                                        node.id = dir.id;
243                                                                        node.name = dir.name;
244                                                                        node.type = 'directory';
[780]245
[846]246                                                                        $(aryChildDirs).each(function(index) {
247                                                                                var id = this.id;
248                                                                                var name = this.name;
249                                                                                var type = 'directory';
250                                                                                var cDir = {
251                                                                                        id : id,
252                                                                                        name : name,
253                                                                                        type : type,
254                                                                                        childs : null
255                                                                                };
256                                                                                aryChildIDs[index] = cDir;
257                                                                        });
[780]258
[846]259                                                                        if ($(aryChildFiles).length > 0) {
260                                                                                if (node.files == undefined)
261                                                                                        node.files = [];
262                                                                                $(aryChildFiles).each(function(index) {
263                                                                                        var id = this.id;
264                                                                                        var name = this.name;
265                                                                                        var type = 'file';
266                                                                                        var cFile = {
267                                                                                                id : id,
268                                                                                                name : name,
269                                                                                                type : type
270                                                                                        };
271                                                                                        node.files[index] = cFile;
272                                                                                });
273                                                                        }
[780]274
[846]275                                                                        if ($(aryChildDirs).length > 0) {
276                                                                                if (node.childs == undefined)
277                                                                                        node.childs = [];
278                                                                                $(aryChildIDs)
279                                                                                                .each(
280                                                                                                                function(index) {
281                                                                                                                        node.childs[index] = new Object;
282                                                                                                                        buildTreeFromParent(
283                                                                                                                                        aryChildIDs[index].id,
284                                                                                                                                        node.childs[index]);
285                                                                                                                });
286                                                                        }
287                                                                }
[780]288
[846]289                                                                var checkChildExisted = function(id) {
290                                                                        var dirList = searchItemsByParent(id,
291                                                                                        'directory');
292                                                                        var fileList = searchItemsByParent(id,
293                                                                                        'file');
294                                                                        return (dirList.length > 0)
295                                                                                        || (fileList.length > 0);
296                                                                }
[780]297
[846]298                                                                var doneInit = function() {
299                                                                        bindEventToToolbars();
300                                                                        documentEventsBinding();
301                                                                };
[780]302
[846]303                                                                var failInit = function(er) {
304                                                                        bootbox.alert(er.err);
305                                                                }
[780]306
[846]307                                                                var init = function() {
308                                                                        layoutRender();
309                                                                        $('#' + o.tree).parent().resizable({
310                                                                                maxWidth : maxWidth,
311                                                                                minWidth : 220,
312                                                                                handles : "e",
313                                                                                resize : function(event, ui) {
314                                                                                        layoutRender();
315                                                                                }
316                                                                        });
317                                                                        $(window).resize(function() {
318                                                                                layoutRender();
319                                                                                $('#' + o.tree).parent().resizable({
320                                                                                        maxWidth : maxWidth
321                                                                                });
322                                                                        });
323                                                                        sendCommand({
324                                                                                postdata : null,
325                                                                                callbackSuccess : createFileManager,
326                                                                                callbackDone : doneInit,
327                                                                                callbackFail : failInit
328                                                                        });
329                                                                };
[780]330
[846]331                                                                var searchItemByID = function(id, type) {
332                                                                        var data = {};
333                                                                        switch (type) {
334                                                                        case 'directory':
335                                                                                data = o.data.DIRECTORIES;
336                                                                                break;
337                                                                        case 'file':
338                                                                                data = o.data.FILES;
339                                                                                break;
340                                                                        default:
341                                                                                break;
342                                                                        }
[780]343
[846]344                                                                        // for (var i = 0; i < data.length; i++) {
345                                                                        for ( var i in data) {
346                                                                                if (data[i].id == id) {
347                                                                                        return i;
348                                                                                }
349                                                                        }
350                                                                }
[780]351
[846]352                                                                var searchItemsByParent = function(parentID,
353                                                                                type) {
354                                                                        var data = {};
355                                                                        var aryItem = [];
356                                                                        var index = aryItem.length;
[780]357
[846]358                                                                        switch (type) {
359                                                                        case 'directory':
360                                                                                data = o.data.DIRECTORIES;
361                                                                                break;
362                                                                        case 'file':
363                                                                                data = o.data.FILES;
364                                                                                break;
365                                                                        default:
366                                                                                break;
367                                                                        }
[780]368
[846]369                                                                        for (i in data) {
370                                                                                if (data[i].parentID == parentID) {
371                                                                                        aryItem[index] = data[i];
372                                                                                        index++;
373                                                                                }
374                                                                        }
[780]375
[846]376                                                                        return aryItem;
377                                                                }
[780]378
[846]379                                                                /***********************************************
380                                                                 * TOOLBAR EVENTS - START *
381                                                                 **********************************************/
382                                                                var btnRefreshClick = function(obj) {
383                                                                        $(o).find('i').addClass('icon-spin');
384                                                                        sendCommand({
385                                                                                postdata : null,
386                                                                                callbackSuccess : function(parseData) {
387                                                                                        o.data = parseData;
388                                                                                        self.updateData({
389                                                                                                updateAll : true
390                                                                                        });
391                                                                                        o.oTree.refeshTree();
392                                                                                },
393                                                                                callbackDone : function() {
394                                                                                        $(o).find('i').removeClass(
395                                                                                                        'icon-spin');
396                                                                                },
397                                                                                callbackFail : failInit
398                                                                        });
399                                                                }
[780]400
[846]401                                                                var btnNewFolderClick = function() {
402                                                                        createFolderStart();
403                                                                }
[780]404
[846]405                                                                var btnUploadClick = function() {
406                                                                        uploadStart();
407                                                                        uploadInit();
[780]408
[846]409                                                                }
410                                                                var btnDownloadClick = function() {
[848]411                                                                        var items = o.oGrid.getHighLightItem();
[846]412                                                                        var fileid = new Array();
413                                                                        var folder = new Array();
414                                                                        for ( var i = 0; i < $(items).length; i++) {
415                                                                                if (items[i].type == "file") {
416                                                                                        var file = items[i].id;
417                                                                                        fileid.push(file);
418                                                                                }
419                                                                                if (items[i].type == "directory") {
420                                                                                        var file = items[i].id;
421                                                                                        folder.push(file);
422                                                                                }
423                                                                        }
[847]424                                                                        var link = o.host + "download/getFile/";
425                                                                        self.redirectPost(link, {
[846]426                                                                                file : fileid.toString(),
427                                                                                folder : folder.toString()
428                                                                        });
429                                                                }
[780]430
[846]431                                                                var btnDelClick = function() {
[848]432                                                                        var items = o.oGrid.getHighLightItem();
[846]433                                                                        if ($(items).length == 0) {
434                                                                                var dirID = $(o.oTree.getSelectedNode())
435                                                                                                .attr('id');
436                                                                                var item = o.data.DIRECTORIES[searchItemByID(
437                                                                                                dirID, 'directory')];
438                                                                                item.type = 'directory';
439                                                                                items = [ item ];
440                                                                        }
441                                                                        self.deleteItem(items);
442                                                                }
[780]443
[846]444                                                                var btnCopyClick = function() {
445                                                                        copy('copy');
446                                                                }
[780]447
[846]448                                                                var btnPasteClick = function() {
449                                                                        paste();
450                                                                }
[780]451
[846]452                                                                var btnCutClick = function() {
453                                                                        copy('move');
454                                                                }
[780]455
[846]456                                                                var bindEventToToolbars = function() {
457                                                                        $(btnRefresh).click(function(e) {
458                                                                                btnRefreshClick(this)
459                                                                        });
[780]460
[846]461                                                                        $(btnNewFolder).click(function(e) {
462                                                                                btnNewFolderClick()
463                                                                        });
464                                                                        $(btnUpload).click(function(e) {
465                                                                                btnUploadClick()
466                                                                        });
[780]467
[846]468                                                                        $(btnDel).click(function(e) {
469                                                                                btnDelClick()
470                                                                        });
471                                                                        $(btnCopy).click(function(e) {
472                                                                                btnCopyClick()
473                                                                        });
474                                                                        $(btnCut).click(function(e) {
475                                                                                btnCutClick()
476                                                                        });
477                                                                        $(btnPaste).click(function(e) {
478                                                                                btnPasteClick()
479                                                                        })
480                                                                        $(btnPreview).click(function(e) {
481                                                                                btnPreviewClick()
482                                                                        })
483                                                                        $(btnDownload).click(function(e) {
484                                                                                btnDownloadClick()
485                                                                        })
[780]486
[846]487                                                                        /*
488                                                                         * btnShare btnPreview btnDownload btnUpload
489                                                                         */
490                                                                }
491                                                                /***********************************************
492                                                                 * TOOLBAR EVENTS - END *
493                                                                 **********************************************/
[780]494
[846]495                                                                /***********************************************
496                                                                 * DOCUMENT EVENTS BINDING - START *
497                                                                 **********************************************/
498                                                                var documentEventsBinding = function() {
499                                                                        $(document)
500                                                                                        .bind(
501                                                                                                        'keydown',
502                                                                                                        function(e) {
503                                                                                                                switch (e.which) {
504                                                                                                                case 113:
505                                                                                                                case 27:
506                                                                                                                        var gridSelectedItems = o.oGrid
[848]507                                                                                                                                        .getHighLightItem();
[846]508                                                                                                                        if ($(gridSelectedItems).length > 0) {
509                                                                                                                                o.oGrid
510                                                                                                                                                .rename(e.which);
511                                                                                                                        } else {
512                                                                                                                                o.oTree
513                                                                                                                                                .rename(e.which);
514                                                                                                                        }
515                                                                                                                        break;
516                                                                                                                case 46:
517                                                                                                                        // delete
518                                                                                                                        btnDelClick();
519                                                                                                                        break;
520                                                                                                                case 65:
521                                                                                                                        if (e.ctrlKey) {
522                                                                                                                                o.oGrid
523                                                                                                                                                .selectAllNode();
524                                                                                                                        }
525                                                                                                                        break;
526                                                                                                                default:
527                                                                                                                        break;
528                                                                                                                }
529                                                                                                        });
530                                                                }
531                                                                /***********************************************
532                                                                 * DOCUMENT EVENTS BINDING - END *
533                                                                 **********************************************/
[807]534
[846]535                                                                /***********************************************
536                                                                 * CREATE FOLDER - START *
537                                                                 **********************************************/
538                                                                var createFolderStart = function() {
539                                                                        var promptOptions = {
540                                                                                title : "Tạo thư mục mới",
541                                                                                buttons : {
542                                                                                        confirm : {
543                                                                                                label : "Lưu"
544                                                                                        },
545                                                                                        cancel : {
546                                                                                                label : "Há»§y"
547                                                                                        }
548                                                                                },
549                                                                                callback : function(result) {
550                                                                                        if (result === null) {
551                                                                                        } else {
552                                                                                                createFolder(treeCurrentNode,
553                                                                                                                result);
554                                                                                        }
555                                                                                }
556                                                                        };
557
558                                                                        return bootbox.prompt(promptOptions);
559                                                                }
560
561                                                                var uploadStart = function() {
562                                                                        var userid = o.data.userinfo.us_id;
563                                                                        var promptOptions = {
564                                                                                title : "Tải lên",
565                                                                                message : "<form id='upload' method='post'  action='"
566                                                                                                + api_url
567                                                                                                + "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='response' value='1'/><input type='hidden' name='dir' value='"
568                                                                                                + self.getTreeCurrentNode()
569                                                                                                + "'/><input type='hidden' name='userid' value='"
570                                                                                                + userid
571                                                                                                + "'/><input type='file' name='upload_file' multiple /></div><ul></ul></form>",
572                                                                                buttons : {
573                                                                                        success : {
574                                                                                                label : "Xong",
575                                                                                                className : "btn btn-primary",
576                                                                                                callback : function(result) {
577
578                                                                                                }
579                                                                                        },
580                                                                                },
581                                                                                onEscape : function() {
582                                                                                        uploadDone(self
583                                                                                                        .getTreeCurrentNode());
584                                                                                }
585                                                                        };
586
587                                                                        return bootbox.dialog(promptOptions);
588                                                                }
589                                                                var uploadDone = function(result) {
590
591                                                                }
592                                                                var btnPreviewClick = function() {
[848]593                                                                        var items = o.oGrid.getHighLightItem();
[846]594                                                                        if ($(items).length == 0) {
595                                                                                var dirID = $(o.oTree.getSelectedNode())
596                                                                                                .attr('id');
597                                                                                var item = o.data.DIRECTORIES[searchItemByID(
598                                                                                                dirID, 'directory')];
599                                                                                item.type = 'directory';
600                                                                                items = [ item ];
601                                                                        }
602                                                                        previewFile(items[0]);
603                                                                }
604
605                                                                var previewFile = function(node) {
606                                                                        var content = "";
607                                                                        $ext = node.fileurl.split('.').pop();
608                                                                        $ext = $ext.toLowerCase();
609                                                                        if ($.inArray($ext, [ "jpg", "jpeg", "png",
610                                                                                        "gif" ]) >= 0) {
611                                                                                content = "<img style='width:100%' src='"
612                                                                                                + node.fileurl
613                                                                                                + "' /><br />"
614                                                                                                + node.name;
615                                                                                bootbox.alert(content);
616                                                                        }
617
618                                                                        if ($.inArray($ext, [ "flv", "mp4", "avi",
619                                                                                        "m4v" ]) >= 0) {
620                                                                                $
621                                                                                                .ajax({
622                                                                                                        url : o.host
623                                                                                                                        + "preview/getVideoPreview/",
624                                                                                                        type : "POST",
625                                                                                                        data : {
626                                                                                                                fileurl : node.fileurl,
627                                                                                                                name : node.name
628                                                                                                        },
629                                                                                                        success : function(data,
630                                                                                                                        textStatus, jqXHR) {
631                                                                                                                bootbox.alert(data);
632                                                                                                        },
633                                                                                                        error : function(jqXHR,
634                                                                                                                        textStatus,
635                                                                                                                        errorThrown) {
636
637                                                                                                        }
638                                                                                                });
639                                                                        }
640
641                                                                        if ($.inArray($ext, [ "ogg" ]) >= 0) {
642                                                                                content = '<audio controls>\
643                        <source src="'
644                                                                                                + node.fileurl
645                                                                                                + '" type="audio/ogg">\
[781]646                      Your browser does not support the audio element.\
[846]647                      </audio> <br />'
648                                                                                                + node.name;
649                                                                                bootbox.alert(content);
650                                                                        }
651                                                                        if ($.inArray($ext, [ "mp3" ]) >= 0) {
652                                                                                content = '<audio controls>\
653                        <source src="'
654                                                                                                + node.fileurl
655                                                                                                + '" type="audio/mpeg">\
[781]656                      Your browser does not support the audio element.\
[846]657                      </audio> <br />'
658                                                                                                + node.name;
659                                                                                bootbox.alert(content);
660                                                                        }
[788]661
[846]662                                                                        if ($.inArray($ext, [ "ppt", "xls", "doc",
663                                                                                        "pdf", "docx", "pptx", "xlsx" ]) >= 0) {
[780]664
[846]665                                                                                $.ajax({
666                                                                                        url : o.host
667                                                                                                        + "preview/getFilePreview/"
668                                                                                                        + node.id,
669                                                                                        type : "POST",
670                                                                                        data : {},
671                                                                                        success : function(data,
672                                                                                                        textStatus, jqXHR) {
673                                                                                                bootbox.alert(data);
674                                                                                        },
675                                                                                        error : function(jqXHR, textStatus,
676                                                                                                        errorThrown) {
[780]677
[846]678                                                                                        }
679                                                                                });
680                                                                        }
681                                                                        if ($.inArray($ext, [ "xvl" ]) >= 0) {
682                                                                                var url = o.host.replace("ajax/", "");
683                                                                                var redirect = url
684                                                                                                + 'frontend/lecture/';
685                                                                                self.redirectPost(redirect, {
686                                                                                        fileid : node.id
687                                                                                });
688                                                                        }
689                                                                        $(".bootbox").addClass("preview");
690                                                                }
[780]691
[846]692                                                                var uploadInit = function() {
693                                                                        var ul = $('#upload ul');
[780]694
[846]695                                                                        $('#drop a').click(function() {
696                                                                                $(this).parent().find('input').click();
697                                                                        });
[780]698
[846]699                                                                        $('#upload')
700                                                                                        .fileupload(
701                                                                                                        {
702                                                                                                                dropZone : $('#drop'),
703                                                                                                                add : function(e, data) {
[780]704
[846]705                                                                                                                        var tpl = $('<li class="working"><input type="text" value="0" data-width="48" data-height="48"'
706                                                                                                                                        + ' data-fgColor="#0788a5" data-readOnly="1" data-bgColor="#3e4043" /><p></p><span></span></li>');
707                                                                                                                        tpl
708                                                                                                                                        .find('p')
709                                                                                                                                        .text(
710                                                                                                                                                        data.files[0].name)
711                                                                                                                                        .append(
712                                                                                                                                                        '<i>'
713                                                                                                                                                                        + formatFileSize(data.files[0].size)
714                                                                                                                                                                        + '</i>');
715                                                                                                                        data.context = tpl
716                                                                                                                                        .appendTo(ul);
717                                                                                                                        tpl.find('input')
718                                                                                                                                        .knob();
719                                                                                                                        tpl
720                                                                                                                                        .find(
721                                                                                                                                                        'span')
722                                                                                                                                        .click(
723                                                                                                                                                        function() {
[780]724
[846]725                                                                                                                                                                if (tpl
726                                                                                                                                                                                .hasClass('working')) {
727                                                                                                                                                                        jqXHR
728                                                                                                                                                                                        .abort();
729                                                                                                                                                                }
[780]730
[846]731                                                                                                                                                                tpl
732                                                                                                                                                                                .fadeOut(function() {
733                                                                                                                                                                                        tpl
734                                                                                                                                                                                                        .remove();
735                                                                                                                                                                                });
[780]736
[846]737                                                                                                                                                        });
[780]738
[846]739                                                                                                                        var jqXHR = data
740                                                                                                                                        .submit();
741                                                                                                                },
742                                                                                                                progress : function(e,
743                                                                                                                                data) {
[780]744
[846]745                                                                                                                        // Calculate the
746                                                                                                                        // completion
747                                                                                                                        // percentage of the
748                                                                                                                        // upload
749                                                                                                                        var progress = parseInt(
750                                                                                                                                        data.loaded
751                                                                                                                                                        / data.total
752                                                                                                                                                        * 100,
753                                                                                                                                        10);
[780]754
[846]755                                                                                                                        // Update the hidden
756                                                                                                                        // input field and
757                                                                                                                        // trigger a change
758                                                                                                                        // so that the
759                                                                                                                        // jQuery knob
760                                                                                                                        // plugin knows to
761                                                                                                                        // update the dial
762                                                                                                                        data.context
763                                                                                                                                        .find(
764                                                                                                                                                        'input')
765                                                                                                                                        .val(
766                                                                                                                                                        progress)
767                                                                                                                                        .change();
[780]768
[846]769                                                                                                                        if (progress == 100) {
770                                                                                                                                data.context
771                                                                                                                                                .removeClass('working');
[780]772
[846]773                                                                                                                        }
774                                                                                                                },
775                                                                                                                fail : function(e, data) {
776                                                                                                                        // Something has
777                                                                                                                        // gone wrong!
778                                                                                                                        data.context
779                                                                                                                                        .addClass('error');
780                                                                                                                },
781                                                                                                                done : function(e, data) {
782                                                                                                                        // var newFileData =
783                                                                                                                        // {"DIRECTORIES":
784                                                                                                                        // [{"id": "5000",
785                                                                                                                        // "name": "Dir1",
786                                                                                                                        // "parentID": 85}],
787                                                                                                                        // "FILES": [{"id":
788                                                                                                                        // "2000", "name":
789                                                                                                                        // "File in root 1",
790                                                                                                                        // "parentID": 85,
791                                                                                                                        // "minetype":
792                                                                                                                        // "text"},{"id":
793                                                                                                                        // "2001", "name":
794                                                                                                                        // "File in root 2",
795                                                                                                                        // "parentID": 85,
796                                                                                                                        // "minetype":
797                                                                                                                        // "text"}],
798                                                                                                                        // "ERROR": {"err":
799                                                                                                                        // "", "errCode":
800                                                                                                                        // 0}};
801                                                                                                                        var newFileData = data.result;
[854]802                                                                                                                        newFileData = $.parseJSON(data.result);
[846]803                                                                                                                        if (newFileData.ERROR.errCode == 0) {
804                                                                                                                                for ( var i = 0; i < $(newFileData.FILES).length; i++) {
805                                                                                                                                        var file = newFileData.FILES[i];
806                                                                                                                                        var node = {
807                                                                                                                                                thumbnail : file.thumbnail,
808                                                                                                                                                id : file.id,
809                                                                                                                                                name : file.name,
810                                                                                                                                                fileurl : file.fileurl,
811                                                                                                                                                parentID : file.parentID,
[854]812                                                                                                                                                minetype : file.minetype,
813                                                                                                                                                size: file.size
[846]814                                                                                                                                        };
[854]815                                                                                                                                        o.oGrid.createNode(node);
[846]816                                                                                                                                        o.data.FILES[$(o.data.FILES).length] = node;
817                                                                                                                                }
[780]818
[846]819                                                                                                                                for ( var i = 0; i < $(newFileData.DIRECTORIES).length; i++) {
820                                                                                                                                        var file = newFileData.DIRECTORIES[i];
821                                                                                                                                        var node = {
822                                                                                                                                                id : file.id,
823                                                                                                                                                name : file.name,
824                                                                                                                                                parentID : file.parentID,
825                                                                                                                                                minetype : file.minetype
826                                                                                                                                        };
[854]827                                                                                                                                        o.oTree.createNode(node);
828                                                                                                                                        o.oGrid.createNode(node);
[846]829                                                                                                                                        o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = node;
830                                                                                                                                }
[780]831
[846]832                                                                                                                                /*
833                                                                                                                                 * var node =
834                                                                                                                                 * {id:
835                                                                                                                                 * parseData.id,
836                                                                                                                                 * name:
837                                                                                                                                 * parseData.name,
838                                                                                                                                 * parentID:
839                                                                                                                                 * parseData.parentID};
840                                                                                                                                 * o.oTree.createNode(node);
841                                                                                                                                 * o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] =
842                                                                                                                                 * node; if
843                                                                                                                                 * (o.oGrid)
844                                                                                                                                 * o.oGrid.reloadGrid();
845                                                                                                                                 */
846                                                                                                                        }
847                                                                                                                }
[780]848
[846]849                                                                                                        });
[780]850
[846]851                                                                        $(document).on('drop dragover',
852                                                                                        function(e) {
853                                                                                                e.preventDefault();
854                                                                                        });
[780]855
[846]856                                                                        function formatFileSize(bytes) {
857                                                                                if (typeof bytes !== 'number') {
858                                                                                        return '';
859                                                                                }
[780]860
[846]861                                                                                if (bytes >= 1000000000) {
862                                                                                        return (bytes / 1000000000)
863                                                                                                        .toFixed(2)
864                                                                                                        + ' GB';
865                                                                                }
[780]866
[846]867                                                                                if (bytes >= 1000000) {
868                                                                                        return (bytes / 1000000).toFixed(2)
869                                                                                                        + ' MB';
870                                                                                }
[780]871
[846]872                                                                                return (bytes / 1000).toFixed(2)
873                                                                                                + ' KB';
874                                                                        }
[780]875
[846]876                                                                };
[780]877
[846]878                                                                var createFolder = function(parent, name) {
879                                                                        var postdata = {
880                                                                                fname : name,
881                                                                                fparentid : parent
882                                                                        };
883                                                                        var script = 'createdir';
884                                                                        /* isDev = true; */
885                                                                        sendCommand({
886                                                                                postdata : postdata,
887                                                                                script : script,
888                                                                                callbackSuccess : function(parseData) {
889                                                                                        createFolderFinish(parseData);
890                                                                                },
891                                                                                callbackFail : function() {
892                                                                                }
893                                                                        });
894                                                                }
[780]895
[846]896                                                                var createFolderFinish = function(parseData) {
897                                                                        /* isDev = false; */
898                                                                        if (parseData.ERROR.errCode == 0) {
899                                                                                var node = {
900                                                                                        id : parseData.id,
901                                                                                        name : parseData.name,
902                                                                                        parentID : parseData.parentID
903                                                                                };
904                                                                                o.oTree.createNode(node);
905                                                                                o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = node;
906                                                                                if (o.oGrid)
907                                                                                        o.oGrid.reloadGrid();
908                                                                        }
909                                                                }
910                                                                /***********************************************
911                                                                 * CREATE FOLDER - END *
912                                                                 **********************************************/
913                                                                /***********************************************
914                                                                 * COPY & PASTE & MOVE - START * =***********
915                                                                 **********************************************/
916                                                                var copy = function(act) {
917                                                                        // detect selected items
918                                                                        // push to clipboard
[848]919                                                                        var items = o.oGrid.getHighLightItem();
[780]920
[846]921                                                                        if ($(items).length == 0) {
922                                                                                var node = o.oTree.getSelectedNode();
923                                                                                var itemID = $(node).attr('id');
[780]924
[846]925                                                                                if (itemID == 0)
926                                                                                        return false;
[780]927
[846]928                                                                                items[0] = o.data.DIRECTORIES[searchItemByID(
929                                                                                                itemID, 'directory')];
930                                                                                items[0].type = 'directory';
931                                                                        }
[780]932
[846]933                                                                        if ($(items).length > 0) {
934                                                                                oClipBoard.items = items;
935                                                                                oClipBoard.act = act;
936                                                                        }
937                                                                        return true;
938                                                                }
[780]939
[846]940                                                                var paste = function() {
941                                                                        if ((oClipBoard.act != 'copy' && oClipBoard.act != 'move')
942                                                                                        || oClipBoard.items == null)
943                                                                                return;
[780]944
[846]945                                                                        var items = [];
946                                                                        var destination = self.getTreeCurrentNode();
947                                                                        if (oClipBoard.act != 'copy') {
948                                                                                $(oClipBoard.items)
949                                                                                                .each(
950                                                                                                                function(index) {
951                                                                                                                        var node = new Object;
952                                                                                                                        if (this.type == 'directory')
953                                                                                                                                buildTreeFromParent(
954                                                                                                                                                this.id,
955                                                                                                                                                node);
956                                                                                                                        else {
957                                                                                                                                node.id = this.id;
958                                                                                                                                node.type = 'file';
959                                                                                                                        }
[780]960
[846]961                                                                                                                        items[index] = node;
962                                                                                                                });
963                                                                        } else {
964                                                                                items = oClipBoard.items;
965                                                                        }
[780]966
[846]967                                                                        for ( var i = 0; i < items.length; i++) {
968                                                                                if (items[i].type == 'directory') {
969                                                                                        items[i] = self
970                                                                                                        .getAllDirChilds(items[i]);
971                                                                                }
972                                                                        }
[780]973
[846]974                                                                        var postdata = {
975                                                                                act : oClipBoard.act,
976                                                                                destination : destination,
977                                                                                data : JSON.stringify(items)
978                                                                        };
979                                                                        var script = oClipBoard.act;
[780]980
[846]981                                                                        sendCommand({
982                                                                                postdata : postdata,
983                                                                                script : script,
984                                                                                callbackSuccess : function(parseData) {
985                                                                                        if (oClipBoard.act == 'copy') {
986                                                                                                $(parseData.DIRECTORIES)
987                                                                                                                .each(
988                                                                                                                                function(index) {
989                                                                                                                                        o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = this;
990                                                                                                                                });
[780]991
[846]992                                                                                                $(parseData.FILES)
993                                                                                                                .each(
994                                                                                                                                function(index) {
995                                                                                                                                        o.data.FILES[$(o.data.FILES).length] = this;
996                                                                                                                                });
[780]997
[846]998                                                                                                o.data.DIRECTORIES
999                                                                                                                .sort(function(a, b) {
1000                                                                                                                        return a.parentID
1001                                                                                                                                        - b.parentID;
1002                                                                                                                });
[780]1003
[846]1004                                                                                                o.oTree
1005                                                                                                                .setData(o.data.DIRECTORIES);
1006                                                                                                o.oGrid.setData(o.data);
1007                                                                                                o.oTree
1008                                                                                                                .createCopyNode(parseData.DIRECTORIES);
1009                                                                                                o.oGrid.reloadGrid();
1010                                                                                        } else if (oClipBoard.act == 'move') {
[780]1011
[846]1012                                                                                        }
1013                                                                                }
1014                                                                        });
1015                                                                }
[780]1016
[846]1017                                                                var move = function() {
[780]1018
[846]1019                                                                }
[780]1020
[846]1021                                                                var copyTo = function() {
[780]1022
[846]1023                                                                }
[780]1024
[846]1025                                                                var moveTo = function() {
[780]1026
[846]1027                                                                }
[780]1028
[846]1029                                                                /***********************************************
1030                                                                 * COPY & PASTE & MOVE - END *
1031                                                                 **********************************************/
[780]1032
[846]1033                                                                this.deleteItem = function(item) {
[806]1034
[846]1035                                                                        var confirmText = 'Bạn có muốn xóa ';
[806]1036
[846]1037                                                                        if ($.isArray(item) && item.length > 1) {
1038                                                                                confirmText += 'các thư mục (và files) đã chọn?';
1039                                                                        } else if (item.length == 1) {
1040                                                                                if (item[0].id == 0)
1041                                                                                        return false;
1042                                                                                confirmText += (item[0].type == 'directory') ? 'thư mục'
1043                                                                                                : 'file';
1044                                                                                confirmText += ' <span style="font-weight:bold">'
1045                                                                                                + item[0].name
1046                                                                                                + "</span> khÃŽng?";
1047                                                                        }
[806]1048
[846]1049                                                                        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>';
[806]1050
[846]1051                                                                        var parentID = item[0].parentID;
[780]1052
[846]1053                                                                        for ( var i = 0; i < item.length; i++) {
1054                                                                                if (item[i].type == 'directory') {
1055                                                                                        item[i] = self
1056                                                                                                        .getAllDirChilds(item[i]);
1057                                                                                }
1058                                                                        }
[780]1059
[846]1060                                                                        var confirmOptions = {
1061                                                                                message : confirmText,
1062                                                                                buttons : {
1063                                                                                        confirm : {
1064                                                                                                label : "Xóa"
1065                                                                                        },
1066                                                                                        cancel : {
1067                                                                                                label : "KhÃŽng xóa"
1068                                                                                        }
1069                                                                                },
1070                                                                                callback : function(result) {
1071                                                                                        if (result) {
1072                                                                                                var delobj = JSON
1073                                                                                                                .stringify(item);
1074                                                                                                var postdata = {
1075                                                                                                        delobj : delobj
1076                                                                                                };
1077                                                                                                var script = 'delete';
1078                                                                                                sendCommand({
1079                                                                                                        postdata : postdata,
1080                                                                                                        script : script,
1081                                                                                                        callbackSuccess : function(
1082                                                                                                                        parseData) {
1083                                                                                                                if ($(parseData.DIRECTORIES).length > 0) {
[854]1084                                                                                                                        $(parseData.DIRECTORIES).each(
1085                                                                                                                                                        function(index) {
1086                                                                                                                                                                o.oTree.deletion(this);
1087                                                                                                                                                                o.oGrid.deletion(this,'directory');
[846]1088                                                                                                                                                        });
1089                                                                                                                }
[780]1090
[846]1091                                                                                                                if ($(parseData.FILES).length > 0) {
[854]1092                                                                                                                        $(parseData.FILES).each(
1093                                                                                                                                                        function(index) {
1094                                                                                                                                                                var file = o.data.FILES[searchItemByID(this,'file')];
1095                                                                                                                                                                o.oGrid.deletion(this,file.minetype);
[846]1096                                                                                                                                                        });
1097                                                                                                                }
1098                                                                                                        },
1099                                                                                                        callbackDone : function(obj) {
1100                                                                                                                if ($(parseData.DIRECTORIES).length > 0) {
[854]1101                                                                                                                        $(parseData.DIRECTORIES).each(
1102                                                                                                                                                        function(index) {
1103                                                                                                                                                                o.data.DIRECTORIES.splice(searchItemByID(this,'directory'), 1);
[846]1104                                                                                                                                                        });
1105                                                                                                                }
[780]1106
[846]1107                                                                                                                if ($(parseData.FILES).length > 0) {
[854]1108                                                                                                                        $(parseData.FILES).each(
1109                                                                                                                                                        function(index) {
1110                                                                                                                                                                o.data.FILES.splice(searchItemByID(this,'file'), 1);
[846]1111                                                                                                                                                        });
1112                                                                                                                }
[780]1113
[854]1114                                                                                                                o.oTree.setData(o.data.DIRECTORIES);
[846]1115                                                                                                                o.oGrid.setData(o.data);
[854]1116                                                                                                                self.setTreeCurrentNode(parentID);
[846]1117                                                                                                                o.oGrid.reloadGrid();
[854]1118                                                                                                                console.log(o.data);
[846]1119                                                                                                        },
1120                                                                                                        callbackFail : function() {
1121                                                                                                        }
1122                                                                                                });
1123                                                                                        }
1124                                                                                }
1125                                                                        };
[780]1126
[846]1127                                                                        bootbox.confirm(confirmOptions);
1128                                                                }
[780]1129
[846]1130                                                                this.getAllDirChilds = function(oDirItem) {
1131                                                                        var aryChildDirTmp = [];
1132                                                                        var aryChildDirID = [];
1133                                                                        var aryChildFiles = searchItemsByParent(
1134                                                                                        oDirItem.id, 'file');
1135                                                                        var aryChildDirs = [];
[780]1136
[846]1137                                                                        getAllDirChild(oDirItem.id, aryChildDirTmp);
1138                                                                        for ( var d = 1; d < aryChildDirTmp.length; d++) {
1139                                                                                aryChildDirID[d - 1] = aryChildDirTmp[d];
1140                                                                        }
[780]1141
[846]1142                                                                        for ( var j = 0; j < aryChildDirID.length; j++) {
1143                                                                                if (o.data.DIRECTORIES[searchItemByID(
1144                                                                                                aryChildDirID[j], 'directory')] != undefined)
1145                                                                                        aryChildDirs[aryChildDirs.length] = o.data.DIRECTORIES[searchItemByID(
1146                                                                                                        aryChildDirID[j],
1147                                                                                                        'directory')];
[780]1148
[846]1149                                                                                var aryTmp = searchItemsByParent(
1150                                                                                                aryChildDirID[j], 'file');
1151                                                                                if (aryTmp.length > 0)
1152                                                                                        for ( var f in aryTmp) {
1153                                                                                                aryChildFiles[aryChildFiles.length] = aryTmp[f];
1154                                                                                        }
1155                                                                        }
[780]1156
[846]1157                                                                        oDirItem.childDirs = aryChildDirs;
1158                                                                        oDirItem.childFiles = aryChildFiles;
1159                                                                        return oDirItem;
1160                                                                }
[837]1161
[846]1162                                                                this.setTreeCurrentNode = function(treeNode) {
1163                                                                        // fire when click a node on Tree
1164                                                                        // then fire action of Grid
1165                                                                        treeCurrentNode = treeNode;
1166                                                                        if (o.oGrid)
1167                                                                                o.oGrid.reloadGrid();
1168                                                                };
[780]1169
[846]1170                                                                this.getTreeCurrentNode = function() {
1171                                                                        return treeCurrentNode;
1172                                                                }
1173
1174                                                                this.gridNodeDblClick = function(node) {
1175                                                                        if (node.minetype == 'directory') {
1176                                                                                var treeNode = $('#' + o.tree)
1177                                                                                                .find(
1178                                                                                                                'UL.vstree[rel^="node'
1179                                                                                                                                + node.parentID
1180                                                                                                                                + '"] > LI[rel^="folder"] > A#'
1181                                                                                                                                + node.id);
1182                                                                                o.oTree.activeNode(treeNode);
1183                                                                        } else {
1184                                                                                // execute or preview file
1185                                                                                previewFile(node);
1186                                                                        }
1187                                                                };
1188
1189                                                                this.createNewFolder = function() {
1190
1191                                                                }
1192
1193                                                                this.updateData = function(p) {
1194                                                                        if (p.item == undefined)
1195                                                                                p.item = null;
1196                                                                        if (p.updateAll == undefined)
1197                                                                                p.updateAll = false;
1198                                                                        if (p.from == undefined)
1199                                                                                p.from = null;
1200                                                                        if (p.type == undefined)
1201                                                                                p.type = null;
1202                                                                        if (p.callback == undefined)
1203                                                                                p.callback = null;
1204
1205                                                                        var obj = p.from == 'tree' ? o.oGrid
1206                                                                                        : o.oTree;
1207                                                                        if (!p.updateAll) {
1208                                                                                var index = searchItemByID(p.item.id,
1209                                                                                                p.type);
1210                                                                                switch (p.type) {
1211                                                                                case 'directory':
1212                                                                                        o.data.DIRECTORIES[index].name = p.item.name;
1213                                                                                        o.data.DIRECTORIES[index].parentID = p.item.parentID;
1214                                                                                        break;
1215                                                                                case 'file':
1216                                                                                        o.data.FILES[index].name = p.item.name;
1217                                                                                        o.data.FILES[index].parentID = p.item.parentID;
1218                                                                                        o.data.FILES[index].minetype = p.item.minetype;
1219                                                                                        o.data.FILES[index].fileurl = p.item.fileurl;
1220                                                                                        break;
1221                                                                                default:
1222                                                                                        break;
1223                                                                                }
1224                                                                        }
1225
1226                                                                        o.oTree.setData(o.data.DIRECTORIES);
1227                                                                        o.oGrid.setData(o.data);
1228
1229                                                                        if (p.callback != null) {
1230                                                                                eval('obj.' + p.callback + '(p.item);')
1231                                                                        }
1232
1233                                                                        // call sendCommand
1234                                                                }
1235
1236                                                                this.searchItemsByParent = function(parentID,
1237                                                                                type) {
1238                                                                        return searchItemsByParent(parentID, type);
1239                                                                }
1240
1241                                                                this.searchItemByID = function(id, type) {
1242                                                                        return searchItemByID(id, type);
1243                                                                }
1244
1245                                                                this.refreshStatusBar = function() {
1246                                                                        var totalSize = 0;
1247                                                                        var message = '';
1248                                                                        if (o.data.FILES.length > 0) {
1249                                                                                for ( var i = 0; i < o.data.FILES.length; i++) {
1250                                                                                        totalSize += parseInt(o.data.FILES[i].size);
1251                                                                                }
1252                                                                        }
1253
1254                                                                        message = '<span>Tổng dung lượng đã sá»­ dụng: <strong>'
1255                                                                                        + self.formatFileSize(totalSize)
1256                                                                                        + '</strong></span>';
1257
[848]1258                                                                        var items = o.oGrid.getHighLightItem();
[849]1259                                                                        if (items.length == 0) {
[850]1260                                                                                var id = $(o.oTree.getSelectedNode()).attr('id');
1261                                                                                var item = o.data.DIRECTORIES[self.searchItemByID(id, 'directory')];
1262                                                                                console.log(item);
[849]1263                                                                        }
[846]1264                                                                        if (items.length == 1) {
1265                                                                                if ((typeof items[0].minetype !== 'undefined')) {
1266                                                                                        message += '<span>Tệp: <strong>'
1267                                                                                                        + items[0].name
1268                                                                                                        + '</strong></span>';
1269                                                                                        message += '<span> - Dung lượng: <strong>'
1270                                                                                                        + self
1271                                                                                                                        .formatFileSize(items[0].size)
1272                                                                                                        + '</strong></span>';
1273                                                                                } else {
1274                                                                                        message += '<span>Thư mục: <strong>'
1275                                                                                                        + items[0].name
1276                                                                                                        + '</strong></span>';
1277                                                                                }
1278                                                                        } else if (items.length > 1) {
1279                                                                                var selectedSize = 0;
1280                                                                                for ( var i = 0; i < items.length; i++) {
1281                                                                                        selectedSize += (typeof items[i].minetype !== 'undefined') ? parseInt(items[i].size)
1282                                                                                                        : 0;
1283                                                                                }
1284                                                                                message += '<span><strong>'
1285                                                                                                + items.length
1286                                                                                                + ' tệp (thư mục)</strong> được chọn</span>';
1287                                                                                message += '<span> - Dung lượng: <strong>'
1288                                                                                                + self
1289                                                                                                                .formatFileSize(selectedSize)
1290                                                                                                + '</strong></span>';
1291                                                                        }
1292
1293                                                                        $(statusbar).html(message);
1294                                                                }
1295
1296                                                                this.redirectPost = function(location, args) {
1297                                                                        var form = '';
1298                                                                        $.each(args, function(key, value) {
1299                                                                                form += '<input type="hidden" name="'
1300                                                                                                + key + '" value="' + value
1301                                                                                                + '">';
1302                                                                        });
1303                                                                        $(
1304                                                                                        '<form action="' + location
1305                                                                                                        + '" method="POST">' + form
1306                                                                                                        + '</form>').appendTo(
1307                                                                                        'body').submit();
1308                                                                }
1309
1310                                                                this.formatFileSize = function(size) {
1311                                                                        var i;
1312                                                                        i = Math.floor(Math.log(size)
1313                                                                                        / Math.log(1024));
1314                                                                        if ((size === 0) || (parseInt(size) === 0)) {
1315                                                                                return "0 kB";
1316                                                                        } else if (isNaN(i)
1317                                                                                        || (!isFinite(size))
1318                                                                                        || (size === Number.POSITIVE_INFINITY)
1319                                                                                        || (size === Number.NEGATIVE_INFINITY)
1320                                                                                        || (size == null) || (size < 0)) {
1321                                                                                console.info("Throwing error");
1322                                                                                throw Error(""
1323                                                                                                + size
1324                                                                                                + " did not compute to a valid number to be humanized.");
1325                                                                        } else {
1326                                                                                return (size / Math.pow(1024, i))
1327                                                                                                .toFixed(2)
1328                                                                                                * 1
1329                                                                                                + " "
1330                                                                                                + [ "B", "KB", "MB", "GB",
1331                                                                                                                "TB", "PB", "EB", "ZB",
1332                                                                                                                "YB" ][i];
1333                                                                        }
1334                                                                }
1335
1336                                                                this.initialize = function() {
1337                                                                        init();
1338                                                                        return this;
1339                                                                };
1340
1341                                                                return this.initialize();
1342                                                        }
1343
1344                                                });
1345        })(jQuery);
Note: See TracBrowser for help on using the repository browser.