source: pro-bachkim-filespace/sourcecode/assets/js/manager.js @ 281

Last change on this file since 281 was 281, checked in by quyenla, 11 years ago

lala

  • Property svn:mime-type set to text/plain
File size: 21.1 KB
RevLine 
[66]1if(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;
[233]15                        if( o.host == undefined ) o.host = 'http://localhost/';
[66]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                       
[233]21                        o.host = o.host + 'ajax/';
22                       
[70]23                        var isDev = false;
24                        var contextmenu = null;
[66]25                        var oContainer = this;
26                        var tree = [];
27                        var totalItem = 0;
28                        var countItem = 0;
29                        var maxWidth = 0;
30                        var treeCurrentNode = null;
[70]31                        var self = this;
32                        var oClipBoard = {items:null, act:null};
[66]33                       
[70]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                       
[66]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;
[121]55                                if( p.parseData == undefined ) p.parseData = null;
56                                if( p.self == undefined ) p.self = this;
[66]57
[70]58                                if (p.script != null && (o.datasource == 'ajax' || isDev)) {
[66]59                                        $.post(o.host + o.hostmodule + p.script, p.postdata, function (data){
60                                                if (data) {
61                                                        parseData = $.parseJSON(data);
[121]62                                                        p.parseData = parseData;
[66]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
[121]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);});
[66]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                        }
[70]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
[121]127                                node.id = dir.id;
128                                node.name = dir.name;
129                                node.type = 'directory';
130
[70]131                                $(aryChildDirs).each(function (index) {
[121]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;
[70]137                                });
138
139                                if ($(aryChildFiles).length > 0 ) {
140                                        if (node.files == undefined) node.files = [];
141                                        $(aryChildFiles).each(function (index) {
[121]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;
[70]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;
[121]154                                                buildTreeFromParent(aryChildIDs[index].id, node.childs[index]);
[70]155                                        });
156                                }
157                        }
[66]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 () {
[70]166                                bindEventToToolbars();
167                                documentEventsBinding();
[66]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                               
[140]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                                        }
[66]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                               
[140]225                                for(i in data) {
[66]226                                        if (data[i].parentID == parentID) {
227                                                aryItem[index] = data[i];
228                                                index ++;
229                                        }
230                                }
231                               
232                                return aryItem;
233                        }
234                       
[70]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                        }
[245]254                       
255                        var btnUploadClick = function () {
[239]256                                uploadStart();
[245]257                upload_init();
[239]258                        }
[70]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 () {                               
[140]272                                copy('copy');
[70]273                        }
274
275                        var btnPasteClick = function () {
276                                paste();
277                        }
278                       
[140]279                        var btnCutClick = function () {
280                                copy('move');
281                        }
[70]282                       
283                        var bindEventToToolbars = function () {
284                                $(btnRefresh).click(function(e){btnRefreshClick(this)});
285                               
286                                $(btnNewFolder).click(function(e){btnNewFolderClick()});
[246]287                $(btnUpload).click(function(e){btnUploadClick()});
288               
[70]289                                $(btnDel).click(function(e){btnDelClick()});
290                                $(btnCopy).click(function(e){btnCopyClick()});
[140]291                                $(btnCut).click(function(e){btnCutClick()});
[70]292                                $(btnPaste).click(function(e){btnPasteClick()})
293                               
[140]294                                /*btnShare
[70]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                       
[66]336                        /*******************************
337                         * CREATE FOLDER - START *
338                         *******************************/
[70]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                        }
[239]361                       
362                        var uploadStart = function () {
[277]363                           
[239]364                                var promptOptions = {
365                                                  title: "Tải lên",
[280]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>",
[239]367                                                  buttons: {
368                                                    confirm: {
369                                                      label: "Lưu"
370                                                    },
371                                                    cancel: {
372                                                      label: "Há»§y"   
373                                                    }
374                                                  },
375                                                  callback: function(result) {               
376                                                      if (result === null) {                                             
377                                                                                     
378                                                      } else {
379                                                         
[281]380                                                         o.oGrid.reloadGrid();
381                                                         alert("1");
382                                                          //createFolder(treeCurrentNode, result);
[239]383                                                      }
384                                                    }
385                                                };
386
387                                return bootbox.dialog(promptOptions);
388                        }
[70]389                       
390                        var createFolder = function (parent, name) {
391                                var postdata = {fname:name,fparentid:parent};
[66]392                                var script = 'createdir';
[70]393                                /*isDev = true;*/
[66]394                                sendCommand ({
395                                        postdata:postdata,
396                                        script:script,
[70]397                                        callbackSuccess:function(parseData){createFolderFinish(parseData);},
[66]398                                        callbackFail: function(){}
399                                });
400                        }
401                       
[70]402                        var createFolderFinish = function (parseData) {
403                                /*isDev = false;*/
404                                if (parseData.ERROR.errCode == 0) {
405                                        var node = {id:parseData.id, name:parseData.name,parentID:parseData.parentID};
406                                        o.oTree.createNode(node);
407                                        o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = node;
[140]408                                        if (o.oGrid) o.oGrid.reloadGrid();
[70]409                                }
[66]410                        }
411                        /*******************************
[70]412                         * CREATE FOLDER - END         *
[66]413                         *******************************/
[70]414                        /********************************
415                         * COPY & PASTE & MOVE - START  *
[140]416                         ************=*******************/     
417                        var copy = function (act){
[70]418                                //detect selected items
419                                //push to clipboard
420                                var items = o.oGrid.getHightLightItem();
421                               
422                                if ($(items).length == 0) {
423                                        var node = o.oTree.getSelectedNode();
424                                        var itemID = $(node).attr('id');
[140]425                                       
426                                        if (itemID == 0) return false;
427                                       
[70]428                                        items[0] = o.data.DIRECTORIES[searchItemByID(itemID, 'directory')];
429                                        items[0].type = 'directory';
430                                }
431
432                                if ($(items).length > 0) {
433                                        oClipBoard.items = items;
[140]434                                        oClipBoard.act = act;
[70]435                                }
[140]436                                return true;
[66]437                        }
438                       
[70]439                        var paste = function () {
440                                if ((oClipBoard.act != 'copy'
441                                        && oClipBoard.act != 'move')
442                                        || oClipBoard.items == null) return;
443                               
444                                var items = [];
445                                var destination = self.getTreeCurrentNode();
[140]446                                if (oClipBoard.act != 'copy') {
447                                        $(oClipBoard.items).each(function (index) {
448                                                var node = new Object;
449                                                if (this.type == 'directory')
450                                                        buildTreeFromParent(this.id, node);
451                                                else {
452                                                        node.id = this.id;
453                                                        node.type = 'file';
454                                                }
455       
456                                                items[index] = node;
457                                        });
458                                }
459                                else {
460                                        items = oClipBoard.items;
461                                }
462                               
463                                var postdata = {act:oClipBoard.act,destination:destination,data:JSON.stringify(items)};
464                                var script = oClipBoard.act;
465                               
[70]466                                sendCommand ({
467                                        postdata:postdata,
468                                        script:script,
469                                        callbackSuccess:function(parseData){
[140]470                                                if (oClipBoard.act == 'copy'){
471                                                        $(parseData.DIRECTORIES).each(function (index) {
472                                                                o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = this;
473                                                        });
474                                                       
475                                                        $(parseData.FILES).each(function (index) {
476                                                                o.data.FILES[$(o.data.FILES).length] = this;
477                                                        });
478                                                                                                       
479                                                        o.data.DIRECTORIES.sort(function (a,b) {
480                                                                return a.parentID - b.parentID;
481                                                        });                                             
482                                                       
483                                                        o.oTree.setData (o.data.DIRECTORIES);
484                                                        o.oGrid.setData (o.data);                                               
485                                                        o.oTree.createCopyNode(parseData.DIRECTORIES);
486                                                        o.oGrid.reloadGrid();
487                                                }
[245]488                                                else if (oClipBoard.act == 'move') {
489                                                       
490                                                }
[70]491                                        }
492                                });
493                               
[66]494                        }
[70]495
496                        var move = function () {
[140]497                               
[70]498                        }
499
500                        var copyTo = function () {
501
502                        }
503
504                        var moveTo = function () {
505
506                        }
[66]507                       
[70]508                        /*****************************
509                         * COPY & PASTE & MOVE - END *
510                         *****************************/
511
[66]512                        this.deleteItem = function (item) {
[70]513                               
[66]514                                var confirmText = 'Bạn có muốn xóa ';
515                               
516                                if ($.isArray(item) && item.length > 1) {
[70]517                                        confirmText += 'các thư mục (và files) đã chọn?';
[66]518                                }
519                                else if (item.length == 1) {
520                                        if (item[0].id == 0) return false;
521                                        confirmText += (item[0].type == 'directory')?'thư mục':'file';
522                                        confirmText += ' <span style="font-weight:bold">' + item[0].name + "</span> khÃŽng?";
523                                }
524                               
[70]525                                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>';
526                               
[140]527                                var parentID = item[0].parentID;
528                               
[66]529                                for (var i = 0; i < item.length; i++) {
530                                        if (item[i].type == 'directory') {
531                                                var aryChildDirTmp = [];
532                                                var aryChildDirID = [];
533                                                var aryChildFiles = searchItemsByParent(item[i].id, 'file');
534                                                var aryChildDirs = [];
535                                               
536                                                getAllDirChild (item[i].id, aryChildDirTmp);
537                                                for(var d = 1; d < aryChildDirTmp.length; d++) {
538                                                        aryChildDirID[d-1] = aryChildDirTmp[d];
539                                                }
540                                               
541                                                for (var j = 0; j < aryChildDirID.length; j++) {
542                                                        if (o.data.DIRECTORIES[searchItemByID(aryChildDirID[j],'directory')] != undefined)
543                                                                aryChildDirs[aryChildDirs.length] = o.data.DIRECTORIES[searchItemByID(aryChildDirID[j],'directory')];
544                                                       
545                                                        var aryTmp = searchItemsByParent(aryChildDirID[j], 'file');
546                                                        if (aryTmp.length > 0)
547                                                                for(var f in aryTmp) {
548                                                                        aryChildFiles[aryChildFiles.length] = aryTmp[f];
549                                                                }
550                                                }
551                                               
552                                                item[i].childDirs = aryChildDirs;
553                                                item[i].childFiles = aryChildFiles;
554                                        }
555                                }
556                               
557                                var confirmOptions = {
558                                                  message:confirmText,
559                                                  buttons: {
560                                                    confirm: {
561                                                      label: "Xóa"
562                                                    },
563                                                    cancel: {
564                                                      label: "KhÃŽng xóa"     
565                                                    }
566                                                  },
567                                                  callback: function(result) {               
568                                                          if (result) {
569                                                                        var delobj = JSON.stringify(item);
570                                                                        var postdata = {delobj:delobj};
[140]571                                                                        var script = 'delete';
[66]572                                                                        sendCommand ({
573                                                                                postdata:postdata,
574                                                                                script:script,
[70]575                                                                                callbackSuccess:function(parseData){
576                                                                                        if($(parseData.DIRECTORIES).length > 0) {
[121]577                                                                                                $(parseData.DIRECTORIES).each (function (index) {
578                                                                                                        o.oTree.deletion(this);
579                                                                                                        o.oGrid.deletion(this, 'directory');   
580                                                                                                });
[70]581                                                                                        }
582
583                                                                                        if($(parseData.FILES).length > 0) {
[121]584                                                                                                $(parseData.FILES).each (function (index) {
585                                                                                                        var file = o.data.FILES[searchItemByID(this, 'file')];                                                                                 
586                                                                                                        o.oGrid.deletion(this, file.minetype);
587                                                                                                });     
[70]588                                                                                        }
589                                                                                },
[121]590                                                                                callbackDone: function (obj) {
591                                                                                        if($(parseData.DIRECTORIES).length > 0) {
[140]592                                                                                                $(parseData.DIRECTORIES).each(function(index){
593                                                                                                        delete o.data.DIRECTORIES[searchItemByID(this, 'directory')];
[121]594                                                                                                });
595                                                                                        }
596                                                                                       
597                                                                                        if($(parseData.FILES).length > 0) {
[140]598                                                                                                $(parseData.FILES).each(function(index){
599                                                                                                        delete o.data.FILES[searchItemByID(this, 'file')];
600                                                                                                });
[121]601                                                                                        }
602                                                                                       
603                                                                                        o.oTree.setData (o.data.DIRECTORIES);
604                                                                                        o.oGrid.setData (o.data);
[140]605                                                                                        self.setTreeCurrentNode(parentID);
606                                                                                        o.oGrid.reloadGrid();
607                                                                        },
[66]608                                                                                callbackFail: function(){}
609                                                                        });
610                                                                }
611                                                    }
612                                                };
613                               
614                                bootbox.confirm(confirmOptions);
615                        }
616                       
617                        this.setTreeCurrentNode = function (treeNode) {
618                                //fire when click a node on Tree
619                                //then fire action of Grid
620                                treeCurrentNode = treeNode;
[140]621                                if (o.oGrid) o.oGrid.reloadGrid();
[66]622                        };
623                       
624                        this.getTreeCurrentNode = function () {
625                                return treeCurrentNode;
626                        }
627                       
[70]628                        this.gridNodeDblClick = function (node) {
629                                if (node.minetype == 'directory') {
630                                        var treeNode = $('#' + o.tree).find('UL.vstree[rel^="node' + node.parentID + '"] > LI[rel^="folder"] > A#' + node.id);
631                                        o.oTree.activeNode(treeNode);
632                                }
633                                else {
634                                        //execute or preview file
635                                }
[66]636                        };
637                       
638                        this.createNewFolder = function () {
[70]639                               
[66]640                        }
641                       
642                        this.updateData = function (p) {
643                                if( p.item == undefined ) p.item = null;
[70]644                                if( p.updateAll == undefined ) p.updateAll = false;
[66]645                                if( p.from == undefined ) p.from = null;
646                                if( p.type == undefined ) p.type = null;
647                                if( p.callback == undefined ) p.callback = null;
[70]648
[66]649                                var obj = p.from == 'tree' ? o.oGrid : o.oTree;
[70]650                                if (!p.updateAll) {
651                                        var index = searchItemByID(p.item.id, p.type);
652                                        switch (p.type) {
653                                                case 'directory':
654                                                        o.data.DIRECTORIES[index].name = p.item.name;
655                                                        o.data.DIRECTORIES[index].parentID = p.item.parentID;
656                                                        break;
657                                                case 'file':
658                                                        o.data.FILES[index].name = p.item.name;
659                                                        o.data.FILES[index].parentID = p.item.parentID;
660                                                        o.data.FILES[index].minetype = p.item.minetype;
661                                                        break;
662                                                default:
663                                                        break;
664                                        }
[66]665                                }
666                               
667                                o.oTree.setData (o.data.DIRECTORIES);
668                                o.oGrid.setData (o.data);
669                               
670                                if (p.callback != null) {
671                                        eval('obj.' + p.callback + '(p.item);')
672                                }
673                               
674                                //call sendCommand
675                        }
676                       
[70]677                        this.searchItemsByParent = function (parentID, type) {
678                                return searchItemsByParent(parentID, type);
679                        }
680                       
681                        this.searchItemByID = function (parentID, type) {
682                                return searchItemByID(parentID, type);
683                        }
684                       
[66]685                        this.initialize = function () {
686                                init();
687                                return this;
688                        };
689                       
690                        return this.initialize();
691                }
692        });
693})(jQuery);
Note: See TracBrowser for help on using the repository browser.