Active node on Fanytree Init - javascript

I am trying to activate a node of the tree generated by the fancytree using Javascript. I am using flask as server side framework and passing the key as a server side variable. As mentioned on http://wwwendt.de/tech/fancytree/demo/index.html#sample-api.html, I am using the following script:
$("#tree2").fancytree("getTree").activateKey('{{key}}');
However, this does not activate any key in spite of the key being present.
P.S. I am customizing my key using alphanumeric code in the source ajax data for fancy tree.

Your code looks ok, given that the selector exists and '{{key}}' resolves to an existing key (you might want to check that using console.log(...)).
Note that the nodes are only available, after the ajax request has returned, so you only can lookup those nodes in the tree.init event or after this happened.

Related

Issue in Fetching the Data from Apache Ignite using Node Express

I am new to Apache Ignite.Can someone help me on how to fetch and load the data from ignite cache
using node js without using sql field queries option. Cache is loaded using CacheJDBCPOJO Store and the Key and Value types are custom types defined using JAVA.As these classes are defined in Java not sure on how to fetch the data using node.
Hope the following example , explains the issue better.
We have ignite cache of custom key Type i.e Person Key with attributes Person First Name and person Last Name and custom value type i.e Person Info with attributes Person Address and Person Age etc.
These classes are defined in Java and the caches are configured in Bean File and loaded using CacheJDBCPOJO Store.
As these classes will not be available in node js, how can we load /fetch the data from node js using cahe.put /cache.get.Tried creating similar classes in node and pass the object of these classes to
cahe.put /cache.get but it is in't working.
I can see the following error:
ERROR: Binary type has different field types [typeName=OrderId, fieldName=OrderID, fieldTypeName1=long, fieldTypeName2=double] (node:13596)
Which will probably be fixed by removing ignite work dir (/tmp/ignite/work or ./ignite/work by default) and restarting all your nodes, and as such, not related directly to node.js
As for examples, have you tried the following:
https://apacheignite.readme.io/docs/nodejs-thin-client-binary-types
As for REST API, it should convert BinaryObject's to JSON by default, this should include all SQL columns' values.
Update: Turns out you have to do query.setIncludeFieldNames(true) to make getFieldNames() return field names.

How to add a read/write customRestService to support editing in Dojo DataGrid?

I am trying to develop a Dojo DataGrid that returns a user's documents from the categorized BidsByDriver view and allows them to edit the Priority field in the grid. After getting past the hurdle of using the keys property to filter over the categoryFilter, this was easy to set up using an xe:viewFileItemService read/write service. However the problem with xe:viewFileItemService as a data source is it will display empty lines for each entry in the view after showing the user's documents in the grid.
To get around the blank lines I went down the path of creating an xe:customRestService that returned the jasonData for just the current user's documents. This fixes my blank lines problem but my data source is not in the correct read/write format to support the in-grid editing.
Here is the resulting Json data returned form the xe:customRestService ...
[{"Driver":"ddd","BidID":"123","Priority":"1","Trip":"644"},
{"Driver":"ddd","BidID":"123","Priority":"2","Trip":"444"},
{"Driver":"ddd","BidID":"123","Priority":"4","Trip":"344"},
{"Driver":"ddd","BidID":"123","Priority":"4","Trip":"643"}
]
Here are the Dojo modules I am loading:
<xp:this.resources>
<xp:dojoModule name="dojo.store.JsonRest"></xp:dojoModule>
<xp:dojoModule name="dojo.data.ObjectStore"></xp:dojoModule>
</xp:this.resources>
And here is the script to develop the data store for the grid:
<xp:scriptBlock id="scriptBlock2">
<xp:this.value><![CDATA[
var jsonStore = new dojo.store.JsonRest({target: "InGridCustom.xsp/pathinfo"});
var dataStore = dojo.data.ObjectStore({objectStore: jsonStore});
]]></xp:this.value>
</xp:scriptBlock>
All of this works very nicely except for the bit on providing the in-grid editing support. Any ideas appreciated.
How are you trying to save the changes? With a custom REST service, I would not expect that saving the data store would make any changes to the back-end data, which is why a refresh would revert it to the original value.
I would expect that you'd need to write a doPost method in your custom REST service to process the change on the server side, along with client-side code to call the post method and pass in the updates to process (along with the document ID).
UPDATED ANSWER:
I would try one or both of these approaches to fix your issue.
1) Have a category in your view, and use a categoryFilter and use the hack to make the service only return the correct values. Outlines in this question: XPages Dojo Grid editable cell does not save value when REST Service save() method is called
2) Change the rest service type to viewJsonService in combination with #1. If you get an error, double check the configuration document that Per mentioned. Also heed Per's comments in the linked question relating to configuration and using Firebug to make sure the correct method is used. The update must be a PUT, a POST will not work with the viewJsonService.
Original Answer (for context of comments)
Paul,
I believe that you need to have a button with code to save the changes back. Maybe you do, but you don't mention it and it isn't in your screen shots. The step that Per mentioned is very necessary so it is good that you have it taken care of. The button is necessary, to 'commit' the changes back. The act of inline editing doesn't trigger the PUT call. If you think about it, you wouldn't want an update after each change but one update when the user is finished editing.
If you don't figure out by this evening, I have working code that I can send you, but don't have access to at work.

Live updating from JSON

I have a JSON file which is dynamically and contain match info including an unique id. The JSON is divided into 3 arrays live, upcoming and recent. Since i'm quite new to Javascript i'm wondering what would be the best way to go in order to make this livescore script. I need it to be updating without refreshing browser? What is my options? Maybe someone has a snippet?
The JSON is automatically updates through another script which is connected to a cron job, so the script does not need to do anything regarding the JSON. Only retrieve and show the data.
I'm using dreamhost, which gives me access to shell, so websockets and so on is an option.
You'll need a jquery user to give you a snippit for this one, but in vanilla ecmascript 6, you use an XMLHttpRequest object to get the JSON from your server. This object can request data from the server asynchronously and is triggered by the client/browser so you can update the live match info when and as often as you like. You would just have to write a function to replace the data on the webpage with the new info when it is updated.

JavaScript code on rails console

I use binding.pry in somewhere in Cabypara code for debugging, and i want to check the value of html element using jQuery.
I can't use debugger, then check the value from browser, because this code is Cabybara code for testing as example:
When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
select(value, :from => field)
binding.pry
end
How can i check the value of this field by jQuery code as $("##{field}").val() on rails console ?
This answer depends on #apneadiving's comment:
Rails console used for server side only, not for client side, these helper links:
Ruby-on-Rails is server side.
Rails console is useful for testing out quick ideas with code and changing data server-side without touching the website.
You can call binding.pry while Rails is rendering your view, even in the javascript portion of the view.
This is not going to give you access to the the client side code. Like #apneadiving and #mohamed-yakout stated you can't access the client from the server, but it can give the the access to all of the server side information that is available at that moment in the rendering process.
erb:
<script>
// some javascript...
"<% binding.pry %>"
</script>
// Note: You can not do this from `.js` files that are assets of the view without
// adding the `.erb` extension to the javascript files.
This may be helpful in checking values being utilized by JQuery or Javascript and verifying that they are being built correctly at this step in the process. Ex: verifying the collection being used to generate the rows of a table
In your case you could verify the value of field, but not the value of the element found by the id being passed by the field variable.
$("##{field}").val()
This can be helpful when the result of "##{field}" is giving an #unexpected result instead of an #expected one, since you can't access the server side code from the client to determine the rendering problem.
Note: This translates to Slim as well
javascript:
// some javascript...
"#{binding.pry}"

i18n in javascript using .properties file

I'm developing a web application with JSF, so I use a Java Properties File (i.e. resources_es_CO.properties) to localize strings for the application and this is working OK.
Mi question is: how can I call localized strings in this kind of files from my javascript validations so alerts show those localized strings to user?
Thanks in advance.
What I do is to send the messages out as part of the page, dropped into hidden <span> tags with "id" values made from the property names.
Alternatively, you could write an Ajax-called action and fetch the properties dynamically.
To do an ajax callback, you'd have to implement a server-side action that would understand something like the property key. The server would just apply the localization (ie look up the property in the locale associated with the session) and then return the string. Alternatively, you could implement a service that'd return a whole set of properties, maybe on a per-form basis, or grouped according to some convention of property names (like, "return all properties that start with 'validation.addressForm'")
The simplest case would look something like this with jQuery:
$.get('/fetchProperty', { property: 'firstNameMissing' }, function(propValue) {
$('#errMsg').text(propValue);
}, "text/plain");
Other frameworks provide similar ajax tools, or you could do the XMLHttpRequest yourself.
you could go to server with an ajax call and send alert texts from server to client and show it. or you could put messages to your page when your jsp's being rendered. both is ok. if you can change language without refreshing the page you probably want to make ajax call. if you can not , putting messages in javascript variables will be easier

Categories

Resources