How can I get sencha architect to read json from rails - ruby-on-rails-3

I have a Ruby on Rails 3 news app. It takes a title, some content and an image attachment (using the paperclip gem). I'm using the RABL gem to provided a Sencha Architect project with a JSON feed.
The problem is Sencha Architect can't read the JSON url. When I try to load the data into the store I get a very unhelpful message saying 'Unable to load data using the supplied configuration' and a link to open the url in the browser (which opens just fine). Does Sencha Architect have a log somewhere that provides more information about this error?
Here are the RABL files:
# show.rabl
object #article
attributes :title, :body
node(:mobile_url) { |article| article.image.url(:mobile, false) }
node(:tablet_url) { |article| article.image.url(:tablet, false) }
node(:original_url) { |article| article.image.url(:original, false) }
# index.rabl
collection #articles
extends "articles/show"
RABL does not provide a content type by default so I have this in the articles controller:
before_filter :default_format_json
def default_format_json
if(request.headers["HTTP_ACCEPT"].nil? && params[:format].nil?)
request.format = "json"
end
end
This is the code generated by Architect to show the configuration options I have used:
# Stories store
Ext.define('MyApp.store.Stories', {
extend: 'Ext.data.Store',
requires: [
'MyApp.model.Story'
],
config: {
autoLoad: true,
model: 'MyApp.model.Story',
storeId: 'Stories',
proxy: {
type: 'jsonp',
url: 'https://feedr.org.uk/articles.json',
reader: {
type: 'json',
rootProperty: 'article'
}
}
}
});
# Story model
Ext.define('MyApp.model.Story', {
extend: 'Ext.data.Model',
config: {
fields: [
{
name: 'title'
},
{
name: 'body'
},
{
name: 'mobile_url'
},
{
name: 'tablet_url'
}
]
}
});
How can I get Sencha Architect to read my JSON data? Any help you can provide is much appreciated.

Ok, it turns out there is nothing wrong with the Sencha configuration, the problem was with my rails app. I'm using the RABL gem to generate a Json response. RABL needs to be configured to generate a JsonP response in the form of an initializer like so:
# config/initializers/rabl_init.rb
Rabl.configure do |config|
config.include_json_root = false
config.include_xml_root = false
config.enable_json_callbacks = true
end
The important option is enable_json_callbacks = true. It causes RABL to serve the response as JsonP which my Sencha app could understand.

Not sure if this applies, but when i worked with sencha i had to use this in my store
config: {
autoLoad: true,
model: 'UniversityData.model.Person',
proxy:{
type:'ajax',
url: 'persons.json'
},
sorters: ['lastName', 'firstName'],
grouper: {
groupFn: function(record){
return record.get('lastName')[0];
}
}
}
It seems the only difference is
type: 'jsonp' to my type: 'ajax'

Related

Alfresco Share Aikau PathTree to show documents not just folders

I am working on an Aikau Share Page where I a side bar that is using the Alfresco Share document library tree picker. The picker allows me to publish the nodeRef to another widget which will display information. I would like to use the tree view but i'm having trouble showing the documents and it is only showing the containers/folders. Anyone have any idea on what I need to do in order to solve this?
Here is the Aikua code i am using:
{
align: "sidebar",
name: "alfresco/layout/Twister",
config: {
label: "twister.library.label",
additionalCssClasses: "no-borders",
widgets: [
{
name: "alfresco/navigation/PathTree",
config: {
showRoot: true,
rootLabel: "Repository",
rootNode: "/app:company_home",
publishTopic: "ALF_ITEM_SELECTED"
}
}
]
}
}
I am wondering if I need to write an extension to the CoreXhr or what the steps would be in order to make this work.
Any help would be appreciated
I was able to figure this out. The problem comes from the repository script in the alfresco explorer side "treenode.get.js". The solution was to do the following
Create a new webscript in alfresco explorer and copy treenode.get.js code into the new webscript. I ended up calling mine customtreenode.get.js.
Remove the logic check for IsContainer in the newly created webscript
Create new Aikau file that extends PathTree. Here is the code below
define(["dojo/_base/declare",
"alfresco/navigation/PathTree",
"alfresco/documentlibrary/_AlfDocumentListTopicMixin",
"service/constants/Default",
"dojo/_base/lang",
"dojo/_base/array",
"dojo/dom-class",
"dojo/query",
"dojo/NodeList-dom"],
function(declare, PathTree, _AlfDocumentListTopicMixin, AlfConstants, lang, array, domClass, query) {
return declare([PathTree, _AlfDocumentListTopicMixin], {
useHash: true,
getTargetUrl: function alfresco_navigation_Tree__getTargetUrl() {
var url = null;
if (this.siteId && this.containerId)
{
url = AlfConstants.PROXY_URI + "slingshot/doclib/treenodeCustom/site/" + this.siteId + "/documentlibrary";
}
else if (this.rootNode)
{
url = AlfConstants.PROXY_URI + "slingshot/doclib/treenodeCustom/node/alfresco/company/home";
}
else if (!this.childRequestPublishTopic)
{
this.alfLog("error", "Cannot create a tree without 'siteId' and 'containerId' or 'rootNode' attributes", this);
}
return url;
}
});
});
Change your code to use the new CustomPathTree
{
align: "sidebar",
name: "alfresco/layout/Twister",
config: {
label: "twister.library.label",
additionalCssClasses: "no-borders",
widgets: [
{
name: "CustomWidgets/widgets/CustomTreeNode",
config: {
showRoot: true,
rootLabel: "Repository",
rootNode: "/app:company_home",
publishTopic: "ALF_ITEM_SELECTED"
}
}
]
}
}
It works after that. I still need to change the icons from folders to documents.

sencha touch accordion list not loading data

I can't figure out why my data won't load to my AccordionList element from here:
https://github.com/kawanoshinobu/Ext.ux.AccordionList
I'm creating it within a panel like so:
{
xtype: 'accordionlist',
store: Ext.create('Rks.store.Bcks'),
flex: 1
},
It calls a store which is defined like so:
Ext.define('Rks.store.Bcks', {
extend: 'Ext.data.TreeStore',
requires: ['Rks.model.Bck'],
config: {
itemId: 'bks',
model: 'Rks.model.Bck',
defaultRootProperty: 'items',
proxy: {
type: 'ajax',
url: 'path/to/ajax',
},
autoLoad: false,
listeners:{
load: function( me, records, successful, operation, eOpts ){
console.log("data loaded", records);
}
}
}
});
When I call the view which contains the accordion, the console logs what appears to be a good object:
items: [{bck_id:3, author_id:1, title:test, items:[{c_id:2, bck_id:3, title:choice1, leaf:true}]}]
But nothing shows up. The panel is empty and no accordion items show.
However, when I replace the proxy with inline JSON, everything looks fine:
Ext.define('Rks.store.Bcks', {
extend: 'Ext.data.TreeStore',
requires: ['Rks.model.Bck'],
config: {
itemId: 'bks',
model: 'Rks.model.Bck',
defaultRootProperty: 'items',
root: {
items: [
{ bck_id: 1, author_id: 1, title: 'bck1', items: [ {c_id: 1, bck_id: 1, title: 'choice1', leaf: true} ] }
]
}
autoLoad: false,
listeners:{
load: function( me, records, successful, operation, eOpts ){
console.log("data loaded", records);
}
}
}
});
Here the items show up in the accordion. I can't figure out why the second example works and the first doesn't. Is there something special I should be doing when calling the store proxy for Accordion?
UPDATE: I have managed to get the accordion list to display data, but when I change the url of the store and reload it, the store reloads but the accordion list does not update. The accordion list continues to display the data it receives from the first URL, not from reloads with modified URLS.
Thanks
I think I figured this out. For the accordionlist component, you need to do like so:
var accordionlist = Ext.ComponentQuery.query('rdb #rdb1')[0];
var brickstore = Ext.getStore('bcs');
bcs.removeAll();
bcs.getProxy().setUrl('newurl');
accordionlist.setStore(bcs);
accordionlist.load();
basically, manually remove all items, set the new url, set the store on the list, then load the list.
I think there was a problem with your proxy configuration. First, remove the defaultRootProperty config (which is out of proxy config), then try this:
proxy: {
type: 'ajax',
url: (your ajax url),
reader: {
type: 'json',
rootProperty: 'items'
}
},

(New in Sencha 2.2) Data store loading data for large data set freezes app

There is a data store in my app that, on a specific user action, gets loaded with a rather large set of data via a local txt file (100kb total). Prior to my upgrade to Sencha 2.2, loading that data set went rather quickly and there was 0 impact on the app performance.
Now that I've upgraded to Sencha 2.2, loading that data freezes the app completely. Even if I'm running the app on my computer, it takes around 5 minutes for the app to unfreeze.
I've tried two approaches: setData() and loading via a proxy (code below). Both approaches have the same result. I've sifted through the Sencha 2.2 changelog and haven't been able to find any relevant changes to data stores. I'm pretty well at a loss here. Any help would be awesome.
Local proxy approach:
Ext.define("addable_exercises", {
extend: "Ext.data.Model",
config: {
idProperty: 'id',
fields: [
{ name: 'ex_id'},
{ name: 'ex_name'},
{ name: 'ex_alias'},
{ name: 'ex_type'},
{ name: 'prot_type'}
]
}
});
var all_exercises = Ext.create('Ext.data.Store', {
storeId: 'all_exercises',
model: 'addable_exercises',
proxy: {
type: 'ajax',
url: 'resources/textfiles/datastores/all_exercises.txt'
}
});
Ext.getStore('all_exercises').load()
setData() approach:
Ext.define("addable_exercises", {
extend: "Ext.data.Model",
config: {
idProperty: 'id',
fields: [
{ name: 'ex_id' },
{ name: 'ex_name'},
{ name: 'ex_alias'},
{ name: 'ex_type'},
{ name: 'prot_type'}
]
}
});
var all_exercises = Ext.create('Ext.data.Store', {
storeId: 'all_exercises',
model: 'addable_exercises'
});
Ext.Ajax.request({
url: 'resources/textfiles/datastores/all_exercises.txt',
success: function(response, opts) {
var exercise_list = response.responseText;
var all_exercises_store = Ext.getStore('all_exercises');
all_exercises_store.setData(exercise_list);
}
});
Turns out the problem wasn't the actual data store, it was what my code does immediately after loading that store: associating that massive store with a dataview list. In Sencha 2.2, lists are no longer set as infinite by default (which I assume was a performance consideration for short lists), so - as a non-infinite list - it was parsing every list item before displaying anything. With infinite enabled, it lets the items load in the background.
var list = new Ext.dataview.List({
id: 'search_list',
height: 500,
width: 500,
infinite: true,
loadingText:'loading...',
store: 'all_exercises',
itemTpl: [
'<tpl for=".">',
'<div class="feed_item">',
'<div class="avatar">{ex_name}</div>',
'</div>',
'</div>',
'</tpl>'
]
});

How to define and send variable?

im new with Sencha Touch 2 and i have a problem working with drupal, json, etc...
It's simple but i can't take the solution.
I have a list who is completed by a json. This json comes from Drupal7 views in json format.
In my view i have something like that:
var listaArtistas = {
xtype: 'list',
title: 'Artistas',
height: 240,
store: {
autoLoad: true,
fields: ['node'],
proxy: {
type: 'ajax',
url: 'http://localhost/json-artistas',
reader: {
type: 'json',
rootProperty: 'nodes'
}
}
},
listeners: {
itemtap: function(lista,index,target,record,e,eOpts)
{
var artistDetail = new Ext.create('app.view.ArtistDetail');
panelHomeNav.push(artistDetail);
}
},
itemTpl: tpl
};
This code Works for me. And complete de list with the artist.
Now i click in the artist and goes to another view (artistDetail). But to show propertly this list with details of the artist, need the ID of the artist who i cliked before.
I need something like this in artistDetail.... url: 'http://localhost/json-artistasDetail'+NID, where the NID is the ID of the artist who is in the list before.
I don't know how to pass this parameters between 2 views in Sencha
Thanks for help... or read :D
Many options are possible, here is one: after creating the detail view, you could set a dedicated property, as an example:
var artistDetail = new Ext.create('app.view.ArtistDetail');
artistDetail.setArtistID(artistID);
panelHomeNav.push(artistDetail);

I retrieving the data from DB using JSP and I want to display that data list in using senchatouch2?

i have following jsp page.and it is displaying the result.
enter code here
<%#page language="java" import="java.sql.*, java.util.*, java.lang.*, net.sf.json.*, org.json.simple.JSONObject" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/thermo?user=root&password=");
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery("select model_number from product");
JSONObject json = new JSONObject();
JSONArray addresses = new JSONArray();
//JSONObject address =new JSONObject();
while(result.next())
{
//address.put(result.getString("model_number"));
addresses.add(result.getString("model_number"));
}
json.put("Addresses", addresses);
out.println(addresses);
response.setContentType("application/json");
response.getWriter().write(json.toString());
}
catch (JSONException jse)
{
}
%>
and i have following js file.
I got the following Exception when i run the js file.
[WARN][Anonymous] [Ext.Loader] Synchronously loading 'Ext.dataview.List'; consider adding 'Ext.dataview.List' explicitly as a require of the corresponding class
:8080/Sample/sdk/src/log/writer/Console.js?_dc=1334137320671:35
[WARN][Anonymous] [Ext.Loader] Synchronously loading 'Ext.data.proxy.JsonP'; consider adding 'Ext.data.proxy.JsonP' explicitly as a require of the corresponding class
Uncaught SyntaxError: Unexpected token ::8080/new/modelnumber_list.jsp?_dc=1334137328213&page=1&start=0&limit=25&callback=Ext.data.JsonP.callback1:1
enter code here
`Ext.define('Sample.view.Blog',{
extend:'Ext.navigation.View',
xtype:'bloglist',
config:{
title:'Blog',
iconCls:'star',
scrollable:true,
styleHtmlContent: true,
items:{
xtype: 'list',
itemTpl: '{model_number}',
store:{
autoLoad: true,
fields: ['model_number'],
proxy:{
type: 'jsonp',
url: 'modelnumber_list.jsp',
reader:{
type: 'json',
rootProperty: 'root'
}
}
}
}
}
});
Thank you.
try adding this on the app.js not the view, this will remove the warning.
requires: ['Ext.data.Store', 'Ext.data.proxy.JsonP', 'Ext.dataview.List'],
Try adding the following line after xtype:'bloglist',. I think this will take care of the warnings you get.
requires: ['Ext.data.proxy.JsonP'],