Welcome, Guest
Username: Password: Remember me

TOPIC: Populate Form Options from JSON or Lookup Table

Populate Form Options from JSON or Lookup Table 24 Jul 2013 17:15 #10562

  • jDoyle
  • jDoyle's Avatar
  • Offline
  • New Member
  • Posts: 2
  • Karma: 0
I am new to Cook and having a difficult time wrapping my head around this requirement.

The Setup:
1. A configuration admin view that sets the credentials to connect to a third party API.
2. A configuration admin view that defines the parameters for a call to the API. Multiple configurations can be added for making various call to the API

The Problem.
Admin view 2 has a few drop down fields whose values need to be set by an initial call to the API but I cannot figure out how to make that call and populate the drop down boxes.

Some Background
I have a content aggregation service that has a dashboard for managing content feeds from different websites. This dashboard allows you to set up groups of feeds, assign templates to those feed groups, and many other things.

In my Joomla component I am building, I need to get some of those dashboard settings using the service's API and allow the Joomla administrator to choose which of those settings to use.

For example, in the content aggregation service's dashboard, you can set up multiple templates for displaying content. Let's assume 3 templates were set up. Now when creating a new content feed action in Joomla, the component needs to offer the choice of which predefined content template to use. So a drop down labeled "Template" with the options [template1, template2, template3] is needed. But how do I populate it with the templates sent back form an API call to the content aggregation system?

It needs to do this in real time since templates and be added and deleted from the content aggregation service's dashboard at any time. I would be OK calling a process that dumps the response form the API call into a lookup table in the Joomla database and then populate the drop down from that table but I am not sure how to do that either.

I have attached what the admin configuration page I am trying to build looks like in a working wordpress plug-in. Look at the Template field as an example.





Here is the response from the API I need to use to populate the drop down:
{
resp: {
status: "OK",
code: 200,
data: {
totalAvailable: 1,
resultList: [
{
templateId: 735,
displayName: "Topic Page Template",
shortCode: "topicpage",
templateSections: [
{
sectionId: 900,
displayName: "Featured"
}
],
templateFields: [
{
displayName: "Placement",
shortCode: "placement",
type: "COMBOBOX",
required: false
},
{
displayName: "Description",
shortCode: "description",
type: "RTE",
required: false
},
{
displayName: "Equine Topic",
shortCode: "topic",
type: "TOPIC",
required: false
}
]
}
]
}
}
}
The administrator has disabled public write access.

Populate Form Options from JSON or Lookup Table 25 Jul 2013 07:10 #10575

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
This is a lot of informations.

For sure the answer is complex and you should provide more details if you want somebody to help you.
You will need to code all this part.

Cook provides an applicative layer with your custom database that almost the only thing it does.
Special features like API integration, will be manually coded at the right place.

If you are new in Cook, first try to create simple component to understand how it works.
Model / Controller / Views ... the best you code (right place), the less you will write.

Maybe your case of study can be splitted in different problematics in different posts.
If you present your problem such way, it is difficult to help you. Please clarify.
Coding is now a piece of cake
The administrator has disabled public write access.

Populate Form Options from JSON or Lookup Table 25 Jul 2013 07:15 #10576

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
I can answer you for the JSON parsing.

uses fsocketopen() to read the http answer.
When you have your JSON answer filled in your response string :
1- Check if the response is not an error.
2- Check if the string is a valid JSON
3- Convert JSON to object
4- Prepare a new array containing those values and send them in JDom (combo) parameters.
Coding is now a piece of cake
The administrator has disabled public write access.

Populate Form Options from JSON or Lookup Table 25 Jul 2013 12:18 #10577

  • jDoyle
  • jDoyle's Avatar
  • Offline
  • New Member
  • Posts: 2
  • Karma: 0
Thanks for the quick response.

To simplify my problem, what I need to do is create a an enumeration field and fill its values dynamically with the result of a web service call.

Your answer about using fsocketopen() and sending the values in JDom is exactly what I needed. That points me in the right direction. Thanks!
The administrator has disabled public write access.
Time to create page: 0.132 seconds

Get Started