Products.CMFPlone/issue_2051: * Add data-base-url attribute in body tag #2051

Rodrigo Ferreira de Souza <jenkins-z4DKO/[email protected]>
Newsgroups gmane.comp.web.zope.plone.cvs
Message-ID <[email protected]>
Repository: Products.CMFPlone
Branch: refs/heads/issue_2051
Date: 2017-07-21T16:05:57-03:00
Author: Rodrigo Ferreira de Souza (rodfersou) <[email protected]>
Commit: https://github.com/plone/Products.CMFPlone/commit/a8aace0b3a28dd7792b9af152717c549b7314958

* Add data-base-url attribute in body tag #2051
* Fix @@plone_lock_operations #2061
* Review @@sharing #2053

Files changed:
M Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js
M Products/CMFPlone/skins/plone_ecmascript/unlockOnFormUnload.js
M Products/CMFPlone/skins/plone_templates/main_template.pt
M docs/CHANGES.rst

diff --git a/Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js b/Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js
index 305e9f715..afa622f38 100644
--- a/Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js
+++ b/Products/CMFPlone/skins/plone_ecmascript/kss-bbb.js
@@ -1,18 +1,5 @@
 (function($){
 
-function createURL(view){
-    // using this method we keep the get parameters used with plone protect
-    // https://gist.github.com/jlong/2428561
-    if (typeof view === 'undefined') {
-        view = '';
-    }
-    var parser = document.createElement('a');
-    parser.href = location.href;
-    parser.pathname = parser.pathname.replace(/\/@@.*/, '');
-    parser.pathname += view;
-    return parser.href;
-}
-
 function refreshPortlet(hash, _options){
     var options = {
         data: {},
@@ -22,7 +9,7 @@ function refreshPortlet(hash, _options){
     $.extend(options, _options);
     options.data.portlethash = hash;
     ajaxOptions = options.ajaxOptions;
-    ajaxOptions.url = createURL('/@@render-portlet');
+    ajaxOptions.url = $('body').attr('data-base-url') + '/@@render-portlet';
     ajaxOptions.success = function(data){
         var container = $('[data-portlethash="' + hash + '"]');
         var portlet = $(data);
@@ -116,7 +103,7 @@ $(document).ready(function(){
 
     $('#content-core').delegate('#sharing-search-button', 'click', function(){
         $.ajax({
-            url: createURL('/@@updateSharingInfo'),
+            url: $('body').attr('data-base-url') + '/@@updateSharingInfo',
             data: {
                 search_term: $('#sharing-user-group-search').val(),
                 'form.button.Search': 'Search'
@@ -135,7 +122,7 @@ $(document).ready(function(){
         var data = form.serializeArray();
         data.push({name: 'form.button.Save', value: 'Save'});
         $.ajax({
-            url: createURL('/@@updateSharingInfo'),
+            url: $('body').attr('data-base-url') + '/@@updateSharingInfo',
             data: data,
             type: 'POST',
             dataType: 'json',
diff --git a/Products/CMFPlone/skins/plone_ecmascript/unlockOnFormUnload.js b/Products/CMFPlone/skins/plone_ecmascript/unlockOnFormUnload.js
index 4498af2d7..73239273c 100644
--- a/Products/CMFPlone/skins/plone_ecmascript/unlockOnFormUnload.js
+++ b/Products/CMFPlone/skins/plone_ecmascript/unlockOnFormUnload.js
@@ -34,24 +34,15 @@ plone.UnlockHandler = {
         // form submit process. This means: no unlock needed,
         // and it also would be harmful (ConflictError)
         if (plone.UnlockHandler.submitting) {return;}
-        $.ajax({url: plone.UnlockHandler._baseUrl() + '/@@plone_lock_operations/safe_unlock', async: false});
+        $.ajax({
+            url: $('body').attr('data-base-url') + '/@@plone_lock_operations/safe_unlock',
+            async: false
+        });
     },
     
     refresh: function() {
         if (plone.UnlockHandler.submitting) {return;}
-        $.get(plone.UnlockHandler._baseUrl() + '/@@plone_lock_operations/refresh_lock');
-    },
-    
-    _baseUrl: function() {
-        var baseUrl, pieces;
-
-        baseUrl = $('base').attr('href');
-        if (!baseUrl) {
-            pieces = window.location.href.split('/');
-            pieces.pop();
-            baseUrl = pieces.join('/');
-        }
-        return baseUrl;
+        $.get($('body').attr('data-base-url') + '/@@plone_lock_operations/refresh_lock');
     }
 };
 
diff --git a/Products/CMFPlone/skins/plone_templates/main_template.pt b/Products/CMFPlone/skins/plone_templates/main_template.pt
index c637e35b2..ca538320e 100644
--- a/Products/CMFPlone/skins/plone_templates/main_template.pt
+++ b/Products/CMFPlone/skins/plone_templates/main_template.pt
@@ -63,7 +63,9 @@
                     sr python:plone_view.have_portlets('plone.rightcolumn', view);
                     body_class python:plone_view.bodyClass(template, view);"
         tal:attributes="class body_class;
-                        dir python: isRTL and 'rtl' or 'ltr'">
+                        dir python: isRTL and 'rtl' or 'ltr';
+                        data-portal-url portal_url;
+                        data-base-url context/absolute_url">
     <div id="visual-portal-wrapper">
 
       <div id="portal-top" i18n:domain="plone">
diff --git a/docs/CHANGES.rst b/docs/CHANGES.rst
index 364b084c3..3006c4330 100644
--- a/docs/CHANGES.rst
+++ b/docs/CHANGES.rst
@@ -9,7 +9,19 @@ Changelog
 4.3.16 (unreleased)
 -------------------
 
-- Nothing changed yet.
+Bug fixes:
+
+- Add data-base-url attribute in body tag.
+  Closes `issue 2051 <https://github.com/plone/Products.CMFPlone/issues/2051>`_
+  [rodfersou]
+
+- Fix @@plone_lock_operations.
+  Fixes `issue 2061 <https://github.com/plone/Products.CMFPlone/issues/2061>`_
+  [rodfersou]
+
+- Review @@sharing
+  Fixes `issue 2053 <https://github.com/plone/Products.CMFPlone/issues/2053>`_.
+  [rodfersou]
 
 
 4.3.15 (2017-07-03)



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.