Javascript Populate list from REST - javascript

I am new to JS but have had some success using the ESRI API to make some web map applications. I am now attempting to step into an application that is going to require some pure JS and am looking for advice on what method to use. I want to create a drop list of unique values contained within a field from a REST data source. Once the user clicks on a value in the list, that value would be passed to a definition query on the REST to display only that data. I am fine with the definition query, but how do I get started with creating the list and collecting the selected value to pass to the query. Any help or assistance is greatly appreciated

I would suggest looking into some client-side templating engines like mustache, handlebars, etc. You can run a template method against your json data and then append the result into the dom anywhere you like.

Related

Alfresco custom UI controls - Associations

I'm trying to build a custom UI control in alfresco to display the associations of an object type that I have.
Basically I have two object types; Code, which is a key value pair, and CodeScheme which contains multiple child associations to codes, it's essentially a mirror of a map structure I have in a different system.
The problem I have is that the codes are automatically generated, so they get the UID names, whereas really I'd like to present them as 'key=value', 'key=value', etc (ideally I'd like to present it as a table).
I've already created a custom control and added it to share-config-custom, and confirmed that the configuration is working correctly. What I'm not really clear on now is:
a) How to attach a javascript to the control so that I can process the association data.
b) How to get hold of the codes in javascript, and read their properties.
I'm just looking for a push in the right direction.
Thanks :)
One idea would be to use a form filter. Your form filter could iterate over the child references, fetch each child node, grab the data you want to display and then add one or more new properties with that data.
Then, your form control is hooked to the fields your form filter dynamically added to the form data. It can then read and display the data as needed.
Without a form filter I think you'd have to use JavaScript to parse the child association refs and use AJAX calls to fetch each child's node data, then format that as needed. The form filter idea would be less traffic from the browser.

Get site collection lists based on a custom content type using javascript CSOM (JSOM)

I need to retreive all the lists (list names) that use a specific custom content type in a site collection. I thought this would be easy using the SharePoint API but I cannot really find how.
Off course, the alternative would be to search recursively for all the lists of the webs and check their content types names but I would rather not do this.
Thank you in advance.

Spring-mvc + Thymeleaf: dealing with complex form

I'm working on an internal tool using spring-mvc and thymeleaf.
A section of this tool is used to create an entity we save in the database.
This entity is quite complex; it contains many properties and relations. Some of these relations contain list and other properties.
I have 2 constraints:
Single page. No "wizard".
To only save a completed object in the database.
Now, I'm not really asking for a specific issue. I know my way around thymeleaf, spring #ModelAttribute, etc.
My question is mostly which strategy are you choosing or how to deal with really complex object creation.
Now I can see 3 ways to do it :
Rendering page with thymeleaf. Every time a new element need to be added to a list, I use Ajax to add the new element on the server and rerender the specific fragment. So doing back and forth to the server with my #ModelAttribute and only save at the end.
Rendering a basic page with thymeleaf. Using JavaScript to create html elements and instead of submitting to a #ModelAttribute, I'm serializing my form to JSON and submit this JSON to the server. (kind of client side model)
Rendering a basic page with thymeleaf. Create the html element dynamically with JavaScript when I need to add list item (being sure I'm putting proper name="" to fit with my Java form object) and submit the whole thing at the end.
I'm personally unsure between 1 or 2.
I feel dealing with complex object is much more easier using JSON than form submission. Also, the input value/field with sub object and property can be quite nasty. Having this kind of syntax
does not sound great to me...
3 can probably work but the way spring data binding is done with sub property is lacking some detail in my humble opinion (section 7.4.1 - http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html).
What do you think ?
Personally I use Thymeleaf's own dynamic field management to ensure clean addition of objects and fields to object.
So I will recommend option 4: Dynamic Field management by Thymeleaf.
Have a read of http://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#dynamic-fields.
I use that for both single field additions as well as addition of nested forms. Does the trick no questions asked.
Hope that helps.

Accessing a List object stored as a session variable in javascript

I have a list of id's stored in my ASP.NET application's session. For contextual purposes:
This is a facebook-like chat module. Id's are relevant to individual chat tabs.
jQuery is handling many things and requires the specific id of each box.
When a new chat session is created, it is given an id on the serverside used for client-side interaction like jQuery event binding
The program works fine I just need a way to access the list on the front-end. I would assume converting the object to a json object makes the most sense but I'm not quite sure where to start.
You can always render server-side content to the client by doing something like:
var ids = '<%= Session["Keys"].ToString() %>';
And then split the results and convert them however you want them. It really depends on what the ID's look like (just numbers, or is more info involved), and how you use them, so it's hard to provide additional advice without more information about the structures.
Add this to your project http://www.nuget.org/packages/Newtonsoft.Json then review this resource http://james.newtonking.com/projects/json/help/index.html?topic=html/SerializingJSON.htm to work out how to do the serialize/deserialize operations ;o)

Passing data between elements in UI

I'm new to web applications and am trying to understand the best way to work with data in HTML. I'm using Appengine (Python) and have managed to load a bunch of data to the view. In the simplest form, it's a set of movie names and each name has associated details with it (e.g. year, rating etc). Now how do I pass data between the movie link and then a div where all the details will be displayed? I'll be using jQuery for some controls in my application so I'm wondering if there's a way to do data binding to controls with that?
Additionally, can anyone tell me what're the standards around this i.e. if I load all this data to the UI in one call (assuming it's not a lot of movie titles), wouldn't it make it easy for people to screen scrape this information? Or is there some obfuscation that's typically used here?
Sorry if I'm not very clear but I really am an absolute beginner with web development!
Update1:
I found the jQuery data() api. It seems like this'll work. Comments?
Update2:
Some testing later and it turns out that data() actually attaches the data to the elements rather than showing it in a div itself.
There's a few ways to do it but the basic idea is to put the data in the HTML in a way that is not visibly rendered, then use Javascript to parse the HTML and pull the data out when you need it.
The easiest way on modern browsers is to use data- attributes. These are any attribute that start with data-, and you can name the rest yourself. For example:
Czar Wars
In this case, the user will only see a link called "Tsar Wars" but your javascript can easily access the data- attributes to get the data it needs. The other benefit of this approach is that jQuery will automatically make data- attributes accessible by the data() api.
Another way to do it is to have a hidden HTML list element with all your data elements in the list, but you'll have to parse this all yourself.
There's no standard obfuscation. You'll need to obfuscate yourself on the server side, and unobfuscate in your JS. It's not too difficult to figure out any obfuscation algorighm in js, so this is not worth your while.
If the data really is private, then you would have to architect it as to do all the processing on the server. For example, only show tokens (like 1234), and use AJAX calls to pass the token to the server so the server can do the data processing and spit back publicly safe results to the script.

Categories