Welcome to the Protogrid Developer Wiki. A place to gather all the documentation and tips&tricks regarding Protogrid.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

protogrid:create_new_card_via_link [2018-11-09 10:39] (current)
46.140.51.3 created
Line 1: Line 1:
 +====== Create New Card Via Link ======
  
 +Imagine you need to check if a certain Card for a given Proto exists and if not you want to redirect the user to crate a new Card.
 +To do so, you first need to create a new Card-Key (example in javascript)
 +<code javascript>​
 +function generate_key()
 +{
 +    //helper functions to generate random strings of length 4
 +    function s4() 
 +    {
 +    return Math.floor((1 + Math.random()) * 0x10000)
 +      .toString(16)
 +      .substring(1);​
 +    }
 +    return s4() + s4() + '​-'​ + s4() + '​-'​ + s4() + '​-'​ +
 +        s4() + '​-'​ + s4() + s4() + s4();
 +}
 +</​code>​
 +Using this function you can now move on and redirect the user to create a new card based on a given proto
 +<code javascript>​
 +//specify the parent proto in proto_key
 +function create_new_card(proto_key)
 +{
 +    let url = '/'​ + $APP_URL_NAME + '/'​ + generate_key() + '?​action=open_new_card&​proto_key='​ + proto_key;
 +    window.open(url,​ '​_self'​);​
 +}
 +</​code>​
Print/export