diff options
author | Hilmar R <u02@u29lx193> | 2021-01-22 01:38:43 +0100 |
---|---|---|
committer | Hilmar R <u02@u29lx193> | 2021-01-22 01:38:43 +0100 |
commit | 523765b968a5d94a98eee12854fc527d5abbc2e7 (patch) | |
tree | a71caba8943c674917821a4afd333eb39ac92b2e /view/js | |
parent | 78f150cfbc1b713bfba3101fdc3f1fd624120637 (diff) | |
parent | 254e30bea173e350a24756cbd8cf4acdfe32933e (diff) | |
download | volse-hubzilla-523765b968a5d94a98eee12854fc527d5abbc2e7.tar.gz volse-hubzilla-523765b968a5d94a98eee12854fc527d5abbc2e7.tar.bz2 volse-hubzilla-523765b968a5d94a98eee12854fc527d5abbc2e7.zip |
Merge branch 'master' into air.5
Diffstat (limited to 'view/js')
-rw-r--r-- | view/js/acl.js | 12 | ||||
-rw-r--r-- | view/js/autocomplete.js | 26 | ||||
-rw-r--r-- | view/js/main.js | 365 | ||||
-rw-r--r-- | view/js/mod_cloud.js | 510 |
4 files changed, 582 insertions, 331 deletions
diff --git a/view/js/acl.js b/view/js/acl.js index 4597184ea..ee6cb062f 100644 --- a/view/js/acl.js +++ b/view/js/acl.js @@ -30,7 +30,7 @@ function ACL(backend_url) { that.custom = $("#acl-custom"); that.acl_select = $("#acl-select"); - // set the initial ACL lists in case the enclosing form gets submitted before the ajax loader completes. + // set the initial ACL lists in case the enclosing form gets submitted before the ajax loader completes. //that.on_submit(); /*events*/ @@ -90,7 +90,7 @@ ACL.prototype.get_form_data = function(event) { } -// no longer called only on submit - call to update whenever a change occurs to the acl list. +// no longer called only on submit - call to update whenever a change occurs to the acl list. ACL.prototype.on_submit = function() { $('.acl-field').remove(); @@ -340,7 +340,13 @@ ACL.prototype.update_view = function(value) { that.list.hide(); //hide acl-list that.info.hide(); //show acl-info that.selected_id = that.contact_ids[that.allow_cid[0]]; - that.update_select('\\^' + that.selected_id); + + if(that.acl_select.find('option[id="\\^' + that.selected_id + '"]').length === 0) { + that.update_view('custom'); + } + else { + that.update_select('\\^' + that.selected_id); + } /* jot acl */ $('#jot-perms-icon, #dialog-perms-icon, #' + that.form_id[0].id + ' .jot-perms-icon').removeClass('fa-unlock').addClass('fa-lock'); diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index 27011b4d4..92db42f6d 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -171,17 +171,6 @@ function string2bb(element) { template: contact_format }; - // Autocomplete forums - forums = { - match: /(^|\s)(\!\!*)([^ \n]{2,})$/, - index: 3, - cache: true, - search: function(term, callback) { contact_search(term, callback, backend_url, 'f', extra_channels, spinelement=false); }, - replace: editor_replace, - template: contact_format - }; - - // Autocomplete hashtags tags = { match: /(^|\s)(\#)([^ \n]{2,})$/, @@ -193,7 +182,6 @@ function string2bb(element) { template: tag_format }; - smilies = { match: /(^|\s)(:[a-z0-9_:]{2,})$/, index: 2, @@ -214,7 +202,7 @@ function string2bb(element) { maxCount: 100 } }); - textcomplete.register([contacts,forums,smilies,tags]); + textcomplete.register([contacts,smilies,tags]); }); }; })( jQuery ); @@ -238,16 +226,6 @@ function string2bb(element) { template: contact_format, }; - // Autocomplete forums - forums = { - match: /(^\!)([^\n]{2,})$/, - index: 2, - cache: true, - search: function(term, callback) { contact_search(term, callback, backend_url, 'f', [], spinelement='#nav-search-spinner'); }, - replace: basic_replace, - template: contact_format - }; - // Autocomplete hashtags tags = { match: /(^\#)([^ \n]{2,})$/, @@ -271,7 +249,7 @@ function string2bb(element) { maxCount: 100 } }); - textcomplete.register([contacts,forums,tags]); + textcomplete.register([contacts,tags]); }); textcomplete.on('selected', function() { this.editor.el.form.submit(); }); diff --git a/view/js/main.js b/view/js/main.js index 8ceb0b143..3e3fd057c 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -20,17 +20,18 @@ var pageHasMoreContent = true; var divmore_height = 400; var last_filestorage_id = null; var mediaPlaying = false; -var contentHeightDiff = 0; var liveRecurse = 0; var savedTitle = ''; var followUpPageLoad = false; var window_needs_alert = true; +var expanded_items = []; var sse_bs_active = false; var sse_offset = 0; var sse_type; var sse_partial_result = false; var sse_rmids = []; +var sse_fallback_interval; var page_cache = {}; @@ -43,7 +44,7 @@ if(localStorage.getItem('uid') !== localUser.toString()) { window.onstorage = function(e) { if(e.key === 'uid' && parseInt(e.newValue) !== localUser) { if(window_needs_alert) { - window_needs_alert = false; + window_needs_alert = false; alert("Your identity has changed. Page reload required!"); window.location.reload(); return; @@ -68,6 +69,13 @@ $(document).ready(function() { this.autocomplete_handled = true; } + + }); + + $(document).on('keydown', '.comment-edit-form textarea.expanded', function (e) { + if (e.ctrlKey && e.keyCode === 13) { + post_comment(this.id.replace('comment-edit-text-','')); + } }); var tf = new Function('n', 's', 'var k = s.split("/")['+aStr['plural_func']+']; return (k ? k : s);'); @@ -91,40 +99,58 @@ $(document).ready(function() { wordSeparator : aStr['t16'], numbers : aStr['t17'], }; - + jQuery.timeago.settings.allowFuture = true; - if(typeof(window.SharedWorker) === 'undefined') { - // notifications with multiple tabs open will not work very well in this scenario - var evtSource = new EventSource('/sse'); + if(sse_enabled) { + if(typeof(window.SharedWorker) === 'undefined') { + // notifications with multiple tabs open will not work very well in this scenario + var evtSource = new EventSource('/sse'); - evtSource.addEventListener('notifications', function(e) { - var obj = JSON.parse(e.data); - sse_handleNotifications(obj, false, false); - }, false); + evtSource.addEventListener('notifications', function(e) { + var obj = JSON.parse(e.data); + sse_handleNotifications(obj, false, false); + }, false); - document.addEventListener('visibilitychange', function() { - if (!document.hidden) { - sse_offset = 0; - sse_bs_init(); + document.addEventListener('visibilitychange', function() { + if (!document.hidden) { + sse_offset = 0; + sse_bs_init(); + } + }, false); + + } + else { + var myWorker = new SharedWorker('/view/js/sse_worker.js', localUser); + + myWorker.port.onmessage = function(e) { + obj = e.data; + console.log(obj); + sse_handleNotifications(obj, false, false); } - }, false); - } - else { - var myWorker = new SharedWorker('/view/js/sse_worker.js', localUser); + myWorker.onerror = function(e) { + myWorker.port.close(); + } - myWorker.port.onmessage = function(e) { - obj = e.data; - console.log(obj); - sse_handleNotifications(obj, false, false); + myWorker.port.start(); } + } + else { + if (!document.hidden) + sse_fallback_interval = setInterval(sse_fallback, updateInterval); - myWorker.onerror = function(e) { - myWorker.port.close(); - } + document.addEventListener('visibilitychange', function() { + if (document.hidden) { + clearInterval(sse_fallback_interval); + } + else { + sse_offset = 0; + sse_bs_init(); + sse_fallback_interval = setInterval(sse_fallback, updateInterval); + } - myWorker.port.start(); + }, false); } $('.notification-link').on('click', { replace: true, followup: false }, sse_bs_notifications); @@ -188,33 +214,6 @@ $(document).ready(function() { updateInit(); - // Allow folks to stop the ajax page updates with the pause/break key - $(document).keydown(function(event) { - if(event.keyCode == '8') { - var target = event.target || event.srcElement; - if (!/input|textarea/i.test(target.nodeName)) { - return false; - } - } - - if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) { - event.preventDefault(); - if(stopped === false) { - stopped = true; - if (event.ctrlKey) { - totStopped = true; - } - $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />'); - } else { - unpause(); - } - } else { - if (!totStopped) { - unpause(); - } - } - }); - var e = document.getElementById('content-complete'); if(e) pageHasMoreContent = false; @@ -288,6 +287,7 @@ function handle_comment_form(e) { // handle clicked form var form = $(this); + var fields = form.find(':input[type=text], textarea'); var fields_empty = true; @@ -298,12 +298,13 @@ function handle_comment_form(e) { $('#' + commentElm).addClass('expanded').removeAttr('placeholder'); $('#' + commentElm).attr('tabindex','9'); $('#' + submitElm).attr('tabindex','10'); - + form.find(':not(:visible)').show(); } + // handle click outside of form (close empty forms) - $(document).on('click', function(e) { + $(document).one('click', function(e) { fields.each(function() { if($(this).val() != '') fields_empty = false; @@ -322,18 +323,19 @@ function handle_comment_form(e) { form.find(':button[type=submit]').prop('title', ''); } }); - + var commentSaveTimer = null; var emptyCommentElm = form.find('.comment-edit-text').attr('id'); var convId = emptyCommentElm.replace('comment-edit-text-',''); - $(document).on('focusout','#' + emptyCommentElm,function(e){ + $('#' + emptyCommentElm).on('focusout',function(e){ if(commentSaveTimer) clearTimeout(commentSaveTimer); commentSaveChanges(convId,true); commentSaveTimer = null; + $('#' + emptyCommentElm).off(); }); - $(document).on('focusin','#' + emptyCommentElm,function(e){ + $('#' + emptyCommentElm).on('focusin', function (e){ commentSaveTimer = setTimeout(function () { commentSaveChanges(convId,false); },10000); @@ -357,11 +359,13 @@ function handle_comment_form(e) { } } } + } + + function commentClose(obj, id) { if(obj.value === '') { - obj.value = aStr.comment; $("#comment-edit-text-" + id).removeClass("expanded"); $("#mod-cmnt-wrap-" + id).hide(); $("#comment-tools-" + id).hide(); @@ -448,7 +452,7 @@ function insertCommentAttach(comment,id) { $('body').css('cursor', 'wait'); $('#invisible-comment-upload').trigger('click'); - + return false; } @@ -616,7 +620,10 @@ function updatePageItems(mode, data) { function updateConvItems(mode,data) { - $(document).trigger('hz:updateConvItems'); + var scroll_position = $(window).scrollTop(); + + if(mode !== 'update') + $(document).trigger('hz:updateConvItems'); if(mode === 'update' || mode === 'replace') { prev = 'threads-begin'; @@ -624,14 +631,13 @@ function updateConvItems(mode,data) { if(mode === 'append') { next = 'threads-end'; } - + if(mode === 'replace') { - $('.thread-wrapper').remove(); // clear existing content + $('.thread-parent').remove(); // clear existing content } $('.thread-wrapper', data).each(function() { if(this.classList.contains('toplevel_item')) { - var ident = this.id; var convId = ident.replace('thread-wrapper-',''); var commentWrap = $('#'+ident+' .collapsed-comments').attr('id'); @@ -646,7 +652,7 @@ function updateConvItems(mode,data) { if($('#collapsed-comments-'+itmId).is(':visible')) isVisible = true; - // insert the content according to the mode and first_page + // insert the content according to the mode and first_page // and whether or not the content exists already (overwrite it) if($('#' + ident).length == 0) { @@ -746,6 +752,8 @@ function updateConvItems(mode,data) { }); + $(window).scrollTop(scroll_position); + if(followUpPageLoad) sse_bs_counts(); else @@ -757,7 +765,7 @@ function updateConvItems(mode,data) { } // Setup to determine if the media player is playing. This affects - // some content loading decisions. + // some content loading decisions. $('video').off('playing'); $('video').off('pause'); @@ -841,25 +849,16 @@ function scrollToItem() { } function collapseHeight() { - var origContentHeight = Math.ceil($("#region_2").height()); - var cDiff = 0; - var i = 0; - var position = $(window).scrollTop(); $(".wall-item-content, .directory-collapse").each(function() { var orgHeight = $(this).outerHeight(true); + var id = $(this).attr('id') + var open = ((expanded_items.indexOf($(this).attr('id')) === -1) ? false : true); if(orgHeight > divmore_height) { if(! $(this).hasClass('divmore') && $(this).has('div.no-collapse').length == 0) { - - // check if we will collapse some content above the visible content and compensate the diff later - if($(this).offset().top + divmore_height - $(window).scrollTop() + cDiff - ($(".divgrow-showmore").outerHeight() * i) < 65) { - diff = orgHeight - divmore_height; - cDiff = cDiff + diff; - i++; - } - $(this).readmore({ speed: 0, + startOpen: open, heightMargin: 50, collapsedHeight: divmore_height, moreLink: '<a href="#" class="divgrow-showmore fakelink">' + aStr.divgrowmore + '</a>', @@ -869,6 +868,10 @@ function collapseHeight() { if((($(element).offset().top + divmore_height) - $(window).scrollTop()) < 65 ) { $(window).scrollTop($(window).scrollTop() - ($(element).outerHeight(true) - divmore_height)); } + expanded_items = expanded_items.filter(expanded_items => expanded_items !== id); + } + else { + expanded_items.push(id); } } }); @@ -877,15 +880,6 @@ function collapseHeight() { } }); - var collapsedContentHeight = Math.ceil($("#region_2").height()); - contentHeightDiff = liking ? 0 : origContentHeight - collapsedContentHeight; - console.log('collapseHeight() - contentHeightDiff: ' + contentHeightDiff + 'px'); - - if(i && !liking){ - var sval = position - cDiff + ($(".divgrow-showmore").outerHeight() * i); - console.log('collapsed above viewport count: ' + i); - $(window).scrollTop(sval); - } } function updateInit() { @@ -920,12 +914,7 @@ function liveUpdate(notify_id) { if((src === null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; } - // if auto updates are enabled and a comment box is open, - // prevent live updates until the comment is submitted - - var lockUpdates = (($('.comment-edit-text.expanded').length && (! bParam_static)) ? true : false); - - if(lockUpdates || in_progress || mediaPlaying) { + if(in_progress || mediaPlaying) { if(livetime) { clearTimeout(livetime); } @@ -1027,11 +1016,6 @@ function liveUpdate(notify_id) { scroll_next = false; updateConvItems(update_mode,data); - // adjust scroll position if new content was added above viewport - if(update_mode === 'update' && !justifiedGalleryActive) { - $(window).scrollTop($(window).scrollTop() + $("#region_2").height() - orgHeight + contentHeightDiff); - } - in_progress = false; $('#image_counter').html(''); @@ -1162,19 +1146,30 @@ function justifyPhotosAjax(id) { $('#' + id).justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; }); } -// Since our ajax calls are asynchronous, we will give a few -// seconds for the first ajax call (setting like/dislike), then -// run the updater to pick up any changes and display on the page. -// The updater will turn any rotators off when it's done. -// This function will have returned long before any of these -// events have completed and therefore there won't be any -// visible feedback that anything changed without all this -// trickery. This still could cause confusion if the "like" ajax call -// is delayed and updateInit runs before it completes. function dolike(ident, verb) { - unpause(); $('#like-rotator-' + ident.toString()).show(); - $.get('like/' + ident.toString() + '?verb=' + verb, updateInit ); + + if(typeof conv_mode == typeof undefined) + conv_mode = ''; + + $.get('like/' + ident.toString() + '?verb=' + verb + '&conv_mode=' + conv_mode, function (data) { + if(data.success) { + // this is a bit tricky since the top level thread wrapper wraps the whole thread + if($('#thread-wrapper-' + data.orig_id).hasClass('toplevel_item')) { + var wrapper = $('<div></div>').html( data.html ).find('#wall-item-outside-wrapper-' + data.id); + $('#wall-item-outside-wrapper-' + data.orig_id).html(wrapper[0].innerHTML); + // those were not replaced - swap the id + $('#thread-wrapper-' + data.orig_id).attr('id', 'thread-wrapper-' + data.id); + $('#wall-item-outside-wrapper-' + data.orig_id).attr('id', 'wall-item-outside-wrapper-' + data.id); + } + else { + $('#thread-wrapper-' + data.orig_id).replaceWith(data.html); + } + $('#wall-item-ago-' + data.id + ' .autotime').timeago(); + collapseHeight(); + liking = 0; + } + }); liking = 1; } @@ -1258,35 +1253,34 @@ function dopin(id) { } function dropItem(url, object) { + var confirm = confirmDelete(); + if(confirm) { + var id = url.split('/')[2]; + $('body').css('cursor', 'wait'); + $(object + ', #pinned-wrapper-' + id).css('opacity', 0.33); - var confirm = confirmDelete(); - if(confirm) { - var id = url.split('/')[2]; - $('body').css('cursor', 'wait'); - $(object + ', #pinned-wrapper-' + id).fadeTo('fast', 0.33, function () { - $.get(url).done(function() { - $(object + ', #pinned-wrapper-' + id).remove(); - $('body').css('cursor', 'auto'); - }); - }); - if($('#wall-item-pinned-' + id).length) - $.post('pin/pin', { 'id' : id }); - return true; - } - else { - return false; + $.get(url, function() { + $(object + ', #pinned-wrapper-' + id).remove(); + $('body').css('cursor', 'auto'); + }); + + if($('#wall-item-pinned-' + id).length) + $.post('pin/pin', { 'id' : id }); + + return true; } + else { + return false; + } } function dosubthread(ident) { - unpause(); $('#like-rotator-' + ident.toString()).show(); $.get('subthread/sub/' + ident.toString(), updateInit ); liking = 1; } function dounsubthread(ident) { - unpause(); $('#like-rotator-' + ident.toString()).show(); $.get('subthread/unsub/' + ident.toString(), updateInit ); liking = 1; @@ -1346,18 +1340,6 @@ function lockview(type, id) { }); } -function filestorage(event, nick, id) { - $('#cloud-index-' + last_filestorage_id).removeClass('cloud-index-active'); - $('#perms-panel-' + last_filestorage_id).hide().html(''); - $('#file-edit-' + id).show(); - $.get('filestorage/' + nick + '/' + id + '/edit', function(data) { - $('#cloud-index-' + id).addClass('cloud-index-active'); - $('#perms-panel-' + id).html(data).show(); - $('#file-edit-' + id).hide(); - last_filestorage_id = id; - }); -} - function submitPoll(id) { $.post('vote/' + id, @@ -1365,44 +1347,53 @@ function submitPoll(id) { function(data) { $.jGrowl(data.message, { sticky: false, theme: ((data.success) ? 'info' : 'notice'), life: 10000 }); if(timer) clearTimeout(timer); - timer = setTimeout(updateInit,1500); + timer = setTimeout(updateInit, 500); } ); } - function post_comment(id) { - unpause(); + commentBusy = true; $('body').css('cursor', 'wait'); $("#comment-preview-inp-" + id).val("0"); + + if(typeof conv_mode == typeof undefined) + conv_mode = ''; + + var form_data = $("#comment-edit-form-" + id).serialize(); + $.post( "item", - $("#comment-edit-form-" + id).serialize(), + form_data + '&conv_mode=' + conv_mode, function(data) { if(data.success) { localStorage.removeItem("comment_body-" + id); $("#comment-edit-preview-" + id).hide(); - $("#comment-edit-wrapper-" + id).hide(); - $("#comment-edit-text-" + id).val(''); + $("#comment-edit-text-" + id).val('').blur().attr('placeholder', aStr.comment); + $('#wall-item-comment-wrapper-' + id).before(data.html); + $('#wall-item-ago-' + data.id + ' .autotime').timeago(); + $('body').css('cursor', 'unset'); + collapseHeight(); + commentBusy = false; + var tarea = document.getElementById("comment-edit-text-" + id); if(tarea) { commentClose(tarea, id); - $(document).unbind( "click.commentOpen"); + $(document).off( "click.commentOpen"); } - if(timer) clearTimeout(timer); - timer = setTimeout(updateInit,1500); - } - if(data.reload) { - window.location.href=data.reload; } }, "json" ); + return false; + } + + function preview_comment(id) { $("#comment-preview-inp-" + id).val("1"); $("#comment-edit-preview-" + id).show(); @@ -1470,25 +1461,18 @@ function preview_mail() { return true; } -function unpause() { - // unpause auto reloads if they are currently stopped - totStopped = false; - stopped = false; - $('#pause').html(''); -} - function bin2hex(s) { - // Converts the binary representation of data to hex - // - // version: 812.316 - // discuss at: http://phpjs.org/functions/bin2hex - // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) - // + bugfixed by: Onno Marsman - // + bugfixed by: Linuxworld - // * example 1: bin2hex('Kev'); - // * returns 1: '4b6576' - // * example 2: bin2hex(String.fromCharCode(0x00)); - // * returns 2: '00' + // Converts the binary representation of data to hex + // + // version: 812.316 + // discuss at: http://phpjs.org/functions/bin2hex + // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) + // + bugfixed by: Onno Marsman + // + bugfixed by: Linuxworld + // * example 1: bin2hex('Kev'); + // * returns 1: '4b6576' + // * example 2: bin2hex(String.fromCharCode(0x00)); + // * returns 2: '00' var v,i, f = 0, a = []; s += ''; f = s.length; @@ -1573,7 +1557,6 @@ function zFormError(elm,x) { } } - $(window).scroll(function () { if(typeof buildCmd == 'function') { // This is a content page with items and/or conversations @@ -1599,22 +1582,6 @@ $(window).scroll(function () { } }); -var chanviewFullSize = false; - -function chanviewFull() { - if(chanviewFullSize) { - chanviewFullSize = false; - $('#chanview-iframe-border').css({ 'position' : 'relative', 'z-index' : '10' }); - $('#remote-channel').css({ 'position' : 'relative' , 'z-index' : '10' }); - } - else { - chanviewFullSize = true; - $('#chanview-iframe-border').css({ 'position' : 'fixed', 'top' : '0', 'left' : '0', 'z-index' : '150001' }); - $('#remote-channel').css({ 'position' : 'fixed', 'top' : '0', 'left' : '0', 'z-index' : '150000' }); - resize_iframe(); - } -} - function addhtmltext(data) { data = h2b(data); addeditortext(data); @@ -1763,8 +1730,6 @@ function sse_bs_init() { } function sse_bs_counts() { - - if(sse_bs_active) return; @@ -1847,8 +1812,6 @@ function sse_bs_notifications(e, replace, followup) { } } - - function sse_handleNotifications(obj, replace, followup) { var primary_notifications = ['dm', 'home', 'intros', 'register', 'mail', 'notify', 'files']; @@ -2022,3 +1985,25 @@ function sse_setNotificationsStatus() { } } + +function sse_fallback() { + $.get('/sse', function(obj) { + if(! obj) + return; + + console.log('sse fallback'); + console.log(obj); + + sse_handleNotifications(obj, false, false); + }); +} + +function makeid(length) { + var result = ''; + var characters = 'abcdef0123456789'; + var charactersLength = characters.length; + for ( var i = 0; i < length; i++ ) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + return result; +} diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 031895caf..5ca1f52a9 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -3,22 +3,408 @@ */ $(document).ready(function () { + // call initialization file if (window.File && window.FileList && window.FileReader) { UploadInit(); } + + var attach_drop_id; + var attach_draging; + + // Per File Tools + + $('.cloud-tool-info-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + close_and_deactivate_all_panels(); + $('#cloud-tool-info-' + id).toggle(); + $('#cloud-index-' + id).addClass('cloud-index-active'); + }); + + $('.cloud-tool-perms-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + activate_id(id); + }); + + $('.cloud-tool-rename-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + activate_id(id); + $('#cloud-tool-rename-' + id).show(); + }); + + $('.cloud-tool-move-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + activate_id(id); + $('#cloud-tool-move-' + id).show(); + }); + + $('.cloud-tool-categories-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + activate_id(id); + $('#id_categories_' + id).tagsinput({ + tagClass: 'badge badge-pill badge-warning text-dark' + }); + $('#cloud-tool-categories-' + id).show(); + }); + + $('.cloud-tool-download-btn').on('click', function (e) { + close_and_deactivate_all_panels(); + }); + + $('.cloud-tool-dir-download-btn').on('click', function (e) { + e.preventDefault(); + close_and_deactivate_all_panels() + + let id = $(this).data('id'); + if(! id) { + return false; + } + + close_and_deactivate_all_panels(); + + $('body').css('cursor', 'wait'); + $.jGrowl(aStr.download_info, { sticky: false, theme: 'info', life: 10000 }); + + let data = [ + {name: 'attach_path', value: window.location.pathname}, + {name: 'channel_id', value: channelId}, + {name: 'attach_ids[]', value: id} + ] + + $.post('attach', data, function (data) { + if (data.success) { + $('body').css('cursor', 'auto'); + window.location.href = '/attach/download?token=' + data.token; + } + }); + + }); + + $('.cloud-tool-delete-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + + close_and_deactivate_all_panels(); + + let confirm = confirmDelete(); + if (confirm) { + $('body').css('cursor', 'wait'); + $('#cloud-index-' + id).css('opacity', 0.33); + + let form = $('#attach_edit_form_' + id).serializeArray(); + form.push({name: 'delete', value: 1}); + + $.post('attach_edit', form, function (data) { + if (data.success) { + $('#cloud-index-' + id + ', #cloud-tools-' + id).remove(); + $('body').css('cursor', 'auto'); + } + return true; + }); + + } + return false; + }); + + $('.cloud-tool-cancel-btn').on('click', function (e) { + e.preventDefault(); + let id = $(this).data('id'); + close_and_deactivate_all_panels(); + $('#attach_edit_form_' + id).trigger('reset'); + $('#id_categories_' + id).tagsinput('destroy'); + }); + + // Per File Tools Eend + + // DnD + + $(document).on('drop', function (e) { + e.preventDefault(); + e.stopPropagation(); + }); + + $(document).on('dragover', function (e) { + e.preventDefault(); + e.stopPropagation(); + }); + + $(document).on('dragleave', function (e) { + e.preventDefault(); + e.stopPropagation(); + }); + + $('.cloud-index.attach-drop').on('drop', function (e) { + + let target = $(this); + let folder = target.data('folder'); + let id = target.data('id'); + + + if(typeof folder === typeof undefined) { + return false; + } + + // Check if it's a file + if (typeof e.dataTransfer !== typeof undefined && e.dataTransfer.files[0]) { + $('#file-folder').val(folder); + return true; + } + + if(id === attach_drop_id) { + return false; + } + + if(target.hasClass('attach-drop-zone') && attach_draging) { + return false; + } + + target.removeClass('attach-drop-ok'); + + $.post('attach_edit', {'channel_id': channelId, 'dnd': 1, 'attach_id': attach_drop_id, ['newfolder_' + attach_drop_id]: folder }, function (data) { + if (data.success) { + $('#cloud-index-' + attach_drop_id + ', #cloud-tools-' + attach_drop_id).remove(); + attach_drop_id = null; + } + }); + }); + + $('.cloud-index.attach-drop').on('dragover', function (e) { + let target = $(this); + + if(target.hasClass('attach-drop-zone') && attach_draging) { + return false; + } + + target.addClass('attach-drop-ok'); + }); + + $('.cloud-index').on('dragleave', function (e) { + let target = $(this); + target.removeClass('attach-drop-ok'); + }); + + $('.cloud-index').on('dragstart', function (e) { + let target = $(this); + attach_drop_id = target.data('id'); + // dragstart is not fired if a file is draged onto the window + // we use this to distinguish between drags and file drops + attach_draging = true; + }); + + $('.cloud-index').on('dragend', function (e) { + let target = $(this); + target.removeClass('attach-drop-ok'); + attach_draging = false; + }); + + // DnD End + + // Multi Tools + + $('#cloud-multi-tool-select-all').on('change', function (e) { + if ($(this).is(':checked')) { + $('.cloud-multi-tool-checkbox').prop('checked', true); + $('.cloud-index:not(#cloud-index-up)').addClass('cloud-index-selected cloud-index-active'); + $('.cloud-tools').addClass('cloud-index-selected'); + } + else { + $('.cloud-multi-tool-checkbox').prop('checked', false); + $('.cloud-index').removeClass('cloud-index-selected cloud-index-active'); + $('.cloud-tools').removeClass('cloud-index-selected'); + } + + $('.cloud-multi-tool-checkbox').trigger('change'); + }); + + + $('.cloud-multi-tool-checkbox').on('change', function (e) { + let id = $(this).val(); + + if ($(this).is(':checked')) { + $('#cloud-index-' + id).addClass('cloud-index-selected cloud-index-active'); + $('#cloud-tools-' + id).addClass('cloud-index-selected'); + $('<input id="aid_' + id + '" class="attach-ids-input" type="hidden" name="attach_ids[]" value="' + id + '">').prependTo('#attach_multi_edit_form'); + } + else { + $('#cloud-index-' + id).removeClass('cloud-index-selected cloud-index-active'); + $('#cloud-tools-' + id).removeClass('cloud-index-selected'); + if ($('#cloud-multi-tool-select-all').is(':checked')) + $('#cloud-multi-tool-select-all').prop('checked', false); + + $('#aid_' + id).remove(); + } + + if($('.cloud-multi-tool-checkbox:checked').length) { + close_all_panels(); + $('#cloud-multi-actions').addClass('bg-warning'); + $('#multi-dropdown-button').fadeIn(); + } + else { + $('#cloud-multi-actions').removeClass('bg-warning'); + $('#multi-dropdown-button').fadeOut(); + close_and_deactivate_all_panels(); + disable_multi_acl(); + } + + }); + + $('#cloud-multi-tool-perms-btn').on('click', function (e) { + e.preventDefault(); + + close_all_panels(); + enable_multi_acl(); + + $('#cloud-multi-tool-submit').show(); + }); + + $('#cloud-multi-tool-move-btn').on('click', function (e) { + e.preventDefault(); + + close_all_panels(); + disable_multi_acl(); + + $('#cloud-multi-tool-submit, #cloud-multi-tool-move').show(); + }); + + $('#cloud-multi-tool-categories-btn').on('click', function (e) { + e.preventDefault(); + + close_all_panels(); + disable_multi_acl(); + + $('#id_categories').tagsinput({ + tagClass: 'badge badge-pill badge-warning text-dark' + }); + + $('#cloud-multi-tool-submit, #cloud-multi-tool-categories').show(); + }); + + $('#cloud-multi-tool-download-btn').on('click', function (e) { + e.preventDefault(); + + let post_data = $('.cloud-multi-tool-checkbox:checked').serializeArray(); + + if(! post_data.length) { + return false; + } + + close_and_deactivate_all_panels(); + + $('body').css('cursor', 'wait'); + $.jGrowl(aStr.download_info, { sticky: false, theme: 'info', life: 10000 }); + + post_data.push( + {name: 'attach_path', value: window.location.pathname}, + {name: 'channel_id', value: channelId} + ); + + $.post('attach', post_data, function (data) { + if (data.success) { + $('body').css('cursor', 'auto'); + window.location.href = '/attach/download?token=' + data.token; + } + }); + + }); + + $('#cloud-multi-tool-delete-btn').on('click', function (e) { + e.preventDefault(); + + close_and_deactivate_all_panels(); + + let post_data = $('.cloud-multi-tool-checkbox:checked').serializeArray(); + + if(! post_data.length) { + return false; + } + + let confirm = confirmDelete(); + if (confirm) { + $('body').css('cursor', 'wait'); + $('.cloud-index-selected').css('opacity', 0.33); + + post_data.push( + { name: 'channel_id', value: channelId }, + { name: 'delete', value: 1}, + ); + + $.post('attach_edit', post_data, function (data) { + if (data.success) { + console.log(data); + $('.cloud-index-selected').remove(); + $('body').css('cursor', 'auto'); + } + return true; + }); + } + return false; + + }); + + $('.cloud-multi-tool-cancel-btn').on('click', function (e) { + e.preventDefault(); + + close_and_deactivate_all_panels(); + disable_multi_acl(); + + $('#attach_multi_edit_form').trigger('reset'); + $('#id_categories').tagsinput('destroy'); + }); + + // Multi Tools End + + // Helper Functions + + function disable_multi_acl() { + $('#multi-perms').val(0); + $('#multi-dbtn-acl, #recurse_container').hide(); + $('#attach-multi-edit-perms').removeClass('btn-group'); + } + + function enable_multi_acl() { + $('#multi-perms').val(1); + $('#multi-dbtn-acl, #recurse_container').show(); + $('#attach-multi-edit-perms').addClass('btn-group'); + } + + function close_all_panels() { + $('.cloud-tool, .cloud-multi-tool').hide(); + } + + function deactivate_all_panels() { + $('.cloud-index').removeClass('cloud-index-active'); + } + + function close_and_deactivate_all_panels() { + close_all_panels(); + deactivate_all_panels(); + } + + function activate_id(id) { + close_and_deactivate_all_panels(); + $('#cloud-multi-tool-select-all, .cloud-multi-tool-checkbox').prop('checked', false).trigger('change'); + + $('#cloud-tool-submit-' + id).show(); + $('#cloud-index-' + id).addClass('cloud-index-active'); + } + }); -// + + + // initialize function UploadInit() { - var fileselect = $("#files-upload"); - var filedrag = $("#cloud-drag-area"); var submit = $("#upload-submit"); var count = 1; + var filedrag = $(".cloud-index.attach-drop"); - $('#invisible-cloud-file-upload').fileupload({ url: 'file_upload', dataType: 'json', @@ -26,8 +412,8 @@ function UploadInit() { maxChunkSize: 4 * 1024 * 1024, add: function(e,data) { - $(data.files).each( function() { this.count = ++ count; prepareHtml(this); }); - + $(data.files).each( function() { this.count = ++ count; prepareHtml(this); }); + var allow_cid = ($('#ajax-upload-files').data('allow_cid') || []); var allow_gid = ($('#ajax-upload-files').data('allow_gid') || []); var deny_cid = ($('#ajax-upload-files').data('deny_cid') || []); @@ -49,7 +435,6 @@ function UploadInit() { }); data.formData = $('#ajax-upload-files').serializeArray(); - data.submit(); }, @@ -58,7 +443,7 @@ function UploadInit() { // there will only be one file, the one we are looking for - $(data.files).each( function() { + $(data.files).each( function() { var idx = this.count; // Dynamically update the percentage complete displayed in the file upload list @@ -70,7 +455,6 @@ function UploadInit() { }, - stop: function(e,data) { window.location.href = window.location.href; } @@ -81,60 +465,17 @@ function UploadInit() { } -// file drag hover -function DragDropUploadFileHover(e) { - e.stopPropagation(); - e.preventDefault(); - e.currentTarget.className = (e.type == "dragover" ? "hover" : ""); -} - -// file selection via drag/drop -function DragDropUploadFileSelectHandler(e) { - // cancel event and hover styling - DragDropUploadFileHover(e); - - // fetch FileList object - var files = e.target.files || e.originalEvent.dataTransfer.files; - $('.new-upload').remove(); - - // process all File objects - for (var i = 0, f; f = files[i]; i++) { - prepareHtml(f, i); - UploadFile(f, i); - } -} - -// file selection via input -function UploadFileSelectHandler(e) { - // fetch FileList object - if(e.target.id === 'upload-submit') { - e.preventDefault(); - var files = e.data[0].files; - } - if(e.target.id === 'files-upload') { - $('.new-upload').remove(); - var files = e.target.files; - } - - // process all File objects - for (var i = 0, f; f = files[i]; i++) { - if(e.target.id === 'files-upload') - prepareHtml(f, i); - if(e.target.id === 'upload-submit') { - UploadFile(f, i); - } - } -} function prepareHtml(f) { var num = f.count - 1; var i = f.count; $('#cloud-index #new-upload-progress-bar-' + num.toString()).after( '<tr id="new-upload-' + i + '" class="new-upload">' + - '<td><i class="fa ' + getIconFromType(f.type) + '" title="' + f.type + '"></i></td>' + + '<td></td>' + + '<td><i class="fa fa-fw ' + getIconFromType(f.type) + '" title="' + f.type + '"></i></td>' + '<td>' + f.name + '</td>' + - '<td id="upload-progress-' + i + '"></td><td></td><td></td><td></td><td></td>' + + '<td id="upload-progress-' + i + '"></td><td></td><td></td>' + '<td class="d-none d-md-table-cell">' + formatSizeUnits(f.size) + '</td><td class="d-none d-md-table-cell"></td>' + '</tr>' + '<tr id="new-upload-progress-bar-' + i + '" class="new-upload">' + @@ -199,63 +540,4 @@ function getIconFromType(type) { return iconFromType; } -// upload files -function UploadFile(file, idx) { - - window.filesToUpload = window.filesToUpload + 1; - - var xhr = new XMLHttpRequest(); - - xhr.withCredentials = true; // Include the SESSION cookie info for authentication - - (xhr.upload || xhr).addEventListener('progress', function (e) { - - var done = e.position || e.loaded; - var total = e.totalSize || e.total; - // Dynamically update the percentage complete displayed in the file upload list - $('#upload-progress-' + idx).html(Math.round(done / total * 100) + '%'); - $('#upload-progress-bar-' + idx).css('background-size', Math.round(done / total * 100) + '%'); - - if(done == total) { - $('#upload-progress-' + idx).html('Processing...'); - } - - }); - - - xhr.addEventListener('load', function (e) { - //we could possibly turn the filenames to real links here and add the delete and edit buttons to avoid page reload... - $('#upload-progress-' + idx).html('Ready!'); - - //console.log('xhr upload complete', e); - window.fileUploadsCompleted = window.fileUploadsCompleted + 1; - - // When all the uploads have completed, refresh the page - if (window.filesToUpload > 0 && window.fileUploadsCompleted === window.filesToUpload) { - - window.fileUploadsCompleted = window.filesToUpload = 0; - - // After uploads complete, refresh browser window to display new files - window.location.href = window.location.href; - } - }); - - - xhr.addEventListener('error', function (e) { - $('#upload-progress-' + idx).html('<span style="color: red;">ERROR</span>'); - }); - - // POST to the entire cloud path -// xhr.open('post', 'file_upload', true); - -// var formfields = $("#ajax-upload-files").serializeArray(); - -// var data = new FormData(); -// $.each(formfields, function(i, field) { -// data.append(field.name, field.value); -// }); -// data.append('userfile', file); - -// xhr.send(data); -} |