diff options
| author | Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de> | 2022-05-11 07:19:42 +0000 |
|---|---|---|
| committer | Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de> | 2022-05-11 07:19:42 +0000 |
| commit | 20240b2aacb15ab3264afbfbbc9dae952db4bb63 (patch) | |
| tree | 597cae73c5ae7ab9eda6d066d45430c3f17a4560 /resources/assets/javascripts/lib | |
| parent | c054faf90288a75fc3680480434ba93b7f5b287b (diff) | |
convert old core plugins to new model, re #814
Merge request studip/studip!440
Diffstat (limited to 'resources/assets/javascripts/lib')
| -rw-r--r-- | resources/assets/javascripts/lib/activityfeed.js | 127 | ||||
| -rw-r--r-- | resources/assets/javascripts/lib/forum.js | 38 | ||||
| -rw-r--r-- | resources/assets/javascripts/lib/quick_selection.js | 7 |
3 files changed, 153 insertions, 19 deletions
diff --git a/resources/assets/javascripts/lib/activityfeed.js b/resources/assets/javascripts/lib/activityfeed.js new file mode 100644 index 0000000..95145cb --- /dev/null +++ b/resources/assets/javascripts/lib/activityfeed.js @@ -0,0 +1,127 @@ +const ActivityFeed = { + user_id : null, + polling: null, + initial: true, + scrolledfrom: null, + maxheight: null, + filter: null, + + init: function() { + STUDIP.ActivityFeed.maxheight = parseInt($('#stream-container').css('max-height').replace(/[^-\d\.]/g, '')); + + STUDIP.ActivityFeed.loadFeed(STUDIP.ActivityFeed.filter); + + $('#stream-container').scroll(function () { + var scrollBottom = $('#stream-container').scrollTop() + $('#stream-container').height() + 250; + + if ($('#stream-container').prop('scrollHeight') < scrollBottom) { + STUDIP.ActivityFeed.loadFeed(STUDIP.ActivityFeed.filter); + } + }); + + + $(document).on('click', '.provider_circle', function () { + $(this).parent().parent().children('.activity-content').toggle(); + }).on('click', '#toggle-all-activities,#toggle-user-activities', function () { + var toggled = $(this).is(':not(.toggled)'); + $(this).toggleClass('toggled', toggled); + + STUDIP.ActivityFeed.setToggleStatus(); + + return false; + }); + }, + + getTemplate: _.memoize(function(name) { + return _.template($("script." + name).html()); + }), + + loadFeed: function(filtertype) { + if (STUDIP.ActivityFeed.user_id === null) { + console.log('Could not retrieve activities, no valid user id found!'); + return false; + } + + if (STUDIP.ActivityFeed.polling || !STUDIP.ActivityFeed.scrolledfrom) { + return false; + } + + STUDIP.ActivityFeed.polling = true; + + STUDIP.api.GET(['user', STUDIP.ActivityFeed.user_id, 'activitystream'], { + data: { + filtertype: filtertype, + scrollfrom: STUDIP.ActivityFeed.scrolledfrom + } + }).done(function (activities) { + var stream = STUDIP.ActivityFeed.getTemplate('activity_stream'); + var activity = STUDIP.ActivityFeed.getTemplate('activity'); + var activity_urls = STUDIP.ActivityFeed.getTemplate('activity-urls'); + var num_entries = Object.keys(activities).length; + var lastelem = $(activities).last(); + + if (lastelem[0]) { + STUDIP.ActivityFeed.scrolledfrom = lastelem[0].mkdate; + } else { + STUDIP.ActivityFeed.scrolledfrom = false; + } + + STUDIP.ActivityFeed.writeToStream(stream({ + stream : activities, + num_entries : num_entries, + activity : activity, + activity_urls : activity_urls, + user_id : STUDIP.ActivityFeed.user_id + })); + + STUDIP.ActivityFeed.setToggleStatus(); + + if ($('#stream-container').height() < STUDIP.ActivityFeed.maxheight) { + STUDIP.ActivityFeed.loadFeed(''); + } + }).fail(function () { + var template = STUDIP.ActivityFeed.getTemplate('activity-load-error'); + STUDIP.ActivityFeed.writeToStream(template()); + }).always(function () { + STUDIP.ActivityFeed.polling = false; + }); + }, + + writeToStream: function (html) { + if (STUDIP.ActivityFeed.initial) { + // replace data in DOM + $('#stream-container').html(''); + + STUDIP.ActivityFeed.initial = false; + } + + $('#stream-container').append(html); + }, + + setToggleStatus: function() { + var show_details = $('#toggle-all-activities').is('.toggled'), + show_own = $('#toggle-user-activities').is('.toggled'); + + // update toggle status fir activity contents + $('.activity-content').toggle(show_details); + + // update toggle status for user's own activities + $('.activity:has(.provider_circle.right)').toggle(show_own); + }, + + updateFilter: function(filter) { + STUDIP.ActivityFeed.filter = filter; + STUDIP.ActivityFeed.initial = true; + STUDIP.ActivityFeed.scrolledfrom = Math.floor(Date.now() / 1000); + + $('#stream-container').html('<div class="loading-indicator">' + + '<span class="load-1"></span>' + + '<span class="load-2"></span>' + + '<span class="load-3"></span>' + + '</div>'); + + STUDIP.ActivityFeed.init(); + } +}; + +export default ActivityFeed; diff --git a/resources/assets/javascripts/lib/forum.js b/resources/assets/javascripts/lib/forum.js index 9a6ff17..7763527 100644 --- a/resources/assets/javascripts/lib/forum.js +++ b/resources/assets/javascripts/lib/forum.js @@ -30,7 +30,7 @@ const Forum = { jQuery.ajax({ type: 'POST', - url: STUDIP.URLHelper.getURL('plugins.php/coreforum/index/savecats?cid=' + STUDIP.Forum.seminar_id), + url: STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/savecats?cid=' + STUDIP.Forum.seminar_id), data: categories }); } @@ -69,7 +69,7 @@ const Forum = { STUDIP.Forum.closeDialog(); // ajax call to make the deletion permanent - jQuery.ajax(STUDIP.URLHelper.getURL('plugins.php/coreforum/index/delete_entry/' + jQuery.ajax(STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/delete_entry/' + STUDIP.Forum.current_area_id + '?cid=' + STUDIP.Forum.seminar_id), { method: 'post', data: {'security_token' : STUDIP.CSRF_TOKEN.value}, @@ -92,7 +92,7 @@ const Forum = { }); // ajax call to make the deletion permanent - jQuery.ajax(STUDIP.URLHelper.getURL('plugins.php/coreforum/index/remove_category/' + jQuery.ajax(STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/remove_category/' + STUDIP.Forum.current_category_id + '?cid=' + STUDIP.Forum.seminar_id), { method: 'post', data: {'security_token' : STUDIP.CSRF_TOKEN.value}, @@ -150,7 +150,7 @@ const Forum = { jQuery('table[data-category-id=' + category_id + '] span.edit_category').remove(); jQuery('table[data-category-id=' + category_id + '] span.category_name').show(); - jQuery.ajax(STUDIP.URLHelper.getURL('plugins.php/coreforum/index/edit_category/' + category_id + '?cid=' + STUDIP.Forum.seminar_id), { + jQuery.ajax(STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/edit_category/' + category_id + '?cid=' + STUDIP.Forum.seminar_id), { type: 'POST', data: name }); @@ -173,7 +173,7 @@ const Forum = { jQuery.ajax({ type: 'POST', - url: STUDIP.URLHelper.getURL('plugins.php/coreforum/area/save_order?cid=' + STUDIP.Forum.seminar_id), + url: STUDIP.URLHelper.getURL('dispatch.php/course/forum/area/save_order?cid=' + STUDIP.Forum.seminar_id), data: areas }); }, @@ -209,7 +209,7 @@ const Forum = { // disable submit and cancel buttons, there is no turning back now $('.button', this).prop('disabled', true); - jQuery.ajax(STUDIP.URLHelper.getURL('plugins.php/coreforum/area/add/' + values.category_id + '?cid=' + STUDIP.Forum.seminar_id), { + jQuery.ajax(STUDIP.URLHelper.getURL('dispatch.php/course/forum/area/add/' + values.category_id + '?cid=' + STUDIP.Forum.seminar_id), { type: 'POST', data: values, success: function(data) { @@ -269,7 +269,7 @@ const Forum = { jQuery('tr[data-area-id=' + area_id + '] div.areacontent').data('content', name.content); // store the modified area and get formatted content-text from server - jQuery.ajax(STUDIP.URLHelper.getURL('plugins.php/coreforum/area/edit/' + area_id + '?cid=' + STUDIP.Forum.seminar_id), { + jQuery.ajax(STUDIP.URLHelper.getURL('dispatch.php/course/forum/area/edit/' + area_id + '?cid=' + STUDIP.Forum.seminar_id), { type: 'POST', data: name, success: function(data) { @@ -315,7 +315,7 @@ const Forum = { // remember current textarea value textarea.data('reset', textarea.val()); - jQuery.ajax(STUDIP.URLHelper.getURL('plugins.php/coreforum/index/update_entry/' + topic_id + '?cid=' + STUDIP.Forum.seminar_id), { + jQuery.ajax(STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/update_entry/' + topic_id + '?cid=' + STUDIP.Forum.seminar_id), { type: 'POST', data: jQuery('form[data-topicid='+ topic_id +']').serializeObject(), @@ -489,7 +489,7 @@ const Forum = { + nl + nl + $gettext('Link zum Beitrag: ') + nl - + STUDIP.URLHelper.getURL('plugins.php/coreforum/index/index/' + + STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/index/' + topic_id + '?cid=' + STUDIP.Forum.seminar_id + '&again=yes#' + topic_id) + nl + nl + content @@ -543,7 +543,7 @@ const Forum = { posting.posting = STUDIP.wysiwyg.markAsHtml(posting.posting); } - jQuery.ajax(STUDIP.URLHelper.getURL('plugins.php/coreforum/index/preview?cid=' + STUDIP.Forum.seminar_id), { + jQuery.ajax(STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/preview?cid=' + STUDIP.Forum.seminar_id), { type: 'POST', data: posting, success: function (html) { @@ -556,7 +556,7 @@ const Forum = { }, loadAction: function(element, action) { - jQuery(element).load(STUDIP.URLHelper.getURL('plugins.php/coreforum/index/' + jQuery(element).load(STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/' + action + '?cid=' + STUDIP.Forum.seminar_id)) }, @@ -578,14 +578,14 @@ const Forum = { }, setFavorite: function(topic_id) { - jQuery('#favorite_' + topic_id).load(STUDIP.URLHelper.getURL('plugins.php/coreforum/index/set_favorite/' + jQuery('#favorite_' + topic_id).load(STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/set_favorite/' + topic_id + '?cid=' + STUDIP.Forum.seminar_id)); jQuery('a.marked[data-topic-id=' + topic_id +']').show(); return false; }, unsetFavorite: function(topic_id) { - jQuery('#favorite_' + topic_id).load(STUDIP.URLHelper.getURL('plugins.php/coreforum/index/unset_favorite/' + jQuery('#favorite_' + topic_id).load(STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/unset_favorite/' + topic_id + '?cid=' + STUDIP.Forum.seminar_id)); jQuery('a.marked[data-topic-id=' + topic_id +']').hide(); return false; @@ -601,7 +601,7 @@ const Forum = { // jQuery('li[data-id=' + topic_id + '] > a.tooltip2').showAjaxNotification(); // load children from server and show them - jQuery.ajax(STUDIP.URLHelper.getURL('plugins.php/coreforum/admin/childs/' + topic_id), { + jQuery.ajax(STUDIP.URLHelper.getURL('dispatch.php/course/forum/admin/childs/' + topic_id), { dataType: 'html', success: function(response) { jQuery('li[data-id=' + topic_id + ']').append(response); @@ -664,7 +664,7 @@ const Forum = { paste: function(topic_id) { // jQuery('li[data-id=' + topic_id + '] > a.tooltip2').showAjaxNotification(); - jQuery.ajax(STUDIP.URLHelper.getURL('plugins.php/coreforum/admin/move/' + topic_id), { + jQuery.ajax(STUDIP.URLHelper.getURL('dispatch.php/course/forum/admin/move/' + topic_id), { data : { 'topics' : STUDIP.Forum.clipboard }, @@ -742,7 +742,7 @@ const Forum = { openThread: function(topic_id, redirect, page, showSuccessMessage) { jQuery.ajax({ type: 'GET', - url: STUDIP.URLHelper.getURL('plugins.php/coreforum/index/open_thread/' + topic_id + '/' + redirect + '/' + page), + url: STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/open_thread/' + topic_id + '/' + redirect + '/' + page), success: function(data) { if (showSuccessMessage == true) { jQuery('#message_area').html(data); @@ -786,7 +786,7 @@ const Forum = { jQuery.ajax({ type: 'GET', - url: STUDIP.URLHelper.getURL('plugins.php/coreforum/index/close_thread/' + topic_id + '/' + redirect + '/' + page), + url: STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/close_thread/' + topic_id + '/' + redirect + '/' + page), success: function(data) { if (showSuccessMessage == true) { jQuery('#message_area').html(data); @@ -800,7 +800,7 @@ const Forum = { makeThreadStickyFromThread: function(topic_id) { jQuery.ajax({ type: 'GET', - url: STUDIP.URLHelper.getURL('plugins.php/coreforum/index/make_sticky/' + topic_id + '/' + topic_id + '/0'), + url: STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/make_sticky/' + topic_id + '/' + topic_id + '/0'), success: function(data) { jQuery('#message_area').html(data); var linkText = $gettext('Hervorhebung aufheben'); @@ -815,7 +815,7 @@ const Forum = { makeThreadUnstickyFromThread: function(topic_id) { jQuery.ajax({ type: 'GET', - url: STUDIP.URLHelper.getURL('plugins.php/coreforum/index/make_unsticky/' + topic_id + '/' + topic_id + '/0'), + url: STUDIP.URLHelper.getURL('dispatch.php/course/forum/index/make_unsticky/' + topic_id + '/' + topic_id + '/0'), success: function(data) { jQuery('#message_area').html(data); var linkText = $gettext('Thema hervorheben'); diff --git a/resources/assets/javascripts/lib/quick_selection.js b/resources/assets/javascripts/lib/quick_selection.js new file mode 100644 index 0000000..7fd0399 --- /dev/null +++ b/resources/assets/javascripts/lib/quick_selection.js @@ -0,0 +1,7 @@ +const QuickSelection = { + update: function (html) { + jQuery('#quickSelectionWrap').replaceWith(html); + } +}; + +export default QuickSelection; |
