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

Last change on this file since 846 was 846, checked in by dungnv, 10 years ago
File size: 40.2 KB
Line 
1if (jQuery)
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;
14
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;
25
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';
40
41                                                                if (o.filehosting == undefined)
42                                                                        o.filehosting = 'http://sbgapi.violet.vn/';
43
44                                                                if (o.invisibledButtons == undefined)
45                                                                        o.invisibledButtons = null;
46
47                                                                o.host = o.host + 'ajax/';
48
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                                                                };
62
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');
91
92                                                                var toolbarButtons = [ btnNewFolder, btnDel,
93                                                                                btnCopy, btnCut, btnPaste, btnShare,
94                                                                                btnPreview, btnDownload, btnUpload,
95                                                                                btnRefresh ];
96                                                                var statusbar = $('DIV#' + o.statusbar);
97
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;
115
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                                                                                                                        }
129
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                                                                                                                        }
139
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                                                                        }
163
164                                                                };
165
166                                                                var getDirTreeMaxWidth = function() {
167                                                                        var scrWidth = $(o.maincontainer).width();
168                                                                        return parseInt(scrWidth / 2);
169                                                                }
170
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);
192
193                                                                        if (o.invisibledButtons != null) {
194                                                                                for ( var i = 0; i < o.invisibledButtons.length; i++) {
195                                                                                        $('#' + o.invisibledButtons[i])
196                                                                                                        .hide();
197                                                                                }
198                                                                        }
199                                                                }
200
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                                                                };
214
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                                                                }
229
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');
241
242                                                                        node.id = dir.id;
243                                                                        node.name = dir.name;
244                                                                        node.type = 'directory';
245
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                                                                        });
258
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                                                                        }
274
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                                                                }
288
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                                                                }
297
298                                                                var doneInit = function() {
299                                                                        bindEventToToolbars();
300                                                                        documentEventsBinding();
301                                                                };
302
303                                                                var failInit = function(er) {
304                                                                        bootbox.alert(er.err);
305                                                                }
306
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                                                                };
330
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                                                                        }
343
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                                                                }
351
352                                                                var searchItemsByParent = function(parentID,
353                                                                                type) {
354                                                                        var data = {};
355                                                                        var aryItem = [];
356                                                                        var index = aryItem.length;
357
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                                                                        }
368
369                                                                        for (i in data) {
370                                                                                if (data[i].parentID == parentID) {
371                                                                                        aryItem[index] = data[i];
372                                                                                        index++;
373                                                                                }
374                                                                        }
375
376                                                                        return aryItem;
377                                                                }
378
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                                                                }
400
401                                                                var btnNewFolderClick = function() {
402                                                                        createFolderStart();
403                                                                }
404
405                                                                var btnUploadClick = function() {
406                                                                        uploadStart();
407                                                                        uploadInit();
408
409                                                                }
410                                                                var btnDownloadClick = function() {
411                                                                        var items = o.oGrid.getHightLightItem();
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                                                                        }
424                                                                        console.log(fileid.toString());
425                                                                        var redirect = o.host + "download/getFile/";
426                                                                        self.redirectPost(redirect, {
427                                                                                file : fileid.toString(),
428                                                                                folder : folder.toString()
429                                                                        });
430                                                                }
431
432                                                                var btnDelClick = function() {
433                                                                        var items = o.oGrid.getHightLightItem();
434                                                                        if ($(items).length == 0) {
435                                                                                var dirID = $(o.oTree.getSelectedNode())
436                                                                                                .attr('id');
437                                                                                var item = o.data.DIRECTORIES[searchItemByID(
438                                                                                                dirID, 'directory')];
439                                                                                item.type = 'directory';
440                                                                                items = [ item ];
441                                                                        }
442                                                                        self.deleteItem(items);
443                                                                }
444
445                                                                var btnCopyClick = function() {
446                                                                        copy('copy');
447                                                                }
448
449                                                                var btnPasteClick = function() {
450                                                                        paste();
451                                                                }
452
453                                                                var btnCutClick = function() {
454                                                                        copy('move');
455                                                                }
456
457                                                                var bindEventToToolbars = function() {
458                                                                        $(btnRefresh).click(function(e) {
459                                                                                btnRefreshClick(this)
460                                                                        });
461
462                                                                        $(btnNewFolder).click(function(e) {
463                                                                                btnNewFolderClick()
464                                                                        });
465                                                                        $(btnUpload).click(function(e) {
466                                                                                btnUploadClick()
467                                                                        });
468
469                                                                        $(btnDel).click(function(e) {
470                                                                                btnDelClick()
471                                                                        });
472                                                                        $(btnCopy).click(function(e) {
473                                                                                btnCopyClick()
474                                                                        });
475                                                                        $(btnCut).click(function(e) {
476                                                                                btnCutClick()
477                                                                        });
478                                                                        $(btnPaste).click(function(e) {
479                                                                                btnPasteClick()
480                                                                        })
481                                                                        $(btnPreview).click(function(e) {
482                                                                                btnPreviewClick()
483                                                                        })
484                                                                        $(btnDownload).click(function(e) {
485                                                                                btnDownloadClick()
486                                                                        })
487
488                                                                        /*
489                                                                         * btnShare btnPreview btnDownload btnUpload
490                                                                         */
491                                                                }
492                                                                /***********************************************
493                                                                 * TOOLBAR EVENTS - END *
494                                                                 **********************************************/
495
496                                                                /***********************************************
497                                                                 * DOCUMENT EVENTS BINDING - START *
498                                                                 **********************************************/
499                                                                var documentEventsBinding = function() {
500                                                                        $(document)
501                                                                                        .bind(
502                                                                                                        'keydown',
503                                                                                                        function(e) {
504                                                                                                                switch (e.which) {
505                                                                                                                case 113:
506                                                                                                                case 27:
507                                                                                                                        var gridSelectedItems = o.oGrid
508                                                                                                                                        .getHightLightItem();
509                                                                                                                        if ($(gridSelectedItems).length > 0) {
510                                                                                                                                o.oGrid
511                                                                                                                                                .rename(e.which);
512                                                                                                                        } else {
513                                                                                                                                o.oTree
514                                                                                                                                                .rename(e.which);
515                                                                                                                        }
516                                                                                                                        break;
517                                                                                                                case 46:
518                                                                                                                        // delete
519                                                                                                                        btnDelClick();
520                                                                                                                        break;
521                                                                                                                case 65:
522                                                                                                                        if (e.ctrlKey) {
523                                                                                                                                o.oGrid
524                                                                                                                                                .selectAllNode();
525                                                                                                                        }
526                                                                                                                        break;
527                                                                                                                default:
528                                                                                                                        break;
529                                                                                                                }
530                                                                                                        });
531                                                                }
532                                                                /***********************************************
533                                                                 * DOCUMENT EVENTS BINDING - END *
534                                                                 **********************************************/
535
536                                                                /***********************************************
537                                                                 * CREATE FOLDER - START *
538                                                                 **********************************************/
539                                                                var createFolderStart = function() {
540                                                                        var promptOptions = {
541                                                                                title : "Tạo thư mục mới",
542                                                                                buttons : {
543                                                                                        confirm : {
544                                                                                                label : "Lưu"
545                                                                                        },
546                                                                                        cancel : {
547                                                                                                label : "Há»§y"
548                                                                                        }
549                                                                                },
550                                                                                callback : function(result) {
551                                                                                        if (result === null) {
552                                                                                        } else {
553                                                                                                createFolder(treeCurrentNode,
554                                                                                                                result);
555                                                                                        }
556                                                                                }
557                                                                        };
558
559                                                                        return bootbox.prompt(promptOptions);
560                                                                }
561
562                                                                var uploadStart = function() {
563                                                                        var userid = o.data.userinfo.us_id;
564                                                                        var promptOptions = {
565                                                                                title : "Tải lên",
566                                                                                message : "<form id='upload' method='post'  action='"
567                                                                                                + api_url
568                                                                                                + "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='"
569                                                                                                + self.getTreeCurrentNode()
570                                                                                                + "'/><input type='hidden' name='userid' value='"
571                                                                                                + userid
572                                                                                                + "'/><input type='file' name='upload_file' multiple /></div><ul></ul></form>",
573                                                                                buttons : {
574                                                                                        success : {
575                                                                                                label : "Xong",
576                                                                                                className : "btn btn-primary",
577                                                                                                callback : function(result) {
578
579                                                                                                }
580                                                                                        },
581                                                                                },
582                                                                                onEscape : function() {
583                                                                                        uploadDone(self
584                                                                                                        .getTreeCurrentNode());
585                                                                                }
586                                                                        };
587
588                                                                        return bootbox.dialog(promptOptions);
589                                                                }
590                                                                var uploadDone = function(result) {
591
592                                                                }
593                                                                var btnPreviewClick = function() {
594                                                                        var items = o.oGrid.getHightLightItem();
595                                                                        if ($(items).length == 0) {
596                                                                                var dirID = $(o.oTree.getSelectedNode())
597                                                                                                .attr('id');
598                                                                                var item = o.data.DIRECTORIES[searchItemByID(
599                                                                                                dirID, 'directory')];
600                                                                                item.type = 'directory';
601                                                                                items = [ item ];
602                                                                        }
603                                                                        previewFile(items[0]);
604                                                                }
605
606                                                                var previewFile = function(node) {
607                                                                        var content = "";
608                                                                        $ext = node.fileurl.split('.').pop();
609                                                                        $ext = $ext.toLowerCase();
610                                                                        if ($.inArray($ext, [ "jpg", "jpeg", "png",
611                                                                                        "gif" ]) >= 0) {
612                                                                                content = "<img style='width:100%' src='"
613                                                                                                + node.fileurl
614                                                                                                + "' /><br />"
615                                                                                                + node.name;
616                                                                                bootbox.alert(content);
617                                                                        }
618
619                                                                        if ($.inArray($ext, [ "flv", "mp4", "avi",
620                                                                                        "m4v" ]) >= 0) {
621                                                                                $
622                                                                                                .ajax({
623                                                                                                        url : o.host
624                                                                                                                        + "preview/getVideoPreview/",
625                                                                                                        type : "POST",
626                                                                                                        data : {
627                                                                                                                fileurl : node.fileurl,
628                                                                                                                name : node.name
629                                                                                                        },
630                                                                                                        success : function(data,
631                                                                                                                        textStatus, jqXHR) {
632                                                                                                                bootbox.alert(data);
633                                                                                                        },
634                                                                                                        error : function(jqXHR,
635                                                                                                                        textStatus,
636                                                                                                                        errorThrown) {
637
638                                                                                                        }
639                                                                                                });
640                                                                        }
641
642                                                                        if ($.inArray($ext, [ "ogg" ]) >= 0) {
643                                                                                content = '<audio controls>\
644                        <source src="'
645                                                                                                + node.fileurl
646                                                                                                + '" type="audio/ogg">\
647                      Your browser does not support the audio element.\
648                      </audio> <br />'
649                                                                                                + node.name;
650                                                                                bootbox.alert(content);
651                                                                        }
652                                                                        if ($.inArray($ext, [ "mp3" ]) >= 0) {
653                                                                                content = '<audio controls>\
654                        <source src="'
655                                                                                                + node.fileurl
656                                                                                                + '" type="audio/mpeg">\
657                      Your browser does not support the audio element.\
658                      </audio> <br />'
659                                                                                                + node.name;
660                                                                                bootbox.alert(content);
661                                                                        }
662
663                                                                        if ($.inArray($ext, [ "ppt", "xls", "doc",
664                                                                                        "pdf", "docx", "pptx", "xlsx" ]) >= 0) {
665
666                                                                                $.ajax({
667                                                                                        url : o.host
668                                                                                                        + "preview/getFilePreview/"
669                                                                                                        + node.id,
670                                                                                        type : "POST",
671                                                                                        data : {},
672                                                                                        success : function(data,
673                                                                                                        textStatus, jqXHR) {
674                                                                                                bootbox.alert(data);
675                                                                                        },
676                                                                                        error : function(jqXHR, textStatus,
677                                                                                                        errorThrown) {
678
679                                                                                        }
680                                                                                });
681                                                                        }
682                                                                        if ($.inArray($ext, [ "xvl" ]) >= 0) {
683                                                                                var url = o.host.replace("ajax/", "");
684                                                                                var redirect = url
685                                                                                                + 'frontend/lecture/';
686                                                                                self.redirectPost(redirect, {
687                                                                                        fileid : node.id
688                                                                                });
689                                                                        }
690                                                                        $(".bootbox").addClass("preview");
691                                                                }
692
693                                                                var uploadInit = function() {
694                                                                        var ul = $('#upload ul');
695
696                                                                        $('#drop a').click(function() {
697                                                                                $(this).parent().find('input').click();
698                                                                        });
699
700                                                                        $('#upload')
701                                                                                        .fileupload(
702                                                                                                        {
703                                                                                                                dropZone : $('#drop'),
704                                                                                                                add : function(e, data) {
705
706                                                                                                                        var tpl = $('<li class="working"><input type="text" value="0" data-width="48" data-height="48"'
707                                                                                                                                        + ' data-fgColor="#0788a5" data-readOnly="1" data-bgColor="#3e4043" /><p></p><span></span></li>');
708                                                                                                                        tpl
709                                                                                                                                        .find('p')
710                                                                                                                                        .text(
711                                                                                                                                                        data.files[0].name)
712                                                                                                                                        .append(
713                                                                                                                                                        '<i>'
714                                                                                                                                                                        + formatFileSize(data.files[0].size)
715                                                                                                                                                                        + '</i>');
716                                                                                                                        data.context = tpl
717                                                                                                                                        .appendTo(ul);
718                                                                                                                        tpl.find('input')
719                                                                                                                                        .knob();
720                                                                                                                        tpl
721                                                                                                                                        .find(
722                                                                                                                                                        'span')
723                                                                                                                                        .click(
724                                                                                                                                                        function() {
725
726                                                                                                                                                                if (tpl
727                                                                                                                                                                                .hasClass('working')) {
728                                                                                                                                                                        jqXHR
729                                                                                                                                                                                        .abort();
730                                                                                                                                                                }
731
732                                                                                                                                                                tpl
733                                                                                                                                                                                .fadeOut(function() {
734                                                                                                                                                                                        tpl
735                                                                                                                                                                                                        .remove();
736                                                                                                                                                                                });
737
738                                                                                                                                                        });
739
740                                                                                                                        var jqXHR = data
741                                                                                                                                        .submit();
742                                                                                                                },
743                                                                                                                progress : function(e,
744                                                                                                                                data) {
745
746                                                                                                                        // Calculate the
747                                                                                                                        // completion
748                                                                                                                        // percentage of the
749                                                                                                                        // upload
750                                                                                                                        var progress = parseInt(
751                                                                                                                                        data.loaded
752                                                                                                                                                        / data.total
753                                                                                                                                                        * 100,
754                                                                                                                                        10);
755
756                                                                                                                        // Update the hidden
757                                                                                                                        // input field and
758                                                                                                                        // trigger a change
759                                                                                                                        // so that the
760                                                                                                                        // jQuery knob
761                                                                                                                        // plugin knows to
762                                                                                                                        // update the dial
763                                                                                                                        data.context
764                                                                                                                                        .find(
765                                                                                                                                                        'input')
766                                                                                                                                        .val(
767                                                                                                                                                        progress)
768                                                                                                                                        .change();
769
770                                                                                                                        if (progress == 100) {
771                                                                                                                                data.context
772                                                                                                                                                .removeClass('working');
773
774                                                                                                                        }
775                                                                                                                },
776                                                                                                                fail : function(e, data) {
777                                                                                                                        // Something has
778                                                                                                                        // gone wrong!
779                                                                                                                        data.context
780                                                                                                                                        .addClass('error');
781                                                                                                                },
782                                                                                                                done : function(e, data) {
783                                                                                                                        // var newFileData =
784                                                                                                                        // {"DIRECTORIES":
785                                                                                                                        // [{"id": "5000",
786                                                                                                                        // "name": "Dir1",
787                                                                                                                        // "parentID": 85}],
788                                                                                                                        // "FILES": [{"id":
789                                                                                                                        // "2000", "name":
790                                                                                                                        // "File in root 1",
791                                                                                                                        // "parentID": 85,
792                                                                                                                        // "minetype":
793                                                                                                                        // "text"},{"id":
794                                                                                                                        // "2001", "name":
795                                                                                                                        // "File in root 2",
796                                                                                                                        // "parentID": 85,
797                                                                                                                        // "minetype":
798                                                                                                                        // "text"}],
799                                                                                                                        // "ERROR": {"err":
800                                                                                                                        // "", "errCode":
801                                                                                                                        // 0}};
802                                                                                                                        var newFileData = data.result;
803                                                                                                                        newFileData = $
804                                                                                                                                        .parseJSON(data.result);
805                                                                                                                        if (newFileData.ERROR.errCode == 0) {
806                                                                                                                                for ( var i = 0; i < $(newFileData.FILES).length; i++) {
807                                                                                                                                        var file = newFileData.FILES[i];
808                                                                                                                                        var node = {
809                                                                                                                                                thumbnail : file.thumbnail,
810                                                                                                                                                id : file.id,
811                                                                                                                                                name : file.name,
812                                                                                                                                                fileurl : file.fileurl,
813                                                                                                                                                parentID : file.parentID,
814                                                                                                                                                minetype : file.minetype
815                                                                                                                                        };
816                                                                                                                                        o.oGrid
817                                                                                                                                                        .createNode(node);
818                                                                                                                                        o.data.FILES[$(o.data.FILES).length] = node;
819                                                                                                                                }
820
821                                                                                                                                for ( var i = 0; i < $(newFileData.DIRECTORIES).length; i++) {
822                                                                                                                                        var file = newFileData.DIRECTORIES[i];
823                                                                                                                                        var node = {
824                                                                                                                                                id : file.id,
825                                                                                                                                                name : file.name,
826                                                                                                                                                parentID : file.parentID,
827                                                                                                                                                minetype : file.minetype
828                                                                                                                                        };
829                                                                                                                                        o.oTree
830                                                                                                                                                        .createNode(node);
831                                                                                                                                        o.oGrid
832                                                                                                                                                        .createNode(node);
833                                                                                                                                        o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = node;
834                                                                                                                                }
835
836                                                                                                                                /*
837                                                                                                                                 * var node =
838                                                                                                                                 * {id:
839                                                                                                                                 * parseData.id,
840                                                                                                                                 * name:
841                                                                                                                                 * parseData.name,
842                                                                                                                                 * parentID:
843                                                                                                                                 * parseData.parentID};
844                                                                                                                                 * o.oTree.createNode(node);
845                                                                                                                                 * o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] =
846                                                                                                                                 * node; if
847                                                                                                                                 * (o.oGrid)
848                                                                                                                                 * o.oGrid.reloadGrid();
849                                                                                                                                 */
850                                                                                                                        }
851                                                                                                                }
852
853                                                                                                        });
854
855                                                                        $(document).on('drop dragover',
856                                                                                        function(e) {
857                                                                                                e.preventDefault();
858                                                                                        });
859
860                                                                        function formatFileSize(bytes) {
861                                                                                if (typeof bytes !== 'number') {
862                                                                                        return '';
863                                                                                }
864
865                                                                                if (bytes >= 1000000000) {
866                                                                                        return (bytes / 1000000000)
867                                                                                                        .toFixed(2)
868                                                                                                        + ' GB';
869                                                                                }
870
871                                                                                if (bytes >= 1000000) {
872                                                                                        return (bytes / 1000000).toFixed(2)
873                                                                                                        + ' MB';
874                                                                                }
875
876                                                                                return (bytes / 1000).toFixed(2)
877                                                                                                + ' KB';
878                                                                        }
879
880                                                                };
881
882                                                                var createFolder = function(parent, name) {
883                                                                        var postdata = {
884                                                                                fname : name,
885                                                                                fparentid : parent
886                                                                        };
887                                                                        var script = 'createdir';
888                                                                        /* isDev = true; */
889                                                                        sendCommand({
890                                                                                postdata : postdata,
891                                                                                script : script,
892                                                                                callbackSuccess : function(parseData) {
893                                                                                        createFolderFinish(parseData);
894                                                                                },
895                                                                                callbackFail : function() {
896                                                                                }
897                                                                        });
898                                                                }
899
900                                                                var createFolderFinish = function(parseData) {
901                                                                        /* isDev = false; */
902                                                                        if (parseData.ERROR.errCode == 0) {
903                                                                                var node = {
904                                                                                        id : parseData.id,
905                                                                                        name : parseData.name,
906                                                                                        parentID : parseData.parentID
907                                                                                };
908                                                                                o.oTree.createNode(node);
909                                                                                o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = node;
910                                                                                if (o.oGrid)
911                                                                                        o.oGrid.reloadGrid();
912                                                                        }
913                                                                }
914                                                                /***********************************************
915                                                                 * CREATE FOLDER - END *
916                                                                 **********************************************/
917                                                                /***********************************************
918                                                                 * COPY & PASTE & MOVE - START * =***********
919                                                                 **********************************************/
920                                                                var copy = function(act) {
921                                                                        // detect selected items
922                                                                        // push to clipboard
923                                                                        var items = o.oGrid.getHightLightItem();
924
925                                                                        if ($(items).length == 0) {
926                                                                                var node = o.oTree.getSelectedNode();
927                                                                                var itemID = $(node).attr('id');
928
929                                                                                if (itemID == 0)
930                                                                                        return false;
931
932                                                                                items[0] = o.data.DIRECTORIES[searchItemByID(
933                                                                                                itemID, 'directory')];
934                                                                                items[0].type = 'directory';
935                                                                        }
936
937                                                                        if ($(items).length > 0) {
938                                                                                oClipBoard.items = items;
939                                                                                oClipBoard.act = act;
940                                                                        }
941                                                                        return true;
942                                                                }
943
944                                                                var paste = function() {
945                                                                        if ((oClipBoard.act != 'copy' && oClipBoard.act != 'move')
946                                                                                        || oClipBoard.items == null)
947                                                                                return;
948
949                                                                        var items = [];
950                                                                        var destination = self.getTreeCurrentNode();
951                                                                        if (oClipBoard.act != 'copy') {
952                                                                                $(oClipBoard.items)
953                                                                                                .each(
954                                                                                                                function(index) {
955                                                                                                                        var node = new Object;
956                                                                                                                        if (this.type == 'directory')
957                                                                                                                                buildTreeFromParent(
958                                                                                                                                                this.id,
959                                                                                                                                                node);
960                                                                                                                        else {
961                                                                                                                                node.id = this.id;
962                                                                                                                                node.type = 'file';
963                                                                                                                        }
964
965                                                                                                                        items[index] = node;
966                                                                                                                });
967                                                                        } else {
968                                                                                items = oClipBoard.items;
969                                                                        }
970
971                                                                        for ( var i = 0; i < items.length; i++) {
972                                                                                if (items[i].type == 'directory') {
973                                                                                        items[i] = self
974                                                                                                        .getAllDirChilds(items[i]);
975                                                                                }
976                                                                        }
977
978                                                                        var postdata = {
979                                                                                act : oClipBoard.act,
980                                                                                destination : destination,
981                                                                                data : JSON.stringify(items)
982                                                                        };
983                                                                        var script = oClipBoard.act;
984
985                                                                        sendCommand({
986                                                                                postdata : postdata,
987                                                                                script : script,
988                                                                                callbackSuccess : function(parseData) {
989                                                                                        if (oClipBoard.act == 'copy') {
990                                                                                                $(parseData.DIRECTORIES)
991                                                                                                                .each(
992                                                                                                                                function(index) {
993                                                                                                                                        o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = this;
994                                                                                                                                });
995
996                                                                                                $(parseData.FILES)
997                                                                                                                .each(
998                                                                                                                                function(index) {
999                                                                                                                                        o.data.FILES[$(o.data.FILES).length] = this;
1000                                                                                                                                });
1001
1002                                                                                                o.data.DIRECTORIES
1003                                                                                                                .sort(function(a, b) {
1004                                                                                                                        return a.parentID
1005                                                                                                                                        - b.parentID;
1006                                                                                                                });
1007
1008                                                                                                o.oTree
1009                                                                                                                .setData(o.data.DIRECTORIES);
1010                                                                                                o.oGrid.setData(o.data);
1011                                                                                                o.oTree
1012                                                                                                                .createCopyNode(parseData.DIRECTORIES);
1013                                                                                                o.oGrid.reloadGrid();
1014                                                                                        } else if (oClipBoard.act == 'move') {
1015
1016                                                                                        }
1017                                                                                }
1018                                                                        });
1019                                                                }
1020
1021                                                                var move = function() {
1022
1023                                                                }
1024
1025                                                                var copyTo = function() {
1026
1027                                                                }
1028
1029                                                                var moveTo = function() {
1030
1031                                                                }
1032
1033                                                                /***********************************************
1034                                                                 * COPY & PASTE & MOVE - END *
1035                                                                 **********************************************/
1036
1037                                                                this.deleteItem = function(item) {
1038
1039                                                                        var confirmText = 'Bạn có muốn xóa ';
1040
1041                                                                        if ($.isArray(item) && item.length > 1) {
1042                                                                                confirmText += 'các thư mục (và files) đã chọn?';
1043                                                                        } else if (item.length == 1) {
1044                                                                                if (item[0].id == 0)
1045                                                                                        return false;
1046                                                                                confirmText += (item[0].type == 'directory') ? 'thư mục'
1047                                                                                                : 'file';
1048                                                                                confirmText += ' <span style="font-weight:bold">'
1049                                                                                                + item[0].name
1050                                                                                                + "</span> khÃŽng?";
1051                                                                        }
1052
1053                                                                        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>';
1054
1055                                                                        var parentID = item[0].parentID;
1056
1057                                                                        for ( var i = 0; i < item.length; i++) {
1058                                                                                if (item[i].type == 'directory') {
1059                                                                                        item[i] = self
1060                                                                                                        .getAllDirChilds(item[i]);
1061                                                                                }
1062                                                                        }
1063
1064                                                                        var confirmOptions = {
1065                                                                                message : confirmText,
1066                                                                                buttons : {
1067                                                                                        confirm : {
1068                                                                                                label : "Xóa"
1069                                                                                        },
1070                                                                                        cancel : {
1071                                                                                                label : "KhÃŽng xóa"
1072                                                                                        }
1073                                                                                },
1074                                                                                callback : function(result) {
1075                                                                                        if (result) {
1076                                                                                                var delobj = JSON
1077                                                                                                                .stringify(item);
1078                                                                                                var postdata = {
1079                                                                                                        delobj : delobj
1080                                                                                                };
1081                                                                                                var script = 'delete';
1082                                                                                                sendCommand({
1083                                                                                                        postdata : postdata,
1084                                                                                                        script : script,
1085                                                                                                        callbackSuccess : function(
1086                                                                                                                        parseData) {
1087                                                                                                                if ($(parseData.DIRECTORIES).length > 0) {
1088                                                                                                                        $(
1089                                                                                                                                        parseData.DIRECTORIES)
1090                                                                                                                                        .each(
1091                                                                                                                                                        function(
1092                                                                                                                                                                        index) {
1093                                                                                                                                                                o.oTree
1094                                                                                                                                                                                .deletion(this);
1095                                                                                                                                                                o.oGrid
1096                                                                                                                                                                                .deletion(
1097                                                                                                                                                                                                this,
1098                                                                                                                                                                                                'directory');
1099                                                                                                                                                        });
1100                                                                                                                }
1101
1102                                                                                                                if ($(parseData.FILES).length > 0) {
1103                                                                                                                        $(parseData.FILES)
1104                                                                                                                                        .each(
1105                                                                                                                                                        function(
1106                                                                                                                                                                        index) {
1107                                                                                                                                                                var file = o.data.FILES[searchItemByID(
1108                                                                                                                                                                                this,
1109                                                                                                                                                                                'file')];
1110                                                                                                                                                                o.oGrid
1111                                                                                                                                                                                .deletion(
1112                                                                                                                                                                                                this,
1113                                                                                                                                                                                                file.minetype);
1114                                                                                                                                                        });
1115                                                                                                                }
1116                                                                                                        },
1117                                                                                                        callbackDone : function(obj) {
1118                                                                                                                if ($(parseData.DIRECTORIES).length > 0) {
1119                                                                                                                        $(
1120                                                                                                                                        parseData.DIRECTORIES)
1121                                                                                                                                        .each(
1122                                                                                                                                                        function(
1123                                                                                                                                                                        index) {
1124                                                                                                                                                                delete o.data.DIRECTORIES[searchItemByID(
1125                                                                                                                                                                                this,
1126                                                                                                                                                                                'directory')];
1127                                                                                                                                                        });
1128                                                                                                                }
1129
1130                                                                                                                if ($(parseData.FILES).length > 0) {
1131                                                                                                                        $(parseData.FILES)
1132                                                                                                                                        .each(
1133                                                                                                                                                        function(
1134                                                                                                                                                                        index) {
1135                                                                                                                                                                delete o.data.FILES[searchItemByID(
1136                                                                                                                                                                                this,
1137                                                                                                                                                                                'file')];
1138                                                                                                                                                        });
1139                                                                                                                }
1140
1141                                                                                                                o.oTree
1142                                                                                                                                .setData(o.data.DIRECTORIES);
1143                                                                                                                o.oGrid.setData(o.data);
1144                                                                                                                self
1145                                                                                                                                .setTreeCurrentNode(parentID);
1146                                                                                                                o.oGrid.reloadGrid();
1147                                                                                                        },
1148                                                                                                        callbackFail : function() {
1149                                                                                                        }
1150                                                                                                });
1151                                                                                        }
1152                                                                                }
1153                                                                        };
1154
1155                                                                        bootbox.confirm(confirmOptions);
1156                                                                }
1157
1158                                                                this.getAllDirChilds = function(oDirItem) {
1159                                                                        var aryChildDirTmp = [];
1160                                                                        var aryChildDirID = [];
1161                                                                        var aryChildFiles = searchItemsByParent(
1162                                                                                        oDirItem.id, 'file');
1163                                                                        var aryChildDirs = [];
1164
1165                                                                        getAllDirChild(oDirItem.id, aryChildDirTmp);
1166                                                                        for ( var d = 1; d < aryChildDirTmp.length; d++) {
1167                                                                                aryChildDirID[d - 1] = aryChildDirTmp[d];
1168                                                                        }
1169
1170                                                                        for ( var j = 0; j < aryChildDirID.length; j++) {
1171                                                                                if (o.data.DIRECTORIES[searchItemByID(
1172                                                                                                aryChildDirID[j], 'directory')] != undefined)
1173                                                                                        aryChildDirs[aryChildDirs.length] = o.data.DIRECTORIES[searchItemByID(
1174                                                                                                        aryChildDirID[j],
1175                                                                                                        'directory')];
1176
1177                                                                                var aryTmp = searchItemsByParent(
1178                                                                                                aryChildDirID[j], 'file');
1179                                                                                if (aryTmp.length > 0)
1180                                                                                        for ( var f in aryTmp) {
1181                                                                                                aryChildFiles[aryChildFiles.length] = aryTmp[f];
1182                                                                                        }
1183                                                                        }
1184
1185                                                                        oDirItem.childDirs = aryChildDirs;
1186                                                                        oDirItem.childFiles = aryChildFiles;
1187                                                                        return oDirItem;
1188                                                                }
1189
1190                                                                this.setTreeCurrentNode = function(treeNode) {
1191                                                                        // fire when click a node on Tree
1192                                                                        // then fire action of Grid
1193                                                                        treeCurrentNode = treeNode;
1194                                                                        if (o.oGrid)
1195                                                                                o.oGrid.reloadGrid();
1196                                                                };
1197
1198                                                                this.getTreeCurrentNode = function() {
1199                                                                        return treeCurrentNode;
1200                                                                }
1201
1202                                                                this.gridNodeDblClick = function(node) {
1203                                                                        if (node.minetype == 'directory') {
1204                                                                                var treeNode = $('#' + o.tree)
1205                                                                                                .find(
1206                                                                                                                'UL.vstree[rel^="node'
1207                                                                                                                                + node.parentID
1208                                                                                                                                + '"] > LI[rel^="folder"] > A#'
1209                                                                                                                                + node.id);
1210                                                                                o.oTree.activeNode(treeNode);
1211                                                                        } else {
1212                                                                                // execute or preview file
1213                                                                                previewFile(node);
1214                                                                        }
1215                                                                };
1216
1217                                                                this.createNewFolder = function() {
1218
1219                                                                }
1220
1221                                                                this.updateData = function(p) {
1222                                                                        if (p.item == undefined)
1223                                                                                p.item = null;
1224                                                                        if (p.updateAll == undefined)
1225                                                                                p.updateAll = false;
1226                                                                        if (p.from == undefined)
1227                                                                                p.from = null;
1228                                                                        if (p.type == undefined)
1229                                                                                p.type = null;
1230                                                                        if (p.callback == undefined)
1231                                                                                p.callback = null;
1232
1233                                                                        var obj = p.from == 'tree' ? o.oGrid
1234                                                                                        : o.oTree;
1235                                                                        if (!p.updateAll) {
1236                                                                                var index = searchItemByID(p.item.id,
1237                                                                                                p.type);
1238                                                                                switch (p.type) {
1239                                                                                case 'directory':
1240                                                                                        o.data.DIRECTORIES[index].name = p.item.name;
1241                                                                                        o.data.DIRECTORIES[index].parentID = p.item.parentID;
1242                                                                                        break;
1243                                                                                case 'file':
1244                                                                                        o.data.FILES[index].name = p.item.name;
1245                                                                                        o.data.FILES[index].parentID = p.item.parentID;
1246                                                                                        o.data.FILES[index].minetype = p.item.minetype;
1247                                                                                        o.data.FILES[index].fileurl = p.item.fileurl;
1248                                                                                        break;
1249                                                                                default:
1250                                                                                        break;
1251                                                                                }
1252                                                                        }
1253
1254                                                                        o.oTree.setData(o.data.DIRECTORIES);
1255                                                                        o.oGrid.setData(o.data);
1256
1257                                                                        if (p.callback != null) {
1258                                                                                eval('obj.' + p.callback + '(p.item);')
1259                                                                        }
1260
1261                                                                        // call sendCommand
1262                                                                }
1263
1264                                                                this.searchItemsByParent = function(parentID,
1265                                                                                type) {
1266                                                                        return searchItemsByParent(parentID, type);
1267                                                                }
1268
1269                                                                this.searchItemByID = function(id, type) {
1270                                                                        return searchItemByID(id, type);
1271                                                                }
1272
1273                                                                this.refreshStatusBar = function() {
1274                                                                        var totalSize = 0;
1275                                                                        var message = '';
1276                                                                        if (o.data.FILES.length > 0) {
1277                                                                                for ( var i = 0; i < o.data.FILES.length; i++) {
1278                                                                                        totalSize += parseInt(o.data.FILES[i].size);
1279                                                                                }
1280                                                                        }
1281
1282                                                                        message = '<span>Tổng dung lượng đã sá»­ dụng: <strong>'
1283                                                                                        + self.formatFileSize(totalSize)
1284                                                                                        + '</strong></span>';
1285
1286                                                                        var items = o.oGrid.getHightLightItem();
1287                                                                        if (items.length == 1) {
1288                                                                                if ((typeof items[0].minetype !== 'undefined')) {
1289                                                                                        message += '<span>Tệp: <strong>'
1290                                                                                                        + items[0].name
1291                                                                                                        + '</strong></span>';
1292                                                                                        message += '<span> - Dung lượng: <strong>'
1293                                                                                                        + self
1294                                                                                                                        .formatFileSize(items[0].size)
1295                                                                                                        + '</strong></span>';
1296                                                                                } else {
1297                                                                                        message += '<span>Thư mục: <strong>'
1298                                                                                                        + items[0].name
1299                                                                                                        + '</strong></span>';
1300                                                                                }
1301                                                                        } else if (items.length > 1) {
1302                                                                                var selectedSize = 0;
1303                                                                                for ( var i = 0; i < items.length; i++) {
1304                                                                                        selectedSize += (typeof items[i].minetype !== 'undefined') ? parseInt(items[i].size)
1305                                                                                                        : 0;
1306                                                                                }
1307                                                                                message += '<span><strong>'
1308                                                                                                + items.length
1309                                                                                                + ' tệp (thư mục)</strong> được chọn</span>';
1310                                                                                message += '<span> - Dung lượng: <strong>'
1311                                                                                                + self
1312                                                                                                                .formatFileSize(selectedSize)
1313                                                                                                + '</strong></span>';
1314                                                                        }
1315
1316                                                                        $(statusbar).html(message);
1317                                                                }
1318                                                               
1319                                                                this.refreshNavigationBar = function () {
1320                                                                        var root = null;
1321                                                                }
1322
1323                                                                this.redirectPost = function(location, args) {
1324                                                                        var form = '';
1325                                                                        $.each(args, function(key, value) {
1326                                                                                form += '<input type="hidden" name="'
1327                                                                                                + key + '" value="' + value
1328                                                                                                + '">';
1329                                                                        });
1330                                                                        $(
1331                                                                                        '<form action="' + location
1332                                                                                                        + '" method="POST">' + form
1333                                                                                                        + '</form>').appendTo(
1334                                                                                        'body').submit();
1335                                                                }
1336
1337                                                                this.formatFileSize = function(size) {
1338                                                                        var i;
1339                                                                        i = Math.floor(Math.log(size)
1340                                                                                        / Math.log(1024));
1341                                                                        if ((size === 0) || (parseInt(size) === 0)) {
1342                                                                                return "0 kB";
1343                                                                        } else if (isNaN(i)
1344                                                                                        || (!isFinite(size))
1345                                                                                        || (size === Number.POSITIVE_INFINITY)
1346                                                                                        || (size === Number.NEGATIVE_INFINITY)
1347                                                                                        || (size == null) || (size < 0)) {
1348                                                                                console.info("Throwing error");
1349                                                                                throw Error(""
1350                                                                                                + size
1351                                                                                                + " did not compute to a valid number to be humanized.");
1352                                                                        } else {
1353                                                                                return (size / Math.pow(1024, i))
1354                                                                                                .toFixed(2)
1355                                                                                                * 1
1356                                                                                                + " "
1357                                                                                                + [ "B", "KB", "MB", "GB",
1358                                                                                                                "TB", "PB", "EB", "ZB",
1359                                                                                                                "YB" ][i];
1360                                                                        }
1361                                                                }
1362
1363                                                                this.initialize = function() {
1364                                                                        init();
1365                                                                        return this;
1366                                                                };
1367
1368                                                                return this.initialize();
1369                                                        }
1370
1371                                                });
1372        })(jQuery);
Note: See TracBrowser for help on using the repository browser.