How to use alloy - 10 common examples

To help you get started, we’ve selected a few alloy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pedropalmero / alloy-unit-test / app / lib / tests_runner.js View on Github external
function run() {
    var Alloy = require('alloy');

    Alloy.CFG.db_name = 'my_db_test';

    // remove and create and empty database
    var db = Ti.Database.open(Alloy.CFG.db_name);
    db.remove();

    var tijasmine = require("tijasmine/tijasmine"),
        reporter = new (require("tijasmine/tijasmine-console").ConsoleReporter);

    tijasmine.addSpecModules(
        "specs/lib/counter_spec",
        "specs/model/book_spec",
        "specs/controller/index_spec",
        "specs/controller/detail_spec"
    );
    tijasmine.addReporter(reporter);
    tijasmine.execute();
}
github CBMVC / CBMVC-Library-For-Titanium-Alloy / app / lib / core.js View on Github external
CB.setupDatabase();

		// Init cache object
		CB.Cache.init();

		// Init utility object
		CB.Util.init(content.index);

		// The main content
		CB.MainContent = content.main;

		// The main content copy
		CB._mainContent = content.main;

		// Get the current controller
		CB._currentController = Alloy.createController(Alloy.CFG.firstController);
	},
	/**
github viezel / napp.alloy.adapter.restsql / sqlrest.js View on Github external
_.isFunction(params.success) && params.success(resp);
			} else {
				// error or offline - save & use local data

				// save data locally when server returned an error
				if (!_response.localOnly && params.disableSaveDataLocallyOnServerError) {
					params.returnErrorResponse && _.isFunction(params.error) && params.error(_response);
					logger(DEBUG, "NOTICE: The data is not being saved locally");
				} else {
					resp = saveData();
					if (_.isUndefined(_response.offline)) {
						// error
						_.isFunction(params.error) && params.error(params.returnErrorResponse ? _response : resp);
					} else {
						//offline - still a data success
						_.isFunction(params.success) && params.success(resp);
					}
				}
			}
		});
		break;
github appcelerator / alloy / Alloy / lib / alloy / sync / properties.js View on Github external
else if (method === 'create' || method === 'update') {
		if (!model.id) {
			model.id = guid();
			model.set(model.idAttribute, model.id);
		}
		TAP.setObject(prefix + '-' + model.id, model.toJSON() || {});
		resp = model.toJSON();
	} else if (method === 'delete') {
		TAP.removeProperty(prefix + '-' + model.id);
		model.clear();
		resp = model.toJSON();
	}

	// process success/error handlers, if present
	if (resp) {
        if (_.isFunction(opts.success)) { opts.success(resp); }
        if (method === "read") { model.trigger("fetch"); }
    } else {
		if (_.isFunction(opts.error)) { opts.error(resp); }
    }
}
github appcelerator / alloy / Alloy / lib / alloy / sync / properties.js View on Github external
model.set(model.idAttribute, model.id);
		}
		TAP.setObject(prefix + '-' + model.id, model.toJSON() || {});
		resp = model.toJSON();
	} else if (method === 'delete') {
		TAP.removeProperty(prefix + '-' + model.id);
		model.clear();
		resp = model.toJSON();
	}

	// process success/error handlers, if present
	if (resp) {
        if (_.isFunction(opts.success)) { opts.success(resp); }
        if (method === "read") { model.trigger("fetch"); }
    } else {
		if (_.isFunction(opts.error)) { opts.error(resp); }
    }
}
github matomo-org / matomo-mobile-2 / app / lib / Piwik / Tracker.js View on Github external
this.prepareVisitCustomVariables = function () {
        
        var locale      = require('Piwik/Locale');
        var Alloy       = require("alloy");
        var numAccounts = Alloy.Collections.instance("appAccounts").length;
            
        this.setCustomVariable(1, 'OS', Ti.Platform.osname + ' ' + Ti.Platform.version, 'visit');

        // Piwik Version
        this.setCustomVariable(2, 'Matomo Mobile Version', require('Piwik').getAppVersion(), 'visit');

        // Locale of the device + configured locale
        this.setCustomVariable(3, 'Locale', locale.getPlatformLocale() + '::' + locale.getLocale(), 'visit');
        this.setCustomVariable(4, 'Num Accounts', numAccounts, 'visit');
        
        locale   = null;
    };
github timanrebel / RebelFrame / WindowManager.js View on Github external
if (win.createStack) {
			addWinToStack(win.createStack, win);
		} else if (win.addToStack) {
			addWinToStack(win.addToStack, win);
		}

		if (OS_IOS) {
			// Sometimes we accidentally set modal and navGroup to true.
			// In that case 'modal' should be preferred, because modal windows are always opened in a new NavWindow
			if (win.navGroup && win.modalWin)
				win.navGroup = false;

			// Show SideMenu button and replace current centerWindow with this new Window
			if (win.showSideMenu) {
				// Show sideMenu button
				var sideMenuButton = Alloy.createWidget(Alloy.CFG.SideMenu.buttonWidget || 'rebel.MenuBarButton', {
					buttonType: 'hamburger',
					delay: 200
				});
				win.leftNavButton = sideMenuButton.getView();
				sideMenuButton.on('click', WM.toggleLeftNavDrawer);

				// Create SideMenu if not yet created.
				// Else replace current centerWindow with this Window
				setupNavDrawer({
					centerWin: WM.createNewNavWindow(win)
				});
			}
			// If window should be Modal Window
			// Also add it to a new navigationGroup
			else if (win.modalWin) {
				WM.createNewNavWindow(win).open({
github shouse / To-Do-Demo / app / lib / logging / logging.js View on Github external
function writeToRemote(level, message, data) {
        remoteProvider = Alloy.CFG.logger.remoteProvider;
        Ti.API.info('[lLOGGER] :: Writing log to remote provider: ' +
            remoteProvider);
        switch (remoteProvider) {
            case "acs":
                //acs(level, message, data);
                break;
                // This will be where to change to interface with our own backend
            case "custom":
                break;
            default:
                alert("You have to edit config.json to supply your remote provider.");
                break;
        }

    }
github timanrebel / RebelFrame / Cloud.js View on Github external
// Prepare the data (if required)
				var url = config.url,
					method = config.method || 'GET',
					data, query;

				if (method == 'GET' || method == 'DELETE') {
					query = toQueryString(config.data);

					if (query)
						url = url + (url.indexOf('?') > 0 ? '&' : '?') + query;
				} else
					data = config.data || {};

				// Add base Url if url does not start with http
				if(url.substr(0, 4) !== 'http')
					url = Alloy.CFG.baseUrl + url;

				Ti.API.debug(method + ': ' + url);
				// Ti.API.info(data);

				// Open connection
				this.httpClient.open(method, url);

				// Set headers after opening connection
				for (var key in config.headers) {
					this.httpClient.setRequestHeader(key, config.headers[key]);
				}

				if(config.json) {
					this.httpClient.setRequestHeader('Content-Type', 'application/json');

					if(data)
github trimethyl / trimethyl / framework / firebase / cloudmessaging.js View on Github external
var _ = require('alloy/underscore')._;

/**
 * @property config
 * @property {String} 	[config.driver="http"] 			The driver to use.
 * @property {Boolean} 	[config.autoReset=true] 		If true, set the badge count to 0 when you open/resume the application.
 * @property {Boolean} 	[config.fakeDeviceToken=false] 	A fake device token.
 * @property {Object[]} [config.channels] 				**Android only** A list of channels to create when subscribing to Firebase notifications.
 * @property {String[]} [config.dataFields] 			A list of data fields to check when receiving a data message.
 * @type {Object}
 */
exports.config = _.extend({
	driver: null,
	autoReset: true,
	fakeDeviceToken: false
}, (Alloy.CFG.T && Alloy.CFG.T.firebase) ? Alloy.CFG.T.firebase.cloudmessaging : {});

var MODULE_NAME = 'firebase/cloudmessaging';

var Event = require('T/event');
var Q = require('T/ext/q');
require('T/firebase/core');
var FCM = require('firebase.cloudmessaging');

var registered_for_push_notifications = false;

var dataFields = {};

// The listener for all received notification messages
function notificationsCallback(e) {
	// Auto-reset the badge when a notification is received
	if (exports.config.autoReset === true) {