[66] | 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;
|
---|
[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 | }
|
---|
[239] | 254 | var btnUploadClick = function () {
|
---|
| 255 | uploadStart();
|
---|
| 256 | upload_init();
|
---|
| 257 | var url = 'http://space.violet.vn/test.php';
|
---|
| 258 | alert("1");
|
---|
| 259 | $.ajax({
|
---|
| 260 | url: "http://vskun.com/test.php",
|
---|
| 261 | dataType: 'jsonp',
|
---|
| 262 | success: function (data) {
|
---|
| 263 | alert(data);
|
---|
| 264 | //Data from the server in the in the variable "data"
|
---|
| 265 | //In the form of an array
|
---|
| 266 |
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | });
|
---|
| 270 | alert("12");
|
---|
| 271 | }
|
---|
[70] | 272 |
|
---|
| 273 | var btnDelClick = function () {
|
---|
| 274 | var items = o.oGrid.getHightLightItem();
|
---|
| 275 | if ($(items).length == 0){
|
---|
| 276 | var dirID = $(o.oTree.getSelectedNode()).attr('id');
|
---|
| 277 | var item = o.data.DIRECTORIES[searchItemByID(dirID,'directory')];
|
---|
| 278 | item.type = 'directory';
|
---|
| 279 | items = [item];
|
---|
| 280 | }
|
---|
| 281 | self.deleteItem(items);
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | var btnCopyClick = function () {
|
---|
[140] | 285 | copy('copy');
|
---|
[70] | 286 | }
|
---|
| 287 |
|
---|
| 288 | var btnPasteClick = function () {
|
---|
| 289 | paste();
|
---|
| 290 | }
|
---|
| 291 |
|
---|
[140] | 292 | var btnCutClick = function () {
|
---|
| 293 | copy('move');
|
---|
| 294 | }
|
---|
[70] | 295 |
|
---|
| 296 | var bindEventToToolbars = function () {
|
---|
| 297 | $(btnRefresh).click(function(e){btnRefreshClick(this)});
|
---|
| 298 |
|
---|
| 299 | $(btnNewFolder).click(function(e){btnNewFolderClick()});
|
---|
[239] | 300 | $(btnUpload).click(function(e){btnUploadClick()});
|
---|
[70] | 301 | $(btnDel).click(function(e){btnDelClick()});
|
---|
| 302 | $(btnCopy).click(function(e){btnCopyClick()});
|
---|
[140] | 303 | $(btnCut).click(function(e){btnCutClick()});
|
---|
[70] | 304 | $(btnPaste).click(function(e){btnPasteClick()})
|
---|
| 305 |
|
---|
[140] | 306 | /*btnShare
|
---|
[70] | 307 | btnPreview
|
---|
| 308 | btnDownload
|
---|
| 309 | btnUpload*/
|
---|
| 310 | }
|
---|
| 311 | /************************
|
---|
| 312 | * TOOLBAR EVENTS - END *
|
---|
| 313 | ************************/
|
---|
| 314 |
|
---|
| 315 | /***********************************
|
---|
| 316 | * DOCUMENT EVENTS BINDING - START *
|
---|
| 317 | ***********************************/
|
---|
| 318 | var documentEventsBinding = function () {
|
---|
| 319 | $(document).bind('keydown', function (e){
|
---|
| 320 | switch( e.which ) {
|
---|
| 321 | case 113:
|
---|
| 322 | case 27:
|
---|
| 323 | var gridSelectedItems = o.oGrid.getHightLightItem();
|
---|
| 324 | if ($(gridSelectedItems).length > 0) {
|
---|
| 325 | o.oGrid.rename(e.which);
|
---|
| 326 | }else {
|
---|
| 327 | o.oTree.rename(e.which);
|
---|
| 328 | }
|
---|
| 329 | break;
|
---|
| 330 | case 46:
|
---|
| 331 | //delete
|
---|
| 332 | btnDelClick();
|
---|
| 333 | break;
|
---|
| 334 | case 65:
|
---|
| 335 | if (e.ctrlKey) {
|
---|
| 336 | o.oGrid.selectAllNode();
|
---|
| 337 | }
|
---|
| 338 | break;
|
---|
| 339 | default:
|
---|
| 340 | break;
|
---|
| 341 | }
|
---|
| 342 | });
|
---|
| 343 | }
|
---|
| 344 | /***********************************
|
---|
| 345 | * DOCUMENT EVENTS BINDING - END *
|
---|
| 346 | ***********************************/
|
---|
| 347 |
|
---|
[66] | 348 | /*******************************
|
---|
| 349 | * CREATE FOLDER - START *
|
---|
| 350 | *******************************/
|
---|
[70] | 351 | var createFolderStart = function () {
|
---|
| 352 | var promptOptions = {
|
---|
| 353 | title: "Tạo thư mục má»i",
|
---|
| 354 | buttons: {
|
---|
| 355 | confirm: {
|
---|
| 356 | label: "Lưu"
|
---|
| 357 | },
|
---|
| 358 | cancel: {
|
---|
| 359 | label: "Há»§y"
|
---|
| 360 | }
|
---|
| 361 | },
|
---|
| 362 | callback: function(result) {
|
---|
| 363 | if (result === null) {
|
---|
| 364 |
|
---|
| 365 | } else {
|
---|
| 366 | createFolder(treeCurrentNode, result);
|
---|
| 367 | }
|
---|
| 368 | }
|
---|
| 369 | };
|
---|
| 370 |
|
---|
| 371 | return bootbox.prompt(promptOptions);
|
---|
| 372 | }
|
---|
[239] | 373 |
|
---|
| 374 | var uploadStart = function () {
|
---|
| 375 | var promptOptions = {
|
---|
| 376 | title: "Tải lên",
|
---|
| 377 | message: "<form id='upload' method='post' action='upload/upload.php' enctype='multipart/form-data'><div id='drop'>Drop Here<a>Browse</a><input type='file' name='upl' multiple /></div><ul></ul></form>",
|
---|
| 378 | buttons: {
|
---|
| 379 | confirm: {
|
---|
| 380 | label: "Lưu"
|
---|
| 381 | },
|
---|
| 382 | cancel: {
|
---|
| 383 | label: "Há»§y"
|
---|
| 384 | }
|
---|
| 385 | },
|
---|
| 386 | callback: function(result) {
|
---|
| 387 | if (result === null) {
|
---|
| 388 |
|
---|
| 389 | } else {
|
---|
| 390 |
|
---|
| 391 |
|
---|
| 392 | createFolder(treeCurrentNode, result);
|
---|
| 393 | }
|
---|
| 394 | }
|
---|
| 395 | };
|
---|
| 396 |
|
---|
| 397 | return bootbox.dialog(promptOptions);
|
---|
| 398 | }
|
---|
[70] | 399 |
|
---|
| 400 | var createFolder = function (parent, name) {
|
---|
| 401 | var postdata = {fname:name,fparentid:parent};
|
---|
[66] | 402 | var script = 'createdir';
|
---|
[70] | 403 | /*isDev = true;*/
|
---|
[66] | 404 | sendCommand ({
|
---|
| 405 | postdata:postdata,
|
---|
| 406 | script:script,
|
---|
[70] | 407 | callbackSuccess:function(parseData){createFolderFinish(parseData);},
|
---|
[66] | 408 | callbackFail: function(){}
|
---|
| 409 | });
|
---|
| 410 | }
|
---|
| 411 |
|
---|
[70] | 412 | var createFolderFinish = function (parseData) {
|
---|
| 413 | /*isDev = false;*/
|
---|
| 414 | if (parseData.ERROR.errCode == 0) {
|
---|
| 415 | var node = {id:parseData.id, name:parseData.name,parentID:parseData.parentID};
|
---|
| 416 | o.oTree.createNode(node);
|
---|
| 417 | o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = node;
|
---|
[140] | 418 | if (o.oGrid) o.oGrid.reloadGrid();
|
---|
[70] | 419 | }
|
---|
[66] | 420 | }
|
---|
| 421 | /*******************************
|
---|
[70] | 422 | * CREATE FOLDER - END *
|
---|
[66] | 423 | *******************************/
|
---|
[70] | 424 | /********************************
|
---|
| 425 | * COPY & PASTE & MOVE - START *
|
---|
[140] | 426 | ************=*******************/
|
---|
| 427 | var copy = function (act){
|
---|
[70] | 428 | //detect selected items
|
---|
| 429 | //push to clipboard
|
---|
| 430 | var items = o.oGrid.getHightLightItem();
|
---|
| 431 |
|
---|
| 432 | if ($(items).length == 0) {
|
---|
| 433 | var node = o.oTree.getSelectedNode();
|
---|
| 434 | var itemID = $(node).attr('id');
|
---|
[140] | 435 |
|
---|
| 436 | if (itemID == 0) return false;
|
---|
| 437 |
|
---|
[70] | 438 | items[0] = o.data.DIRECTORIES[searchItemByID(itemID, 'directory')];
|
---|
| 439 | items[0].type = 'directory';
|
---|
| 440 | }
|
---|
| 441 |
|
---|
| 442 | if ($(items).length > 0) {
|
---|
| 443 | oClipBoard.items = items;
|
---|
[140] | 444 | oClipBoard.act = act;
|
---|
[70] | 445 | }
|
---|
[140] | 446 | return true;
|
---|
[66] | 447 | }
|
---|
| 448 |
|
---|
[70] | 449 | var paste = function () {
|
---|
| 450 | if ((oClipBoard.act != 'copy'
|
---|
| 451 | && oClipBoard.act != 'move')
|
---|
| 452 | || oClipBoard.items == null) return;
|
---|
| 453 |
|
---|
| 454 | var items = [];
|
---|
| 455 | var destination = self.getTreeCurrentNode();
|
---|
[140] | 456 | if (oClipBoard.act != 'copy') {
|
---|
| 457 | $(oClipBoard.items).each(function (index) {
|
---|
| 458 | var node = new Object;
|
---|
| 459 | if (this.type == 'directory')
|
---|
| 460 | buildTreeFromParent(this.id, node);
|
---|
| 461 | else {
|
---|
| 462 | node.id = this.id;
|
---|
| 463 | node.type = 'file';
|
---|
| 464 | }
|
---|
| 465 |
|
---|
| 466 | items[index] = node;
|
---|
| 467 | });
|
---|
| 468 | }
|
---|
| 469 | else {
|
---|
| 470 | items = oClipBoard.items;
|
---|
| 471 | }
|
---|
| 472 |
|
---|
| 473 | var postdata = {act:oClipBoard.act,destination:destination,data:JSON.stringify(items)};
|
---|
| 474 | var script = oClipBoard.act;
|
---|
| 475 |
|
---|
[70] | 476 | sendCommand ({
|
---|
| 477 | postdata:postdata,
|
---|
| 478 | script:script,
|
---|
| 479 | callbackSuccess:function(parseData){
|
---|
[140] | 480 | if (oClipBoard.act == 'copy'){
|
---|
| 481 | $(parseData.DIRECTORIES).each(function (index) {
|
---|
| 482 | o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = this;
|
---|
| 483 | });
|
---|
| 484 |
|
---|
| 485 | $(parseData.FILES).each(function (index) {
|
---|
| 486 | o.data.FILES[$(o.data.FILES).length] = this;
|
---|
| 487 | });
|
---|
| 488 |
|
---|
| 489 | o.data.DIRECTORIES.sort(function (a,b) {
|
---|
| 490 | return a.parentID - b.parentID;
|
---|
| 491 | });
|
---|
| 492 |
|
---|
| 493 | o.oTree.setData (o.data.DIRECTORIES);
|
---|
| 494 | o.oGrid.setData (o.data);
|
---|
| 495 | o.oTree.createCopyNode(parseData.DIRECTORIES);
|
---|
| 496 | o.oGrid.reloadGrid();
|
---|
| 497 | }
|
---|
[70] | 498 | }
|
---|
| 499 | });
|
---|
| 500 |
|
---|
[66] | 501 | }
|
---|
[70] | 502 |
|
---|
| 503 | var move = function () {
|
---|
[140] | 504 |
|
---|
[70] | 505 | }
|
---|
| 506 |
|
---|
| 507 | var copyTo = function () {
|
---|
| 508 |
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | var moveTo = function () {
|
---|
| 512 |
|
---|
| 513 | }
|
---|
[66] | 514 |
|
---|
[70] | 515 | /*****************************
|
---|
| 516 | * COPY & PASTE & MOVE - END *
|
---|
| 517 | *****************************/
|
---|
| 518 |
|
---|
[66] | 519 | this.deleteItem = function (item) {
|
---|
[70] | 520 |
|
---|
[66] | 521 | var confirmText = 'Bạn có muá»n xóa ';
|
---|
| 522 |
|
---|
| 523 | if ($.isArray(item) && item.length > 1) {
|
---|
[70] | 524 | confirmText += 'các thư mục (và files) Äã chá»n?';
|
---|
[66] | 525 | }
|
---|
| 526 | else if (item.length == 1) {
|
---|
| 527 | if (item[0].id == 0) return false;
|
---|
| 528 | confirmText += (item[0].type == 'directory')?'thư mục':'file';
|
---|
| 529 | confirmText += ' <span style="font-weight:bold">' + item[0].name + "</span> khÃŽng?";
|
---|
| 530 | }
|
---|
| 531 |
|
---|
[70] | 532 | 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>';
|
---|
| 533 |
|
---|
[140] | 534 | var parentID = item[0].parentID;
|
---|
| 535 |
|
---|
[66] | 536 | for (var i = 0; i < item.length; i++) {
|
---|
| 537 | if (item[i].type == 'directory') {
|
---|
| 538 | var aryChildDirTmp = [];
|
---|
| 539 | var aryChildDirID = [];
|
---|
| 540 | var aryChildFiles = searchItemsByParent(item[i].id, 'file');
|
---|
| 541 | var aryChildDirs = [];
|
---|
| 542 |
|
---|
| 543 | getAllDirChild (item[i].id, aryChildDirTmp);
|
---|
| 544 | for(var d = 1; d < aryChildDirTmp.length; d++) {
|
---|
| 545 | aryChildDirID[d-1] = aryChildDirTmp[d];
|
---|
| 546 | }
|
---|
| 547 |
|
---|
| 548 | for (var j = 0; j < aryChildDirID.length; j++) {
|
---|
| 549 | if (o.data.DIRECTORIES[searchItemByID(aryChildDirID[j],'directory')] != undefined)
|
---|
| 550 | aryChildDirs[aryChildDirs.length] = o.data.DIRECTORIES[searchItemByID(aryChildDirID[j],'directory')];
|
---|
| 551 |
|
---|
| 552 | var aryTmp = searchItemsByParent(aryChildDirID[j], 'file');
|
---|
| 553 | if (aryTmp.length > 0)
|
---|
| 554 | for(var f in aryTmp) {
|
---|
| 555 | aryChildFiles[aryChildFiles.length] = aryTmp[f];
|
---|
| 556 | }
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | item[i].childDirs = aryChildDirs;
|
---|
| 560 | item[i].childFiles = aryChildFiles;
|
---|
| 561 | }
|
---|
| 562 | }
|
---|
| 563 |
|
---|
| 564 | var confirmOptions = {
|
---|
| 565 | message:confirmText,
|
---|
| 566 | buttons: {
|
---|
| 567 | confirm: {
|
---|
| 568 | label: "Xóa"
|
---|
| 569 | },
|
---|
| 570 | cancel: {
|
---|
| 571 | label: "KhÎng xóa"
|
---|
| 572 | }
|
---|
| 573 | },
|
---|
| 574 | callback: function(result) {
|
---|
| 575 | if (result) {
|
---|
| 576 | var delobj = JSON.stringify(item);
|
---|
| 577 | var postdata = {delobj:delobj};
|
---|
[140] | 578 | var script = 'delete';
|
---|
[66] | 579 | sendCommand ({
|
---|
| 580 | postdata:postdata,
|
---|
| 581 | script:script,
|
---|
[70] | 582 | callbackSuccess:function(parseData){
|
---|
| 583 | if($(parseData.DIRECTORIES).length > 0) {
|
---|
[121] | 584 | $(parseData.DIRECTORIES).each (function (index) {
|
---|
| 585 | o.oTree.deletion(this);
|
---|
| 586 | o.oGrid.deletion(this, 'directory');
|
---|
| 587 | });
|
---|
[70] | 588 | }
|
---|
| 589 |
|
---|
| 590 | if($(parseData.FILES).length > 0) {
|
---|
[121] | 591 | $(parseData.FILES).each (function (index) {
|
---|
| 592 | var file = o.data.FILES[searchItemByID(this, 'file')];
|
---|
| 593 | o.oGrid.deletion(this, file.minetype);
|
---|
| 594 | });
|
---|
[70] | 595 | }
|
---|
| 596 | },
|
---|
[121] | 597 | callbackDone: function (obj) {
|
---|
| 598 | if($(parseData.DIRECTORIES).length > 0) {
|
---|
[140] | 599 | $(parseData.DIRECTORIES).each(function(index){
|
---|
| 600 | delete o.data.DIRECTORIES[searchItemByID(this, 'directory')];
|
---|
[121] | 601 | });
|
---|
| 602 | }
|
---|
| 603 |
|
---|
| 604 | if($(parseData.FILES).length > 0) {
|
---|
[140] | 605 | $(parseData.FILES).each(function(index){
|
---|
| 606 | delete o.data.FILES[searchItemByID(this, 'file')];
|
---|
| 607 | });
|
---|
[121] | 608 | }
|
---|
| 609 |
|
---|
| 610 | o.oTree.setData (o.data.DIRECTORIES);
|
---|
| 611 | o.oGrid.setData (o.data);
|
---|
[140] | 612 | self.setTreeCurrentNode(parentID);
|
---|
| 613 | o.oGrid.reloadGrid();
|
---|
| 614 | },
|
---|
[66] | 615 | callbackFail: function(){}
|
---|
| 616 | });
|
---|
| 617 | }
|
---|
| 618 | }
|
---|
| 619 | };
|
---|
| 620 |
|
---|
| 621 | bootbox.confirm(confirmOptions);
|
---|
| 622 | }
|
---|
| 623 |
|
---|
| 624 | this.setTreeCurrentNode = function (treeNode) {
|
---|
| 625 | //fire when click a node on Tree
|
---|
| 626 | //then fire action of Grid
|
---|
| 627 | treeCurrentNode = treeNode;
|
---|
[140] | 628 | if (o.oGrid) o.oGrid.reloadGrid();
|
---|
[66] | 629 | };
|
---|
| 630 |
|
---|
| 631 | this.getTreeCurrentNode = function () {
|
---|
| 632 | return treeCurrentNode;
|
---|
| 633 | }
|
---|
| 634 |
|
---|
[70] | 635 | this.gridNodeDblClick = function (node) {
|
---|
| 636 | if (node.minetype == 'directory') {
|
---|
| 637 | var treeNode = $('#' + o.tree).find('UL.vstree[rel^="node' + node.parentID + '"] > LI[rel^="folder"] > A#' + node.id);
|
---|
| 638 | o.oTree.activeNode(treeNode);
|
---|
| 639 | }
|
---|
| 640 | else {
|
---|
| 641 | //execute or preview file
|
---|
| 642 | }
|
---|
[66] | 643 | };
|
---|
| 644 |
|
---|
| 645 | this.createNewFolder = function () {
|
---|
[70] | 646 |
|
---|
[66] | 647 | }
|
---|
| 648 |
|
---|
| 649 | this.updateData = function (p) {
|
---|
| 650 | if( p.item == undefined ) p.item = null;
|
---|
[70] | 651 | if( p.updateAll == undefined ) p.updateAll = false;
|
---|
[66] | 652 | if( p.from == undefined ) p.from = null;
|
---|
| 653 | if( p.type == undefined ) p.type = null;
|
---|
| 654 | if( p.callback == undefined ) p.callback = null;
|
---|
[70] | 655 |
|
---|
[66] | 656 | var obj = p.from == 'tree' ? o.oGrid : o.oTree;
|
---|
[70] | 657 | if (!p.updateAll) {
|
---|
| 658 | var index = searchItemByID(p.item.id, p.type);
|
---|
| 659 | switch (p.type) {
|
---|
| 660 | case 'directory':
|
---|
| 661 | o.data.DIRECTORIES[index].name = p.item.name;
|
---|
| 662 | o.data.DIRECTORIES[index].parentID = p.item.parentID;
|
---|
| 663 | break;
|
---|
| 664 | case 'file':
|
---|
| 665 | o.data.FILES[index].name = p.item.name;
|
---|
| 666 | o.data.FILES[index].parentID = p.item.parentID;
|
---|
| 667 | o.data.FILES[index].minetype = p.item.minetype;
|
---|
| 668 | break;
|
---|
| 669 | default:
|
---|
| 670 | break;
|
---|
| 671 | }
|
---|
[66] | 672 | }
|
---|
| 673 |
|
---|
| 674 | o.oTree.setData (o.data.DIRECTORIES);
|
---|
| 675 | o.oGrid.setData (o.data);
|
---|
| 676 |
|
---|
| 677 | if (p.callback != null) {
|
---|
| 678 | eval('obj.' + p.callback + '(p.item);')
|
---|
| 679 | }
|
---|
| 680 |
|
---|
| 681 | //call sendCommand
|
---|
| 682 | }
|
---|
| 683 |
|
---|
[70] | 684 | this.searchItemsByParent = function (parentID, type) {
|
---|
| 685 | return searchItemsByParent(parentID, type);
|
---|
| 686 | }
|
---|
| 687 |
|
---|
| 688 | this.searchItemByID = function (parentID, type) {
|
---|
| 689 | return searchItemByID(parentID, type);
|
---|
| 690 | }
|
---|
| 691 |
|
---|
[66] | 692 | this.initialize = function () {
|
---|
| 693 | init();
|
---|
| 694 | return this;
|
---|
| 695 | };
|
---|
| 696 |
|
---|
| 697 | return this.initialize();
|
---|
| 698 | }
|
---|
| 699 | });
|
---|
| 700 | })(jQuery); |
---|