I want to display an extjs combo with a JsonStore
Server side I use python/Django.
So, this is my combo:
xtype: 'combo',
store: new Ext.data.JsonStore({
url: 'get_peoples',
root: 'data',
totalProperty: 'total',
fields: [
{name: 'name', mapping: 'fields.name'},
{name: 'subname', mapping: 'fields.subname'}
],
autoLoad: true
}),
trigerAction: 'all'
and the views.py server side:
def get_peoples(request):
queryset = People.objects.all()
data = '{"total": %s, "%s": %s}' % \
(queryset.count(), 'data', serializers.serialize('json', queryset))
return HttpResponse(data, mimetype='application/json')
the get_people call give me
{"total": 1, "data": [{"pk": 1, "model": "myapp.people", "fields": {"name": "Paul", "subname": "Di Anno"}}
I think i'm not doing it right, cause my combo doesn't display any item
You need to add displayField and valueField declarations to your ComboBox so that it knows which fields from your store to use for either role. Also, setting autoLoad in the store is not necessary.
new Ext.form.ComboBox({
xtype: 'combo',
store: new Ext.data.JsonStore({
url: 'get_peoples',
root: 'data',
totalProperty: 'total',
fields: [
{name: 'name', mapping: 'fields.name'},
{name: 'subname', mapping: 'fields.subname'}
]
}),
triggerAction: 'all',
// Just guessing at the proper fields here.
// Set them to whatever you wish.
displayField: 'name',
valueField: 'subname'
});
Related
I'm trying to create new project sheets in a folder, however I can't find a way to ensure the sheet is a project sheet.
Here is my code so far:
def create_resource_sheet(name):
""" Create a new resource sheet.
:param name:
:return:
"""
folder_id = get_resource_folder_id()
# TODO: Find and delete existing sheet with this name
resource_sheet = SS.models.Sheet({
'name': name,
# 'gantt_enabled': True, # This was added as an attempt to force it to a project sheet, but error 1032
'columns': [{
'title': 'Task',
'type': 'TEXT_NUMBER',
'primary': True,
'width': 200
}, {
'title': 'Status',
'type': 'PICKLIST',
'options': ['wtg', 'hld', 'ip', 'rdy', 'rev', 'fin', 'omt'], # TODO: Update this list
'width': 180
}, {
'title': '% Complete',
'type': 'TEXT_NUMBER',
'tag': ['GANTT_PERCENT_COMPLETE'],
'width': 85
}, {
'title': 'Assigned To',
'type': 'CONTACT_LIST',
'tag': ['GANTT_ASSIGNED_RESOURCE', 'GANTT_DISPLAY_LABEL'],
'width': 150
}, {
'title': '% Use',
'type': 'TEXT_NUMBER',
'tag': ['GANTT_ALLOCATION'],
'width': 60
}, {
'title': 'Days',
'type': 'DURATION',
'tag': ['GANTT_DURATION'],
'width': 70
}, {
'title': 'Start',
'type': 'ABSTRACT_DATETIME',
'tag': ['CALENDAR_START_DATE', 'GANTT_START_DATE'],
'width': 80
}, {
'title': 'Start',
'type': 'ABSTRACT_DATETIME',
'tag': ['CALENDAR_START_DATE', 'GANTT_START_DATE'],
'width': 80
}, {
'title': 'Finish',
'type': 'ABSTRACT_DATETIME',
'tag': ['CALENDAR_END_DATE', 'GANTT_END_DATE'],
'width': 80
}, {
'title': 'Type',
'type': 'TEXT_NUMBER',
'width': 150
}, {
'title': 'Comments',
'type': 'TEXT_NUMBER',
'width': 700
}
]
})
response = SS.Folders.create_sheet_in_folder(folder_id, resource_sheet)
new_sheet = response.result
return new_sheet
I am getting the following error code:
smartsheet.exceptions.ApiError: {"result": {"shouldRetry": false,
"code": 1142, "name": "ApiError", "errorCode": 1142, "recommendation":
"Do not retry without fixing the problem. ", "message": "Column type
DURATION is reserved for project sheets and may not be manually set on
a column.", "refId": "6gurrzzwhepe", "statusCode": 400}}
Is there a way I can create project sheets from scratch?
I have tried setting gantt_enabled to true but that just triggered a different error, so did setting 'project_settings'.
I have tried creating the sheet with just the primary column, then update_sheet to set project settings, which tells me: To set projectSettings, you must first enable dependencies on the sheet.
I have tried setting dependencies enabled, both directly in the create_sheet and in update_sheet, but both return: The attribute(s) sheet.dependenciesEnabled are not allowed for this operation.
I'm going to keep trying things, but I'm getting out of ideas.
Create the sheet from a template, either using the global project template or a user defined template if you want to customize.
templates = SS.Templates.list_public_templates()
for template in templates.data:
if template.global_template ==
smartsheet.models.enums.GlobalTemplate.PROJECT_SHEET:
break
sheet = smartsheet.models.Sheet({
'name': name,
'from_id': template.id
})
resource_sheet = SS.Folders.create_sheet_in_folder(folder_id, sheet)
If you want to customize create a project sheet using the Smartsheet web UI, make your changes and then Save As Template. Once you have the template, grab the ID from the Properties if you don't want to search for it, or SS.Templates.list_user_created_templates().
You cannot create a new dependency-enabled sheet through the API. You'll need to manually create a template and then use the API to make a copy.
I have a ember data model like this:
var attr = DS.attr,
hasMany = DS.hasMany,
belongsTo = DS.belongsTo;
App.Message = DS.Model.extend({
partner_pk: attr(),
message: attr(),
user: belongsTo('user', {async: true}),
inquiry: belongsTo('inquiry', {async: true}),
created_at: attr(),
updated_at: attr()
});
and route returning array of data like this:
App.TripMessagesRoute = Ember.Route.extend({
model: function(){
return this.store.find('message', {inquiry_id: 2});
}
})
My rest-api return data like this format:
{
"data": [
{
"id": 10,
"message": "this message is updated by ember.js",
"inquiry_id": 2,
"user_id": 1,
"created_at": "2014-08-05 14:20:46",
"updated_at": "2014-08-05 14:20:46"
},
{
"id": 17,
"message": "this is a test message by ember.js",
"inquiry_id": 2,
"user_id": 39,
"created_at": "2014-08-26 17:34:55",
}
]
}
in my template I am displaying the properties like this:
<script type="text/x-handlebars" data-template-name="trip/messages">
<h2>message is: {{message}}</h2> <!-- This works fine -->
<h2>User id: {{log user}}</h2> <!-- it gives null -->
<h2>User id: {{log user_id}}</h2> <!-- it gives undefined -->
</script>
My question is how do I display user_id in my template. Thanks in advance.
By default the property name in your Model definition should match the property being returned in your JSON.
Your choices are...
change your model to look like user_id: belongsTo('user', {async: true})
change your JSON to look like "user_id": 39
Add a MessageSerializer and change the object from user_id to user in the serializer.
You should then be able to put something like {{user.id}} in your template.
i have very simple newbie questions params hashs here, this is the following code of params hash from my view,
{ name: 'name supplier',
fax: 'fax supplier',
contact_persons: [
{name: 'contact person 1', value_number: '123456', value_type: 'mobile phone'},
{name: 'contact person 2', value_number: '123456', value_type: 'mobile phone'},
{name: 'contact person 3', value_number: '123456', value_type: 'email'},
{name: 'contact person 4', value_number: '123456', value_type: 'bb'}
]
}
i want to save it on db, but how i do that, its not just simple ContactPerson.new(params[:contat_persons]) right??
Assuming you have a has_many relationship between your Supplier and ContactPerson you could do something from supplier.rb like:
params[:contact_persons].each { |person| contact_persons.build(person) }
contact_persons.save
I'm trying to use Ember App Kit with Ember Data (I'm using the latest of Both) using Fixtures - but for some reason I'm getting the following:
Assertion failed: No model was found for 'todo' [VM] ember.js (4005):415
Error while loading route: TypeError {} [VM] ember.js (4005):415
Uncaught TypeError: Cannot set property 'store' of undefined ember-data.js:2182
Application
import Resolver from 'resolver';
import registerComponents from 'appkit/utils/register_components';
var App = Ember.Application.extend({
LOG_ACTIVE_GENERATION: true,
LOG_MODULE_RESOLVER: true,
LOG_TRANSITIONS: true,
LOG_TRANSITIONS_INTERNAL: true,
LOG_VIEW_LOOKUPS: true,
modulePrefix: 'appkit', // TODO: loaded via config
Resolver: Resolver
});
App.initializer({
name: 'Register Components',
initialize: function(container, application) {
registerComponents(container);
}
});
App.ApplicationAdapter = DS.FixtureAdapter.extend();
export default App;
Index Route
import Todo from 'appkit/models/Todo';
var IndexRoute = Ember.Route.extend({
model: function() {
return this.store.findAll('todo');
}
});
export default IndexRoute;
Todo Model
var Todo = DS.Model.extend({
'title': DS.attr('string'),
'user': DS.attr('object'),
'comment': DS.attr('string'),
'mood': DS.attr('string')
});
Todo.FIXTURES = [{
'title': 'Received Hardware!',
'user': { 'username': 'alvincrespo' },
'comment': 'Finally received my hardware!',
'mood': 'happy'
}, {
'title': 'This is honorable.',
'user': { 'username': 'robwolf' },
'comment': 'I regret it already.',
'mood': 'happy'
}, {
'title': 'I can\'t seem to speak',
'user': { 'username': 'catstark' },
'comment': 'Wait a minute, why am I hear?',
'mood': 'sad'
}, {
'title': 'Attendance is poor.',
'user': { 'username': 'cerlan' },
'comment': 'Kings landing seems pretty empty after the war.',
'mood': 'neutral'
}];
export default Todo;
I've declared the DS.FixtureAdapter in app.js but for some reason its still not working? Any ideas?
Thanks!
I'm not positive about what the register components pieces does. But essentially it's saying it doesn't know about the Todo Model (generally it find it by looking for model's described in its namespace, aka App.Todo = DS.Model.extend....)
You might also need to still declare the store.
App.Store = DS.Store.extend();
And in Ember Data 1.0 beta 1 you do the adapter like so
App.ApplicationAdapter = DS.MyRESTAdapter; // note you don't extend/create it
My server returns a JSON response like this:
{
artists: [{
id: "1",
first_name: "Foo",
last_name: "Bar"
}],
studios: [{
id: 1,
name: "Test",
// ...
artist_ids: ["1"]
}]
}
'artist' is in fact a User model but with a different name. How can I map artist to the User model? Maybe a bad explanation but if I rename the JSON response serverside to 'users' instead of 'artist' and use the models below everything works like I want. I simply want to use the name 'artist' instead of 'user', both server side and client side. Hope you guys understand what i mean.
App.Studio = DS.Model.extend
name: DS.attr 'string'
// ..
users: DS.hasMany 'App.User'
App.User = DS.Model.extend
firstName: DS.attr 'string'
lastName: DS.attr 'string'
studio: DS.belongsTo 'App.Studio'
I guess that the simplest thing to do would be something like artists: DS.hasMany 'App.User' but obviously this does not work.
First, I recommend using the latest Ember / EmberData, so relationships are defined like this:
App.Studio = DS.Model.extend({
name: DS.attr('string'),
// ..
users: DS.hasMany('user')
});
App.User = DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
studio: DS.belongsTo('studio')
});
Next, I recommend using the ActiveModelAdapter if you are getting underscores in your response JSON:
App.ApplicationAdapter = DS.ActiveModelAdapter;
Finally, overriding typeForRoot and keyForRelationship in a custom serializer should fix your issue:
App.ApplicationSerializer = DS.ActiveModelSerializer.extend({
typeForRoot: function(root) {
if (root == 'artist' || root == 'artists') { root = 'user'; }
return this._super(root);
},
keyForRelationship: function(key, kind) {
if (key == 'users') { key = 'artists'; }
return this._super(key, kind);
}
});
Example JSBin
One last thing: you can even get rid of the custom keyForRelationship if you name the relationship artists in Studio:
App.Studio = DS.Model.extend({
name: DS.attr('string'),
// ..
artists: DS.hasMany('user')
});
Have you tried just creating an Artist model extended from User?
App.Artist = App.User.extend({})
I haven't tried it, but I suspect that might work.