Load select options dynamically from external service in Touch UI dialog in AEM? - aem

My problem is to load a select field in touch UI dialog with dynamic options. These options are coming from a external URL via webservices, I am consuming this RESTful services using url defined in one of our global javascript objects like
$.get(mec.serviceConfig.baseUrl + '/movies';
Please understand that the options are coming from third party webservice please do not mention datasource. Whenever I search for loading select options dynamically I get this tutorial
Link to Tutorial
This is is not what I want.
In classic UI it is easy with optionsProvider.
In touch UI I am trying to write a script that fetches the data from the external webservice via AJAX ON DIALOG load and set these options in the select field.
Is there any better easier approach ? Can someone please share code snippets?

you should create JS listener for your component.
$document.on("dialog-ready", function() {
// there you should find your select field
//for example
var language = $("[name='./language']").closest(".coral-Select");
//then append to your select field new options from your datasource
});
please see doc: Dynamically updating AEM TouchUI Dialog Select Fields

Related

Angular2 How to get specific data that users choose after selecting choices from dropdown option.

Hi I am really new to Angular2 (I know most of the concepts that angular2 provides tho) and I am having problems with getting specific data after choosing some options.
Currently, I have fake database and created some profiles of random people in the database.
And I have components with dropdown options. I want users to choose one of the options and once they are done with choosing, I want them to click 'Complete' button.
Once they do, they will be redirected to another component that shows data corresponding to their choice.
I am guessing I need to store data that users choose into a service and communication between these two components(one components with options, the other with lists of information based on users' choice) should utilize the service.
But I've got no idea how to do so. Help will be appreciated! Thank you!
First,Define you routes with an parameter like '/anotherRouter:option'
Then, keep the selected option in you component.
<select id="option" name="option" required [(ngModel)]="selectedOption" #address="ngModel">
...
</select>
Then, By click the Complete button, goto another component like this.
<button (click)="go()">Complete</button>
And at your component, define a function go like this(let guess you have inject Router from #angular/router):
go() {
this.router.navigate(['anotherRouter', selectedOption]);
}
Then get the selectedOption in your new component from the Params of #angular/router like +params['option'](the parameter passed while navigate).

Laravel HTML form on multiple pages

How to make a form across multiple pages in Laravel like here
http://www.html-form-guide.com/php-form/php-order-form.html
I have a lot of input fields and i can't find any info on Laravel multiple pages forms. If someone has any good website where to read about it and to see how it is done?
Any help is appreciated.
You can achieve through session of laravel, you can set your values with key and value:
public function step1(Request $request)
{
$request->session()->put('key', 'value');
}
for further information see this link
Other way is make in your client side, with localStorage is cleaner for me, you can use Single Page Aplication and send the data when you're at the final step.
localStorage works seemed to PHP session, check out this link :
you can set the item thought steps, like this:
localStorage.setItem("key", "value");
and retrieve the information like this:
localStorage.getItem("key");
The Single Page application lets you render diferent pages in a route and it's not neccesary to reload the page, you can check out Angular or Ember.js Framework.
If you are looking to do this on server side and not with javascript framework here is what you can approach.
You can make use of Laravel session to store intermediate data between the pages and then pull data out of session to insert into database at the final step.
Detailed Tutorial
https://www.5balloons.info/multi-page-step-form-in-laravel-with-validation/

SuiteCRM : How to Add Dashlet which renders external project

Anybody knows how to create dashlet that render an external app in suiteCRM/sugarCRM ?
Thanx.
SuiteCRM:
What you need to do is create your module using module builder. Then edit the default dashlet see modules/your_module/Dashlets/your_module_name/your_module_name.php.
You need to override the display() so that it returns the code that you wish to use. Typically you would return the HTML from an external file.
function display()
{
$path = 'modules/your_module_name/Dashlets/your_module_name/your_module_name.html';
parent::display();
return file_get_contents($path);
}
you can configure a new dashboard in suitecrm and while adding new dashboard, select "Web" type of dashboard and enter URL of you external app there. SuiteCRM will load this in iframe. Give it a try and let me know if you face any issue.
Creating new module and custom dashboard is to much work for something which is already available in suiteCRM.

Implement Inbox Functionality in custom cq component?

We want to develop a smooth-flowing workflow experience (but still use workflows). Currently, a user needs to use the sidekick to initiate the workflow, then to the inbox, which takes them back to the page to use the sidekick again. When they go to the inbox, they need to restrict to the model and path of the page. It would be nice for the user to only have to go to the content page and from there, launch the different workflow forms that need to happen, like a little "inbox" right on the page that is subject to the workflow.
I have written a custom component that can initiate the custom workflow. The custom component can also query the WorkFlowSession and obtain any active WorkItems for the current page that the component resides (using the WorkItemFilter interface). What I want to do is provide a link to the user to the next step in the workflow from the custom component, just like the inbox does.
Here is an example output from an WorkItem instance toString method:
21.05.2014 09:45:29.300 *ERROR* [0:0:0:0:0:0:0:1%0 [1400679929160] GET /content/test/mailing1.html HTTP/1.1] org.rand.whatcounts.EmailCampaignCoordinator Found workitem: -----------------------------
WorkItem Id: /etc/workflow/instances/2014-05-21/model_1400679794564399000/workItems/node4_etc_workflow_instances_2014-05-21_model_1400679794564399000
Workflow Id: /etc/workflow/instances/2014-05-21/model_1400679794564399000
Payload: /content/test/mailing1
Payload Type: JCR_PATH
key = historyEntryPath value = /etc/workflow/instances/2014-05-21/model_1400679794564399000/history/1400679924113
key = comment value =
My hope is that by using the workflow api items, I can create the link that the user could click on to proceed in the workflow (just like the inbox).
Thanks for listening!
Phillip
There are two ways to implement this
Java-Based Solution
I was able to figure out one way by looking at
http://localhost:4502/libs/cq/workflow/components/inbox/list/json.jsp
The important part of this jsp is that, given a workItem instance, you can get the path for your next step using the JcrPathBuilderManager:
pathBuilder.getPath(wi);
Using this, I was able to output a link to the next step in the workflow to the user (without having user go to their inbox).
Javascript/JSON Based Solution
I didn't go far with this solution (I didn't write any js) but this was my fall back position if I didn't find the java-solution listed above. Once could implement custom JS in CQ Component that would call the json feed for the user inbox, do some client side filtering (to restrict it to only items related to current page). The URL to the feed is
http://localhost:4502/libs/cq/workflow/content/inbox/list.json?start=0&limit=40
Thanks!

Google Search autocomplete API?

Does Google provide API access to autocomplete for search like on the actual site? I have not been able to find anything.
I would like to use Google's autocomplete logic for web search on my own site which relies on Google's search API.
The new url is:
http://suggestqueries.google.com/complete/search?client=firefox&q=YOURQUERY
the client part is required; I did't test other clients.
[EDIT]
If you want the callback use this:
http://suggestqueries.google.com/complete/search?client=chrome&q=YOURQUERY&callback=callback
As #Quandary found out; the callback does not work with client "firefox".
[EDIT2]
As indicated by # user2067021 this api will stop working as of 10-08-2015: Update on the Autocomplete API
First, go to google, click Settings (bottom right corner), change Search Settings to "never show instant results. That way, you'll get regular autocomplete instead of a full page of instant results.
After your settings are saved, go back to the Google main home page. Open your browser's developer tools and go to the Network tab. If you're in Firefox, you might have to reload the page.
Type a letter in the search box. A new line should appear in the Network window you just opened. That line is showing where the autocomplete data came from. Copy that url. It should look something like this:
https://www.google.com/complete/search?client=hp&hl=en&sugexp=msedr&gs_rn=62&gs_ri=hp&cp=1&gs_id=9c&q=a&xhr=t&callback=hello
You'll notice your search term right after the part that says q=.
Add &callback=myAmazingFunction to the end of the url. You may replace myAmazingFunction with whatever you want to name your function that will handle the data.
Here's an example of the code required to show the autocomplete data for the search term "a".
<div id="output"></div>
<script>
/* this function shows the raw data */
function myAmazingFunction(data){
document.getElementById('output').innerHTML = data;
}
</script>
<script src="https://www.google.com/complete/search?client=hp&hl=en&sugexp=msedr&gs_rn=62&gs_ri=hp&cp=1&gs_id=9c&q=a&xhr=t&callback=hello&callback=myAmazingFunction"></script>
Now that you know how to get the data, the next step is to automatically change that last script (the one with the autocomplete url). The basic procedure is: each time the user types something in the search box (onkeyup) replace the search term (q=whatever) in the url, and then append to the body a script with that url. Remove the previous script so that the body doesn't get cluttered.
For more info, see http://simplestepscode.com/autocomplete-data-tutorial/
Most of the above mentioned methods works for me, specifically the following serves my purpose.
http://suggestqueries.google.com/complete/search?client=firefox&q=YOURQUERY
Being a newbie in web programming, I'm not much aware of the "Callback" functionality and the format of the file returned by query. I'm little aware of AJAX and JSON.
Could someone provide more details about the format of file returned by the query.
Thanks.
Hi I don't know if this answer is relevant for you anymore or not but google returns JSON data through following get request (although this isn't an official API but many toolbars are using this API so there's no reason why google might discontinue it):
http://google.com/complete/search?q=<Your keywords here>&hl=en
You should use AutocompleteService and pass that text box value into the service.getPlacePredictions function. It send the data in callback function.
let service = new google.maps.places.AutocompleteService();
let displaySuggestions = function(predictions, status) {
}
service.getPlacePredictions({
input: value
}, displaySuggestions);
Base: https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompleteService.getPlacePredictions
example: https://dzone.com/articles/implement-and-optimize-autocomplete-with-google-pl
I'm using (( Edrra.com )) API that have google search and suggestions that works with both GET & POST:
Google suggestions:
https://edrra.com/v1/api.php?c=google&f=suggest&k=YOUR_API_KEY&v=YOUR_SEARCH
Google search:
https://edrra.com/v1/api.php?c=google&f=search&k=YOUR_API_KEY&v=YOUR_SEARCH
and more...
What are you trying to use an auto-complete for? More information would help narrow it down.
As far as I know, google does not provide one, but they do exist like jQuery UI's auto-complete.
EDIT:
If you are using their custom search API view here for autocomplete.