Adobe pdf embede api – How to generate the file ID to place in metaData

I am using Adobe PDF Embedded API to view, edit & save the PDF and it is working fine.

The problem is when I tried to get the add or get the annotation list there is a File ID inside a metaData object which has to pass to it mandatory.

Using the below code to access the annotations from the PDF:

 document.addEventListener("adobe_dc_view_sdk.ready", function()

 {

  var adobeDCView = new AdobeDC.View({clientId: "<YOUR_CLIENT_ID>", divId: "adobe-dc-view"});

  var previewFilePromise = adobeDCView.previewFile({

   content:   {location: {url: "https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf"}},
   //id is 
   metaData:  {
          fileName: "Bodea Brochure.pdf", 
           /* file ID */
          id: "77c6fa5d-6d74-4104-8349-657c8411a834"}

  },

  {

   enableAnnotationAPIs: true,

  });


  previewFilePromise.then(adobeViewer => {

   adobeViewer.getAnnotationManager().then(annotationManager => {

    // All annotation APIs can be invoked here

   });

  });

 });

Can anyone tell me how to get the File ID to add inside a metaData Object.

Carousel not working properly if closed and re-opened

I’m having an issue with a carousel. Let me explain.
When i click on any of the photos, it opens a modal/carousel which is working as planned. But once i close this said modal and try to click on any other photo, when clicking on the next button, it’s not doing +1, but +2 and increasing each time i close the modal.

Any solution ? Code below (i tried to comment it as much as possible to make it being understandable.

let currentState = 0
//Display photo/video inside modal + carousel
function displayPhoto() {
    const photos = document.querySelectorAll(".photo")
    const prevButton = document.querySelector(".prev-button");
    const nextButton = document.querySelector(".next-button");
    console.log(photos)

    for(let i = 0; i<photos.length; i++) {
        photos[i].addEventListener("click", () => {
        currentState = i
        var imageSrc = photos[i].getAttribute("src")  

        photoModal.style.display = "flex"
        //Insert image into the singlePhoto div
        singlePhoto.appendChild(img).setAttribute("src", imageSrc)

        //Next photo
        nextButton.addEventListener("click", () => {
            if(currentState < photos.length - 1) {
                currentState += 1
                console.log("current", currentState, "i", i);
                singlePhoto.appendChild(img).setAttribute("src", photos[currentState].getAttribute("src"))
            } else { 
                currentState = 0
                console.log("current", currentState, "i", i);
                singlePhoto.appendChild(img).setAttribute("src", photos[currentState].getAttribute("src"))
            }
        })
 
        //Close photo modal/carousel
        function closePhoto() {
            closePhotoModal.addEventListener("click", () => photoModal.style.display = "none")
        }
        closePhoto()

    })
  }
}

How to select different ModelForms based on select value for DJANGO model form

I have a list of values. Within the list of values is a status which has a hyperlink to a particular model form.

I want to dynamically change the hyperlink based on the select value to direct the user to different forms based on the select value.

So, for example, when the Model value is pending, I want the hyperlink to go to the pending form. When the status is invoice sent and the use clicks the hyperlink I want the user to to go to the payment form.

The code is below

              <table id="example1" class="table table-bordered table-striped" data-order='[[ 0, "desc" ]]' data-page-length='25'><button onClick="refreshPage()" class="btn btn-secondary float-right" title="Refresh"><i class="fa fa-sync"></i></button>
                <thead>
                  <tr>
                    <th>Script No.</th>
                    <th>Entered on</th>
                    <th>Script Type</th>
                    <th>Patient</th>
                    <th>Address</th>
                    <th>Email</th>
                    <th>Contact No</th>
                    <th>Product</th>
                    <th>Form</th>
                    <th>Units</th>
                    <th>Dispensing Price</th>
                    <th>Status</th>
                    <th>Dispatch Date</th>
                    <th>Worksheet ID</th>
                    <th></th>
                  </tr>
                </thead>
                <tbody>
                 {% for script in scripts %}
                 <tr>
                  <td>{{script.pk}}</td>
                  <td>{{script.entered_on}}</td>
                  <td>{{script.get_script_type_display}}
                  <td>{{script.patient}}</td>
                  <td>{{script.patient.address}}&nbsp;{{script.patient.city}}&nbsp;{{script.patient.AU_states}}&nbsp;{{script.patient.postal_code}}</td>
                  <td>{{script.patient.email}}</td>
                  <td>{{script.patient.mobile_number}}</td>
                  <td>{{script.product}}</td>
                  <td>{{script.product.form.description}}</td>
                  <td>{{script.quantity}}</td>
                  <td>$&nbsp;{{ script.dispensing_price }}</td>
                  {% if script.dispatch_date is not none %}
                  <td>{{script.get_script_status_display}}</td>
                  {% else %}
                  <td> <a class="edit" href="#" data-url="{% url "script:script_update_status" script.pk %}">{{script.get_script_status_display}}</a></td>
                  {% endif %}
                  {% if script.dispatch_date is none %}
                  <td>Not Sent</td>
                  {% else %}
                  <td>{{script.dispatch_date}}</td>
                  {% endif %}
                  {% if script.document_id is none %}
                  <td>Not Made</td>
                  {% else %}
                  <style></style>
                  <td>{{script.document_id}}</td>
                  {% endif %}
                  <td><small><a href = "{% url 'script:script_detail' script.pk %}">View</a>&nbsp;|&nbsp; <a href="{% url "script:script_update" script.pk %}">Edit</a>&nbsp;|&nbsp;<a href="{% url 'label:product_label' script.pk %}">Lab Label</a>&nbsp;|&nbsp;<a href="{% url 'label:dispense_label' script.pk %}">Dispense Label
                  </a>&nbsp;|&nbsp;<a href="{% url 'label:shipping_label' script.pk %}">Shipping Label</a>&nbsp;|&nbsp;<a href="{% url "label:receipt" script.pk %}" >Health Fund Receipt</a>&nbsp;|&nbsp;<a href="{% url "label:repeat" script.pk %}">Repeat</a><!--0&nbsp;{% if script.patient.target_species == 'A' %}|&nbsp;<a href = "{% url 'communication:send_counselling_email' script.pk %} ">Counselling Email</a>{% endif %}--></td>
                </tr>
                {% endfor %}
              </tbody>
            </table>
            <script>
              document.querySelectorAll('#example1 a.edit').forEach(function(a) {
                a.addEventListener('click', function(e) {
                  e.preventDefault();
                  const url = this.dataset.url;
                  window.open(url, "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=250");
                });
              });
            </script>
          </div>```

Thanks in advance for any help.

Kind Regards,
AC

How to make Third Party Javascript [duplicate]

I’m a web developer and I want to use third party Javascript in my html file. I tried uploading it to google drive and then using the scr attribute of the script tag but it doesn’t work. Please help.

Html code:

<!DOCTYPE html>
<html>
<head>

</head>
<body>

<script src = "https://drive.google.com/uc?export=download&id=1WU2AoUgwBxgH0yLoed9SQ71rP-JnBvgR" >

</script>
</body>
</html>

Javascript I uploaded:

console.log("Hello World");

So how can I make the Javascript Code (console.log(“Hello World”);) a Third Party Javascript? I don’t have my own website domain though so please give some suggestions like Google or something that I can use to host my Third Party Javascript code. Thank you so much!

need to access dynamically the array name and properties

I have javascript object with array as showing below

const object1 = {
        "sublists": {
        "item": [
            {            
                "line": "1",
                "amount": "1200.00",
                "id": "227",
                "item": "227",
                "item_display": "5800520002800",
                "quantity": "1"
            }
            
        ] ,
        "shipping": [
            {            
                "line": "1",
                "amount": "1200.00",
                "id": "227",
                "quantity": "1"
            }
            
        ]
        }
    }

here is the code

jv = jsonData.sublists ;

 function printValues(obj) {
        for(var k in obj) {
        //    console.log(k+obj[k]);
            if(obj[k] instanceof Object) {
                printValues(obj[k]);
            } else {
                console.log(k+''+obj[k] );
            };
        }
    };
printValues(jv );

with this code i can get the array properties and values but cant get the desired output as showing below

desired output

Array name :item, line: , 1 
Array name :item ,amount : 1200 
Array name :item, id : 227 and so son

and so on … the array properties can varry depending on the json ouput , im looking for a dynamic script in which i could access the array name and properties

Read a Javascript cookie-value from a .NET codebehind

In my part of the web page I have put a value in a Javascript cookie like this:

function SkrivJSCookie() {
         document.cookie = "test_cookie=Test99";
         }

In my codebehind (VB), I want to have the value of the cookie (‘Test99’) transferred to a textbox (Textbox1) when a button is clicked.

From a large Google search it seems, that the solution may be to use ‘HttpServletRequest’ in some way, but I cannot make it work at all.

It seems like a pretty simple issue but how can this be accomplished?

Thank you in advance!

How to target array index position correctly in Vuejs?

HelloWorld.vue

<template>
  <div>
    <div v-for="(piza, index) in pizas" :key="piza.pname">
      {{ piza.pname }}
      <List
        :content="matchpizza"
        :pname="piza.pname"
        :qname="quantitys[index] ? quantitys[index].qname : ''"
      />
    </div>
  </div>
</template> 

<script>
import List from "./List.vue";
export default {
  name: "HelloWorld",
  components: {
    List,
  },
  data() {
    return {
      pizas: [
        {
          pname: "chicken pizza",
        },
        {
          pname: "chicken pizza spl",
        },
        {
          pname: "mutton pizza",
        },
        {
          pname: "plain pizza",
        },
      ],

      quantitys: [
        {
          qname: "one",
        },
        {
          qname: "two",
        },
        {
          qname: "three",
        },
        {
          qname: "four",
        },
        {
          qname: "five",
        },
      ],

      matchpizza: [
        {
          matchnum: "1",
          availability: "later",
          pname: "plain pizza",
          qname: "five",
        },
        {
          matchnum: "2",
          availability: "buy now",
          pname: "chicken pizza",
          qname: "one",
        },
        {
          matchnum: "3",
          availability: "buy now",
          pname: "plain pizza",
          qname: "five",
        },
        {
          matchnum: "4",
          availability: "buy now",
          pname: "chicken pizza spl",
          qname: "five",
        },
        {
          matchnum: "5",
          availability: "later",
          pname: "mutton pizza",
          qname: "five",
        },
      ],
    };
  },
};
</script>

List.vue

<template>
  <div>
    <div v-if="matchpizza.length > 0">
      <div
        v-for="match in matchpizza"
        :key="match.matchnum"
        :class="{
          green: match.availability === 'buy now',
          red: match.availability === 'later',
        }"
      >
        <div v-for="quantity in quantitys" :key="quantity.qname">
          {{ quantity.qname }}
        </div>
        <div class="next-data-two">{{ match.availability }}</div>
      </div>
    </div>
    <div v-else class="next-data"><p>No availability</p></div>
  </div>
</template>
<script>
export default {
  components: {},
  props: {
    content: {
      type: Array,
      required: true,
    },
    pname: {
      type: String,
      required: true,
    },
    qname: {
      type: String,
      required: true,
    },
  },
  data: function () {
    return {};
  },
  methods: {},
  computed: {
    quantitys() {
      return this.content.filter((a) => a.qname === this.qname);
    },
    matchpizza() {
      return this.content.filter((a) => a.pname === this.pname);
    },
  },
};
</script>
<style scoped>
.next-data {
  display: flex;
  flex-direction: row-reverse;
  margin-top: -2%;
  margin-right: 40%;
  color: blue;
}
.next-data-two {
  display: flex;
  flex-direction: row-reverse;
  margin-top: -1%;
  margin-right: 42%;
  color: red;
  margin-bottom: 1%;
}
</style>

See my working code here:-

https://codesandbox.io/s/data-display-tcr8oj?file=/src/components/HelloWorld.vue

From the helloworld.vue you can see this line :qname=”quantitys[index] ? quantitys[index].qname : ””

Where as per the above code, from the quantitys array. it is not pointing to the particular index value correctly?.

According to my output from codesandbox:-

For chicken pizza it showing as , chicken pizza –> one –> later
But correct path is, chicken pizza –> later –> five

Similarly for others too, having same issue….

Is it because of index position wrong or issue with logic??

discord.js throws TOKEN_INVALID when I use the token I got from browser in discord.com

My final goal : I would like to get every single channels in every single guilds I belong to.

As a first step, created simple program that I identify that I am logged in as myself.

I first found my token via this video

In a nutshell the video instructs to get the token via

Chrome -> discord.com -> F12 -> Application -> Local Storage -> filter “token” -> click “Toggle device toolbar” -> voila

Threw it in .env as variable TOKEN=... and my index.js is implemented as followings

const Discord = require("discord.js");
const dotenv = require("dotenv");
dotenv.config();

const client = new Discord.Client({
  intents: [
    Discord.Intents.FLAGS.GUILDS,
  ]
});

client.on('ready', ()=> {
  console.log(`Logged in as ${client.user.tag}`);
});

client.login(process.env.TOKEN);

However, when I run node index.js I receive following errors

D:SourceTreediscord.js0_get_server_channel_listnode_modulesdiscord.jssrcclientwebsocketWebSocketManager.js:129
    const invalidToken = new Error(WSCodes[4004]);
                         ^

Error [TOKEN_INVALID]: An invalid token was provided.

Is the token found in the video wrong?
Or is there something else I am doing wrong?

Salesforce REST API returns only first 10 reports how to get them all?

For my project in javascript I am using salesforce API to get all reports what user have in salesforce account.
At current API GET call to
Reports/GetReportList?search=&offset=0
it returns only first 10 reports from the start.

  • offset -The starting row offset into the result set returned.
    proof
    proof of 10 reports
    full call/method looks like
let result = await this.Api.Service.get(`Reports/GetReportList?search=${search}&offset=${offset}`)
//where search is '' and offset is 0

Using:

  • for REST api calls I am using axios package
  • salesforces api version v2 (I am not sure what exactly it means v2 or version v2x)
  • javascript as programming language

Main question is how to get all reports from salesforce?

Repeater issue/problm

We are trying to use this repeater:
https://www.jqueryscript.net/form/Form-Fields-Repeater.html

It seems there is problem if you look at the demo.
https://www.jqueryscript.net/demo/Form-Fields-Repeater/

Try on demo to add for example four groups.(press three times add button).

Then remove all four groups by pressing Delete button.

Then press add again to add a new group.

If you inspect the name element it is:

The problem is with test[4]name. Normally it should be test[0]name.

It seems that when you delete element does not delete the counting.

So if you play a little bit with delete/add buttons counting is wrong.

Javascript of this is :

    jQuery.fn.extend({
     createRepeater: function () {
         var addItem = function (items, key) {
        var itemContent = items;
        var group = itemContent.data("group");
        var item = itemContent;
        var input = item.find('input,select');
        input.each(function (index, el) {
            var attrName = $(el).data('name');
            var skipName = $(el).data('skip-name');
            if (skipName != true) {
                $(el).attr("name", group + "[" + key + "]" + attrName);
            } else {
                if (attrName != 'undefined') {
                    $(el).attr("name", attrName);
                }
            }
        })
        var itemClone = items;
        $("<div class='items'>" + itemClone.html() + "<div/>").appendTo(repeater);
    };
    /* find elements */
    var repeater = this;
    var items = repeater.find(".items");
    var key = 0;
    var addButton = repeater.find('.repeater-add-btn');
    var newItem = items;
    if (key == 0) {
        items.remove();
        addItem(newItem, key);
    }

    /* handle click and add items */
    addButton.on("click", function () {
        key++;
        addItem(newItem, key);
    });
}
 });

Have anyone ever used this repeater? or have a version of this that works correct?

Javascript Performance Test

I was just curious why javascipt have many methods to convert a string to number, exploring that i found at this website called jsBench.me. I am not sure what these kind of websites called but for me it was a website to compare the codes i write. While playing around,
enter image description here
I got a result which was a bit surprising for me. From what I understood this can be,

  1. Something I am not aware about.
  2. This website is a bullshit.
  3. I have some theories in my mind which supports this result, like it might me because javascript stores the value first in cache and blah blah blah..(I have no idea on how to explain what I think)

But I am not sure about anything, is there anyone who can help me understand this?

Javascript JSON not parsing properly

I’m trying to get data out of a reply given to me from a backend API. I have an object called result which contains the following reply from the server:

{
  connection: 'Keep-Alive',
  'content-language': 'en-GB',
  'content-length': '0',
  'content-type': 'text/html'
  date: 'Fri, 11 Mar 2022 06:41:06 GMT',
  'keep-alive': 'timeout=5, max=100',
}

I’m trying to get the ‘keep-alive’ part but I’m unsure how I can access it.

I’ve tried parsing result as JSON

const obj = JSON.parse(result)
console.log(obj)

But this throws the following error:

undefined:1
[object Object]
 ^

SyntaxError: Unexpected token o in JSON at position 1

The issue seems to be that connection and date aren’t within single quotes and I don’t know how to fix this.