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