]> git.mxchange.org Git - friendica.git/blobdiff - view/theme/frio/templates/jot-header.tpl
New function for contact suggestions
[friendica.git] / view / theme / frio / templates / jot-header.tpl
index 9f226cda4997bba86e2e5334738e60bf463f2fb8..f9e10ca8cd1454c9d144887655a1e924720556c7 100644 (file)
@@ -1,7 +1,7 @@
 
-<script type="text/javascript" src="{{$baseurl}}/view/js/ajaxupload.js"></script>
-<script type="text/javascript" src="{{$baseurl}}/view/js/linkPreview.js"></script>
-<script type="text/javascript" src="{{$baseurl}}/view/theme/frio/js/jot.js"></script>
+<script type="text/javascript" src="{{$baseurl}}/view/js/ajaxupload.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
+<script type="text/javascript" src="{{$baseurl}}/view/js/linkPreview.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
+<script type="text/javascript" src="{{$baseurl}}/view/theme/frio/js/jot.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
 
 <script type="text/javascript">
        var editor = false;
                        jotTextOpenUI(document.getElementById("profile-jot-text"));
                        jotActive();
                        addeditortext(embedcode);
-               });
-               $('body').on('fbrowser.file.main', function(e, filename, embedcode, id) {
+               })
+               .on('fbrowser.file.main', function(e, filename, embedcode, id) {
                        jotTextOpenUI(document.getElementById("profile-jot-text"));
                        jotActive();
                        addeditortext(embedcode);
+               })
+               // Asynchronous jot submission
+               .on('submit', '#profile-jot-form', function (e) {
+                       e.preventDefault();
+
+                       // Disable jot submit buttons during processing
+                       let $share = $('#profile-jot-submit').button('loading');
+                       let $sharePreview = $('#profile-jot-preview-submit').button('loading');
+
+                       let formData = new FormData(e.target);
+                       // This cancels the automatic redirection after item submission
+                       formData.delete('return');
+
+                       $.ajax({
+                               url: 'item',
+                               data: formData,
+                               processData: false,
+                               contentType: false,
+                               type: 'POST',
+                       })
+                       .then(function () {
+                               // Reset to form for jot reuse in the same page
+                               e.target.reset();
+                               $('#jot-modal').modal('hide');
+                       })
+                       .always(function() {
+                               // Reset the post_id_random to avoid duplicate post errors
+                               let new_post_id_random = Math.floor(Math.random() * (Number.MAX_SAFE_INTEGER - (Number.MAX_SAFE_INTEGER / 10))) + Number.MAX_SAFE_INTEGER / 10;
+                               $('#profile-jot-form [name=post_id_random]').val(new_post_id_random);
+
+                               // Reset jot submit button state
+                               $share.button('reset');
+                               $sharePreview.button('reset');
+
+                               // Force the display update of the edited post/comment
+                               if (formData.get('post_id')) {
+                                       force_update = true;
+                                       update_item = formData.get('post_id');
+                               }
+
+                               NavUpdate();
+                       })
                });
 
                $('#wall-image-upload').on('click', function(){