I have Ext.dataview.List, I successfully can see it in my browser. But after buildind my application for android list and it's title doesn't shown. I tried almost everything but noghing helps.
Here is my code:
MenuTabPanel.js:
Ext.define('App.view.MenuTabPanel', {
extend: 'Ext.tab.Panel',
xtype: 'menutb',
requires: [
'Ext.TitleBar',
'Ext.dataview.List'
],
config: {
tabBarPosition: 'bottom',
fullscreen : true,
id: 'menuTabPanel',
//layout: 'fit',
listeners: {
painted : function(element, eOpts) {
if(this.getActiveItem()) {
var title = this.getActiveItem().child('[xtype=list]').title;
var navBar = Ext.getCmp('navMenu').getNavigationBar();
navBar.setTitle(title);
}
}
}
},
initialize: function() {
var content = [];
//var menuStore = Ext.getStore('menuItemsStore');
var menuStore = Ext.create('App.store.MenuItemsStore');
var onMenuItemClicked = function(list, index, node,record){
var navigateTo = Ext.create('App.view.' + record.get('Id') + 'View');
var navMenu = Ext.getCmp('navMenu');
navMenu.push(navigateTo);
};
var tabPanel = this;
var onStoreLoad = function(){
menuStore.filter("Level",1);
menuStore.each(function(record) {
var tabItem = {};
var items = {};
tabItem['iconCls'] = record.get('Id');
tabItem['layout'] = 'fit';
items['id'] = record.get('Id');
items['title'] = record.get('Title');
items['xtype'] = 'list';
items['height'] = '100%';
items['width'] = '100%';
//items['layout'] = 'vbox';
//items['flex'] = 1;
items['itemTpl'] = '<div class="menuitem-text"><img src="../resources/icons/{Id}.png" /> {Title}</div>';
//items['store'] = Ext.getStore('menuItemsStore');
var listen = {};
listen['itemtap'] = onMenuItemClicked;
items['listeners'] = listen;
tabItem['items'] = [items];
content.push(tabItem);
}
);
tabPanel.add(content);
}
menuStore.load(onStoreLoad);
this.callParent(arguments);
}
});
MenuController.js:
Ext.define('App.controller.MenuController', {
extend: 'Ext.app.Controller',
requires: [
'Ext.dataview.List'
],
config: {
control: {
"menutb": {
activeitemchange: 'onTabPanelActiveItemChange'
}
}
},
onTabPanelActiveItemChange: function(othis, value, oldValue, eOpts) {
var list = value.child('[xtype=list]');
var mainStore = Ext.getStore('menuItemsStore');
var results = mainStore.queryBy(function(rec){
if(rec.get('Level') == 2 && rec.get('Parent') == list.title)
return true;
});
var data1 = Ext.Array.pluck(results.getRange(), 'data');
list.setStore({
model: 'Mobile.model.MenuItem',
data: data1
});
var navBar = othis.getParent().getNavigationBar();
navBar.setTitle(list.title);
}
});
MenuView.js:
Ext.define('App.view.MenuView', {
extend: 'Ext.NavigationView',
xtype: 'menu',
requires: [
'Ext.TitleBar',
'Ext.dataview.List',
'App.view.MenuTabPanel'
],
config: {
id: 'navMenu',
items: [{
xtype: 'menutb'
}
]
}
});
My app starts from MenuView.js.
What I am doing wrong or what I miss? Or maybe it is problem in android with Lists?
Edited:
I find out that there is some problem with activeitemchange event, it fires after initialize. When I commented this event list normally is shown on android. Also when I don't load store and write manually data, the event fires normally.
Related
I would like to re-initialize my map view after a certain action performed in the controller.
This is my mapview:
Ext.define("App.view.MapView", {
extend: 'Ext.Container',
requires: [
'Ext.device.Geolocation',
'Ext.MessageBox'
],
xtype: 'mapview',
constructor: function () {
this.callParent(arguments);
this.element.setVisibilityMode(Ext.Element.OFFSETS);
this.on('painted', this.renderMap, this);
},
renderMap: function(){
var me = this,
lat = localStorage.getItem('latitude'),
lng = localStorage.getItem('longitude'),
geo = [lat, lng];
var map = L.map('map', {
center: geo,
zoom: 13
});
var layer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
var marker = L.marker(geo, {
draggable: true,
title: 'Your position'
}).addTo(map);
}
});
How do I get and reset(re-initialize) my map view? I tried to make a reference to the mapview in the controller:
config: {
refs: {
mapCmp: 'mapview',
},
And then called it like this:
this.getApplication().getMapCmp.reset();
But it didn't work - I got 'function is undefined'. Basically I need it to initialize again like when the app starts up.
Please advise.
You get function is undefined message because the reset() function is not defined in your view.
However, if you want to initialize the MapView, you need to use the initialize() function. Add it in your file:
Ext.define("App.view.MapView", {
extend: 'Ext.Container',
requires: [
'Ext.device.Geolocation',
'Ext.MessageBox'
],
xtype: 'mapview',
constructor: function () {
this.callParent(arguments);
this.element.setVisibilityMode(Ext.Element.OFFSETS);
this.on('painted', this.renderMap, this);
},
initialize: function() {
// This function is launched each time the application starts up
}
renderMap: function(){
var me = this,
lat = localStorage.getItem('latitude'),
lng = localStorage.getItem('longitude'),
geo = [lat, lng];
var map = L.map('map', {
center: geo,
zoom: 13
});
var layer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
var marker = L.marker(geo, {
draggable: true,
title: 'Your position'
}).addTo(map);
},
});
I am looking for a ExtJS itemselector with search/filter option. Is there a existing plugin for this or any ideas to implement it? Since itemselector internally uses Multiselect, do I need to implement my own version on Multiselect?
The multiselect extension has an option for configuring the tbar (Top bar) property. I used the following code to configure the "toField" of itemselector:
tbar : {
xtype: 'toolbar',
flex: 1,
dock: 'top',
items: [
'Filter:',
{
xtype: 'textfield',
fieldStyle: 'text-align: left;',
enableKeyEvents: true,
listeners: {
scope: this,
change : function(field, newValue, oldValue, options) {
var toStore = this.toField.boundList.getStore();
toStore.clearFilter();
if (String(newValue).trim() != "")
{
toStore.filterBy(function(rec, id){
return this.filterFunc(rec, newValue);
}, this);
}
}
}
}
]
}
And my filterFunc is :
filterFunc: function(rec, filter)
{
var value = rec.get(this.displayField);
if (this.filterIgnoreCase) value = value.toLocaleUpperCase();
if (this.filterIgnoreCase) filter = filter.toLocaleUpperCase();
if (Ext.isEmpty(filter)) return true;
if (this.filterAnyMatch && this.filterWordStart)
{
var re_opts = this.filterIgnoreCase ? 'i' : '';
var re = new RegExp('(^|[\\s\\.!?;"\'\\(\\)\\[\\]\\{\\}])'+Ext.escapeRe(filter), re_opts);
return re.test(value);
}
else if (this.filterAnyMatch)
{
var re_opts = this.filterIgnoreCase ? 'i' : '';
var re = new RegExp(Ext.escapeRe(filter), re_opts);
return re.test(value);
}
else
{
var re_opts = this.filterIgnoreCase ? 'i' : '';
var re = new RegExp('^\s*'+Ext.escapeRe(filter), re_opts);
return re.test(value);
}
}
I am trying to create a simple rallycardboard app that displays projects as columns with the project backlog stories as cards. Then allow the drag/drop of cards to set the project. Code is attached.
If I specify 'Project" as the attribute, the board contains columns for all projects in the workspace. I wish to limit the columns shown to either
Scoped parent and children, or
Code a list of project columns. I have tried the manipulate the columns, columnConfig, context settings, but nothing produces the desired results.
<!DOCTYPE html>
<html>
<head>
<title>CardBoard Example</title>
<script type="text/javascript" src="/apps/2.0rc2/sdk.js"></script>
<script type="text/javascript">
Rally.onReady(function() {
Ext.define('ProjBoard', {
extend: 'Rally.app.App',
launch: function() {
if (cardBoardConfig) {
cardBoardConfig.destroy();
}
var cardBoardConfig = {
xtype: 'rallycardboard',
types: ['User Story'],
attribute: 'Project',
fieldToDisplay: 'Project',
cardConfig: {
fields: ['Project', 'Parent','Iteration']
},
storeConfig: {
filters: [
{ property: 'ScheduleState', operator: '<', value: 'In-Progress' },
{ property: 'Iteration', operator: '=', value: '' }
],
sorters: [
{ property: 'Rank', direction: 'DESC' }
],
//Specify current project and scoping
context: this.getContext().getDataContext()
}
};
this.add(cardBoardConfig);
}
});
Rally.launchApp('ProjBoard', {
name: 'Backlog Project Board'
});
});
</script>
<style type="text/css">
</style>
</head>
<body></body>
</html>
You should be able to specify the columns via config:
https://help.rallydev.com/apps/2.0rc2/doc/#!/api/Rally.ui.cardboard.CardBoard-cfg-columns
columns: [
{
value: '/project/12345',
columnHeaderConfig: {
headerTpl: '{project}',
headerData: {project: 'Project 1'}
}
},
//more columns...
]
The code below allowed me to cut down a dozen of project columns to three. First I get current project and query a collection of its child projects to build an array of projects I want to have on the board (you may choose a different criteria for what projects you want on the board), and then I extended Rally.ui.cardboard.CardBoard to overwrite its _buildColumnsFromModel method where only columns that meet this condition are filtered in :
retrievedColumns = _.select(retrievedColumns, function(project){
return that.arrayOfProjectRefs.indexOf(project.value) != -1
});
Here is the full js file. Apart from those changes, this is your code.
Ext.define('CustomApp', { extend: 'Rally.app.App', componentCls: 'app',
launch: function() {
var that = this;
that.arrayOfProjectRefs = [];
var p = this.getContext().getProject();
Ext.create('Rally.data.wsapi.Store', {
model: 'Project',
fetch: ['Children'],
filters:[
{
Property: '_ref',
value: p
}
],
pageSize: 1,
autoLoad: true,
listeners: {
load: function(store, records) {
var project = records[0];
var childProjects = project.get('Children');
var childProjectsCount = project.get('Children').Count;
console.log('childProjectsCount', childProjectsCount);
that.arrayOfProjectRefs.push(project.get('_ref'));
project.getCollection('Children').load({
fetch: ['_ref', 'Name', 'State'],
callback: function(records, operation, success) {
Ext.Array.each(records, function(child) {
console.log(child.get('_ref') + ' - ' + child.get('Name') + child.get('State'));
if (child.get('State') === 'Open') {
that.arrayOfProjectRefs.push(child.get('_ref'));
--childProjectsCount;
if (childProjectsCount === 0) {
that._buildBoard();
}
}
});
}
});
}
}
});
},
_buildBoard:function(){
var that = this;
console.log('app._arrayOfProjectRefs', this.arrayOfProjectRefs);
Ext.define('ProjectCardboard', {extend: 'Rally.ui.cardboard.CardBoard',
xtype: 'projectCardboard',
_buildColumnsFromModel: function() {
var model = this.models[0];
if (model) {
var attribute = model.getField('Project');
if (attribute) {
attribute.getAllowedValueStore().load({
callback: function(records, operation, success) {
var retrievedColumns = _.map(records, function(allowedValue) {
var displayValue, value = allowedValue.get('StringValue');
if (!value && attribute.attributeDefinition.AttributeType.toLowerCase() === 'rating') {
value = "None";
} else if (attribute.attributeDefinition.AttributeType.toLowerCase() === 'object') {
displayValue = value;
value = allowedValue.get('_ref');
if (value === 'null') {
value = null;
}
}
return {
value: value,
columnHeaderConfig: {
headerTpl: displayValue || value || 'None'
}
};
});
this.fireEvent('columnsretrieved', this, retrievedColumns);
retrievedColumns = _.select(retrievedColumns, function(project){
return that.arrayOfProjectRefs.indexOf(project.value) != -1
});
console.log('retrievedColumns after filter', retrievedColumns)
this.columnDefinitions = [];
_.each(retrievedColumns, this.addColumn, this);
this.renderColumns();
},
scope: this
});
}
}
}
});
var addNewConfig = {
xtype: 'rallyaddnew',
recordTypes: ['User Story'],
ignoredRequiredFields: ['Name', 'Iteration'],
showAddWithDetails: false,
};
this.addNew = this.add(addNewConfig);
var myCardConfig = {
xtype: 'rallycard',
fields: ['ScheduleState','Name'],
maxHeight: 100
}
var cardBoardConfig = {
xtype: 'projectCardboard',
types: ['User Story'],
attribute: 'Project',
cardConfig: myCardConfig
};
this.cardBoard = this.add(cardBoardConfig);
}
});
I have a menu system set up in a panel which needs to be dynamically created. I have created a mock static menu which the client likes but the menu categories and items will need to be loaded via JSON from a store.
Here is what I have for the first few menu items set statically:
Ext.define('SimpleSearch.view.FacetSDL' ,{
extend: 'Ext.panel.Panel',
alias : 'widget.facetsdl', //alias is referenced in MasterList.js
requires: ['SimpleSearch.store.SDLResults', 'FacetData' ],
title: 'Facet Search',
html: null,
frame: true,
layouts: 'fit',
items: [
{
id: 'group-menu',
title: 'Browse',
xtype: 'menu',
plain: true,
floating: false,
layouts: 'fit',
items: [
{
text: 'Security',
listeners:
{
click: function() {
var groupmenu = Ext.ComponentQuery.query('#group-menu')[0];
groupmenu.hide()
var securitymenu = Ext.ComponentQuery.query('#security-menu')[0];
securitymenu.setPosition(0,-groupmenu.getHeight(),false);
securitymenu.show()
}
},
menu: { // <-- submenu by nested config object
items: [
{
text: 'Classification',
listeners:
{
click: function() {
var groupmenu = Ext.ComponentQuery.query('#group-menu')[0];
groupmenu.hide()
var securitymenu = Ext.ComponentQuery.query('#security-menu')[0];
var classificationmenu = Ext.ComponentQuery.query('#classification-menu')[0];
classificationmenu.setPosition(0,-groupmenu.getHeight() - securitymenu.getHeight(),false);
classificationmenu.show()
}
I was thinking that maybe creating a class that loads all of the necessary data and then iterating through that class for the "items" field may be the way to go, but I am not sure if that will work.
You should look at using a Tree and TreeStore. Then make use of the ui:'menu' or viewConfig { ui: 'menu' } config properties to differentiate it from a regular tree. Then style it however your client wants.
This way you have all the mechanisms in place for free to handle the data dynamically and all your submenus, you'll just have to get a little creative on the CSS side of things.
I got it working like this:
var scrollMenu = Ext.create('Ext.menu.Menu');
for (var i = 0; i < store.getCount(); ++i){
var rec = store.getAt(i);
var item = new Ext.menu.Item({
text: rec.data.DISPLAY_FIELD,
value:rec.data.VALUE_FIELD,
icon: 'js/images/add.png',
handler: function(item){
myFunction(item.value); //Handle the item click
}
});
scrollMenu.add(item);
}
Then just add scrollMenu to your form or container. Hope this helps!
This menu is created dynamically with ExtJs, the data is loaded from Json.
See my demo with the code.
Demo Online:
https://fiddle.sencha.com/#view/editor&fiddle/2vcq
Json loaded:
https://api.myjson.com/bins/1d9tdd
Code ExtJs:
//Description: ExtJs - Create a dynamical menu from JSON
//Autor: Ronny Morán <ronney41#gmail.com>
Ext.application({
name : 'Fiddle',
launch : function() {
var formPanelFMBtn = Ext.create('Ext.form.Panel', {
bodyPadding: 2,
waitMsgTarget: true,
fieldDefaults: {
labelAlign: 'left',
labelWidth: 85,
msgTarget: 'side'
},
items: [
{
xtype: 'container',
layout: 'hbox',
items: [
]
}
]
});
var win = Ext.create('Ext.window.Window', {
title: 'EXTJS DYNAMICAL MENU FROM JSON',
modal: true,
width: 680,
closable: true,
layout: 'fit',
items: [formPanelFMBtn]
}).show();
//Consuming JSON from URL using method GET
Ext.Ajax.request({
url: 'https://api.myjson.com/bins/1d9tdd',
method: 'get',
timeout: 400000,
headers: { 'Content-Type': 'application/json' },
//params : Ext.JSON.encode(dataJsonRequest),
success: function(conn, response, options, eOpts) {
var result = Ext.JSON.decode(conn.responseText);
//passing JSON data in 'result'
viewMenuDinamical(formPanelFMBtn,result);
},
failure: function(conn, response, options, eOpts) {
//Ext.Msg.alert(titleAlerta,msgErrorGetFin);
}
});
}
});
//Generate dynamical menu with data from JSON
//Params: formPanelFMBtn - > Panel
// result - > Json data
function viewMenuDinamical(formPanelFMBtn,result){
var resultFinTarea = result;
var arrayCategoriaTareas = resultFinTarea.categoriaTareas;
var containerFinTarea = Ext.create('Ext.form.FieldSet', {
xtype: 'fieldset',
title: 'Menu:',
margins:'0 0 5 0',
flex:1,
layout: 'anchor',
//autoHeight: true,
autoScroll: true,
height: 200,
align: 'stretch',
items: [
]
});
var arrayMenu1 = [];
//LEVEL 1
for(var i = 0; i < arrayCategoriaTareas.length; i++)
{
var categoriaPadre = arrayCategoriaTareas[i];
var nombrePadre = categoriaPadre.nombreCategoria;
var hijosPadre = categoriaPadre.hijosCategoria;
var arrayMenu2 = [];
//LEVEL 2
for(var j = 0; j<hijosPadre.length; j++)
{
var categoriaHijo = hijosPadre[j];
var nombreHijo = categoriaHijo.nombreHijo;
var listaTareas = categoriaHijo.listaTareas;
var arrayMenu3 = [];
//LEVEL 3
for(var k = 0; k < listaTareas.length; k++)
{
var tarea = listaTareas[k];
var nombreTarea = tarea.nombreTarea;
var objFinLTres =
{
text: nombreTarea,
handler: function () {
alert("CLICK XD");
}
};
arrayMenu3.push(objFinLTres);
}
var menuLevel3 = Ext.create('Ext.menu.Menu', {
items: arrayMenu3
});
var objFinLDos;
if(arrayMenu3.length > 0)
{
objFinLDos = {
text: nombreHijo,
menu:menuLevel3
};
}
else
{
//without menu parameter If don't have children
objFinLDos = {
text: nombreHijo
};
}
arrayMenu2.push(objFinLDos);
}
var menuLevel2 = Ext.create('Ext.menu.Menu', {
items: arrayMenu2
});
var objFinLUno;
if(arrayMenu2.length > 0)
{
objFinLUno = {
text: nombrePadre,
menu:menuLevel2
};
}
else
{
//without menu parameter If don't have children
objFinLUno = {
text: nombrePadre
};
}
arrayMenu1.push(objFinLUno);
}
var mymenu = new Ext.menu.Menu({
items: arrayMenu1
});
containerFinTarea.add({
xtype: 'splitbutton',
text: 'Example xD',
menu: mymenu
});
formPanelFMBtn.add(containerFinTarea);
}
I have the following sample MVC application trying to dynamically creating carousel with image source being obtained from some remote url,when i execute the application i don't see any images being appended to my carouselview,please can any one highlight where i am going wrong?
Model Code:
Ext.define('Sencha.model.ImageModel', {
extend: 'Ext.data.Model',
config: {
fields: [
'id', 'title', 'link', 'author', 'content',
{
name: 'image',
type: 'string',
convert: function (value, record) {
var content = record.get('content'),
regex = /img src=\"([a-zA-Z0-9\_\.\/\:]*)\"/,
match = content.match(regex),
src = match ? match[1] : '';
if (src != "" && !src.match(/\.gif$/)) {
src = "http://src.sencha.io/screen.width/" + src;
}
return src;
}
}
]
}
});
Store Code:
Ext.define('Sencha.store.ImageStore', {
extend: 'Ext.data.Store',
config: {
model: 'Sencha.model.ImageModel',
proxy: {
type: 'jsonp',
url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://www.acme.com/jef/apod/rss.xml&num=20',
reader: {
type: 'json',
rootProperty: 'responseData.feed.entries'
}
}
}
});
Controller Code:
Ext.define('Sencha.controller.CarouselController', {
extend: 'Ext.app.Controller',
config:
{
init: function () {
var carousel = Ext.getCmp('imagecarousel');
Ext.getStore('ImageStore').load(function (pictures) {
var items = [];
Ext.each(pictures, function (picture) {
if (!picture.get('image')) {
return;
}
items.push({
xtype: 'apodimage',
picture: picture
});
});
carousel.setItems(items);
carousel.setActiveItem(0);
});
}
}
});
View code:
Ext.define('Sencha.view.CarouselView', {
extend: 'Ext.Img',
id:'imagecarousel',
xtype: 'apodimage',
config: {
/**
* #cfg {apod.model.Picture} picture The Picture to show
*/
picture: null
},
updatePicture: function (picture) {
this.setSrc(picture.get('image'));
}
});
App.js Code:
Ext.Loader.setConfig({
enabled: true
});
Ext.require([
'Ext.carousel.Carousel',
'Ext.data.proxy.JsonP'
]);
Ext.application({
name: 'Sencha',
controllers: ['CarouselController'],
stores: ['ImageStore'],
models: ['ImageModel'],
//views:['CarouselView'],
launch: function () {
Ext.create('Sencha.view.CarouselView');
}
});
Could be more specific about what doesn't work. Try to add console.logs in your code and give us the results, like the size the items at the end end of Ext.each of stuff like that.
My first idea would be to use the callback function of store.load :
Ext.getStore('ImageStore').load(
callback: function (pictures) {
var items = [];
Ext.each(pictures, function (picture) {
if (!picture.get('image')) {
return;
}
items.push({
xtype: 'apodimage',
picture: picture
});
});
carousel.setItems(items);
carousel.setActiveItem(0);
});
Hope this helps