Changeset 283 for pro-bachkim-filespace


Ignore:
Timestamp:
Oct 16, 2014 10:55:43 AM (11 years ago)
Author:
quyenla
Message:

lala

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pro-bachkim-filespace/sourcecode/assets/js/manager.js

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