[780] | 1 | if (jQuery)
|
---|
| 2 | (function ($) {
|
---|
| 3 | $.extend($.fn, {
|
---|
| 4 | violetFileManager: function (o) {
|
---|
| 5 | if (!o)
|
---|
| 6 | var o = {};
|
---|
| 7 | if (o.tree == undefined)
|
---|
| 8 | o.tree = null;
|
---|
| 9 | if (o.grid == undefined)
|
---|
| 10 | o.grid = null;
|
---|
| 11 |
|
---|
| 12 | if (o.maincontainer == undefined)
|
---|
| 13 | o.maincontainer = null;
|
---|
| 14 | if (o.titlebar == undefined)
|
---|
| 15 | o.titlebar = null;
|
---|
| 16 | if (o.toolsbar == undefined)
|
---|
| 17 | o.toolsbar = null;
|
---|
| 18 | if (o.statusbar == undefined)
|
---|
| 19 | o.statusbar = null;
|
---|
| 20 |
|
---|
| 21 | if (o.oTree == undefined)
|
---|
| 22 | o.oTree = null;
|
---|
| 23 | if (o.oGrid == undefined)
|
---|
| 24 | o.oGrid = null;
|
---|
| 25 | if (o.host == undefined)
|
---|
| 26 | o.host = 'http://localhost/';
|
---|
| 27 | if (o.hostmodule == undefined)
|
---|
| 28 | o.hostmodule = 'privatecontent/';
|
---|
| 29 | if (o.script == undefined)
|
---|
| 30 | o.script = 'getcontent';
|
---|
| 31 | if (o.data == undefined)
|
---|
| 32 | o.data = null;
|
---|
| 33 | if (o.datasource == undefined)
|
---|
| 34 | o.datasource = 'ajax';
|
---|
| 35 |
|
---|
| 36 | o.host = o.host + 'ajax/';
|
---|
| 37 |
|
---|
| 38 | var isDev = false;
|
---|
| 39 | var contextmenu = null;
|
---|
| 40 | var oContainer = this;
|
---|
| 41 | var tree = [];
|
---|
| 42 | var totalItem = 0;
|
---|
| 43 | var countItem = 0;
|
---|
| 44 | var maxWidth = 0;
|
---|
| 45 | var treeCurrentNode = null;
|
---|
| 46 | var self = this;
|
---|
| 47 | var oClipBoard = {items: null, act: null};
|
---|
| 48 |
|
---|
| 49 | /**
|
---|
| 50 | * Toolbar defined
|
---|
| 51 | * */
|
---|
| 52 | var btnNewFolder = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnNewFolder');
|
---|
| 53 | var btnDel = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnDel');
|
---|
| 54 | var btnCopy = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnCopy');
|
---|
| 55 | var btnCut = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnCut');
|
---|
| 56 | var btnPaste = $('#' + o.toolsbar + ' > DIV.btn-group.basic > #btnPaste');
|
---|
| 57 | var btnShare = $('#' + o.toolsbar + ' > DIV.btn-group.social > #btnShare');
|
---|
| 58 | var btnPreview = $('#' + o.toolsbar + ' > DIV.btn-group.social > #btnPreview');
|
---|
| 59 | var btnDownload = $('#' + o.toolsbar + ' > DIV.btn-group.creation > #btnDownload');
|
---|
| 60 | var btnUpload = $('#' + o.toolsbar + ' > DIV.btn-group.creation > #btnUpload');
|
---|
| 61 | var btnRefresh = $('#' + o.toolsbar + ' > DIV.btn-group.control > #btnRefresh');
|
---|
| 62 |
|
---|
| 63 | var sendCommand = function (p) {
|
---|
| 64 | if (p.postdata == undefined)
|
---|
| 65 | p.postdata = null;
|
---|
| 66 | if (p.script == undefined)
|
---|
| 67 | p.script = o.script;
|
---|
| 68 | if (p.callbackSuccess == undefined)
|
---|
| 69 | p.callbackSuccess = null;
|
---|
| 70 | if (p.callbackDone == undefined)
|
---|
| 71 | p.callbackDone = null;
|
---|
| 72 | if (p.callbackFail == undefined)
|
---|
| 73 | p.callbackFail = null;
|
---|
| 74 | if (p.callbackAlways == undefined)
|
---|
| 75 | p.callbackAlways = null;
|
---|
| 76 | if (p.parseData == undefined)
|
---|
| 77 | p.parseData = null;
|
---|
| 78 | if (p.self == undefined)
|
---|
| 79 | p.self = this;
|
---|
| 80 |
|
---|
| 81 | if (p.script != null && (o.datasource == 'ajax' || isDev)) {
|
---|
| 82 | $.post(o.host + o.hostmodule + p.script, p.postdata, function (data) {
|
---|
| 83 | if (data) {
|
---|
| 84 | parseData = $.parseJSON(data);
|
---|
| 85 | p.parseData = parseData;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | if (p.callbackSuccess != null) {
|
---|
| 89 | if (parseInt(parseData.ERROR.errCode) === 0)
|
---|
| 90 | p.callbackSuccess(parseData);
|
---|
| 91 | else {
|
---|
| 92 | p.callbackFail(parseData.ERROR);
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | }).done(function () {
|
---|
| 97 | if (p.callbackDone != null)
|
---|
| 98 | p.callbackDone(p.parseData);
|
---|
| 99 | }).fail(function () {
|
---|
| 100 | if (p.callbackFail != null)
|
---|
| 101 | p.callbackFail(this);
|
---|
| 102 | }).always(function () {
|
---|
| 103 | if (p.callbackAlways != null)
|
---|
| 104 | p.callbackAlways(this);
|
---|
| 105 | });
|
---|
| 106 | }
|
---|
| 107 | else if (o.datasource == 'json') {
|
---|
| 108 | if (p.callbackSuccess != null)
|
---|
| 109 | p.callbackSuccess(o.data);
|
---|
| 110 | if (p.callbackDone != null)
|
---|
| 111 | p.callbackDone(this);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | };
|
---|
| 115 |
|
---|
| 116 | var getDirTreeMaxWidth = function () {
|
---|
| 117 | var scrWidth = $(o.maincontainer).width();
|
---|
| 118 | return parseInt(scrWidth / 2);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | var layoutRender = function () {
|
---|
| 122 | var scrWidth = $('#' + o.maincontainer).width();
|
---|
| 123 | var scrHeght = $(window).height();
|
---|
| 124 | var dirTreeHeight = scrHeght - $('#' + o.titlebar).height() - $('#' + o.toolsbar).height() - $('#' + o.statusbar).height() - 2;
|
---|
| 125 | $('#' + o.tree).parent().height(dirTreeHeight);
|
---|
| 126 | $('#' + o.grid).parent().height(dirTreeHeight);
|
---|
| 127 | $('#' + o.grid).parent().width('calc(100% - ' + ($('#' + o.tree).parent().width() + 8) + 'px)');
|
---|
| 128 | var scollWidth = $('#' + o.grid).parent().width();
|
---|
| 129 | maxWidth = getDirTreeMaxWidth();
|
---|
| 130 | $(o.tree).height(dirTreeHeight - 5);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | var createFileManager = function (parseData) {
|
---|
| 134 | o.data = parseData;
|
---|
| 135 | totalItem = o.data.DIRECTORIES.length;
|
---|
| 136 | o.oTree = $('#' + o.tree).violetTree({data: o.data.DIRECTORIES, manager: oContainer});
|
---|
| 137 | o.oGrid = $('#' + o.grid).violetGrid({data: o.data, manager: oContainer});
|
---|
| 138 | };
|
---|
| 139 |
|
---|
| 140 | var getAllDirChild = function (parentID, aryChild) {
|
---|
| 141 | parentID = parentID == null ? 0 : parentID;
|
---|
| 142 | var dirList = searchItemsByParent(parentID, 'directory');
|
---|
| 143 | var index = aryChild.length;
|
---|
| 144 | aryChild[index] = parentID;
|
---|
| 145 | if (dirList.length > 0) {
|
---|
| 146 | for (var i = 0; i < dirList.length; i++) {
|
---|
| 147 | getAllDirChild(dirList[i].id, aryChild);
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | var buildTreeFromParent = function (dirID, node) {
|
---|
| 153 | var aryChildFiles = [];
|
---|
| 154 | var aryChildDirs = [];
|
---|
| 155 | var aryChildIDs = [];
|
---|
| 156 | var aryTmp = [];
|
---|
| 157 | var dir = o.data.DIRECTORIES[searchItemByID(dirID, 'directory')];
|
---|
| 158 | aryChildDirs = searchItemsByParent(dirID, 'directory');
|
---|
| 159 | aryChildFiles = searchItemsByParent(dirID, 'file');
|
---|
| 160 |
|
---|
| 161 | node.id = dir.id;
|
---|
| 162 | node.name = dir.name;
|
---|
| 163 | node.type = 'directory';
|
---|
| 164 |
|
---|
| 165 | $(aryChildDirs).each(function (index) {
|
---|
| 166 | var id = this.id;
|
---|
| 167 | var name = this.name;
|
---|
| 168 | var type = 'directory';
|
---|
| 169 | var cDir = {id: id, name: name, type: type, childs: null};
|
---|
| 170 | aryChildIDs[index] = cDir;
|
---|
| 171 | });
|
---|
| 172 |
|
---|
| 173 | if ($(aryChildFiles).length > 0) {
|
---|
| 174 | if (node.files == undefined)
|
---|
| 175 | node.files = [];
|
---|
| 176 | $(aryChildFiles).each(function (index) {
|
---|
| 177 | var id = this.id;
|
---|
| 178 | var name = this.name;
|
---|
| 179 | var type = 'file';
|
---|
| 180 | var cFile = {id: id, name: name, type: type};
|
---|
| 181 | node.files[index] = cFile;
|
---|
| 182 | });
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | if ($(aryChildDirs).length > 0) {
|
---|
| 186 | if (node.childs == undefined)
|
---|
| 187 | node.childs = [];
|
---|
| 188 | $(aryChildIDs).each(function (index) {
|
---|
| 189 | node.childs[index] = new Object;
|
---|
| 190 | buildTreeFromParent(aryChildIDs[index].id, node.childs[index]);
|
---|
| 191 | });
|
---|
| 192 | }
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | var checkChildExisted = function (id) {
|
---|
| 196 | var dirList = searchItemsByParent(id, 'directory');
|
---|
| 197 | var fileList = searchItemsByParent(id, 'file');
|
---|
| 198 | return (dirList.length > 0) || (fileList.length > 0);
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | var doneInit = function () {
|
---|
| 202 | bindEventToToolbars();
|
---|
| 203 | documentEventsBinding();
|
---|
| 204 | };
|
---|
| 205 |
|
---|
| 206 | var failInit = function (er) {
|
---|
| 207 | bootbox.alert(er.err);
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | var init = function () {
|
---|
| 211 | layoutRender();
|
---|
| 212 | $('#' + o.tree).parent().resizable({
|
---|
| 213 | maxWidth: maxWidth,
|
---|
| 214 | minWidth: 220,
|
---|
| 215 | handles: "e",
|
---|
| 216 | resize: function (event, ui) {
|
---|
| 217 | layoutRender();
|
---|
| 218 | }
|
---|
| 219 | });
|
---|
| 220 | $(window).resize(function () {
|
---|
| 221 | layoutRender();
|
---|
| 222 | $('#' + o.tree).parent().resizable({maxWidth: maxWidth});
|
---|
| 223 | });
|
---|
| 224 | sendCommand({postdata: null, callbackSuccess: createFileManager, callbackDone: doneInit, callbackFail: failInit});
|
---|
| 225 | };
|
---|
| 226 |
|
---|
| 227 | var searchItemByID = function (id, type) {
|
---|
| 228 | var data = {};
|
---|
| 229 | switch (type) {
|
---|
| 230 | case 'directory':
|
---|
| 231 | data = o.data.DIRECTORIES;
|
---|
| 232 | break;
|
---|
| 233 | case 'file':
|
---|
| 234 | data = o.data.FILES;
|
---|
| 235 | break;
|
---|
| 236 | default:
|
---|
| 237 | break;
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | //for (var i = 0; i < data.length; i++) {
|
---|
| 241 | for (var i in data) {
|
---|
| 242 | if (data[i].id == id) {
|
---|
| 243 | return i;
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | var searchItemsByParent = function (parentID, type) {
|
---|
| 249 | var data = {};
|
---|
| 250 | var aryItem = [];
|
---|
| 251 | var index = aryItem.length;
|
---|
| 252 |
|
---|
| 253 | switch (type) {
|
---|
| 254 | case 'directory':
|
---|
| 255 | data = o.data.DIRECTORIES;
|
---|
| 256 | break;
|
---|
| 257 | case 'file':
|
---|
| 258 | data = o.data.FILES;
|
---|
| 259 | break;
|
---|
| 260 | default:
|
---|
| 261 | break;
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | for (i in data) {
|
---|
| 265 | if (data[i].parentID == parentID) {
|
---|
| 266 | aryItem[index] = data[i];
|
---|
| 267 | index++;
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | return aryItem;
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | /**************************
|
---|
| 275 | * TOOLBAR EVENTS - START *
|
---|
| 276 | **************************/
|
---|
| 277 | var btnRefreshClick = function (obj) {
|
---|
| 278 | $(o).find('i').addClass('icon-spin');
|
---|
| 279 | sendCommand({postdata: null,
|
---|
| 280 | callbackSuccess: function (parseData) {
|
---|
| 281 | o.data = parseData;
|
---|
| 282 | self.updateData({updateAll: true});
|
---|
| 283 | o.oTree.refeshTree();
|
---|
| 284 | },
|
---|
| 285 | callbackDone: function () {
|
---|
| 286 | $(o).find('i').removeClass('icon-spin');
|
---|
| 287 | },
|
---|
| 288 | callbackFail: failInit
|
---|
| 289 | });
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | var btnNewFolderClick = function () {
|
---|
| 293 | createFolderStart();
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | var btnUploadClick = function () {
|
---|
| 297 | uploadStart();
|
---|
| 298 | uploadInit();
|
---|
| 299 |
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | var btnDelClick = function () {
|
---|
| 303 | var items = o.oGrid.getHightLightItem();
|
---|
| 304 | if ($(items).length == 0) {
|
---|
| 305 | var dirID = $(o.oTree.getSelectedNode()).attr('id');
|
---|
| 306 | var item = o.data.DIRECTORIES[searchItemByID(dirID, 'directory')];
|
---|
| 307 | item.type = 'directory';
|
---|
| 308 | items = [item];
|
---|
| 309 | }
|
---|
| 310 | self.deleteItem(items);
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | var btnCopyClick = function () {
|
---|
| 314 | copy('copy');
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | var btnPasteClick = function () {
|
---|
| 318 | paste();
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | var btnCutClick = function () {
|
---|
| 322 | copy('move');
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | var bindEventToToolbars = function () {
|
---|
| 326 | $(btnRefresh).click(function (e) {
|
---|
| 327 | btnRefreshClick(this)
|
---|
| 328 | });
|
---|
| 329 |
|
---|
| 330 | $(btnNewFolder).click(function (e) {
|
---|
| 331 | btnNewFolderClick()
|
---|
| 332 | });
|
---|
| 333 | $(btnUpload).click(function (e) {
|
---|
| 334 | btnUploadClick()
|
---|
| 335 | });
|
---|
| 336 |
|
---|
| 337 | $(btnDel).click(function (e) {
|
---|
| 338 | btnDelClick()
|
---|
| 339 | });
|
---|
| 340 | $(btnCopy).click(function (e) {
|
---|
| 341 | btnCopyClick()
|
---|
| 342 | });
|
---|
| 343 | $(btnCut).click(function (e) {
|
---|
| 344 | btnCutClick()
|
---|
| 345 | });
|
---|
| 346 | $(btnPaste).click(function (e) {
|
---|
| 347 | btnPasteClick()
|
---|
| 348 | })
|
---|
| 349 | $(btnPreview).click(function (e) {
|
---|
| 350 | btnPreviewClick()
|
---|
| 351 | })
|
---|
| 352 |
|
---|
| 353 | /*btnShare
|
---|
| 354 | btnPreview
|
---|
| 355 | btnDownload
|
---|
| 356 | btnUpload*/
|
---|
| 357 | }
|
---|
| 358 | /************************
|
---|
| 359 | * TOOLBAR EVENTS - END *
|
---|
| 360 | ************************/
|
---|
| 361 |
|
---|
| 362 | /***********************************
|
---|
| 363 | * DOCUMENT EVENTS BINDING - START *
|
---|
| 364 | ***********************************/
|
---|
| 365 | var documentEventsBinding = function () {
|
---|
| 366 | $(document).bind('keydown', function (e) {
|
---|
| 367 | switch (e.which) {
|
---|
| 368 | case 113:
|
---|
| 369 | case 27:
|
---|
| 370 | var gridSelectedItems = o.oGrid.getHightLightItem();
|
---|
| 371 | if ($(gridSelectedItems).length > 0) {
|
---|
| 372 | o.oGrid.rename(e.which);
|
---|
| 373 | } else {
|
---|
| 374 | o.oTree.rename(e.which);
|
---|
| 375 | }
|
---|
| 376 | break;
|
---|
| 377 | case 46:
|
---|
| 378 | //delete
|
---|
| 379 | btnDelClick();
|
---|
| 380 | break;
|
---|
| 381 | case 65:
|
---|
| 382 | if (e.ctrlKey) {
|
---|
| 383 | o.oGrid.selectAllNode();
|
---|
| 384 | }
|
---|
| 385 | break;
|
---|
| 386 | default:
|
---|
| 387 | break;
|
---|
| 388 | }
|
---|
| 389 | });
|
---|
| 390 | }
|
---|
| 391 | /***********************************
|
---|
| 392 | * DOCUMENT EVENTS BINDING - END *
|
---|
| 393 | ***********************************/
|
---|
| 394 |
|
---|
| 395 | /*******************************
|
---|
| 396 | * CREATE FOLDER - START *
|
---|
| 397 | *******************************/
|
---|
| 398 | var createFolderStart = function () {
|
---|
| 399 | var promptOptions = {
|
---|
| 400 | title: "Tạo thư mục má»i",
|
---|
| 401 | buttons: {
|
---|
| 402 | confirm: {
|
---|
| 403 | label: "Lưu"
|
---|
| 404 | },
|
---|
| 405 | cancel: {
|
---|
| 406 | label: "Há»§y"
|
---|
| 407 | }
|
---|
| 408 | },
|
---|
| 409 | callback: function (result) {
|
---|
| 410 | if (result === null) {
|
---|
| 411 | } else {
|
---|
| 412 | createFolder(treeCurrentNode, result);
|
---|
| 413 | }
|
---|
| 414 | }
|
---|
| 415 | };
|
---|
| 416 |
|
---|
| 417 | return bootbox.prompt(promptOptions);
|
---|
| 418 | }
|
---|
| 419 |
|
---|
| 420 | var uploadStart = function () {
|
---|
| 421 | var userid = o.data.userinfo.us_id;
|
---|
| 422 | var promptOptions = {
|
---|
| 423 | title: "Tải lên",
|
---|
| 424 | message: "<form id='upload' method='post' action='http://sbgapi.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='response' value='1'/><input type='hidden' name='dir' value='" + self.getTreeCurrentNode() + "'/><input type='hidden' name='userid' value='"+userid+"'/><input type='file' name='upload_file' multiple /></div><ul></ul></form>",
|
---|
| 425 | buttons: {
|
---|
| 426 | success: {
|
---|
| 427 | label: "Xong",
|
---|
| 428 | className: "btn btn-primary",
|
---|
| 429 | callback: function (result) {
|
---|
| 430 |
|
---|
| 431 | }
|
---|
| 432 | },
|
---|
| 433 | },
|
---|
| 434 | onEscape: function() {uploadDone(self.getTreeCurrentNode());}
|
---|
| 435 | };
|
---|
| 436 |
|
---|
| 437 | return bootbox.dialog(promptOptions);
|
---|
| 438 | }
|
---|
| 439 | var uploadDone = function (result) {
|
---|
| 440 |
|
---|
| 441 | }
|
---|
| 442 | var btnPreviewClick = function(){
|
---|
| 443 | var items = o.oGrid.getHightLightItem();
|
---|
| 444 | if ($(items).length == 0) {
|
---|
| 445 | var dirID = $(o.oTree.getSelectedNode()).attr('id');
|
---|
| 446 | var item = o.data.DIRECTORIES[searchItemByID(dirID, 'directory')];
|
---|
| 447 | item.type = 'directory';
|
---|
| 448 | items = [item];
|
---|
| 449 | }
|
---|
[788] | 450 | previewFile(items[0]);
|
---|
[780] | 451 | }
|
---|
| 452 |
|
---|
| 453 | var previewFile = function(node) {
|
---|
| 454 | var content="";
|
---|
[781] | 455 | $ext=node.fileurl.split('.').pop();
|
---|
[782] | 456 | if($.inArray( $ext, [ "jpg", "jpeg","png","gif"])>=0)
|
---|
| 457 | {
|
---|
[781] | 458 | content="<img style='width:100%' src='"+node.fileurl+"' /><br />"+node.name;
|
---|
| 459 | bootbox.alert(content);
|
---|
[780] | 460 | }
|
---|
[781] | 461 |
|
---|
| 462 | if($.inArray( $ext, [ "flv", "mp4","avi"])>=0)
|
---|
| 463 | {
|
---|
| 464 | content='<div id="myElement">Loading the player...</div> <br />'+node.name;
|
---|
| 465 | bootbox.alert(content);
|
---|
| 466 | jwplayer("myElement").setup({
|
---|
| 467 | file: node.fileurl,
|
---|
| 468 | image: "",
|
---|
| 469 | width: 550,
|
---|
| 470 | height: 350
|
---|
| 471 | });
|
---|
[780] | 472 | }
|
---|
[781] | 473 |
|
---|
| 474 | if($.inArray( $ext, [ "ogg"])>=0)
|
---|
| 475 | {
|
---|
| 476 | content='<audio controls>\
|
---|
| 477 | <source src="'+node.fileurl+'" type="audio/ogg">\
|
---|
| 478 | Your browser does not support the audio element.\
|
---|
| 479 | </audio> <br />'+node.name;
|
---|
| 480 | bootbox.alert(content);
|
---|
| 481 | }
|
---|
| 482 | if($.inArray( $ext, [ "mp3"])>=0)
|
---|
| 483 | {
|
---|
| 484 | content='<audio controls>\
|
---|
| 485 | <source src="'+node.fileurl+'" type="audio/mpeg">\
|
---|
| 486 | Your browser does not support the audio element.\
|
---|
| 487 | </audio> <br />'+node.name;
|
---|
| 488 | bootbox.alert(content);
|
---|
| 489 | }
|
---|
[788] | 490 | if($.inArray( $ext, ["ppt","xls","doc","pdf","docx","pptx","xlsx"])>=0)
|
---|
[781] | 491 | {
|
---|
[791] | 492 | content=node.name+'<br /><div id="preview"></div>'
|
---|
[781] | 493 |
|
---|
[791] | 494 | bootbox.alert(content);
|
---|
[788] | 495 | $.ajax({
|
---|
| 496 | url: o.host+"preview/getPreview",
|
---|
| 497 | type: "POST",
|
---|
| 498 | data: {'fileId':node.id},
|
---|
| 499 | success: function(data, textStatus, jqXHR)
|
---|
| 500 | {
|
---|
[791] | 501 | $("#preview").html(data);
|
---|
| 502 | setTimeout(function(){
|
---|
| 503 | $("#slides").slidesjs({
|
---|
| 504 | width: 500,
|
---|
| 505 |
|
---|
| 506 | navigation: false,
|
---|
| 507 | });
|
---|
| 508 | },500);
|
---|
| 509 |
|
---|
| 510 |
|
---|
[788] | 511 | }
|
---|
| 512 | ,
|
---|
| 513 | error: function(jqXHR, textStatus, errorThrown)
|
---|
| 514 | {
|
---|
| 515 |
|
---|
| 516 | }
|
---|
| 517 | });
|
---|
[781] | 518 | }
|
---|
| 519 |
|
---|
| 520 |
|
---|
| 521 |
|
---|
| 522 |
|
---|
[780] | 523 | }
|
---|
| 524 |
|
---|
| 525 | var uploadInit = function () {
|
---|
| 526 | var ul = $('#upload ul');
|
---|
| 527 |
|
---|
| 528 | $('#drop a').click(function () {
|
---|
| 529 | $(this).parent().find('input').click();
|
---|
| 530 | });
|
---|
| 531 |
|
---|
| 532 | $('#upload').fileupload({
|
---|
| 533 | dropZone: $('#drop'),
|
---|
| 534 | add: function (e, data) {
|
---|
| 535 |
|
---|
| 536 | var tpl = $('<li class="working"><input type="text" value="0" data-width="48" data-height="48"' +
|
---|
| 537 | ' data-fgColor="#0788a5" data-readOnly="1" data-bgColor="#3e4043" /><p></p><span></span></li>');
|
---|
| 538 | tpl.find('p').text(data.files[0].name)
|
---|
| 539 | .append('<i>' + formatFileSize(data.files[0].size) + '</i>');
|
---|
| 540 | data.context = tpl.appendTo(ul);
|
---|
| 541 | tpl.find('input').knob();
|
---|
| 542 | tpl.find('span').click(function () {
|
---|
| 543 |
|
---|
| 544 | if (tpl.hasClass('working')) {
|
---|
| 545 | jqXHR.abort();
|
---|
| 546 | }
|
---|
| 547 |
|
---|
| 548 | tpl.fadeOut(function () {
|
---|
| 549 | tpl.remove();
|
---|
| 550 | });
|
---|
| 551 |
|
---|
| 552 | });
|
---|
| 553 |
|
---|
| 554 | var jqXHR = data.submit();
|
---|
| 555 | },
|
---|
| 556 | progress: function (e, data) {
|
---|
| 557 |
|
---|
| 558 | // Calculate the completion percentage of the upload
|
---|
| 559 | var progress = parseInt(data.loaded / data.total * 100, 10);
|
---|
| 560 |
|
---|
| 561 | // Update the hidden input field and trigger a change
|
---|
| 562 | // so that the jQuery knob plugin knows to update the dial
|
---|
| 563 | data.context.find('input').val(progress).change();
|
---|
| 564 |
|
---|
| 565 | if (progress == 100) {
|
---|
| 566 | data.context.removeClass('working');
|
---|
| 567 |
|
---|
| 568 |
|
---|
| 569 |
|
---|
| 570 |
|
---|
| 571 | }
|
---|
| 572 | },
|
---|
| 573 | fail: function (e, data) {
|
---|
| 574 | // Something has gone wrong!
|
---|
| 575 | data.context.addClass('error');
|
---|
| 576 | },
|
---|
| 577 | done: function (e, data) {
|
---|
| 578 | //var newFileData = {"DIRECTORIES": [{"id": "5000", "name": "Dir1", "parentID": 85}], "FILES": [{"id": "2000", "name": "File in root 1", "parentID": 85, "minetype": "text"},{"id": "2001", "name": "File in root 2", "parentID": 85, "minetype": "text"}], "ERROR": {"err": "", "errCode": 0}};
|
---|
| 579 | var newFileData=data.result;
|
---|
| 580 | newFileData=$.parseJSON(data.result);
|
---|
| 581 | if (newFileData.ERROR.errCode == 0) {
|
---|
| 582 | for (var i = 0; i < $(newFileData.FILES).length; i++) {
|
---|
| 583 | var file = newFileData.FILES[i];
|
---|
| 584 | var node = {id: file.id, name: file.name,fileurl: file.fileurl, parentID: file.parentID, minetype:file.minetype};
|
---|
| 585 | o.oGrid.createNode(node);
|
---|
| 586 | o.data.FILES[$(o.data.FILES).length] = node;
|
---|
| 587 | }
|
---|
| 588 |
|
---|
| 589 | for (var i = 0; i < $(newFileData.DIRECTORIES).length; i++) {
|
---|
| 590 | var file = newFileData.DIRECTORIES[i];
|
---|
| 591 | var node = {id: file.id, name: file.name, parentID: file.parentID, minetype:file.minetype};
|
---|
| 592 | o.oTree.createNode(node);
|
---|
| 593 | o.oGrid.createNode(node);
|
---|
| 594 | o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = node;
|
---|
| 595 | }
|
---|
| 596 |
|
---|
| 597 | /*var node = {id: parseData.id, name: parseData.name, parentID: parseData.parentID};
|
---|
| 598 | o.oTree.createNode(node);
|
---|
| 599 | o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = node;
|
---|
| 600 | if (o.oGrid) o.oGrid.reloadGrid();*/
|
---|
| 601 | }
|
---|
| 602 | }
|
---|
| 603 |
|
---|
| 604 | });
|
---|
| 605 |
|
---|
| 606 | $(document).on('drop dragover', function (e) {
|
---|
| 607 | e.preventDefault();
|
---|
| 608 | });
|
---|
| 609 |
|
---|
| 610 | function formatFileSize(bytes) {
|
---|
| 611 | if (typeof bytes !== 'number') {
|
---|
| 612 | return '';
|
---|
| 613 | }
|
---|
| 614 |
|
---|
| 615 | if (bytes >= 1000000000) {
|
---|
| 616 | return (bytes / 1000000000).toFixed(2) + ' GB';
|
---|
| 617 | }
|
---|
| 618 |
|
---|
| 619 | if (bytes >= 1000000) {
|
---|
| 620 | return (bytes / 1000000).toFixed(2) + ' MB';
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | return (bytes / 1000).toFixed(2) + ' KB';
|
---|
| 624 | }
|
---|
| 625 |
|
---|
| 626 | };
|
---|
| 627 |
|
---|
| 628 | var createFolder = function (parent, name) {
|
---|
| 629 | var postdata = {fname: name, fparentid: parent};
|
---|
| 630 | var script = 'createdir';
|
---|
| 631 | /*isDev = true;*/
|
---|
| 632 | sendCommand({
|
---|
| 633 | postdata: postdata,
|
---|
| 634 | script: script,
|
---|
| 635 | callbackSuccess: function (parseData) {
|
---|
| 636 | createFolderFinish(parseData);
|
---|
| 637 | },
|
---|
| 638 | callbackFail: function () {
|
---|
| 639 | }
|
---|
| 640 | });
|
---|
| 641 | }
|
---|
| 642 |
|
---|
| 643 | var createFolderFinish = function (parseData) {
|
---|
| 644 | /*isDev = false;*/
|
---|
| 645 | if (parseData.ERROR.errCode == 0) {
|
---|
| 646 | var node = {id: parseData.id, name: parseData.name, parentID: parseData.parentID};
|
---|
| 647 | o.oTree.createNode(node);
|
---|
| 648 | o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = node;
|
---|
| 649 | if (o.oGrid)
|
---|
| 650 | o.oGrid.reloadGrid();
|
---|
| 651 | }
|
---|
| 652 | }
|
---|
| 653 | /*******************************
|
---|
| 654 | * CREATE FOLDER - END *
|
---|
| 655 | *******************************/
|
---|
| 656 | /********************************
|
---|
| 657 | * COPY & PASTE & MOVE - START *
|
---|
| 658 | ************=*******************/
|
---|
| 659 | var copy = function (act) {
|
---|
| 660 | //detect selected items
|
---|
| 661 | //push to clipboard
|
---|
| 662 | var items = o.oGrid.getHightLightItem();
|
---|
| 663 |
|
---|
| 664 | if ($(items).length == 0) {
|
---|
| 665 | var node = o.oTree.getSelectedNode();
|
---|
| 666 | var itemID = $(node).attr('id');
|
---|
| 667 |
|
---|
| 668 | if (itemID == 0)
|
---|
| 669 | return false;
|
---|
| 670 |
|
---|
| 671 | items[0] = o.data.DIRECTORIES[searchItemByID(itemID, 'directory')];
|
---|
| 672 | items[0].type = 'directory';
|
---|
| 673 | }
|
---|
| 674 |
|
---|
| 675 | if ($(items).length > 0) {
|
---|
| 676 | oClipBoard.items = items;
|
---|
| 677 | oClipBoard.act = act;
|
---|
| 678 | }
|
---|
| 679 | return true;
|
---|
| 680 | }
|
---|
| 681 |
|
---|
| 682 | var paste = function () {
|
---|
| 683 | if ((oClipBoard.act != 'copy'
|
---|
| 684 | && oClipBoard.act != 'move')
|
---|
| 685 | || oClipBoard.items == null)
|
---|
| 686 | return;
|
---|
| 687 |
|
---|
| 688 | var items = [];
|
---|
| 689 | var destination = self.getTreeCurrentNode();
|
---|
| 690 | if (oClipBoard.act != 'copy') {
|
---|
| 691 | $(oClipBoard.items).each(function (index) {
|
---|
| 692 | var node = new Object;
|
---|
| 693 | if (this.type == 'directory')
|
---|
| 694 | buildTreeFromParent(this.id, node);
|
---|
| 695 | else {
|
---|
| 696 | node.id = this.id;
|
---|
| 697 | node.type = 'file';
|
---|
| 698 | }
|
---|
| 699 |
|
---|
| 700 | items[index] = node;
|
---|
| 701 | });
|
---|
| 702 | }
|
---|
| 703 | else {
|
---|
| 704 | items = oClipBoard.items;
|
---|
| 705 | }
|
---|
| 706 |
|
---|
| 707 | var postdata = {act: oClipBoard.act, destination: destination, data: JSON.stringify(items)};
|
---|
| 708 | var script = oClipBoard.act;
|
---|
| 709 |
|
---|
| 710 | sendCommand({
|
---|
| 711 | postdata: postdata,
|
---|
| 712 | script: script,
|
---|
| 713 | callbackSuccess: function (parseData) {
|
---|
| 714 | if (oClipBoard.act == 'copy') {
|
---|
| 715 | $(parseData.DIRECTORIES).each(function (index) {
|
---|
| 716 | o.data.DIRECTORIES[$(o.data.DIRECTORIES).length] = this;
|
---|
| 717 | });
|
---|
| 718 |
|
---|
| 719 | $(parseData.FILES).each(function (index) {
|
---|
| 720 | o.data.FILES[$(o.data.FILES).length] = this;
|
---|
| 721 | });
|
---|
| 722 |
|
---|
| 723 | o.data.DIRECTORIES.sort(function (a, b) {
|
---|
| 724 | return a.parentID - b.parentID;
|
---|
| 725 | });
|
---|
| 726 |
|
---|
| 727 | o.oTree.setData(o.data.DIRECTORIES);
|
---|
| 728 | o.oGrid.setData(o.data);
|
---|
| 729 | o.oTree.createCopyNode(parseData.DIRECTORIES);
|
---|
| 730 | o.oGrid.reloadGrid();
|
---|
| 731 | }
|
---|
| 732 | else if (oClipBoard.act == 'move') {
|
---|
| 733 |
|
---|
| 734 | }
|
---|
| 735 | }
|
---|
| 736 | });
|
---|
| 737 |
|
---|
| 738 | }
|
---|
| 739 |
|
---|
| 740 | var move = function () {
|
---|
| 741 |
|
---|
| 742 | }
|
---|
| 743 |
|
---|
| 744 | var copyTo = function () {
|
---|
| 745 |
|
---|
| 746 | }
|
---|
| 747 |
|
---|
| 748 | var moveTo = function () {
|
---|
| 749 |
|
---|
| 750 | }
|
---|
| 751 |
|
---|
| 752 | /*****************************
|
---|
| 753 | * COPY & PASTE & MOVE - END *
|
---|
| 754 | *****************************/
|
---|
| 755 |
|
---|
| 756 | this.deleteItem = function (item) {
|
---|
| 757 |
|
---|
| 758 | var confirmText = 'Bạn có muá»n xóa ';
|
---|
| 759 |
|
---|
| 760 | if ($.isArray(item) && item.length > 1) {
|
---|
| 761 | confirmText += 'các thư mục (và files) Äã chá»n?';
|
---|
| 762 | }
|
---|
| 763 | else if (item.length == 1) {
|
---|
| 764 | if (item[0].id == 0)
|
---|
| 765 | return false;
|
---|
| 766 | confirmText += (item[0].type == 'directory') ? 'thư mục' : 'file';
|
---|
| 767 | confirmText += ' <span style="font-weight:bold">' + item[0].name + "</span> khÃŽng?";
|
---|
| 768 | }
|
---|
| 769 |
|
---|
| 770 | 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>';
|
---|
| 771 |
|
---|
| 772 | var parentID = item[0].parentID;
|
---|
| 773 |
|
---|
| 774 | for (var i = 0; i < item.length; i++) {
|
---|
| 775 | if (item[i].type == 'directory') {
|
---|
| 776 | var aryChildDirTmp = [];
|
---|
| 777 | var aryChildDirID = [];
|
---|
| 778 | var aryChildFiles = searchItemsByParent(item[i].id, 'file');
|
---|
| 779 | var aryChildDirs = [];
|
---|
| 780 |
|
---|
| 781 | getAllDirChild(item[i].id, aryChildDirTmp);
|
---|
| 782 | for (var d = 1; d < aryChildDirTmp.length; d++) {
|
---|
| 783 | aryChildDirID[d - 1] = aryChildDirTmp[d];
|
---|
| 784 | }
|
---|
| 785 |
|
---|
| 786 | for (var j = 0; j < aryChildDirID.length; j++) {
|
---|
| 787 | if (o.data.DIRECTORIES[searchItemByID(aryChildDirID[j], 'directory')] != undefined)
|
---|
| 788 | aryChildDirs[aryChildDirs.length] = o.data.DIRECTORIES[searchItemByID(aryChildDirID[j], 'directory')];
|
---|
| 789 |
|
---|
| 790 | var aryTmp = searchItemsByParent(aryChildDirID[j], 'file');
|
---|
| 791 | if (aryTmp.length > 0)
|
---|
| 792 | for (var f in aryTmp) {
|
---|
| 793 | aryChildFiles[aryChildFiles.length] = aryTmp[f];
|
---|
| 794 | }
|
---|
| 795 | }
|
---|
| 796 |
|
---|
| 797 | item[i].childDirs = aryChildDirs;
|
---|
| 798 | item[i].childFiles = aryChildFiles;
|
---|
| 799 | }
|
---|
| 800 | }
|
---|
| 801 |
|
---|
| 802 | var confirmOptions = {
|
---|
| 803 | message: confirmText,
|
---|
| 804 | buttons: {
|
---|
| 805 | confirm: {
|
---|
| 806 | label: "Xóa"
|
---|
| 807 | },
|
---|
| 808 | cancel: {
|
---|
| 809 | label: "KhÎng xóa"
|
---|
| 810 | }
|
---|
| 811 | },
|
---|
| 812 | callback: function (result) {
|
---|
| 813 | if (result) {
|
---|
| 814 | var delobj = JSON.stringify(item);
|
---|
| 815 | var postdata = {delobj: delobj};
|
---|
| 816 | var script = 'delete';
|
---|
| 817 | sendCommand({
|
---|
| 818 | postdata: postdata,
|
---|
| 819 | script: script,
|
---|
| 820 | callbackSuccess: function (parseData) {
|
---|
| 821 | if ($(parseData.DIRECTORIES).length > 0) {
|
---|
| 822 | $(parseData.DIRECTORIES).each(function (index) {
|
---|
| 823 | o.oTree.deletion(this);
|
---|
| 824 | o.oGrid.deletion(this, 'directory');
|
---|
| 825 | });
|
---|
| 826 | }
|
---|
| 827 |
|
---|
| 828 | if ($(parseData.FILES).length > 0) {
|
---|
| 829 | $(parseData.FILES).each(function (index) {
|
---|
| 830 | var file = o.data.FILES[searchItemByID(this, 'file')];
|
---|
| 831 | o.oGrid.deletion(this, file.minetype);
|
---|
| 832 | });
|
---|
| 833 | }
|
---|
| 834 | },
|
---|
| 835 | callbackDone: function (obj) {
|
---|
| 836 | if ($(parseData.DIRECTORIES).length > 0) {
|
---|
| 837 | $(parseData.DIRECTORIES).each(function (index) {
|
---|
| 838 | delete o.data.DIRECTORIES[searchItemByID(this, 'directory')];
|
---|
| 839 | });
|
---|
| 840 | }
|
---|
| 841 |
|
---|
| 842 | if ($(parseData.FILES).length > 0) {
|
---|
| 843 | $(parseData.FILES).each(function (index) {
|
---|
| 844 | delete o.data.FILES[searchItemByID(this, 'file')];
|
---|
| 845 | });
|
---|
| 846 | }
|
---|
| 847 |
|
---|
| 848 | o.oTree.setData(o.data.DIRECTORIES);
|
---|
| 849 | o.oGrid.setData(o.data);
|
---|
| 850 | self.setTreeCurrentNode(parentID);
|
---|
| 851 | o.oGrid.reloadGrid();
|
---|
| 852 | },
|
---|
| 853 | callbackFail: function () {
|
---|
| 854 | }
|
---|
| 855 | });
|
---|
| 856 | }
|
---|
| 857 | }
|
---|
| 858 | };
|
---|
| 859 |
|
---|
| 860 | bootbox.confirm(confirmOptions);
|
---|
| 861 | }
|
---|
| 862 |
|
---|
| 863 | this.setTreeCurrentNode = function (treeNode) {
|
---|
| 864 | //fire when click a node on Tree
|
---|
| 865 | //then fire action of Grid
|
---|
| 866 | treeCurrentNode = treeNode;
|
---|
| 867 | if (o.oGrid)
|
---|
| 868 | o.oGrid.reloadGrid();
|
---|
| 869 | };
|
---|
| 870 |
|
---|
| 871 | this.getTreeCurrentNode = function () {
|
---|
| 872 | return treeCurrentNode;
|
---|
| 873 | }
|
---|
| 874 |
|
---|
| 875 | this.gridNodeDblClick = function (node) {
|
---|
| 876 | if (node.minetype == 'directory') {
|
---|
| 877 | var treeNode = $('#' + o.tree).find('UL.vstree[rel^="node' + node.parentID + '"] > LI[rel^="folder"] > A#' + node.id);
|
---|
| 878 | o.oTree.activeNode(treeNode);
|
---|
| 879 | }
|
---|
| 880 | else {
|
---|
| 881 | //execute or preview file
|
---|
| 882 | previewFile(node);
|
---|
| 883 | }
|
---|
| 884 | };
|
---|
| 885 |
|
---|
| 886 | this.createNewFolder = function () {
|
---|
| 887 |
|
---|
| 888 | }
|
---|
| 889 |
|
---|
| 890 | this.updateData = function (p) {
|
---|
| 891 | if (p.item == undefined)
|
---|
| 892 | p.item = null;
|
---|
| 893 | if (p.updateAll == undefined)
|
---|
| 894 | p.updateAll = false;
|
---|
| 895 | if (p.from == undefined)
|
---|
| 896 | p.from = null;
|
---|
| 897 | if (p.type == undefined)
|
---|
| 898 | p.type = null;
|
---|
| 899 | if (p.callback == undefined)
|
---|
| 900 | p.callback = null;
|
---|
| 901 |
|
---|
| 902 | var obj = p.from == 'tree' ? o.oGrid : o.oTree;
|
---|
| 903 | if (!p.updateAll) {
|
---|
| 904 | var index = searchItemByID(p.item.id, p.type);
|
---|
| 905 | switch (p.type) {
|
---|
| 906 | case 'directory':
|
---|
| 907 | o.data.DIRECTORIES[index].name = p.item.name;
|
---|
| 908 | o.data.DIRECTORIES[index].parentID = p.item.parentID;
|
---|
| 909 | break;
|
---|
| 910 | case 'file':
|
---|
| 911 | o.data.FILES[index].name = p.item.name;
|
---|
| 912 | o.data.FILES[index].parentID = p.item.parentID;
|
---|
| 913 | o.data.FILES[index].minetype = p.item.minetype;
|
---|
| 914 | o.data.FILES[index].fileurl = p.item.fileurl;
|
---|
| 915 | break;
|
---|
| 916 | default:
|
---|
| 917 | break;
|
---|
| 918 | }
|
---|
| 919 | }
|
---|
| 920 |
|
---|
| 921 | o.oTree.setData(o.data.DIRECTORIES);
|
---|
| 922 | o.oGrid.setData(o.data);
|
---|
| 923 |
|
---|
| 924 | if (p.callback != null) {
|
---|
| 925 | eval('obj.' + p.callback + '(p.item);')
|
---|
| 926 | }
|
---|
| 927 |
|
---|
| 928 | //call sendCommand
|
---|
| 929 | }
|
---|
| 930 |
|
---|
| 931 | this.searchItemsByParent = function (parentID, type) {
|
---|
| 932 | return searchItemsByParent(parentID, type);
|
---|
| 933 | }
|
---|
| 934 |
|
---|
| 935 | this.searchItemByID = function (parentID, type) {
|
---|
| 936 | return searchItemByID(parentID, type);
|
---|
| 937 | }
|
---|
| 938 |
|
---|
| 939 | this.initialize = function () {
|
---|
| 940 | init();
|
---|
| 941 | return this;
|
---|
| 942 | };
|
---|
| 943 |
|
---|
| 944 | return this.initialize();
|
---|
| 945 | }
|
---|
| 946 | });
|
---|
| 947 | })(jQuery); |
---|