Beispiel #1
0
exports['Social'] = function (evt) {
    // Be sure to include the "facebook" module when running this app. It is now separate from the sdk.
    var Facebook = Ti.Facebook ? Ti.Facebook : require('facebook');
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });
    var rows = [
        'Search Facebook Friends'
    ];
    if (Facebook.createLoginButton) {
        var available = true;
        try {
            Facebook.createLoginButton();
        }
        catch (err) {
            available = false;
        }
        if (available) {
            rows.push('External Link');
            rows.push('External Login');
            rows.push('External Unlink');
        }
    }
    var table = Ti.UI.createTableView({
        backgroundColor: '#fff',
        top: 0,
        data: Utils.createRows(rows)
    });
    table.addEventListener('click', WindowManager.handleOpenWindow);
    win.add(table);
    return win;
};
exports['Create Geo Fence'] = function (evt) {
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });
    var content = Ti.UI.createScrollView({
        top: 0,
        contentHeight: 'auto',
        layout: 'vertical'
    });
    win.add(content);

    var geo_fence = Ti.UI.createTextField({
        hintText: 'geo_fence',
        top: 10 + Utils.u, left: 10 + Utils.u, right: 10 + Utils.u,
        height: 40 + Utils.u,
        borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED
    });
    content.add(geo_fence);

    var button = Ti.UI.createButton({
        title: 'Create',
        top: 10 + Utils.u, left: 10 + Utils.u, right: 10 + Utils.u, bottom: 10 + Utils.u,
        height: 40 + Utils.u
    });
    content.add(button);

    var fields = [ geo_fence ];

    function submitForm() {
        for (var i = 0; i < fields.length; i++) {
            if (!fields[i].value.length) {
                fields[i].focus();
                return;
            }
            fields[i].blur();
        }
        button.hide();

        Cloud.GeoFences.create({
            geo_fence: geo_fence.value
        }, function (e) {
            if (e.success) {
                alert('Created!');
            } else {
                Utils.error(e);
            }
            button.show();
        });
    }

    button.addEventListener('click', submitForm);
    for (var i = 0; i < fields.length; i++) {
        fields[i].addEventListener('return', submitForm);
    }

    win.addEventListener('open', function () {
        geo_fence.focus();
    });
    return win;
};
exports['Show Event Occurrences'] = function (evt) {
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });
    var content = Ti.UI.createScrollView({
        top: 0,
        contentHeight: 'auto',
        layout: 'vertical'
    });
    win.add(content);

    var status = Ti.UI.createLabel({
        text: 'Loading, please wait...', textAlign: 'left',
        height: 30 + Utils.u, left: 20 + Utils.u, right: 20 + Utils.u
    });
    content.add(status);

    Cloud.Events.showOccurrences({
        event_id: evt.id
    }, function (e) {
        content.remove(status);
        if (e.success) {
            Utils.enumerateProperties(content, e.event_occurrences, 20);
        } else {
            Utils.error(e);
        }
    });

    return win;
};
exports['Remove Status'] = function (evt) {
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });

    var button = Ti.UI.createButton({
        title: 'Delete',
        top: 10 + Utils.u, left: 10 + Utils.u, right: 10 + Utils.u, bottom: 10 + Utils.u,
        height: 40 + Utils.u
    });
    win.add(button);

    var status = Ti.UI.createLabel({
        text: '', textAlign: 'center',
        left: 20 + Utils.u, right: 20 + Utils.u
    });
    win.add(status);

    button.addEventListener('click', function () {
        button.hide();
        status.text = 'Removing, please wait...';
        Cloud.Statuses.remove({
            status_id: evt.id
        }, function (e) {
            if (e.success) {
                status.text = 'Removed!';
            } else {
                status.text = '' + (e.error && e.message) || e;
            }
        });
    });

    return win;
};
Beispiel #5
0
exports['Push Notifications'] = function () {
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });

    var rows = [
        'Notify',
        'Notify Tokens',
        'Query Subscriptions',
        'Show Channels',
        'Query Channels',
        'Set Badge',
        'Reset Badge'
    ];
    if (Ti.Platform.name === 'iPhone OS' || Ti.Platform.name === 'android') {
        rows.push('Settings for This Device');
        rows.push('Subscribe');
        rows.push('Unsubscribe');
        rows.push('Subscribe Token');
        rows.push('Unsubscribe Token');
        rows.push('Update Subscription');
    }
    else {
        // Our other platforms do not support push notifications yet.
    }

    var table = Ti.UI.createTableView({
        backgroundColor: '#fff',
        top: 0,
        data: Utils.createRows(rows)
    });
    table.addEventListener('click', WindowManager.handleOpenWindow);
    win.add(table);
    return win;
};
exports['Create Like'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var content = Ti.UI.createScrollView({
		top: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	var userId = Ti.UI.createTextField({
		hintText: 'user_id',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(userId);

	var button = Ti.UI.createButton({
		title: 'Create',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	content.add(button);


	function submitForm() {
		button.hide();

		Cloud.Likes.create({
			user_id: userId.value
		}, function(e) {
			if (e.success) {
				alert('Created!');
			} else {
				Utils.error(e);
			}
			button.show();
		});
	}

	button.addEventListener('click', submitForm);
	var fields = [userId];
	for (var i = 0; i < fields.length; i++) {
		fields[i].addEventListener('return', submitForm);
	}

	win.addEventListener('open', function() {
		userId.focus();
	});
	return win;
};
exports['Show Channels'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});

	var name = Ti.UI.createTextField({
		hintText: 'channel name',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		autocapitalization: Ti.UI.TEXT_AUTOCAPITALIZATION_NONE,
		autocorrect: false
	});
	win.add(name);

	var button = Ti.UI.createButton({
		title: 'Show Channels',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	win.add(button);

	var table = Ti.UI.createTableView({
		backgroundColor: '#fff',
		top: 0,
		bottom: 0,
		color: 'black',
		data: []
	});
	win.add(table);

	button.addEventListener('click', submitQuery);
	name.addEventListener('return', submitQuery);

	function submitQuery() {
		Cloud.PushNotifications.showChannels({
			name: name.value
		}, function(e) {
			if (e.success) {
				var data = [];
				var row = Ti.UI.createTableViewRow({
					layout: 'vertical',
					color: 'black'
				});
				Utils.enumerateProperties(row, e.devices, 20);
				data.push(row);
				table.setData(data);
			} else {
				Utils.error(e);
			}
		});
	}

	return win;
};
exports['Geolocate Me'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var content = Ti.UI.createScrollView({
		top: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	var status = Ti.UI.createLabel({
		text: 'Loading, please wait...',
		textAlign: 'left',
		height: 30 + Utils.u,
		left: 20 + Utils.u,
		right: 20 + Utils.u,
		color: 'black'
	});
	content.add(status);

	Cloud.Clients.geolocate(function(e) {
		content.remove(status);
		if (e.success) {
			Utils.enumerateProperties(content, e, 20);
		} else {
			Utils.error(e);
		}
	});

	return win;
};
exports['Show Threads'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});

	var table = Ti.UI.createTableView({
		backgroundColor: '#fff',
		top: 0,
		bottom: 0,
		color: 'black',
		data: [{
			title: 'Loading, please wait...'
		}]
	});

	table.addEventListener('click', function(evt) {
		if (evt.row.id) {
			WindowManager.handleOpenWindow({
				target: 'Show Messages In Thread',
				id: evt.row.id
			});
		}
	});
	win.add(table);

	function showThreads() {
		Cloud.Messages.showThreads(function(e) {
			if (e.success) {
				if (e.messages.length == 0) {
					table.setData([{
						title: 'No messages',
						color: 'black'
					}]);
				} else {
					var data = [];
					for (var i = 0, l = e.messages.length; i < l; i++) {
						var message = e.messages[i];
						var row = Ti.UI.createTableViewRow({
							title: message.subject,
							id: message.thread_id,
							color: 'black'
						});
						data.push(row);
					}
					table.setData(data);
				}
			} else {
				table.setData([{
					title: (e.error && e.message) || e
				}]);
				Utils.error(e);
			}
		});
	}

	win.addEventListener('open', showThreads);
	return win;
};
Beispiel #10
0
exports['Show Message'] = function (evt) {
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });
    var content = Ti.UI.createScrollView({
        top: 0,
        contentHeight: 'auto',
        layout: 'vertical'
    });
    win.add(content);

    var status = Ti.UI.createLabel({
        text: 'Loading, please wait...', textAlign: 'left',
        height: 30 + Utils.u, left: 20 + Utils.u, right: 20 + Utils.u
    });
    content.add(status);

    Cloud.Messages.show({
        message_id: evt.id
    }, function (e) {
        content.remove(status);
	    if (e.success) {
		    if (evt.allowReply) {
		        var reply = Ti.UI.createButton({
		            title: 'Reply',
		            top: 10 + Utils.u, left: 10 + Utils.u, right: 10 + Utils.u, bottom: 10 + Utils.u,
		            height: 40 + Utils.u
		        });
		        reply.addEventListener('click', function () {
		            WindowManager.handleOpenWindow({ target: 'Reply Message', id: evt.id, subject: e.messages[0].subject });
		        });
		        content.add(reply);
		    }

	        var remove = Ti.UI.createButton({
	            title: 'Remove Message',
	            top: 10 + Utils.u, left: 10 + Utils.u, right: 10 + Utils.u, bottom: 10 + Utils.u,
	            height: 40 + Utils.u
	        });
	        remove.addEventListener('click', function () {
	            WindowManager.handleOpenWindow({ target: 'Remove Message', id: evt.id });
	        });
	        content.add(remove);

            Utils.enumerateProperties(content, e.messages[0], 20);
        } else {
            Utils.error(e);
        }
    });

    return win;
};
Beispiel #11
0
exports['Search Events'] = function (evt) {
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });

    var table = Ti.UI.createTableView({
        backgroundColor: '#fff',
        top: 0, bottom: 0,
        data: [
            { title: 'Loading, please wait...' }
        ]
    });

    table.addEventListener('click', function (evt) {
        if (evt.row.id) {
	        WindowManager.handleOpenWindow({ target: 'Show Event', id: evt.row.id });
        }
    });
    win.add(table);

    function searchEvents() {
        Cloud.Events.search(function (e) {
            if (e.success) {
	            if (e.events.length == 0) {
                    table.setData([
                        { title: 'No events' }
                    ]);
                } else {
	                var data = [];
		            for (var i = 0, l = e.events.length; i < l; i++) {
              	        var event = e.events[i];
                        var row = Ti.UI.createTableViewRow({
                            title: event.name,
                            id: event.id
                        });
                        data.push(row);
                    }
		            table.setData(data);
	            }
            } else {
                table.setData([
                    { title: (e.error && e.message) || e }
                ]);
                Utils.error(e);
            }
        })
    }

    win.addEventListener('open', searchEvents);
    return win;
};
Beispiel #12
0
exports['Query Place'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});

	var table = Ti.UI.createTableView({
		backgroundColor: '#fff',
		top: 0,
		bottom: 0,
		color: 'black',
		data: [{
			title: 'Loading, please wait...'
		}]
	});
	table.addEventListener('click', function(evt) {
		if (evt.row.id) {
			WindowManager.handleOpenWindow({
				target: 'Show Place',
				id: evt.row.id
			});
		}
	});
	win.add(table);

	win.addEventListener('open', function() {
		Cloud.Places.query(function(e) {
			if (e.success) {
				if (e.places.length == 0) {
					table.setData([{
						title: 'No Results!'
					}]);
				} else {
					var data = [];
					for (var i = 0, l = e.places.length; i < l; i++) {
						data.push(Ti.UI.createTableViewRow({
							title: e.places[i].name,
							id: e.places[i].id,
							color: 'black'
						}));
					}
					table.setData(data);
				}
			} else {
				Utils.error(e);
			}
		});
	});
	return win;
};
Beispiel #13
0
exports['Reviews'] = function (evt) {
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });
    var table = Ti.UI.createTableView({
        backgroundColor: '#fff',
        top: 0,
        data: Utils.createRows([
            'Create Review',
            'Query Review'
        ])
    });
    table.addEventListener('click', WindowManager.handleOpenWindow);
    win.add(table);
    return win;
};
exports['Search Facebook Friends'] = function (evt) {
    var Facebook = Ti.Facebook ? Ti.Facebook : require('facebook');
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });

    var table = Ti.UI.createTableView({
        backgroundColor: '#fff',
        top: 0, bottom: 0,
        data: [
            { title: 'Loading, please wait...' }
        ]
    });
    table.addEventListener('click', function (evt) {
        if (evt.row.id) {
            WindowManager.handleOpenWindow({ target: 'Show User', id: evt.row.id });
        }
    });
    win.add(table);

    win.addEventListener('open', function () {
        Cloud.SocialIntegrations.searchFacebookFriends(function (e) {
            if (e.success) {
                if (e.users.length == 0) {
                    table.setData([
                        { title: 'No Results!' }
                    ]);
                }
                else {
                    var data = [];
                    for (var i = 0, l = e.users.length; i < l; i++) {
                        data.push(Ti.UI.createTableViewRow({
                            title: e.users[i].first_name + ' ' + e.users[i].last_name,
                            id: e.users[i].id
                        }));
                    }
                    table.setData(data);
                }
            }
            else {
                Utils.error(e);
            }
        });
    });
    return win;
};
Beispiel #15
0
exports['Query Push Schedules'] = function (evt) {
  var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });

  var table = Ti.UI.createTableView({
    backgroundColor: '#fff',
    top: 0, bottom: 0,
    data: [
      { title: 'Loading, please wait...' }
    ]
  });
  table.addEventListener('click', function (evt) {
    if (evt.row.id) {
      WindowManager.handleOpenWindow({ target: 'Remove Push Schedules', id: evt.row.id });
    }
  });
  win.add(table);

  win.addEventListener('open', function () {
    Cloud.PushSchedules.query(function (e) {
      if (e.success) {
        if (e.push_schedules.length === 0) {
          table.setData([
            { title: 'No Push Schedules!' }
          ]);
        } else {
          var data = [];
          for (var i = 0, l = e.push_schedules.length; i < l; i++) {
            data.push(Ti.UI.createTableViewRow({
              title: JSON.stringify(e.push_schedules[i]),
              id: e.push_schedules[i].id,
              font: { fontSize: 12 + Utils.u }
            }));
          }
          table.setData(data);
        }
      } else {
        Utils.error(e);
      }
    });
  });

  return win;
};
Beispiel #16
0
exports['Messages'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var table = Ti.UI.createTableView({
		backgroundColor: '#fff',
		top: 0,
		color: 'black',
		data: Utils.createRows([
			'Create Message',
			'Show Inbox',
			'Show Sent',
			'Show Threads'
		])
	});
	table.addEventListener('click', WindowManager.handleOpenWindow);
	win.add(table);
	return win;
};
Beispiel #17
0
exports['Photos'] = function (evt) {
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });
    var rows = [
        'Query Photo',
        'Search Photo'
    ];
    if (Ti.Media.openPhotoGallery || Ti.Media.showCamera) {
        rows.unshift('Create Photo');
    }
    var table = Ti.UI.createTableView({
        backgroundColor: '#fff',
        top: 0,
        data: Utils.createRows(rows)
    });
    table.addEventListener('click', WindowManager.handleOpenWindow);
    win.add(table);
    return win;
};
exports['Login Status'] = function() {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var content = Ti.UI.createScrollView({
		top: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	content.add(Ti.UI.createLabel({
		text: 'accessToken: ' + Cloud.accessToken,
		textAlign: 'left',
		height: 40 + Utils.u,
		left: 20 + Utils.u,
		right: 20 + Utils.u,
		color: 'black'
	}));
	content.add(Ti.UI.createLabel({
		text: 'expiresIn: ' + Cloud.expiresIn,
		textAlign: 'left',
		height: 40 + Utils.u,
		left: 20 + Utils.u,
		right: 20 + Utils.u,
		color: 'black'
	}));
	content.add(Ti.UI.createLabel({
		text: 'sessionId: ' + Cloud.sessionId,
		textAlign: 'left',
		height: 40 + Utils.u,
		left: 20 + Utils.u,
		right: 20 + Utils.u,
		color: 'black'
	}));

	return win;
};
Beispiel #19
0
exports['Create Object'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var content = Ti.UI.createScrollView({
		top: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	var fields = [];

	var classname = Ti.UI.createTextField({
		hintText: 'Class Name',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		autocapitalization: Ti.UI.TEXT_AUTOCAPITALIZATION_NONE,
		autocorrect: false,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(classname);

	function doCreateNewProperty() {
		if (!newProperty.value) {
			alert('Please fill in the "New Property Key" text field!');
			newProperty.focus();
			return;
		}
		var textField = Ti.UI.createTextField({
			hintText: newProperty.value,
			top: 10 + Utils.u,
			left: 10 + Utils.u,
			right: 10 + Utils.u,
			height: 40 + Utils.u,
			borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
			color: "black",
			hintTextColor: "gray"
		});
		newProperty.value = '';
		content.remove(button);
		content.add(textField);
		textField.addEventListener('return', submitForm);
		fields.push(textField);
		content.add(button);
	}

	var newProperty = Ti.UI.createTextField({
		hintText: 'New Property Key',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		autocapitalization: Ti.UI.TEXT_AUTOCAPITALIZATION_NONE,
		autocorrect: false,
		color: "black",
		hintTextColor: "gray"
	});
	newProperty.addEventListener('return', doCreateNewProperty);
	content.add(newProperty);
	var createNewProperty = Ti.UI.createButton({
		title: 'Add New Property',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	createNewProperty.addEventListener('click', doCreateNewProperty);
	content.add(createNewProperty);

	var button = Ti.UI.createButton({
		title: 'Create',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	content.add(button);

	function submitForm() {
		if (!classname.value) {
			alert('Please enter a class name!');
			classname.focus();
			return;
		}
		if (!fields.length) {
			alert('Please create at least one field!');
			newProperty.focus();
			return;
		}
		var data = {
			classname: classname.value,
			fields: {}
		};
		for (var i = 0; i < fields.length; i++) {
			data.fields[fields[i].hintText] = fields[i].value;
			fields[i].blur();
		}
		button.hide();

		Cloud.Objects.create(data, function(e) {
			if (e.success) {
				alert('Created!');
				for (var i = 0; i < fields.length; i++) {
					fields[i].value = '';
				}
			} else {
				Utils.error(e);
			}
			button.show();
		});
	}

	classname.addEventListener('return', submitForm);
	button.addEventListener('click', submitForm);

	win.addEventListener('open', function() {
		classname.focus();
	});
	return win;
};
Beispiel #20
0
exports['Update Photo Collection'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var content = Ti.UI.createScrollView({
		top: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	var name = Ti.UI.createTextField({
		hintText: 'Name',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(name);

	var button = Ti.UI.createButton({
		title: 'Update',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	content.add(button);

	function submitForm() {
		button.hide();

		Cloud.PhotoCollections.update({
			collection_id: evt.id,
			name: name.value
		}, function(e) {
			if (e.success) {
				alert('Updated!');
			} else {
				Utils.error(e);
			}
			button.show();
		});
	}

	button.addEventListener('click', submitForm);
	var fields = [name];
	for (var i = 0; i < fields.length; i++) {
		fields[i].addEventListener('return', submitForm);
	}

	var status = Ti.UI.createLabel({
		text: 'Loading, please wait...',
		textAlign: 'center',
		top: 0,
		right: 0,
		bottom: 0,
		left: 0,
		backgroundColor: '#fff',
		zIndex: 2,
		color: "black",
		hintTextColor: "gray"
	});
	win.add(status);

	win.addEventListener('open', function() {
		Cloud.PhotoCollections.show({
			collection_id: evt.id
		}, function(e) {
			status.hide();
			if (e.success) {
				var photocollection = e.collections[0];
				name.value = photocollection.name;
				name.focus();
			} else {
				Utils.error(e);
			}
		});
	});
	return win;
};
Beispiel #21
0
exports['Create Checkin'] = function (evt) {
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });

    var table = Ti.UI.createTableView({
        backgroundColor: '#fff',
        top: 0, bottom: 0
    });
    table.addEventListener('click', function (evt) {
        if (evt.row.id) {
            var oldTitle = evt.row.title;
            evt.row.title = 'Checking in, please wait...';
            Cloud.Checkins.create({
                place_id: evt.row.id
            }, function (e) {
                evt.row.title = oldTitle;
                if (e.success) {
                    alert('Checked in to ' + oldTitle + '!');
                }
                else {
                    Utils.error(e);
                }
            })
        }
    });
    win.add(table);

    function findPlaces(lat, lon) {
        Cloud.Places.search({
            latitude: lat,
            longitude: lon
        }, function (e) {
            if (e.success) {
                if (e.places.length == 0) {
                    table.setData([
                        { title: 'No Results!' }
                    ]);
                }
                else {
                    var data = [];
                    for (var i = 0, l = e.places.length; i < l; i++) {
                        data.push(Ti.UI.createTableViewRow({
                            title: e.places[i].name,
                            id: e.places[i].id
                        }));
                    }
                    table.setData(data);
                }
            }
            else {
                Utils.error(e);
            }
        });
    }

    function findMe() {

        table.setData([
            { title: 'Geolocating...' }
        ]);

        if (Ti.Geolocation) {
            Ti.Geolocation.purpose = 'To find nearby places.';
            Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;
            Ti.Geolocation.distanceFilter = 0;
            Ti.Geolocation.getCurrentPosition(function (e) {
                if (!e.success || e.error) {
                    findPlaces(null, null);
                    table.setData([
                        { title: 'GPS lost, looking nearby...' }
                    ]);
                }
                else {
                    table.setData([
                        { title: 'Located, looking nearby...' }
                    ]);
                    findPlaces(e.coords.latitude, e.coords.longitude);
                }
            });
        }
        else {
            Cloud.Clients.geolocate(function (e) {
                if (e.success) {
                    table.setData([
                        { title: 'Located, looking nearby...' }
                    ]);
                    findPlaces(e.location.latitude, e.location.longitude)
                }
                else {
                    findPlaces(null, null);
                    table.setData([
                        { title: 'GPS lost, looking nearby...' }
                    ]);
                }
            });
        }
    }

    win.addEventListener('open', findMe);
    return win;
};
exports['External Unlink'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var content = Ti.UI.createScrollView({
		top: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	function unlinkAccount(evt) {
		Cloud.SocialIntegrations.externalAccountUnlink({
			id: evt.source.accountID,
			type: evt.source.accountType
		}, function(e) {
			if (e.success) {
				alert('Unlinked from ' + evt.source.accountType + '!');
				content.remove(evt.source);
			} else {
				Utils.error(e);
			}
		});
	}

	var status = Ti.UI.createLabel({
		text: 'Loading, please wait...',
		textAlign: 'center',
		top: 0,
		right: 0,
		bottom: 0,
		left: 0,
		backgroundColor: '#fff',
		zIndex: 2,
		color: 'color'
	});
	win.add(status);

	win.addEventListener('open', function() {
		Cloud.Users.showMe(function(e) {
			status.hide();
			if (e.success) {
				var user = e.users[0];
				if (user.external_accounts.length == 0) {
					alert('No linked accounts');
				} else {
					for (var i = 0; i < user.external_accounts.length; i++) {
						var button = Ti.UI.createButton({
							title: 'Unlink from ' + user.external_accounts[i].external_type,
							top: 10 + Utils.u,
							left: 10 + Utils.u,
							right: 10 + Utils.u,
							bottom: 10 + Utils.u,
							height: 40 + Utils.u,
							accountType: user.external_accounts[i].external_type,
							accountID: user.external_accounts[i].external_id
						});
						button.addEventListener('click', unlinkAccount);
						content.add(button);
					}
				}
			} else {
				Utils.error(e);
			}
		});
	});
	return win;
};
Beispiel #23
0
exports['Create Photo Collection'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var content = Ti.UI.createScrollView({
		top: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	var name = Ti.UI.createTextField({
		hintText: 'Name',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(name);

	var parentCollectionID;
	var chooseCollection = Ti.UI.createButton({
		title: 'Choose Parent Collection',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	chooseCollection.addEventListener('click', function() {
		var table = Ti.UI.createTableView({
			backgroundColor: '#fff',
			color: 'black',
			data: [{
				title: 'Loading, please wait...'
			}]
		});
		table.addEventListener('click', function(evt) {
			parentCollectionID = evt.row.id;
			win.remove(table);
		});
		win.add(table);

		function findCollections(userID) {
			Cloud.PhotoCollections.search({
				user_id: userID
			}, function(e) {
				if (e.success) {
					if (e.collections.length == 0) {
						win.remove(table);
						alert('No photo collections exist! Create one first.');
					} else {
						var data = [];
						data.push(Ti.UI.createTableViewRow({
							title: 'No Collection',
							id: '',
							color: 'black',
							hasCheck: !parentCollectionID
						}));
						for (var i = 0, l = e.collections.length; i < l; i++) {
							if (e.collections[i].id == evt.id) {
								continue;
							}
							data.push(Ti.UI.createTableViewRow({
								title: e.collections[i].name,
								id: e.collections[i].id,
								color: 'black',
								hasCheck: parentCollectionID == e.collections[i].id
							}));
						}
						table.setData(data);
					}
				} else {
					win.remove(table);
					Utils.error(e);
				}
			});
		}

		Cloud.Users.showMe(function(e) {
			if (e.success) {
				findCollections(e.users[0].id);
			} else {
				table.setData([{
					title: (e.error && e.message) || e
				}]);
				Utils.error(e);
			}
		});
	});
	content.add(chooseCollection);

	var button = Ti.UI.createButton({
		title: 'Create',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	content.add(button);

	function submitForm() {
		for (var i = 0; i < fields.length; i++) {
			if (!fields[i].value.length) {
				fields[i].focus();
				return;
			}
			fields[i].blur();
		}

		button.hide();

		Cloud.PhotoCollections.create({
			name: name.value,
			parent_collection_id: parentCollectionID
		}, function(e) {
			if (e.success) {
				alert('Created!');
				name.value = '';
				parentCollectionID = null;
			} else {
				Utils.error(e);
			}
			button.show();
		});
	}

	button.addEventListener('click', submitForm);
	var fields = [name];
	for (var i = 0; i < fields.length; i++) {
		fields[i].addEventListener('return', submitForm);
	}

	win.addEventListener('open', function() {
		name.focus();
	});
	return win;
};
Beispiel #24
0
exports['Key Values'] = function (evt) {
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });
    var content = Ti.UI.createScrollView({
        top: 0,
        contentHeight: 'auto',
        layout: 'vertical'
    });
    win.add(content);

    var name = Ti.UI.createTextField({
        hintText: 'Name',
        top: 10 + Utils.u, left: 10 + Utils.u, right: 10 + Utils.u,
        height: 40 + Utils.u,
        borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
        autocapitalization: Ti.UI.TEXT_AUTOCAPITALIZATION_NONE,
        autocorrect: false
    });
    content.add(name);

    var value = Ti.UI.createTextField({
        hintText: 'Value',
        top: 10 + Utils.u, left: 10 + Utils.u, right: 10 + Utils.u,
        height: 40 + Utils.u,
        borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
        autocapitalization: Ti.UI.TEXT_AUTOCAPITALIZATION_NONE,
        autocorrect: false
    });
    content.add(value);

    var setButton = Ti.UI.createButton({
        title: 'Set',
        top: 10 + Utils.u, left: 10 + Utils.u, right: 10 + Utils.u, bottom: 10 + Utils.u,
        height: 40 + Utils.u
    });
    setButton.addEventListener('click', function submitForm() {
        Cloud.KeyValues.set({
            name: name.value,
            value: value.value
        }, function (e) {
            if (e.success) {
                alert('Set!');
            }
            else {
                Utils.error(e);
            }
        });
    });
    content.add(setButton);

    var getButton = Ti.UI.createButton({
        title: 'Get',
        top: 0, left: 10 + Utils.u, right: 10 + Utils.u, bottom: 10 + Utils.u,
        height: 40 + Utils.u
    });
    getButton.addEventListener('click', function (evt) {
        Cloud.KeyValues.get({
            name: name.value
        }, function (e) {
            if (e.success) {
                value.value = e.keyvalues[0].value;
                alert('Got!');
            }
            else {
                Utils.error(e);
            }
        });
    });
    content.add(getButton);

    var appendButton = Ti.UI.createButton({
        title: 'Append',
        top: 0, left: 10 + Utils.u, right: 10 + Utils.u, bottom: 10 + Utils.u,
        height: 40 + Utils.u
    });
    appendButton.addEventListener('click', function (evt) {
        Cloud.KeyValues.append({
            name: name.value,
            value: value.value
        }, function (e) {
            if (e.success) {
                alert('Appended!');
            }
            else {
                Utils.error(e);
            }
        });
    });
    content.add(appendButton);

    var incrementButton = Ti.UI.createButton({
        title: 'Increment',
        top: 0, left: 10 + Utils.u, right: 10 + Utils.u, bottom: 10 + Utils.u,
        height: 40 + Utils.u
    });
    incrementButton.addEventListener('click', function (evt) {
    	var incrby = parseInt(value.value, 10);
    	if (isNaN(incrby)) {
    		alert('Enter a valid number for the increment');
    		value.focus();
    		return;
    	}
        Cloud.KeyValues.increment({
            name: name.value,
            value: incrby
        }, function (e) {
            if (e.success) {
                alert('Incremented!');
            }
            else {
                Utils.error(e);
            }
        });
    });
    content.add(incrementButton);

    var removeButton = Ti.UI.createButton({
        title: 'Remove',
        top: 0, left: 10 + Utils.u, right: 10 + Utils.u, bottom: 10 + Utils.u,
        height: 40 + Utils.u
    });
    removeButton.addEventListener('click', function (evt) {
        Cloud.KeyValues.remove({
            name: name.value
        }, function (e) {
            if (e.success) {
                alert('Removed!');
                value.value = '';
            }
            else {
                Utils.error(e);
            }
        });
    });
    content.add(removeButton);

    win.addEventListener('open', function () {
        name.focus();
    });
    return win;
};
Beispiel #25
0
exports['Create Message'] = function (evt) {
    var win = WindowManager.createWindow({
        backgroundColor: 'white'
    });
    var content = Ti.UI.createScrollView({
        top: 0,
        contentHeight: 'auto',
        layout: 'vertical'
    });
    win.add(content);

	var toView = Ti.UI.createView({
		top: 10 + Utils.u, left: 10 + Utils.u, right: 10 + Utils.u,
		height: Ti.UI.SIZE || 'auto',
		layout: 'horizontal'
	});
	var toSet = {
		ids: [],
		names: []
	};
    var toButton = Ti.UI.createButton({
        title: 'To:', 
        height: 40 + Utils.u,
        width: Ti.UI.SIZE || 'auto'
    });
    toButton.addEventListener('click', function (e) {
	    WindowManager.handleOpenWindow({ target: 'Select Users for Message', toSet: toSet });
    });
    toView.add(toButton);

	var toNames = Ti.UI.createTextField({
		left: 10 + Utils.u, right: 0,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		editable: false,
		ellipsize: true
	});
	toView.add(toNames);
	content.add(toView);

	var subject = Ti.UI.createTextField({
		hintText: 'Subject',
		top: 10 + Utils.u, left: 10 + Utils.u, right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		autocorrect: false
	});
	content.add(subject);

	var body = Ti.UI.createTextArea({
		hintText: 'Body',
		top: 10 + Utils.u, left: 10 + Utils.u, right: 10 + Utils.u,
		height: 120 + Utils.u,
      	borderWidth: 2,
      	borderColor: '#bbb',
      	borderRadius: 5,
      	font: {fontSize:20 }
	});
	content.add(body);

    var createButton = Ti.UI.createButton({
        title: 'Create',
        top: 10 + Utils.u, left: 10 + Utils.u, right: 10 + Utils.u, bottom: 10 + Utils.u,
        height: 40 + Utils.u
    });
    createButton.addEventListener('click', function (evt) {
    	createButton.hide();
        Cloud.Messages.create({
	        to_ids: toSet.ids.join(','),
	        body: body.value,
	        subject: subject.value
        }, function (e) {
            if (e.success) {
                alert('Created!');
	            body.value = subject.value = toNames.value = '';
	            toSet.ids = [];
	            toSet.names = [];
            } else {
                Utils.error(e);
            }
            createButton.show();
        });
    });
    content.add(createButton);

    win.addEventListener('open', function () {
        subject.focus();
    });
	win.addEventListener('focus', function () {
        toNames.value = toSet.names.join(',');
    });
    return win;
};
exports['Update Users in ACL'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var content = Ti.UI.createScrollView({
		top: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	var name = Ti.UI.createTextField({
		hintText: 'Name',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		autocapitalization: Ti.UI.TEXT_AUTOCAPITALIZATION_NONE,
		autocorrect: false,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(name);

	var readers = {
		ids: []
	};
	var readersButton = Ti.UI.createButton({
		title: 'Select Readers',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	readersButton.addEventListener('click', function submitForm() {
		WindowManager.handleOpenWindow({
			target: 'Select Users for ACL',
			access: readers
		});
	});
	content.add(readersButton);

	var writers = {
		ids: []
	};
	var writersButton = Ti.UI.createButton({
		title: 'Select Writers',
		top: 0,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	writersButton.addEventListener('click', function(evt) {
		WindowManager.handleOpenWindow({
			target: 'Select Users for ACL',
			access: writers
		});
	});
	content.add(writersButton);

	var addButton = Ti.UI.createButton({
		title: 'Add Users',
		top: 0,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	addButton.addEventListener('click', function(evt) {
		if (name.value.length == 0) {
			name.focus();
			return;
		}
		Cloud.ACLs.addUser({
			name: name.value,
			reader_ids: readers.ids.join(','),
			writer_ids: writers.ids.join(',')
		}, function(e) {
			if (e.success) {
				alert('Added!');
			} else {
				Utils.error(e);
			}
		});
	});
	content.add(addButton);

	var removeButton = Ti.UI.createButton({
		title: 'Remove Users',
		top: 0,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	removeButton.addEventListener('click', function(evt) {
		Cloud.ACLs.removeUser({
			name: name.value,
			reader_ids: readers.ids.join(','),
			writer_ids: writers.ids.join(',')
		}, function(e) {
			if (e.success) {
				alert('Removed!');
			} else {
				Utils.error(e);
			}
		});
	});
	content.add(removeButton);

	win.addEventListener('open', function() {
		name.focus();
	});
	return win;
};
Beispiel #27
0
exports['Create Event'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var content = Ti.UI.createScrollView({
		top: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	var name = Ti.UI.createTextField({
		hintText: 'Name',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(name);

	var date = Ti.UI.createTextField({
		hintText: 'Date MM/DD/YYYY',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(date);

	var time = Ti.UI.createTextField({
		hintText: 'Time HH:MM',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(time);

	var duration = Ti.UI.createTextField({
		hintText: 'Duration (seconds)',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		keyboardType: Ti.UI.KEYBOARD_NUMBER_PAD,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(duration);

	var recurring = Ti.UI.createTextField({
		hintText: 'Recurring',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		autocapitalization: Ti.UI.TEXT_AUTOCAPITALIZATION_NONE,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(recurring);

	var recurringCount = Ti.UI.createTextField({
		hintText: 'Recurring Count (0-1000)',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		keyboardType: Ti.UI.KEYBOARD_NUMBER_PAD,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(recurringCount);

	var button = Ti.UI.createButton({
		title: 'Create',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	content.add(button);


	function submitForm() {
		button.hide();
		var data = {
			name: name.value
		};
		var value;
		value = Date.parse(date.value + ' ' + time.value);
		if (isNaN(value)) {
			alert("Please enter a valid date/time");
			date.focus();
			return;
		}
		data.start_time = new Date(value);
		value = parseInt(duration.value, 10);
		if (!isNaN(value)) {
			data.duration = value;
		}
		if (recurring.value.length > 0) {
			data.recurring = recurring.value.toLowerCase();
			var validValues = {
				daily: 1,
				weekly: 1,
				monthly: 1,
				yearly: 1
			};
			if (!validValues[data.recurring]) {
				alert("Enter 'daily', 'weekly', 'monthly', or 'yearly'");
				recurring.focus();
				return;
			}
		}
		value = parseInt(recurringCount.value, 10);
		if (!isNaN(value)) {
			data.recurring_count = value;
		}

		Cloud.Events.create(data, function(e) {
			if (e.success) {
				alert('Created!');
				name.value = date.value = time.value = duration.value = recurring.value = recurringCount.value = '';
			} else {
				Utils.error(e);
			}
			button.show();
		});
	}

	button.addEventListener('click', submitForm);
	var fields = [name, date, time, duration, recurring, recurringCount];
	for (var i = 0; i < fields.length; i++) {
		fields[i].addEventListener('return', submitForm);
	}

	win.addEventListener('open', function() {
		name.focus();
	});
	return win;
};
Beispiel #28
0
exports['Create Review'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var content = Ti.UI.createScrollView({
		top: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	var status = Ti.UI.createLabel({
		text: 'Loading, please wait...',
		textAlign: 'center',
		color: '#000',
		backgroundColor: '#fff',
		top: 0,
	});
	win.add(status);

	var userID;
	Cloud.Users.showMe(function(e) {
		if (e.success) {
			win.remove(status);
			userID = e.users[0].id;
		} else {
			Utils.error(e);
			status.text = (e.error && e.message) || e;
		}
	});

	var contentText = Ti.UI.createTextField({
		hintText: 'Content',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(contentText);

	var rating = Ti.UI.createSlider({
		value: 5,
		min: 1,
		max: 5,
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u
	});
	content.add(rating);

	var button = Ti.UI.createButton({
		title: 'Create',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	content.add(button);

	function submitForm() {
		button.hide();

		Cloud.Reviews.create({
			user_id: userID,
			content: contentText.value,
			rating: rating.value,
			allow_duplicate: 1
		}, function(e) {
			if (e.success) {
				alert('Created!');
				contentText.value = '';
			} else {
				Utils.error(e);
			}
			button.show();
		});
	}

	button.addEventListener('click', submitForm);
	var fields = [contentText];
	for (var i = 0; i < fields.length; i++) {
		fields[i].addEventListener('return', submitForm);
	}

	win.addEventListener('open', function() {
		contentText.focus();
	});
	return win;
};
exports['Update Subscription'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var content = Ti.UI.createScrollView({
		top: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	if (!Utils.pushDeviceToken) {
		content.add(Ti.UI.createLabel({
			text: 'Please visit Push Notifications > Settings to enable push!',
			textAlign: 'center',
			color: '#000',
			height: 'auto'
		}));
		return win;
		return;
	}

	// These variables represent the device's geographic coordinates,
	// and are passed in the 'loc' parameter to the updateSubscription() method.
	// This enables a Dashboard administrator to send a push notification to this user based on their location.

	var currentLatitude = "37.3895100";
	var currentLongitude = "-122.0502150";

	var latitude = Ti.UI.createTextField({
		hintText: 'Latitude',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		autocapitalization: Ti.UI.TEXT_AUTOCAPITALIZATION_NONE,
		autocorrect: false,
		value: currentLatitude,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(latitude);

	var longitude = Ti.UI.createTextField({
		hintText: 'Longitude',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		height: 40 + Utils.u,
		borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
		autocapitalization: Ti.UI.TEXT_AUTOCAPITALIZATION_NONE,
		autocorrect: false,
		value: currentLongitude,
		color: "black",
		hintTextColor: "gray"
	});
	content.add(longitude);

	var button = Ti.UI.createButton({
		title: 'Update',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	content.add(button);

	var fields = [longitude, latitude];

	function submitForm() {
		for (var i = 0; i < fields.length; i++) {
			if (!fields[i].value.length) {
				fields[i].focus();
				return;
			}
			fields[i].blur();
		}
		button.hide();

		Cloud.PushNotifications.updateSubscription({
			device_token: Utils.pushDeviceToken,
			loc: [parseFloat(longitude.value), parseFloat(latitude.value)]
		}, function(e) {
			if (e.success) {
				alert('Subscription Updated! ' + Utils.pushDeviceToken);
			} else {
				Utils.error(e);
			}
			button.show();
		});
	}

	button.addEventListener('click', submitForm);
	for (var i = 0; i < fields.length; i++) {
		fields[i].addEventListener('return', submitForm);
	}

	win.addEventListener('open', function() {
		latitude.focus();
	});
	return win;
};
Beispiel #30
0
exports['Show Photo Collection'] = function(evt) {
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var content = Ti.UI.createScrollView({
		top: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	var status = Ti.UI.createLabel({
		text: 'Loading, please wait...',
		textAlign: 'left',
		height: 30 + Utils.u,
		left: 20 + Utils.u,
		right: 20 + Utils.u,
		color: 'black'
	});
	content.add(status);

	Cloud.PhotoCollections.show({
		collection_id: evt.id
	}, function(e) {
		content.remove(status);

		if (e.success) {

			var collection = e.collections[0];

			if (collection.counts.photos) {
				var showPhotos = Ti.UI.createButton({
					title: 'Show Photos',
					top: 10 + Utils.u,
					left: 10 + Utils.u,
					right: 10 + Utils.u,
					bottom: 10 + Utils.u,
					height: 40 + Utils.u
				});
				showPhotos.addEventListener('click', function() {
					WindowManager.handleOpenWindow({
						target: 'Show Collection\'s Photos',
						id: evt.id
					});
				});
				content.add(showPhotos);
			}
			if (collection.counts.subcollections) {
				var showSubcollections = Ti.UI.createButton({
					title: 'Show Subcollections',
					top: 10 + Utils.u,
					left: 10 + Utils.u,
					right: 10 + Utils.u,
					bottom: 10 + Utils.u,
					height: 40 + Utils.u
				});
				showSubcollections.addEventListener('click', function() {
					WindowManager.handleOpenWindow({
						target: 'Show Subcollections',
						id: evt.id
					});
				});
				content.add(showSubcollections);
			}

			var update = Ti.UI.createButton({
				title: 'Update',
				top: 10 + Utils.u,
				left: 10 + Utils.u,
				right: 10 + Utils.u,
				bottom: 10 + Utils.u,
				height: 40 + Utils.u
			});
			update.addEventListener('click', function() {
				WindowManager.handleOpenWindow({
					target: 'Update Photo Collection',
					id: evt.id
				});
			});
			content.add(update);

			var remove = Ti.UI.createButton({
				title: 'Remove',
				top: 10 + Utils.u,
				left: 10 + Utils.u,
				right: 10 + Utils.u,
				bottom: 10 + Utils.u,
				height: 40 + Utils.u
			});
			remove.addEventListener('click', function() {
				WindowManager.handleOpenWindow({
					target: 'Remove Photo Collection',
					id: evt.id
				});
			});
			content.add(remove);

			Utils.enumerateProperties(content, collection, 20);
		} else {
			Utils.error(e);
		}
	});

	return win;
};