Decimal Separator Format
Depending on the user (or location if null in user), the user can have numbers displayed in the formats 100,00 or 100.00 (1.000,00 or 1000.00 with the comma separator used in the one format). Users should be able to enter a decimal symbol as a comma or as a fullstop/period in the inputs. In every place where we do anything with numbers, we must do the following to ensure Javascript can correctly handle numbers:
Call the following method. This will check if the user/location format and if the user uses the comma-decimal-format, the code will remove all the '.' (thousand separator symbols) and replace the ',' character with a fullstop/period symbol. Javascript only knows the universal format for numbers, eg, 100.00 or 1000.00.
number = dispatch(convertToGlobalNumberFormat(number));
After doing the above, you can do your calculations but you must achieve the following, which will convert the number to the localised string. (We use de-DE for the correct format expected.) This method takes the number, precision (number of decimal places to show) and an optional isRaw boolean, which avoids the rounding and shows the number as is.
dispatch(formatDecimalByLocale(number, precision));
Date Format
The user has a date format set; if it is null, it will use the location or DD-MM-YYY as the ultimate fallback. The date components and displays must always obtain the date format and show accordingly.
Generic String Replacement
General rule for replacement characters in strings is this:
Any text that will be automatically generated or require other logic (such as a link with clickable text) will use the replacement characters starting with {0} and then incremented.
Use the function to replace the generated text in the brackets: genericStringReplacement(message, values). Message is the message and values are an array of strings based on the replacement characters.
"Page {0} of {1}"
"Cannot find the record. {0} to search."
In the above examples, the full message in quotes will be passed along with the values ["1", "10"], or simply ["click here"] which would be generated automatically or manually, given the scenario.
Editing a Transaction
A user is able to open a draft in edit mode and then re-save t. (The draft can be re-saved as a draft or as a transaction, updating the status to complete.) A user can also do a rebill.
window.StockControl.Constants.routeTransaction + "?id=" + transactionID + "&status=edit";
Clicking a draft form will pre-populate the values in edit mode. The transaction ID and action (draft/rebill) will be passed to the page. There will be a security check against the logged-in user to verify that they are able to edit the transaction based on their location. If they are not permitted to edit the draft, they will be redirected to error page.
There is also security in place to prevent the user editing a transaction that is not a draft status. The details and the transaction page will look at the transaction ID and determine if the transaction is editable. The status of the transaction will enable the transaction to be displayed in either the details page or the draft form.
If the draft they are editing is a Receipt transaction, note that they will be unable to click onto the 'split delivery' checkbox. They will just have the one receiving device field (which may be pre-populated if they have entered these details).
If editing a draft and the data does not exist, the user will be redirected to an error page.
The DRN validation still applies. If the fields have not been changed and the item is a DRAFT, the validation on this will not be completed again. (The date and timestamp will match the transaction unique id in order to pass the validation.)
If doing a Contra, the transaction will have the status updated to cancelled. If doing a Contra & Rebill, the original transaction will be cancelled and a new one will be duplicated with Contra status and open in form mode. The user can update the values (or click rebill to edit at any time) and upon saving, it will save the transaction. It keeps the DRN the same and updates the status.
So editing a transaction will take a status of rebill or draft. If user manually changes status, it will check that the status action is allowed (if a draft, it must be edit)
SAML POST form API call
Since SAML has been integrated, there are added extra OOTB security on AEM to verify the user token and to pass it in the header. Instead of using fetch, developers should use XHR as below to complete the call. The first step is to get the token in AEM.
if (window.StockControl.Constants.isAEM) { //if AEM....
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
let msg = JSON.parse(xhr.responseText);
token = msg.token;
self.sendArchiveRequest(fileid, token, target);
}
};
// Open the request to the token endpoint and send the GET
xhr.open("GET", "/libs/granite/csrf/token.json", true); //path to obtain token in AEM
xhr.send();
}
After getting the token, set up your POST to your endpoint and pass the token.
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
//test the JSON.parse(xhr.responseText) is not an error and place in here what you want to happen after the call
}
};
xhr.open("POST", endpointURL, true);
if (token !== null) {
xhr.setRequestHeader("CSRF-Token", token);
}
xhr.send(JSON.stringify(archivePostData)); //must stringify Json or send as . FormData object
SAML required headers for user API
The headers must be set in the fetchUser API for older or out-dated browsers. Otherwise, it will not use the correct credentials headers. Please set the below in curly brackets.
fetch(endpointURL, { cache: "no-cache", credentials: 'same-origin' } )
If the call needs some access to admin page or AEM nodes, it needs to pass the credentials if you want to access via localhost.
fetch(endpointURL, { cache: "no-cache", credentials: 'includes' } )
Leave a comment