Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


HTML
<script>

function
 download_file(data, downloadFileName) {

   console.log("Download filename: ", downloadFileName);

   var fileName = downloadFileName.replace("+", " ") {
	
;
   console.log("Filename: ", fileName);

   var fileData = data;
	
   var byteChars = $.base64('decode', fileData);
	
	
   var ab = new ArrayBuffer(byteChars.length);
	
   var ia = new Uint8Array(ab);
	
   for (var i = 0; i < byteChars.length; i++) {
		      ia[i] = byteChars.charCodeAt(i{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true);
   }				
	
   var blob = new Blob([ab], { type: 'application/pdf{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true' }); 
	
	
   if (window.navigator.msSaveOrOpenBlob) { // IE hack; see http://msdn.microsoft.com/en-us/library/ie/hh779016.aspx
  	    window.navigator.msSaveOrOpenBlob(blob, fileName{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true}
	
else {
		
);
   } else {
     var downloadUrl = URL.createObjectURL(blob);
		 $(
"#download")
		.attr({
			
'download': fileName,
			
'href': downloadUrl{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true});	
		     $(
"#download")
	 [0].click();
		 window.history.ba{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true}{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true};


function getQueryParametersback();
   }
};

AJS.toInit(function() {
  // Function varto queryParamsparse =URL {};parameters
  function  var query = getParameterByName(name) {
    console.log(window.location.search.substring(1href);
    varname pairs = queryname.split('replace(/[\[\]]/g, '\\$&');
    for (var iregex = 0; i < pairs.length; i++) {
        var pair = pairs[i].split('=');
        var key = decodeURIComponent(pair[0]);
        var value = decodeURIComponent(pair[1]);new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        queryParams[key]results = value{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true}
    console.log("Queryparams: ", queryParamsregex.exec(window.location.href);
    return queryPara{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true}

function updateMacroOnExistingPage() {

	console.log("updateMacroOnExistingPage");
if (!results) return null;
    varif queryParams = getQueryParameters();

    // Define the macro name and parameters based on query parameters
    var macroName = 'Mineaftaler(!results[2]) return '';
    var macroParameters = {
 		REST_HTML_URL: 'http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html',
	    REST_DOWNLOAD_URL: 'http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes',
	    include_user_info: true{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true};

    // Generate the updated macro markup
    var updatedMacroMarkup = '{' + macroName + ':';
    for (var key in macroParameters) {
        if (macroParameters.hasOwnProperty(key)) {
            updatedMacroMarkup += key + '=' + macroParameters[key]{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true}{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true}
    // Remove the trailing '|' character
    updatedMacroMarkup = updatedMacroMarkup.slice(0, -1);
    updatedMacroMar{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true}';

    // Page ID of the existing Confluence page
    var pageId = '33594461'; // Replace with the actual Page ID

    // Make an AJAX request to retrieve the current page content
    AJS.$.ajax({
        url: '/rest/api/content/' + pageId + '?expand=body.storage,version',
        type: 'GET',
        success: function(data) {
            // Get the current page content

			console.log("Get content ok - data: ", data);

            var currentContent = data.body.storage.value;
			
			console.log("CurrentContent: ", currentContent);
            
            // Replace the old macro markup with the updated macro markup
            var updatedContent = currentContent.replace(/([^\]\{MineAftaler:[^{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true}]{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true})/g, updatedMacroMarkup);

            // Create a JSON payload for the REST API request to update the page
            var payload = {
                version: {
                   number: data.version.number + 1 // Increment this number if you want to update the page content{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true},  
                type: 'page',      
                title: 'Mine aftaler',
                body: {
                    storage: {
                        value: updatedContent,
                        representation: 'storage{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true}{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true}{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true};

            // Make an AJAX request to update the page content
            AJS.$.ajax({
                url: '/rest/api/content/' + pageId,
                type: 'PUT',
                contentType: 'application/json',
                data: JSON.stringify(payload),
                success: function(data) {
                    console.log('Macro on the page updated successfull{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true},
                error: function(error) {
                    console.error('Error updating macro on the page:', error{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true}{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true}{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes|include_user_info=true},
        error: function(error) {
            console.error('Error retrieving page content:', error{Mineaftaler:REST_HTML_URL=http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html|REST_DOWNLOAD_URL=return decodeURIComponent(results[2].replace(/\+/g, ' '));
  }

  // Example usage
  var paramValue = getParameterByName('kategori');
  console.log('Kategori:', paramValue);
  if (paramValue === 'KOM' || paramValue === 'REG' || paramValue === 'STA' || paramValue === 'LPS' || paramValue === 'APO' || paramValue === 'ITL' || paramValue === 'OVR') {
		console.log("switch ", paramValue);
	    $('.toggle-agreements').hide();
	    $('#agreement-category-' + paramValue).show();
  }
  
  paramValue = getParameterByName('link');
  console.log('Header value:', paramValue);
  if (paramValue !== null) {
		$('html, body').scrollTop($('#' + paramValue).offset().top);
  }
  
});

</script>

Aftaleoversigt
REST_DOWNLOAD_URLhttp://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/base64encodefilebytes

...

include_user_info

...

true
REST_HTML_URL

...

http://foedus01.nsi.netic.dk:8080/NSI_Aftaler-1.1.1-SNAPSHOT/rest/html

...