How can I protect a page in confluence from accidental changes? - confluence

I use custome template in confluence with Task list elements to create a page
Description of content using checkboxes - is very important for me
After creating any page the user can click on an item by chance and thereby change the value of the field
How can I protect a page from accidental changes ?
I don't want to use Page Restrictions, maybe there is another solving of this problem ?

The only method I found for achieving this was to write JavaScript inside a {html} macro which gets the current userid, checks the userid against a list of allowed users, if the userid is not on the list then disables or hides the HTML code on the page in this DOM so the current user can't change it. This is not the best way or recommended but it can work quite well.
For example, to hide the checkbox from users who are not logged in:
{html}
<script>
AJS.$(document).ready(function() {
if(jQuery(".login-link").size()>0) {
AJS.$(".checkboxeditclass").hide();
}
});
<script>
{html}

Related

Track form conversions confirmation page URL is the same as the form

I'm trying to track form completions on a page where the form's URL is the same as the confirmation page.
Form Page
Does anybody know if this can be done with Google Tag Manager/Google Analytics please?
Completion page
Simply tracking clicks of the Submit button will result in false positives because sometimes people will not type the security code correctly.
Is there a tracking code of some sort that can be added to the confirmation page, so that each time it loads the count goes up one?
I'm grateful of any help you can provide.
Thanks!
You can use the built-in visibility trigger - e.g. as soon as a link element with the link back to the homepage becomes visible you let the trigger fire. Specifics depend on the CSS id or class for that link (if any, else you'd have to test the click text).
In the visibility trigger you might have to enable "listen for DOM changes" if the confirmation message is loaded per Ajax (as opposed to just have their CSS display property set to 'none'.

Creating a Tumblr Landing Page Using Redirect Code

there was a similar question to this one asked a while back - but for some reason the comment that contained specific instructions for the workaround was deleted.
I am attempting to create a landing page on a tumblr page using the redirect code below.
<script type="text/javascript">
if(location.href == 'http://labellablog.com/') location.replace('http://labellablog.com/welcome');;
</script>
The issue that I'm experiencing is the same as the person who posted the question in the first place - by putting the redirect code in the index page, it creates a loop. i.e. In trying to click the link on the 'welcome page' in order to get to the home page containing blog posts, navigation etc., it simply re-directs to the 'welcome' page.
The solution that is mentioned (not in great detail) on another question states that you must set the cookies to expire in a certain amount of time. Unfortunately I'm a huge amateur when it comes to coding and am not entirely sure how to achieve this.
Thanks in advance for any advice.
Method 1
Based on your question this is how I would resolve it (this is not using the cookie method at all, but I will come to that).
Make sure jquery is installed in your theme, alot of themes already have it, if not you can add it to the head of the document like so:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Lets look for the index page:
var primaryDir = document.location.pathname.split("/")[1]; // get the first directory
if (!primaryDir){ // if the primary directory is empty (index page) lets redirect to another page
window.location('/welcome');
}
You can use /welcome and that will work if you change the name/url of your site/tumblr.
So this method means this will always run (unless you disable javascript) for every client that connects to your site. This means effectively that the index page is never visible.
Now if you wanted a cookie method, this would mean that you would create the redirect on the first visit, then set the cookie and then after that the index page would be visible.
If that is what you want, let me know, but that involves quite a bit more code, slightly more complex solution.
EDIT
Another way to achieve this is to create a hidden div in the main template that only shows on the index page and is hidden on all other pages, this means you don't have to rely on a slightly slower redirect.
I only posted an answer to that issue the other day: How can I make a Tumblr background image only for one page?
Method 2
OK here is a method adopting cookies.
First I recommend downloading this jquery cookie plugin
You will then need to link to that as a resource in your theme, so you need somewhere to host that file. I use dropbox, but tumblr also has a repository for linking to files (well it used to seems to have disappeared).
Now create an element that will sit over the main page:
Enter
You can style this to fill the whole page if required (modify to your needs):
#entry {
position:fixed;
top:0;
right:0;
bottom:0;
left:0;
background:#CCC;
color:#FFF;
// yadda yadda
}
Now we need some click event to create the cookie when we click on this huge anchor:
$(document).ready(function(){
var entry = $('#entry'); // lets cache the selector in a variable
entry.on('click',function(){
$.cookie('deadlyrhythm', '1', { path: '/', expires: 1}); // set a cookie with the name deadlyrhythm to the value of 1 on the entire site for 1 day.
$(this).hide();
return false;
});
});
Now we need a method to check if the cookie exists, so inside the same document ready function:
if ($.cookie('deadlyrhythm') != '1'){
entry.hide();
}
This should mean that for 24 hours the cookie is set and the entry will not display if the same user revists the site, but it will after one day, of course you can set that value to anything you like.
As I mentioned this is slightly more complex to implement, but in the console of the browser you can check to see if a cookie exists and delete it manually (I use chrome for this) this is really useful for testing.

How do I make a link that pre-fills a form checkbox?

I have a page called contact.htm with a working form. One of the checkbox fields on the form is named Garden (so either it is checked or not when using the form).
I have another page that I want to link to my form page, so that if a user clicks a particular link, they are sent to the form page and the field Garden is pre-clicked.
I have not been able to do this though I have tried several methods...such as:
a href="contact.htm?checkbox=Garden,on" or
a href="contact.htm?checkbox=Garden,checked" or
a href="contact.htm?input type="checkbox" name="Garden" value="checked", and some others.
I would appreciate any help.
You'll need to use JavaScript on the target webpage to process the argument and fill the values in. There is no automatic way of doing this just by URL.
This link shows how to retrieve URL arguments from JavaScript. From there, it's a matter of using standard JavaScript or JQuery to fill the values in.

Page switch in Tumblr

I'm modifying a Tumblr theme. I have a page newsletter and only on this page I want to add a sign up form (hard coded).
Is it possible in Tumblr to see if the current page == 'newsletter' or something? Maybe by ID?
I know it is possible for posts but I need it for a page.
Thanks!
A (slightly) safer solution/hack -
{block:PermalinkPage}{block:Posts}{block:PostTitle}
<script>
var postID = '{PostID}',
postTitle = {JSPostTitle};
if (!postID && postTitle === 'Name of your Newsletter Page') {
// Tumblr custom "pages" have no post ID
// Dynamically insert your HTML, or Dynamically "Show" a hidden element
}
</script>
{/block:PostTitle}{/block:Posts}{/block:PermalinkPage}
Where Name of your Newsletter Page is the Page Title you assign your newsletter page on Tumblr.
Wrapping this <script> in {block:PermalinkPage}...etc ensures the script only renders on the right kinds of pages.
Then, to be safe we must then check this permalink page does not have a Post ID, so we don't accidentally match an actual Post. The only other possibility for a permalink page with no Post ID is a custom tumblr Page, so it suffices to check the Page Title to some preset value.
In general, switching based on the window.location of a page is really not a good solution.
As for creating / showing the signup form -- I'd personally go with hard-coding the form on the Tumblr Theme with display: none and just toggle the form visible with the JavaScript -- but that's my opinion. You could insert it into the DOM with the script as well.
Unfortunately, that function does not exist in Tumblr. What you'll need to do is check the URL of the page that you're on, which is pretty simple.
You should be able to do something like this in JavaScript:
var currentPath = window.location.pathname; // store current path
if( currentPath.indexOf('newsletter') ) { // check if 'newsletter' is in our path
// add your sign up form here
}

Edit a confluence page title to add its ID?

I'm trying to add a unique ID to page titles in confluence.
I managed to add a user macro which uses jQuery to add the page ID & a string prefix to the title;
## #param _prefix:title=Prefix|type=string|required=true|desc=Prefix for the page ID
<script type="text/javascript">
jQuery("document").ready(function() {
if ("${param_prefix}" != "${_prefix}")
jQuery('#title-text a').prepend('${param_prefix}', '$content.getIdAsString()', ' ');
});
</script>
But I want this to actually edit the title, not just get added at runtime. It needs to be consistent throughout, allowing that ID to be a search term & appear in all menus etc.
I can't find anything which suggests this is even possible but it must be, surely!?
$content.setTitle("newtitle") should work. BUT! you will have to make sure that this only happens once, otherwise your title will get repeatedly prepended with your text every time this macro is rendered. I guess you might check if the title starts with your prefix already. And then you might want to add handling of changing the prefix.
See http://confluence.atlassian.com/display/CONF35/Guide+to+User+Macro+Templates#GuidetoUserMacroTemplates-OtherObjectsAvailabletoyourMacro for more details.
That being said, this seems like a pretty kludgey way of solving whatever problem you have. I would suggest reconsidering if this is really what you want to do.
You can use the actual Confluence page ID or the page tiny link rather than generating an ID of your own. Both of these are static.
On any Confluence page, type "k" to see a hyperlink. You might be surprised to see it also contains a tiny link. Atlassian confirms that the tiny link stays the same, even if you move and rename the page (https://jira.atlassian.com/browse/CONF-27049). This is a consistent way to reference the same page with a fixed URL. Another way is to use the Confluence built in PageID.
Confluence Knowledge Base: How to get Confluence page ID
https://confluence.atlassian.com/confkb/how-to-get-confluence-page-id-648380445.html
Ensure that the current user has permissions to View and Edit the
page Navigate to a specific page
Go to Edit Mode by clicking Edit button or press 'e' key
The URL in the address bar will change once you enter Edit Mode
Page ID will be displayed as the parameter in the URL e.g.: When entering Edit Mode, the URL will change to http://my.domain.com/pages/editpage.action?pageId=1540132
In the example above, 1540132 is the Page ID.
To get the page ID with a macro:
ContentEntityObject contentEntityObject = conversionContext.getEntity();
System.out.println("pageId : " + contentEntityObject.getId());
To change a title: content.setTitle("newtitle").
Remember, check if title contains the page id before setting title = title + page ID.