How can I allocate different ID or class to my list item? - sencha-touch

First, I apologize for my poor English.
I am trying to build a list where each item has a different ID or class, because I want to control which items are displayed (hidden or visible).
Can anyone help?
I will be grateful!

Ext.define('Contact', {
extend: 'Ext.data.Model',
config: {
fields: ['firstName', 'lastName']
}
});
var store = Ext.create('Ext.data.Store', {
model: 'Contact',
sorters: 'lastName',
data: [
{ firstName: 'Tommy', lastName: 'Maintz' },
{ firstName: 'Rob', lastName: 'Dougan' },
{ firstName: 'Ed', lastName: 'Spencer' },
{ firstName: 'Jamie', lastName: 'Avins' },
{ firstName: 'Aaron', lastName: 'Conran' },
{ firstName: 'Dave', lastName: 'Kaneda' },
{ firstName: 'Jacky', lastName: 'Nguyen' },
{ firstName: 'Abraham', lastName: 'Elias' },
{ firstName: 'Jay', lastName: 'Robinson'},
{ firstName: 'Nigel', lastName: 'White' },
{ firstName: 'Don', lastName: 'Griffin' },
{ firstName: 'Nico', lastName: 'Ferrero' },
{ firstName: 'Nicolas', lastName: 'Belmonte'},
{ firstName: 'Jason', lastName: 'Johnston'}
]
});
Ext.create('Ext.List', {
fullscreen: true,
itemTpl: '<div class="contact custom_class_{firstName}">{firstName} <strong>{lastName}</strong></div>',
store: store
});
by using above code you can add custom css classes to every item in list view, just specify custom_class_{uniqueid of model} for every node and then you can access it using Ext.DomQuery.select('div{class=contact custom_class_{firstName}}'); and then you traverse the DOM to get the parent element which you can use it to hide list item
var div = Ext.DomQuery.select('div{class=contact custom_class_{firstName}}');
var listItem = div.up().up();

Related

Vue Tables 2 custom row style

So I'm using vue tables 2 and found little problem.
Let's assume Im getting list of items and they have column called status, each status is constant and now I need to get translated values so making here relation status=key(constant).
Table with translated values has color which I'd like to use to fill row.
I see in documentation that there is rowClassCallback, but I'd to return inline style like: background-image: $color (for selected status).
Even in this function (rowClassCallback) I can't check value of color because it's in data.
Here in options rowClassCallback is example what I'd to make.
Vue.use(VueTables.ClientTable);
new Vue({
el: "#app",
data: {
columns: ['name', 'code', 'uri'],
data: getData(),
options: {
headings: {
name: 'Country Name',
code: 'Country Code',
uri: 'View Record'
},
editableColumns: ['name'],
sortable: ['name', 'code'],
filterable: ['name', 'code'],
rowClassCallback: row => {
return `background-color: ${this.getProperColor(row.id)}`;
}
}
},
methods: {
getProperColor(id) {
if (id === 245) {
return "#32CD32"
}
}
},
});
function getData() {
return [{
code: "ZW",
name: "Zimbabwe",
created_at: "2015-04-24T01:46:50.459583",
updated_at: "2015-04-24T01:46:50.459593",
uri: "http://api.lobbyfacts.eu/api/1/country/245",
id: 245
}, {
code: "ZM",
name: "Zambia",
created_at: "2015-04-24T01:46:50.457459",
updated_at: "2015-04-24T01:46:50.457468",
uri: "http://api.lobbyfacts.eu/api/1/country/244",
id: 244
}, {
code: "YE",
name: "Yemen",
created_at: "2015-04-24T01:46:50.454731",
updated_at: "2015-04-24T01:46:50.454741",
uri: "http://api.lobbyfacts.eu/api/1/country/243",
id: 243
}, {
code: "EH",
name: "Western Sahara",
created_at: "2015-04-24T01:46:50.452002",
updated_at: "2015-04-24T01:46:50.452011",
uri: "http://api.lobbyfacts.eu/api/1/country/242",
id: 242
}, {
code: "RS",
name: "Serbia",
created_at: "2015-04-24T01:46:50.342496",
updated_at: "2015-04-24T01:46:50.342501",
uri: "http://api.lobbyfacts.eu/api/1/country/196",
id: 196
}];
}
You can use similar method named rowAttributesCallback instead of rowClassCallback to pass your arguments to row.
options: {
editableColumns: ['name'],
sortable: ['name', 'code'],
filterable: ['name', 'code'],
rowAttributesCallback: row => {
return {"style": "color: red"};
}
}

Vuelidate - Do not mutate vuex store state outside mutation handlers

I am validating a vue form with Vuelidate and I am getting the following error when trying to edit it:
Error: [vuex] do not mutate vuex store state outside mutation handlers.
This is my form input structure:
<hp-text-input
id="company-name"
v-model.trim="$v.formData.companyName.$model"
:code="$v.formData.companyName.$model"
:v="$v.formData.companyName"
:disabled="formData.loading"
:labeltext="$t('components.add_address_modal.company')"
name="company-name"
></hp-text-input>
This is my state:
data() {
return {
formData: {
country: 'Ireland',
address: '',
addressAdditional: '',
addressType: '',
city: '',
companyName: '',
firstName: '',
lastName: '',
zipCode: '',
},
}
},
These are my Vuelidate validations:
validations() {
return {
formData: {
country: {},
address: { required, max: maxLength(32) },
addressAdditional: { max: maxLength(32) },
addressType: { required },
city: { required },
companyName: {},
firstName: { required },
lastName: { required },
zipCode: { required, max: maxLength(10), zipValidate },
},
}
},
I do use a vuex store in this component but it is not even related to the form data itself.
The only thing that worked to get rid of the error for now was creating a copy of the formData and passing it to the form, which for me doesn't make any sense to do.
Do you have any suggestions?

Load attributes from associated model in sequelize.js

I have two models. User and Manager
User Model
const UserMaster = sequelize.define('User', {
UserId: {
type: DataTypes.BIGINT,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
RelationshipId: {
type: DataTypes.STRING,
allowNull: true,
foreignKey: true
},
UserName: {
type: DataTypes.STRING,
allowNull: true
}
})
Manager model
const Manager = sequelize.define('Manager', {
ManagerId: {
type: DataTypes.BIGINT,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
RelationshipId: {
type: DataTypes.STRING,
allowNull: true,
foreignKey: true
},
MangerName: {
type: DataTypes.STRING,
allowNull: true
}
})
Models are minified to simplyfy the problem
Associations..
User.belongsTo(models.Manager, {
foreignKey: 'RelationshipId',
as: 'RM'
});
Manger.hasMany(model.User, {
foreignKey: 'RelationshipId',
as: "Users"
})
So, on user.findAll()
var userObject = models.User.findAll({
include: [{
model: models.Manager,
required: false,
as: 'RM',
attributes: ['ManagerName']
}]
});
I get the following.
userObject = [{
UserId: 1,
RelationshipId: 4545,
UserName: 'Jon',
RM: {
ManagerName: 'Sam'
}
},
{
UserId: 2,
RelationshipId: 432,
UserName: 'Jack',
RM: {
ManagerName: 'Phil'
}
},
...
]
How can I move 'ManagerName' attribute from Manager model (associated as RM) to UserObject?
Is it possible to somehow load attributes from eagerly-loaded models without nesting them under a separate object?
I expected the resulting Object to look Like the object
Expected Object --
userObject = [{
UserId: 1,
RelationshipId: 4545,
UserName: 'Jon',
ManagerName: 'Sam' // <-- from Manager model
},
{
UserId: 2,
RelationshipId: 432,
UserName: 'Jack',
ManagerName: 'Phil' // <-- from Manager model
},
...
]
Thank you.
Adding raw: true along with attributes option worked to get the desired object format.
So,
var userObject = models.User.findAll({
raw:true,
attributes: {
include: [Sequelize.col('RM.ManagerName'), 'ManagerName']
},
include: [{
model: models.Manager,
required: false,
as: 'RM',
attributes: []
}]
});

List is empty when loading page

Im trying to load data into a list using a store. When i run my code the list value is blank, the list is not empty but it is blank.
Here is the part of my controller where i try to add data to store.
var loginStore = Ext.getStore('instance');
var record = [{id:id, issued_at:issued, instance_url:instance, signature:sig, access_token:access, myBaseUri:baseUri}];
loginStore.add(record);
Here is the part of the view where i make the list
{
xtype :'list',
id : 'list1',
loadingText: 'Loading Projects',
emptyText: '<div>No Projects Found</div>',
onItemDisclosure: true,
itemTpl: '<div>{issued_at}</div>',
height: 320,
store : 'instance'
}
This doesnt work but when i replace itemTpl:'<div>{issued_at}</div>' with
itemTpl:'<div>{id}</div>'
it seems to work. What am I doing wrong?
Here is my store:
Ext.define('GS.store.instance',{
extend: 'Ext.data.Store',
requires: ['GS.model.login'],
config:{
model: 'GS.model.login'
}
});
And here is my model:
Ext.define('GS.model.login',{
extend: 'Ext.data.Model',
fields:[
{name: 'id', type: 'string'},
{name: 'issued_at', type:'string'},
{name: 'instance_url', type:'string'},
{name: 'signature', type:'string'},
{name: 'access_token', type:'string'},
{name: 'myBaseUri', type:'string'}
]
});
The way you create your record is wrong. Try this way :
var record = Ext.create('YOUR_MODEL', {
id : id,
issued_at: issued,
instance_url: instance,
...
});
Hope this helps.
Try it using this example:
Ext.define('Contact', {
extend: 'Ext.data.Model',
config: {
fields: ['firstName', 'lastName']
}
});
var store = Ext.create('Ext.data.Store', {
model: 'Contact',
},
data: [
{ firstName: 'Tommy', lastName: 'Maintz' },
{ firstName: 'Rob', lastName: 'Dougan' },
{ firstName: 'Ed', lastName: 'Spencer' },
{ firstName: 'Jamie', lastName: 'Avins' },
{ firstName: 'Aaron', lastName: 'Conran' },
{ firstName: 'Dave', lastName: 'Kaneda' },
{ firstName: 'Jacky', lastName: 'Nguyen' },
{ firstName: 'Abraham', lastName: 'Elias' },
{ firstName: 'Jay', lastName: 'Robinson'},
{ firstName: 'Nigel', lastName: 'White' },
{ firstName: 'Don', lastName: 'Griffin' },
{ firstName: 'Nico', lastName: 'Ferrero' },
{ firstName: 'Jason', lastName: 'Johnston'}
]
});
Ext.create('Ext.List', {
fullscreen: true,
itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>',
store: store,
});
As you get values in the list when using id instead of issued_at, the problem seems to be, not with the functions/models/store so much, but with the issued_at variable itself. Are you certain it's getting through to the store?
Try adding this when your store has loaded, or run it in the browser using for instance chrome
console.log(Ext.getStore("instance").getAt(0).data.id);
console.log(Ext.getStore("instance").getAt(0).data.issued_at);
You should see some result from your first data item.
If you get an id but just "undefined" for issued_at, you'll know that the issue is with the records. And in that case I would try to log your issued variable before you try to add it to the store to make sure that it is actually defined.
Please report with results for further help/discussions if needed.
It turns out that i was missing the config option on my model definition.
Ext.define('GS.model.login',{
extend: 'Ext.data.Model',
config:{
fields:[ 'id','issued_at','instance_url','signature','access_token','myBaseUri' ]
}
});

Sencha Touch List of a panel

I have a app set up and on my hoe page/screen several links. When I click on a link it will then display a list of items (like a contact list ), then again a detailed view when the list item is clicked on as well.
I have the following set up:
App.views.Viewport = Ext.extend(Ext.Panel, {
fullscreen: true,
layout: 'card',
cardSwitchAnimation: 'slide',
dockedItems: [
{
dock : 'top',
xtype: 'toolbar',
title: '<img src="res/img/generic/TT_Small.png" />',
cls: 'homeHeader'
},
],
});
and the view I want as a list is:
App.views.HomeAbout = Ext.regModel('Contact', {
fields: ['firstName', 'lastName']
});
var store = new Ext.data.JsonStore({
model : 'Contact',
root: 'images',
sorters: 'firstName',
getGroupString : function(record) {
return record.get('firstName')[0];
},
data: [
{firstName: 'Tommy', lastName: 'Maintz'},
{firstName: 'Rob', lastName: 'Dougan'},
{firstName: 'Ed', lastName: 'Spencer'},
{firstName: 'Jamie', lastName: 'Avins'},
{firstName: 'Aaron', lastName: 'Conran'},
{firstName: 'Dave', lastName: 'Kaneda'},
{firstName: 'Michael', lastName: 'Mullany'},
{firstName: 'Abraham', lastName: 'Elias'},
{firstName: 'Jay', lastName: 'Robinson'}
]
});
var list = new Ext.List({
fullscreen: true,
itemTpl : '{firstName} {lastName}',
grouped : true,
indexBar: false,
store: store
});
I am using the simple 'contact' eg to start with so once running I will amend my data etc as needed, but when I click on the link to go to this view I get the following
Uncaught Attempting to create a component with an xtype that has not been registered: HomeAbout
But in my controller i have :
about: function()
{
if ( ! this.aboutView)
{
this.aboutView = this.render({
xtype: 'HomeAbout',
});
}.....
Any ideas or help would be appreciated
First change:
App.views.HomeAbout = Ext.regModel('Contact', {
fields: ['firstName', 'lastName']
});
to
App.models.Contact = Ext.regModel('Contact', {
fields: ['firstName', 'lastName']
});
Then have this
App.views.HomeAbout = Ext.extend(Ext.List, {
fullscreen: true,
itemTpl : '{firstName} {lastName}',
grouped : true,
indexBar: false,
store: store
});
instead of var list...
and finally reg the new xtype - class that extends default sencha-touch class - like this
Ext.reg('HomeAbout', App.views.HomeAbout);