I have a widget.js with a table and in his headerView I have a controller view. The code:
var table = Ti.UI.createTableView({
id: ('table' + i),
data: tableData,
separatorStyle: OS_ANDROID ? Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_NONE : Ti.UI.iPhone.TableViewSeparatorStyle.NONE,
headerView: Alloy.createController("Principal/Componentes/LocalizacionRow", {parent: $.board}).getView()
});
I want to pass an event from LocalizacionRow to widget.js using $.trigger but it doesn't work.
My code:
LocalizacionRow.js
if(!e.cancel){
$.localizacion.text = e.data[0].value;
$.trigger('recargar');
Ti.API.info("## PeriĆ³dico: " + Ti.App.Properties.getString('media') + " " + $.localizacion.text);
}
widget.js
var header = table.getHeaderView();
header.on('recargar', function(e){
Ti.API.debug("--- Recargar");
});
"--- Recargar" is never showed. What am I doing bad?
I've seen this code here: http://www.tidev.io/2014/09/10/the-case-against-ti-app-fireevent-2/
And here: https://wiki.appcelerator.org/display/guides2/Controller+events
If you want receive the event, you must add a trigger to the LocalizacionRow controller, like this :
var LocalizacionRowController = Alloy.createController("Principal/Componentes/LocalizacionRow", {parent: $.board});
LocalizacionRowController.on('recargar', function(e){
Ti.API.debug("--- Recargar");
});
var table = Ti.UI.createTableView({
id: ('table' + i),
data: tableData,
separatorStyle: OS_ANDROID ? Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_NONE : Ti.UI.iPhone.TableViewSeparatorStyle.NONE,
headerView: LocalizacionRowController.getView()
});
you have to fire event in the controller not in the view, try this :
var controller = Alloy.createController("Principal/Componentes/LocalizacionRow", {parent: $.board});
var table = Ti.UI.createTableView({
id: ('table' + i),
data: tableData,
separatorStyle: OS_ANDROID ?,
headerController : controller,
headerView: controller.getView();
});
var header = table.headerController;
header.on('recargar', function(e){
Ti.API.debug("--- Recargar");
});
Related
I have some trouble declaring my controller using ui.router and requirejs.
I'm trying calling route from a variable (menu) to create dynamic route.
See my code below
controller declaration:
var Portal = angular.module('Portal');
Portal.controller('SUSR',['$scope', function($scope)
{
$scope.name = 'This my name';
}]);
this is my loader:
var menu = {
'SUSR':
['ACTIVITY',
'SETTINGS',
'TIMELINE'],
// 'SEU':
// ['MODULE'],
};
var loadController = function(controllerName) {
return ["$q","$rootScope", function($q,$rootScope) {
var deferred = $q.defer();
require([controllerName], function() {
deferred.resolve();
$rootScope.$apply();
});
return deferred.promise;
}];
}
_.each(menu,function(value,key){
var module = baseDirectories + key + '/' + key ;
$stateProvider.state('/' + key,{
url: '/' + key,
templateUrl : module + '.html',
controller: key,
resolve : loadController(module),
});
})
And I'm getting the error below :
Argument 'SUSR' is not aNaNunction, got undefined
Could you please tell me where the problem is?
thanks and regards.
I using Android application using Titanium Appcelerator.. I trying to click and retrieve a row view value from my table . i getting "undefined" ..help me to retrieve my row value..
Here is my code...
var row = Ti.UI.createTableViewRow();
row.title = 'row';
row.postid = '' + post.id;
row.addEventListener('longclick', function(e) {
Titanium.API.info(evt.postid);
});
You mistyped parameter name, instead of:
row.addEventListener('longclick', function(e) {
Titanium.API.info(evt.postid);
});
it should be:
row.addEventListener('longclick', function(e) {
Titanium.API.info(e.postid);
});
Also in case of TableView and rows it's better to create event listener on whole table like this:
var table = Ti.UI.createTableView();
var row = Ti.UI.createTableViewRow();
row.title = 'row';
row.postid = '' + post.id;
table.setData([row]);
table.addEventListener('longclick', function(e) {
Titanium.API.info(e.row.postid);
});
I've got the below bit of code which pull back a list of the users facebook contacts along with their profile picture, however the images are not loading for each user, it is only showing the images for a few users.
fb.requestWithGraphPath('me/friends', {
fields : 'first_name,last_name,id,installed,picture.width(120).height(120),gender'
}, 'GET', function(e) {
if (e.success) {
var d = JSON.parse(e.result);
var pData = [];
var iData = [];
var row = d.data;
row = row.sort(sortByName)
for (var i = 0; i < d.data.length; i++) {
var img = row[i].picture.data.url
if (row[i].installed) {
pData.push({
properties : {
title : row[i].first_name + " " + row[i].last_name,
id : row[i].id,
image : img,
gender : row[i].gender,
accessoryType : Ti.UI.LIST_ACCESSORY_TYPE_DISCLOSURE
},
template : Ti.UI.LIST_ITEM_TEMPLATE_DEFAULT
});
} else {
iData.push({
properties : {
title : row[i].first_name + " " + row[i].last_name,
id : row[i].id,
image : img,
accessoryType : Ti.UI.LIST_ACCESSORY_TYPE_DISCLOSURE
},
template : Ti.UI.LIST_ITEM_TEMPLATE_DEFAULT
});
}
}
var play = Ti.UI.createListSection({
headerTitle : 'Play with Facebook Friends',
items : pData
});
var invite = Ti.UI.createListSection({
headerTitle : 'Invite Facebook Friends',
items : iData
});
var listView = Ti.UI.createListView({
sections : [play, invite],
});
self.add(listView)
} else {
alert("Facebook Error");
}
})
The images are stored in var img = row[i].picture.data.url and pushed into the data array as part of image : img but not all images are loading.
Is there a way to force the images to load? and show a default image whilst they are loading?
Here is a link to complete example to do exactly what you are trying to accomplish abaove
http://www.clearlyinnovative.com/blog/post/34758524584/alloy-listview-facebook-friends#.UgexZGRATrg
i have two panel. when i'm click on the left panel items its calling web service and populating the right panel and same time its updating the number of items in the right panel to the left panel item which is clicked.
for first time its updating the left panel items but when i click on the other left panel item its not updating left panel items again.
its updating only first time.
my code is:
onInboxListTap:function (dataview, index, item, record) {
console.log('Inside onInboxListTap function');
var queuestore = dataview.getStore();
var rec = queuestore.getAt(index);
console.log(rec.data.workSetName);
var store = Ext.getStore('InboxWorkitemStore');
store.clearData(); //Function To clear WorkitemStore
//creating object of InboxQueueServices class
var inboxQueueServiceObject =
Ext.create('InfoImage.common.services.InboxQueueServices', {
config:{
scope:this
}
}, this.onQueueContentRetrievalSuccess, this.onQueueContentRetrievalFailure());
// calling loadQueueContent function to load queue contents
inboxQueueServiceObject.loadQueueContent(rec.data.workSetName);
},
//To call Function onQueueContentRetrievalSuccess after loadQueueContent successful
onQueueContentRetrievalSuccess:function () {
console.log('Inside onQueueContent Retrieval Success function');
var store = Ext.getStore('InboxWorkitemStore');
//Getting componenet queueDetails list
var inboxWorkitemList = Ext.getCmp('inboxWorkitemList');
var queueDetails = Ext.getCmp('queueDetails');
var queueList = Ext.getCmp('queuelist'); //Getting component list
var queueViewPanel = Ext.getCmp('queueViewPanel'); //Getting queueViewPanel
queueDetails.setStore(store);
store.sync();
var queueCount = store.getCount();
if (queueCount > 0) {
var queueItem = store.getAt(0);
var queueStore = queueList.getStore();
queueStore.each(function (record) {
if (record.get('workSetName') == queueItem.get('sourceWorkstep')) {
record.data.queueName = queueItem.get('sourceWorkstep') + '(' +
queueCount + ')';
}
});
queueList.setStore(queueStore);
queueStore.sync();
queueList.getStore().each(function (record) {
console.log('queueList:' + record.data.queueName);
});
console.log('store UPDATED');
}
queueList.refresh();
console.log('store count: ' + store.getCount());
console.log(queueDetails);
// navigates the panel
queueViewPanel.animateActiveItem(
inboxWorkitemList, {
type:'slide',
direction:'up',
duration:250
});
},
Please help me on this isssue.
i have to set record for that i resolve it.
queueStore.each(function (record) {
if (record.get('workSetName') == workitem.get('sourceWorkset')) {
record.data.queueName = workitem.get('sourceWorkset')
+ '(' + queueCount + ')';
// queueStore.updateRecord(record.data.queueName);
record.set(record.data.queueName);
}
});
im using for first time appcelerator for a Iphone app, im using a TableViewRow, when the window load all is fine, but if i want to refresh the window, the TableViewRow repeat the same data every time that i push refresh, so, i have 5 Categories, after refresh im having the same Categories repeting every time that im trying to refresh.
Ti.UI.backgroundColor = '#dddddd';
var url = "http://remoteJSON.js";
var win = Titanium.UI.currentWindow;
var table = Titanium.UI.createTableView();
var tableData = [];
var json, categorias, categoria, i, row, categoriaLabel, descripcionLabel;
var refreshBtn = Titanium.UI.createButton({
systemButton: Ti.UI.iPhone.SystemButton.REFRESH
});
refreshBtn.addEventListener('click', function() {
loadTutoriales();
});
win.setRightNavButton(refreshBtn);
var actInd = Titanium.UI.createActivityIndicator({
bottom:10,
height:50,
width:10,
style:Titanium.UI.iPhone.ActivityIndicatorStyle.PLAIN
});
function loadTutoriales(){
if(!Titanium.Network.online){
alert("Debe conectarse a internet.");
}
var xhr = Ti.Network.createHTTPClient({
onload: function() {
actInd.show();
actInd.message = 'Loading...';
//Ti.API.debug(this.responseText);
json = JSON.parse(this.responseText);
for (i = 0; i < json.categorias.length; i++) {
var rowColor = '#eeeeee';
if(i & 1){
rowColor = '#ffffff';
}
categoria = json.categorias[i];
var row = Ti.UI.createTableViewRow({
height:'auto',
hasChild:true
});
row.backgroundColor=rowColor;
/* add */
var post_view = Titanium.UI.createView({
height:'auto',
layout:'vertical',
top:5,
right:5,
bottom:5,
left:5
});
var av_image = Titanium.UI.createImageView({
image:categoria.imageUrl,
top:0,
left:0,
height:48,
width:48
});
post_view.add(av_image);
var inner_view = Titanium.UI.createView({
height:'auto',
layout:'vertical',
top:0,
right:0,
bottom:0,
left:0
});
/* end add */
var categoriaLabel = Ti.UI.createLabel({
text:categoria.categoryName,
left:54,
width:120,
top:-48,
bottom:0,
height:18,
textAlign:'left',
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:14,fontWeight:'bold'}
});
inner_view.add(categoriaLabel);
var descripcionLabel = Ti.UI.createLabel({
text:'"' + categoria.description + '"',
left:54,
top:0,
bottom:2,
height:'auto',
width:'auto',
textAlign:'left',
font:{fontSize:14}
});
inner_view.add(descripcionLabel);
post_view.add(inner_view);
row.add(post_view);
//row.add(descripcionLabel);
tableData.push(row);
}
table.setData(tableData);
},
onerror: function(e) {
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT: " + this.responseText);
Ti.API.debug("ERROR: " + e.error);
alert('There was an error retrieving the remote data. Try again.');
},
timeout:5000
});
//win.add(actInd);
win.add(table);
win.open();
//actInd.hide();
xhr.open("GET", url);
xhr.send();
}
loadTutoriales();
When you press the refresh button clear the tableData array and assign to table set data function before you fill your table again. So it will empty your table first and than fill new refreshed data.
Like this,
refreshBtn.addEventListener('click', function() {
tableData = [];
table.setData(tableData);
loadTutoriales();
});