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