Modify URL on copy (-paste) - javascript

I need to modify the url on copy from an angular project.
When the user selects URL and copy (like ctrl+c), it is
page/item/123
I need to modify that to
page/item?id=123
How can I do that?
Reason: I could not make the web.config work to pass the full path (item/123), so angular cannot parse what is not there.
However, I can make item?id=.... work, so it opens "item" and there I can get the query parameter.
Added: in the comments it was suggested to do it one way/the right way only and I agree - but I am here because my original problem cannot be solved: web.config - forward full path with parameter
How to make rules work with parameters and pass the full path for parsing

Here's how it can be done:
html
<div (copy)="handleCopy($event)">page/item/1234</div>
ts
handleCopy(event: ClipboardEvent) {
event.clipboardData.setData('text/plain',
document.getSelection().toString().replace(/\/(?=[^\/]*$)/, "?id="));
event.preventDefault();
}

Related

Parse Server - How to Translate The Pages of Email Confirmation and Password Reset

I have a project with parse server which I need translate the pages of Email Confirmation and Password Reset, and I don't find anywhere a solution for this. I found about the emails templates, but not about the pages where the user go after click on the link sent to email by Parse Server.
Take a look at this option: https://github.com/parse-community/parse-server#custom-pages
You can create your custom pages and pass customPages option to Parse Server with their locations.
You can find the default ones and use them as template in here: https://github.com/parse-community/parse-server/tree/master/public_html
As Davi Macedo showed, I create the files and solved the problem with them. But I don't know if Parse should automatically replace the files in public_html. In my case just put the files there was not enough. My solution was create /public/pages with the custom files, and point my customFiles config like that:
customPages: {
passwordResetSuccess: base + "/public/pages/password_reset_success.html",
verifyEmailSuccess: base + "/public/pages/verify_email_success.html",
invalidVerificationLink: base + "/public/pages/invalid_verification_link.html",
invalidLink: base + "/public/pages/invalid_link.html",
choosePassword: base + "/public/pages/choose_password.html",
linkSendSuccess: base + "/public/pages/link_send_success.html",
linkSendFail: base + "/public/pages/link_send_fail.html",
}
Besides, to choose password page I used this file: https://github.com/parsegroundapps/pg-app-tynwrjdecdmr69ke5d8fec6ixljzx5/tree/master/public/pages
Another detail is that the file choose_password.html on the repository above makes de POST request adding "/1/" to url, but in my case, I needed make the url pointing to "/parse", so I replaced the line 181 to
var base = window.location.origin + '/parse/';
Parse Server 5.0 will contain the PagesRouter which should make translation of pages easier. It is currently only available on the master branch, if you want to give it a try.
See https://github.com/parse-community/parse-server/pull/7128

Express req.param deprecated syntax

On Node.js I am getting this error, in some JavaScript code:
express deprecated req.param(name): Use req.params, req.body,
Here is the relevant code:
response.render('pages/' + displayPage, {
MYVAR: request.param('MYVAR'),
MYVAR2: request.MYVAR,
MYVAR3: request.params.MYVAR
});
In other words this line is deprecated
MYVAR: request.param('MYVAR'),
But, it does the job (at least for now).
And the other type of syntax I tried, by guessing or by finding on the net after searching, all failed.
Including these lines:
MYVAR2: request.MYVAR,
MYVAR3: request.params.MYVAR
and a few more options that would be pointless to list here.
So the question is: what is the right syntax to use?
Here is some more information, added by editing the post after reading some comments:
I send the request parameters this way:
https://myapp.herokuapp.com/branch?MYVAR=64.39
Inside index.js the code processing the /branch is:
response.render('pages/' + displayPage, {
MYVAR: request.param('MYVAR'),
MYVAR2: request.params.MYVAR,
MYVAR3: request.params['MYVAR']
});
Inside the branch.ejs file I have placed the following in order to see what I am getting:
<body bgcolor=#221122E>
<b>MYVAR=<%= MYVAR %></b><br/>
<b>MYVAR2=<%= MYVAR2 %></b><br/>
<b>MYVAR3=<%= MYVAR3 %></b><br/>
......
And finally this is what I can see in the browser, displayed by branch.ejs:
MYVAR=64.39
MYVAR2=
MYVAR3=
It shows that the variable passed with the old syntax arrives as expected, but not the other ones.
Which of the variants is needed depends on how you send request parameters:
You need to use req.query.MYVAR if your request uses the GET method with parameters after the ? like /path?MYVAR=123.
If you have your parameters in the path (e.g. /path/:MYVAR in your express get call), req.params.MYVAR is correct.
If you use POST or PUT, you need to use req.body.MYVAR, because of the data is transferred in the body. Since express doesn't parse the body , you need to include and use an additional package like body-parser
Instead of using:
request.param('MYVAR')
You are supposed to use:
request.params['MYVAR']
// Or this:
request.params.MYVAR

Troubling using QuaggaJS - Javascript Barcode Scanner

I am using QuaggaJS. On the home page there, it has basic descriptions of its main methods, as well as an example html folder in its downloadable zip. My problem, is that one of the example HTMLs is called static_images. This takes in image src's for its scanning procedure, but I cannot figure out how to give it a custom single src that I specify. (The example HTML seems to use a pre-set list of images in the folder).
I read (on QuaggaJS git homepage) that the method Quagga.decodeSingle(config, callback) does exactly what I want.
In contrast to the calls described above, this method does not rely on
getUserMedia and operates on a single image instead. The provided
callback is the same as in onDetected and contains the result data
object.
But I cannot figure out how to implement that method into his example code. Can someone guide me, and explain, how I am to implement that method within QuaggaJS? (quagga/example/static_images.html/js)
The method Quagga.decodeSingle takes an object as the first parameter (config) that has a property called "src". You can pass your src to this property.
The example the author gives is:
Quagga.decodeSingle({
readers: ['code_128_reader'],
locate: true, // try to locate the barcode in the image
src: '/test/fixtures/code_128/image-001.jpg' // or 'data:image/jpg;base64,' + data
}, function(result){
console.log(result);
});
where the readers property indicates the method will only decode code_128 barcodes. You can add the other barcode types in this array, which are basically the names of the protocols with underscores instead of spaces with "_reader" at the end (e.g., ["code_128_reader", "code_39_reader", "code_39_vin_reader", "ean_reader", "ean_8_reader", "upc_reader", "upc_e_reader", "codabar_reader"]).

base link and search api

I am attempting to query a database through an API which I don't fully understand. I have been sent an example of the API being used with a keyword search form. The form is an html file and uses jquery return JSON documents, format items into an array array, and display.
I tried to build the design of my application and manipulate the form to work within my pages. The file the uses the API requires that the a base link be used.
<base href="{{app_root}}">
If I remove this base link my functionality of the search is lost. If I use the base link all of presentation and CSS is lost.
I thought maybe I could change the base link dynamically when I needed to call the search file with:
<script type="text/javascript">
function setbasehref(basehref) {
var thebase = document.getElementsByTagName("base");
thebase[0].href = basehref;
}
//setbasehref("{{app_root}}");
setbasehref("{{app_root}}");
</script>
Then use setbasehref() to change it back to my original base link, but that didn't work.
I'm new to javascript and JSON, and I'm not entirely sure what app_root is doing. Any thoughts?

Expression Engine Extension Development - Add custom javascript to rendered entry

I'm working on an extension and one of the options available in the settings needs a custom javascript to be added to the document head when rendered. The problem I am having is with the parsing order. (There may also be a better way of doing the include too)
I am using the channel_entries_tagdata hook.
Inside this, once the settings are processed, I am doing the following:
// Add the required javascript
$jscript = "
<script type="text/javascript">
/*! etc......
</script></head>
";
// Add js
$tagdata = str_replace("</head>", $jscript, $tagdata);
I would like to be able to just keep my javascript in a separate file and include it somehow by reference, but I don't know how to do that at this stage.
The other issue I am running into is the parsing order of the EE variables. Inside the javascript, I am using the variables from the $tagdata. Something like this:
$.post("URL", { channel: "{channel}", entryId: "{entry_id}", urlTitle: "{url_title}", lastSegment: "{last_segment}", editDate: eo.editDate, field: eo.eleName }, function(data){...
How would I call/use the EE variables in this case?
Elaborated...
This extension is for the following:
In the Addons -> Extensions from the control panel, they will activate the extension. In the 'Settings' for that extension, they will be able to authorize, by Channel, the members or groups that can 'edit' entries in that channel.
The extension, after checking permissions, edits each custom field type before it is rendered and wraps it in a class element. The JavaScript file is for this functionality next. When that element is clicked, a modal is opened which will contain the custom field type as well as the channel/entry information, so it can save the field once edited.
Could you let the script in the <head> be a generic function and pass variables to it by calling it from inside your channel entries?
<head>
...
<script>
function W3bGuy_function(channel, entry_id, last_segment) {
...whatever...
}
</script>
</head>
<body>
...
{exp:channel:entries}
some action triggers: W3bGuy_function('{channel}', '{entry_id}', '{segment_3}');
{/exp:channel:entries}
...
channel_entries_tagdata contains the raw template code pulled from within each {exp:channel:entries} loop, and then has another variable ($row) which is an array of the actual data for that entry. (As per the docs.)
So first, you'll have to make sure your entire page template is within your Channel Entries loop if you want to add JS to the <head> in this manner - and that may not work if your <head> is inside an embed.
Second, I'd suggest dumping the $row data that's passed via that hook, to see if you can extract your data in your returned JS from there.
Hope that helps.

Categories

Resources