I try to use Ext.Direct with the ExtJS 4 MVC structure, and I'm not able to add the provider.
I get the error Uncaught TypeError: Cannot call method 'addProvider' of undefined while calling addProvider:
Ext.Direct.addProvider(Ext.app.REMOTING_API);
I tried both in launch of the application and in initof the controller.
Ext.define('Dir.Application', {
require: [
'Ext.direct.*',
'Ext.data.*',
'Ext.grid.*'
],
launch: function(){
Ext.Direct.addProvider(Ext.app.REMOTING_API);
}
...
});
and
Ext.define('Dir.controller.Main', {
init: function(){
Ext.Direct.addProvider(Ext.app.REMOTING_API);
}
...
});
both give the same error.
Where is the correct location to put addProvider into the code ?
Update: applying the recommendations of #rixo.
Ext.define('Dir.Application', {
view:['Grid'],
requires: [
'Ext.direct.*',
'Ext.data.*',
'Ext.grid.*'
],
launch: function(){
Ext.Direct.addProvider(Ext.app.REMOTING_API);
}
...
});
My view is defining a store and a proxy:
Ext.define('Dir.view.Grid', {
extend: 'Ext.grid.Panel',
store: {
proxy: {
type: 'direct',
reader:{root: 'table'},
api: {
create: QueryDatabase.createRecord,
read: QueryDatabase.getResults,
update: QueryDatabase.updateRecords,
destroy: QueryDatabase.destroyRecord
}
}
...
}
Now the first error is OK, but I receiver an error complaining that QueryDatabase is not defined. It gets defined through the provider at Ext.Direct.addProvider(Ext.app.REMOTING_API); but it is not ready when the view is loaded through the views: [] declaration in the application definition.
Is there a way to get this working without nesting Ext.application inside Ext.onReady like in my solution?
No nesting would be better for the MVC way like explained here in the docs.
The require in your application definition won't do anything. It should be plural requires.
Also, you seem to have devised this in your own answer, but the name Ext.direct.Manager seems to be the favored by Sencha over Ext.Direct now.
Edit
According to the docs, you can set your direct functions using a string. Apparently, this is intended to solve exactly the kind of problems you've run into.
This should work and fix your issue:
api: {
create: 'QueryDatabase.createRecord',
read: 'QueryDatabase.getResults',
update: 'QueryDatabase.updateRecords',
destroy: 'QueryDatabase.destroyRecord'
}
Probably you are missing the API definition before calling the provider, take a look to this definition from Sencha's examples page
Ext.ns("Ext.app"); Ext.app.REMOTING_API = {
"url": "php\/router.php",
"type": "remoting",
"actions": {
"TestAction": [{
"name": "doEcho",
"len": 1
}, {
"name": "multiply",
"len": 1
}, {
"name": "getTree",
"len": 1
}, {
"name": "getGrid",
"len": 1
}, {
"name": "showDetails",
"params": ["firstName", "lastName", "age"]
}], ...}]
} };
It should be included as a javascript file inside your webpage
<script type="text/javascript" src="api.php"></script>
Something like this example.
Hope it helps.
Adding Direct providers is better done before the Application constructor runs:
Ext.define('Foo.Application', {
extend: 'Ext.app.Application',
requires: [
'Ext.direct.Manager',
'Ext.direct.RemotingProvider'
],
name: 'Foo',
constructor: function() {
Ext.direct.Manager.addProvider(...);
this.callParent(arguments);
}
});
Ext.application('Foo.Application');
I found this solution:
Ext.require([
'Ext.direct.RemotingProvider',
'Ext.direct.Manager',
'Ext.data.proxy.Direct'
]);
Ext.onReady(function(){
Ext.direct.Manager.addProvider(Ext.app.REMOTING_API);
Ext.application({
name: 'Dir',
extend: 'Dir.Application'
});
});
It doesn't look really nice, because it uses the ExtJS 4 application instantiation inside a Ext.onReady.
At least it works. Maybe there is a better solution ?
Related
I had to upgrade from 4.1.2 to 5.1.1 for the sole sake of widget columns. I'm having trouble getting hasone associations to work.
I've got a model that looks like this:
Ext.define('PP.model.LM.FOOModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.Field'
],
fields: [
{
name: 'ID'
},
//Boatload of simple fields
],
hasOne: {
model: 'PP.model.LM.FOO1Model',
name: 'FOO1',
associationKey: 'FOO1'
}
});
When I interact with the model, there is no getter \ setter methods, and FOO1Model's data is only present as an object that can be accessed by
record.get('FOO1');
Could someone please point out what exactly am I doing wrong?
I tried doing it with the new approach - creating a field with a reference to the desired model. It works fine when I call setFoo1, and then do a get. But.
When I make an Ajax request, and try reading received JSON using Ext.data.reader.Json, it seems to fail to understand that a certain property in the object is in fact an associated model. The data in Foo1 appears in the model as an object in Foo1 property. The reqest returns an array of models that have many FooModels.
The Json looks like this:
{
"root": [{
"ID": 4241,
"Foos": [{
ID: 2237,
"Foo1": {
"ID": 1216
}
}]
}],
"success": true
}
It seems that hasOne doesn't exist in ExtJS 5.1 it is now done like this:
fields: [{
name: 'addressId',
reference: 'Address',
unique: true
}]
Check Model api for more info.
Had to debug the Ext.data.reader.Json to understand. The key was passing associationKey in reference config. Unless it's specified the reader will assume that the data for the association resides under '_foo1' field in JSON.
Is it mentioned anywhere in sencha docs? I don't think so. Am I supposed to feel like an imbecile for not guessing that?
Sample for unfortunate poor sods like me, who might encounter the problem in future:
{
name: 'Foo1',
reference: {
type: 'FOO1Model',
association: 'Foo1',
associationKey: 'Foo1'
},
unique: true
}
i'm facing some problems when using an extended user model in my AngularJS application.
here is my user.json:
{
"name": "user",
"base": "User",
"strict": false,
"idInjection": true,
"properties": {
"clientType": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
],
"methods": []
}
here is my model-config.json:
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
]
},
"User": {
"dataSource": "mongo"
},
"AccessToken": {
"dataSource": "mongo",
"public": false
},
"ACL": {
"dataSource": "mongo",
"public": false
},
"RoleMapping": {
"dataSource": "mongo",
"public": false
},
"Role": {
"dataSource": "mongo",
"public": false
},
"Store": {
"dataSource": "mongo",
"public": true
},
"user": {
"dataSource": "mongo",
"public": true
}
}
this is my UserCtrl.js
angular.module('app.controllers.user', [])
.controller('UserCtrl', ['user', function (user) {
var vm = this;
vm.addUser = function () {
user.create({
firstName: vm.firstName,
lastName: vm.lastName,
email: vm.email,
password: vm.password,
userType: 'customer'
})
.$promise
.then(function (c) {
console.log('added user: ' + c.email);
});
};
}])
i'm getting the following error:
Error: [$injector:unpr] Unknown provider: userProvider <- user <- UserCtrl
if i use 'User' instead of 'user' it works, but it doesn't use my extended user-model with the specified ACL (READ for everyone)
i've read that you can specify var myUser = app.model.user to make sure that LoopBack uses the extended model. but i don't know how to do that in AngularJS since i specify the model as function parameter in the controller..
can you tell me how to use my extended user model within my AngularJS app?
thanks in advance!!
Do you have your user model generated inside Angular client library? If your application works when you use loopback auto-generated "User" model, then my best guess is that you have created your extended model "user", after you initially generated your angular services. If you are not using grunt task then you should regenerate angular services to update file with all changes and new models that you added since you last time generated the file.
Use lb-ng command to do it. As documentation suggests
For example, if your application has the standard LoopBack project layout, then in the /client sub-directory, enter these commands:
$ mkdir js
$ lb-ng ../server/server.js js/lb-services.js
You can find more information on the following link
http://docs.strongloop.com/display/public/LB/AngularJS+JavaScript+SDK
You need to define a Service, Factory, Provider, Value or Constant called 'user' in order for the service to be injectable in your controller. I do not see either of these in your post.
My suggestion is, if your extended user model is an instance of a class, then use a service:
app.service('user', fn);
If your extended user model is an object literal in JSON format, then use a factory:
app.factory('user', function() { return { ... }; });
Trying to display Milestone for each release, but when trying to create DataStore for Milestone getting error
Uncaught Rally.data.ModelFactory.getModel(): Could not find registered factory for type: milestone
below is my code any ideas or suggestions on this
_getMileStones: function(startDate, endDate, project_id) {
var startDateFilter = Ext.create('Rally.data.QueryFilter', {
property: 'TargetDate',
operator: '>',
value: startDate
});
startDateFilter = startDateFilter.and({
property: 'TargetDate',
operator: '<',
value: endDate
});
startDateFilter = startDateFilter.and({
property: 'TargetDate',
operator: '!=',
value: null
});
startDateFilter = startDateFilter.and({
property: 'TargetDate',
operator: '!=',
value: null
});
var filters = startDateFilter;
Ext.create('Rally.data.wsapi.Store',{
model: 'milestone',
autoLoad: true,
filters: filters,
context: {
project: project_id,
projectScopeDown: true,
projectScopeUp: false
},
fetch: ['Name','FormattedID','DisplayColor'],
listeners: {
load: function(store,records) {
console.log("records values", records);
}
}
}, this);
},
The current stable rc3 release candidate of AppSDK2 predates milestones. They are not available in rc3. When I use rc3 I get the same error you get. If I switch to "x", in the app's config file, and use rab build to rebuild the app, the error goes away:
{
"name": "myapp",
"className": "CustomApp",
"server": "https://rally1.rallydev.com",
"sdk": "x",
"javascript": [
"App.js"
],
"css": [
"app.css"
]
}
Generally it is not recommend using "x" because it is constantly changes. It is not a stable version. But as long as you know that, you may use "x". The AppSDK next release may not be too far in the future, and it will include support for Milestones.
UPDATE: AppSDK2.0 GA has not been announced yet, but it is expected to be released soon. If you use "sdk":"2.0" you get Milestone data.
"x" returns Milestones, but it is a head version that is subject to constant changes. 2.0rc3 does not have Milestones.
You may choose to use 2.0 even though it is not formally available yet.
This app example:
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
launch: function() {
Ext.create('Rally.data.wsapi.Store',{
model: 'milestone',
autoLoad: true,
fetch: ['Name'],
listeners: {
load: function(store,records) {
console.log("records values", records);
}
}
}, this);
}
});
Along with this config:
{
"name": "milestones",
"className": "CustomApp",
"server": "https://rally1.rallydev.com",
"sdk": "2.0",
"javascript": [
"App.js"
],
"css": [
"app.css"
]
}
will return milestone data:
I am trying to display math-equations in a Sencha view component (extends: Ext.Container), using a Ext.Label Component and MathJax JS. (As was suggested answering my other question: Display math symbols in Ext.js / Sencha Touch)
This is the initialization of the view component:
Ext.define('TIQuiz3.view.Question', {
extend: 'Ext.Container',
...
requires: ['Ext.Label', ...],
config: {
fullscreen: true,
...
layout: {
type: 'vbox',
align: 'stretch'
}
},
initialize: function() {
this.callParent();
...
var questionLabel = {
xtype: 'label',
style: {
'border':'1px solid black',
'background':'white'
},
margin: 10,
padding: 10,
html: "<div>Es sei $L = \{011, 01, 11, 100\}$ \"uber dem Alphabet $\Sigma = \{0,1\}$.</div>",
flex: 1
};
...
this.add([...,questionLabel,...]);
}
I have included a local copy of MathJAX in the app.json file:
"js": [
{
"path": "touch/sencha-touch.js",
"x-bootstrap": true
},
{
"path": "bootstrap.js",
"x-bootstrap": true
},
{
"path": "resources/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML",
"update": "delta"
},
{
"path": "app.js",
"bundle": true, /* Indicates that all class dependencies are concatenated into this file when build */
"update": "delta"
}
],
MathJax indicates to be loaded successfully.
But the output of the label does not display math properly. Instead it simply looks like this:
Es sei $L = {011, 01, 11, 100}$ "uber dem Alphabet $Sigma = {0,1}$.
Is displaying math with MathJax and HTML possible using a Sencha Label Component?
Any advice appreciated!
Thanks,
Thomas
Ok, thanks Peter, that brought me to the solution.
The problem was indeed the rendering of the content after the onload-event of the page.
For these cases MathJax holds a method to invoke the typesetting manually at a later time. So what I did was adding the following afterPainted-Listener to the rendered view component:
listeners : {
order : 'after',
painted : function() {
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
}
Note that, as Peter pointed out, in order for the upper to work one has to configure $ to be accepted as math delimiter from MathJax - which is not default behaviour.
Thanks for the advice!
I am working in extjs4 MVC. I am getting stuck at a point where I have been working on association.Association is working properly when I am using in my system local side.But when I am uploading it to server side then the associated data is not displaying.I am trying a lot but not getting answer how this conflict occurs.
My application is working properly at client side.It displays associated data also.But when when I uploading data to server side then it does not display associated data.
Here is my application's some part which is working at local side:--
But when I am uploading my side to server side then the options means associated data is not displayed
Here Is my some code:--
1) Model class :--
Ext.define('B.model.kp.PollModel',{
extend: 'Ext.data.Model',
idproperty:'',//fields property first position pk.
fields: ['pollId','pollQuestion','isActive','pollTypeId','createDate','userId','publishDate','isPublished','approvalUserId','percentagevotes','optionId'],
hasMany:{
model:'B.model.kp.PolloptionModel',
foreignKey:'pollId',
name:'options',
},
proxy:
{
type:'ajax',
api:
{
read:'index.php/KnowledgePortal/Poll/GetPublicPoll',
create:'index.php/KnowledgePortal/Pollvote/setPollVote',
},//End of api
reader:
{
type:'json',
root: 'polls',
//successProperty: ,
},//End of reader
writer:
{
type:'json',
root: 'records',
//successProperty: ,
},
}//End of proxy
});
2) Store class :--
Ext.define('B.store.kp.PollStore',{
extend: 'Ext.data.Store',
model: 'B.model.kp.PollModel',
autoLoad: true,
});//End of store
3) View class:--
Ext.define('B.view.kp.poll.PollView',{
extend:'Ext.view.View',
id:'pollViewId',
alias:'widget.PollView',
store:'kp.PollStore',
config:
{
tpl:'<tpl for=".">'+
'<div id="main">'+
'</br>'+
'<b>Question :-</b> {pollQuestion}</br>'+
'<tpl for="options">'+
'<p>{#}.<input type="radio" name="{parent.pollId}" value="{optionId}"> {option}</p>'+
'</tpl></p>'+
'</div>'+
'</tpl>',
itemSelector:'div.main',
},
});// End of login class
4) here is my main view class
Ext.define('B.view.kp.poll.Poll',{
extend:'Ext.form.Panel',
requires:[
'B.view.kp.poll.PollView'
],
id:'pollId',
alias:'widget.Poll',
title:'Poll',
//height:180,
items:[
{
xtype:'PollView',
},
],//end of items square
buttons:[
{
disabled:true,
name:'vote',
formBind:true,
text:'vote',
action:'voteAction'
},
{
text:'result',
action:'resultAction',
}
]
});
5) And here is the json file --
{
'polls': [
{
"pollId": 1,
"pollQuestion": 'Who will win the match',
"options": [
{
"optionId":1,
"option":'India',
"pollId":1
},
{
"optionId": 2,
"option": 'Pakistan',
"pollId":1
},
{
"optionId": 3,
"option": 'Srilanka',
"pollId":1
},
{
"optionId": 4,
"option": 'Australia',
"pollId":1
},
],
}
]
}
6) PollOption model class :--
Ext.define('B.model.kp.PolloptionModel',{
extend: 'Ext.data.Model',
//idproperty:'',//fields property first position pk.
fields: ['optionId','option','pollId','percentagevotes'],
associations:[
{type:'HasMany', model:'Pollvotemodel', foreignKey:'optionId'},
{type:'BelongsTo', model:'PollModel', foreignKey:'pollId'},
]
});
Please someone give me some suggestion to solve this problem...
are you sure your server-side data feed is exactly the same as your local data feed.
Are the related questions entered into the live database?