Example #1
0
exports.C = function(name, modelDesc, model) {
	var extendObj = { model: model };
	var config = (model ? model.prototype.config : {}) || {};
	var mod;

	if (config.adapter && config.adapter.type) {
		mod = require('alloy/sync/' + config.adapter.type);
		extendObj.sync = function(method, model, opts) {
			mod.sync(method,model,opts);
		};
	} else {
		extendObj.sync = function(method, model, opts) {
			Ti.API.warn('Execution of ' + method + '#sync() function on a collection that does not support persistence');
			Ti.API.warn('model: ' + JSON.stringify(model.toJSON()));
		};
	}

	var Collection = Backbone.Collection.extend(extendObj);
	Collection.prototype.config = config;

	// extend the collection object
	if (_.isFunction(modelDesc.extendCollection)) {
		Collection = modelDesc.extendCollection(Collection) || Collection;
	}

	// do any post collection creation code form the sync adapter
	if (mod && _.isFunction(mod.afterCollectionCreate)) {
		mod.afterCollectionCreate(Collection);
	}

	return Collection;
};
Example #2
0
exports.C = function(name, modelDesc, model) {
    var extendObj = {
		model: model,
        sync: function(method, model, opts) {
			var config = (model.config || {});
			var type = (config.adapter ? config.adapter.type : null) || 'localDefault';
			if (type === 'localDefault') {
		    	type = OS_MOBILEWEB ? 'localStorage' : 'sql';
		    }

			require('alloy/sync/'+type).sync(method,model,opts);
		}
	};

	var Collection = Backbone.Collection.extend(extendObj);
	var config = Collection.prototype.config = model.prototype.config;

	var type = (config.adapter ? config.adapter.type : null) || 'localDefault';
	var adapter = require('alloy/sync/'+type);
	if (_.isFunction(adapter.afterCollectionCreate)) { adapter.afterCollectionCreate(Collection); }

	if (_.isFunction(modelDesc.extendCollection)) {
		Collection = modelDesc.extendCollection(Collection) || Collection;
	}

	return Collection;
};
Example #3
0
exports.C = function(name, modelDesc, model) {
    var extendObj = {
		model: model,
        sync: function(method, model, opts) {
			var config = (model.config || {});
			var type = (config.adapter ? config.adapter.type : null) || 'localDefault';
			if (Ti.Platform.osname === 'mobileweb' && type === 'localDefault') {
				type = 'localStorage';
			}
			else if (type === 'localDefault') {
				type = 'sql';
			}

			require('alloy/sync/'+type).sync(model,method,opts);
		}
	};

	var Collection = Backbone.Collection.extend(extendObj); 
	Collection.prototype.config = model.prototype.config;

	if (_.isFunction(modelDesc.extendModel)) {
		Collection = modelDesc.extendCollection(Collection) || Collection;
	}
	
	return Collection;
};
exports.C = function(name, modelDesc, model) {
    var extendObj = {
        model: model,
        sync: function(method, model, opts) {
            var config = model.config || {}, type = (config.adapter ? config.adapter.type : null) || "localDefault";
            Ti.Platform.osname === "mobileweb" && type === "localDefault" ? type = "localStorage" : type === "localDefault" && (type = "sql");
            require("alloy/sync/" + type).sync(model, method, opts);
        }
    }, Collection = Backbone.Collection.extend(extendObj), config = Collection.prototype.config = model.prototype.config, type = (config.adapter ? config.adapter.type : null) || "localDefault", adapter = require("alloy/sync/" + type);
    _.isFunction(adapter.afterCollectionCreate) && adapter.afterCollectionCreate(Collection);
    _.isFunction(modelDesc.extendModel) && (Collection = modelDesc.extendCollection(Collection) || Collection);
    return Collection;
};
Example #5
0
exports.C = function(name, modelDesc, model) {
    var extendObj = {
        model: model,
        sync: function(method, model, opts) {
            var config = model.config || {};
            var type = (config.adapter ? config.adapter.type : null) || "localDefault";
            "localDefault" === type && (type = "sql");
            require("alloy/sync/" + type).sync(method, model, opts);
        }
    };
    var Collection = Backbone.Collection.extend(extendObj);
    var config = Collection.prototype.config = model.prototype.config;
    var type = (config.adapter ? config.adapter.type : null) || "localDefault";
    var adapter = require("alloy/sync/" + type);
    _.isFunction(adapter.afterCollectionCreate) && adapter.afterCollectionCreate(Collection);
    _.isFunction(modelDesc.extendCollection) && (Collection = modelDesc.extendCollection(Collection) || Collection);
    return Collection;
};
Example #6
0
exports.C = function(name, modelDesc, model) {
    var extendObj = {
        model: model
    };
    var config = (model ? model.prototype.config : {}) || {};
    var mod;
    if (config.adapter && config.adapter.type) {
        mod = require("alloy/sync/" + config.adapter.type);
        extendObj.sync = function(method, model, opts) {
            mod.sync(method, model, opts);
        };
    } else extendObj.sync = function(method, model) {
        Ti.API.warn("Execution of " + method + "#sync() function on a collection that does not support persistence");
        Ti.API.warn("model: " + JSON.stringify(model.toJSON()));
    };
    var Collection = Backbone.Collection.extend(extendObj);
    Collection.prototype.config = config;
    _.isFunction(modelDesc.extendCollection) && (Collection = modelDesc.extendCollection(Collection) || Collection);
    mod && _.isFunction(mod.afterCollectionCreate) && mod.afterCollectionCreate(Collection);
    return Collection;
};
Example #7
0
function ucfirst(e){return e?e[0].toUpperCase()+e.substr(1):e}function addNamespace(e){return(CONST.IMPLICIT_NAMESPACES[e]||CONST.NAMESPACE_DEFAULT)+"."+e}function processStyle(e,t,i,n,r){n=n||{},n.classes=i,t.apiName&&(n.apiName=t.apiName),t.id&&(n.id=t.id),t.applyProperties(exports.createStyle(e,n,r)),t.classes=i}function isTabletFallback(){return Math.min(Ti.Platform.displayCaps.platformHeight,Ti.Platform.displayCaps.platformWidth)>=700}function deepExtend(){var e,t,i,n,r,o,a=arguments[0]||{},s=1,l=arguments.length,u=!1;for("boolean"==typeof a&&(u=a,a=arguments[1]||{},s=2),"object"==typeof a||_.isFunction(a)||(a={});l>s;s++)if(e=arguments[s],null!=e){"string"==typeof e&&(e=e.split(""));for(t in e)i=a[t],n=e[t],a!==n&&(u&&n&&(_.isObject(n)&&!_.has(n,"apiName")||(r=_.isArray(n)))&&!n.colors?(r?(r=!1,o=i&&_.isArray(i)?i:[]):o=_.isDate(n)?new Date(n.valueOf()):i&&_.isObject(i)?i:{},a[t]=deepExtend(u,o,n)):"undefined"!=typeof n?a[t]=n:n.colors&&(a[t]=n))}return a}var _=require("alloy/underscore")._,Backbone=require("alloy/backbone"),CONST=require("alloy/constants");exports.version="1.5.1",exports._=_,exports.Backbone=Backbone;var DEFAULT_WIDGET="widget",TI_VERSION=Ti.version,MW320_CHECK=!1,IDENTITY_TRANSFORM=Ti.UI.create2DMatrix(),RESET={bottom:null,left:null,right:null,top:null,height:null,width:null,shadowColor:null,shadowOffset:null,backgroundImage:null,backgroundRepeat:null,center:null,layout:null,backgroundSelectedColor:null,backgroundSelectedImage:null,opacity:1,touchEnabled:!0,enabled:!0,horizontalWrap:!0,zIndex:0,backgroundColor:"transparent",font:null,visible:!0,color:"#000",transform:IDENTITY_TRANSFORM,backgroundGradient:null,borderColor:null,borderRadius:null,borderWidth:null};RESET=_.extend(RESET,{backgroundDisabledColor:null,backgroundDisabledImage:null,backgroundFocusedColor:null,backgroundFocusedImage:null,focusable:!1,keepScreenOn:!1}),exports.M=function(e,t,i){var n,r=(t||{}).config||{},o=r.adapter||{},a={},s={};o.type?(n=require("alloy/sync/"+o.type),a.sync=function(e,t,i){n.sync(e,t,i)}):a.sync=function(e,t){Ti.API.warn("Execution of "+e+"#sync() function on a model that does not support persistence"),Ti.API.warn("model: "+JSON.stringify(t.toJSON()))},a.defaults=r.defaults,i&&(s.migrations=i),n&&_.isFunction(n.beforeModelCreate)&&(r=n.beforeModelCreate(r,e)||r);var l=Backbone.Model.extend(a,s);return l.prototype.config=r,_.isFunction(t.extendModel)&&(l=t.extendModel(l)||l),n&&_.isFunction(n.afterModelCreate)&&n.afterModelCreate(l,e),l},exports.C=function(e,t,i){var n,r={model:i},o=(i?i.prototype.config:{})||{};o.adapter&&o.adapter.type?(n=require("alloy/sync/"+o.adapter.type),r.sync=function(e,t,i){n.sync(e,t,i)}):r.sync=function(e,t){Ti.API.warn("Execution of "+e+"#sync() function on a collection that does not support persistence"),Ti.API.warn("model: "+JSON.stringify(t.toJSON()))};var a=Backbone.Collection.extend(r);return a.prototype.config=o,_.isFunction(t.extendCollection)&&(a=t.extendCollection(a)||a),n&&_.isFunction(n.afterCollectionCreate)&&n.afterCollectionCreate(a),a},exports.UI={},exports.UI.create=function(controller,apiName,opts){opts=opts||{};var baseName,ns,parts=apiName.split(".");if(1===parts.length)baseName=apiName,ns=opts.ns||CONST.IMPLICIT_NAMESPACES[baseName]||CONST.NAMESPACE_DEFAULT;else{if(!(parts.length>1))throw"Alloy.UI.create() failed: No API name was given in the second parameter";baseName=parts[parts.length-1],ns=parts.slice(0,parts.length-1).join(".")}opts.apiName=ns+"."+baseName,baseName=baseName[0].toUpperCase()+baseName.substr(1);var style=exports.createStyle(controller,opts);return eval(ns)["create"+baseName](style)},exports.createStyle=function(e,t,i){var n,r;if(!t)return{};n=_.isArray(t.classes)?t.classes.slice(0):_.isString(t.classes)?t.classes.split(/\s+/):[],r=t.apiName,r&&-1===r.indexOf(".")&&(r=addNamespace(r));var o;o=require(e&&_.isObject(e)?"alloy/widgets/"+e.widgetId+"/styles/"+e.name:"alloy/styles/"+e);var a,s,l={};for(a=0,s=o.length;s>a;a++){var u=o[a],c=u.key;if(u.isApi&&-1===c.indexOf(".")&&(c=(CONST.IMPLICIT_NAMESPACES[c]||CONST.NAMESPACE_DEFAULT)+"."+c),u.isId&&t.id&&u.key===t.id||u.isClass&&_.contains(n,u.key));else{if(!u.isApi)continue;if(-1===u.key.indexOf(".")&&(u.key=addNamespace(u.key)),u.key!==r)continue}u.queries&&u.queries.formFactor&&!Alloy[u.queries.formFactor]||deepExtend(!0,l,u.style)}var d=_.omit(t,[CONST.CLASS_PROPERTY,CONST.APINAME_PROPERTY]);return deepExtend(!0,l,d),l[CONST.CLASS_PROPERTY]=n,l[CONST.APINAME_PROPERTY]=r,MW320_CHECK&&delete l[CONST.APINAME_PROPERTY],i?_.defaults(l,i):l},exports.addClass=function(e,t,i,n){if(!i)return void(n&&(MW320_CHECK&&delete n.apiName,t.applyProperties(n)));var r=t[CONST.CLASS_PROPERTY]||[],o=r.length;i=_.isString(i)?i.split(/\s+/):i;var a=_.union(r,i||[]);return o===a.length?void(n&&(MW320_CHECK&&delete n.apiName,t.applyProperties(n))):void processStyle(e,t,a,n)},exports.removeClass=function(e,t,i,n){i=i||[];var r=t[CONST.CLASS_PROPERTY]||[],o=r.length;if(!o||!i.length)return void(n&&(MW320_CHECK&&delete n.apiName,t.applyProperties(n)));i=_.isString(i)?i.split(/\s+/):i;var a=_.difference(r,i);return o===a.length?void(n&&(MW320_CHECK&&delete n.apiName,t.applyProperties(n))):void processStyle(e,t,a,n,RESET)},exports.resetClass=function(e,t,i,n){i=i||[],i=_.isString(i)?i.split(/\s+/):i,processStyle(e,t,i,n,RESET)},exports.createWidget=function(e,t,i){return"undefined"!=typeof t&&null!==t&&_.isObject(t)&&!_.isString(t)&&(i=t,t=DEFAULT_WIDGET),new(require("alloy/widgets/"+e+"/controllers/"+(t||DEFAULT_WIDGET)))(i)},exports.createController=function(e,t){return new(require("alloy/controllers/"+e))(t)},exports.createModel=function(e,t){return new(require("alloy/models/"+ucfirst(e)).Model)(t)},exports.createCollection=function(e,t){return new(require("alloy/models/"+ucfirst(e)).Collection)(t)},exports.isTablet=function(){var e=Ti.Platform.Android.physicalSizeCategory;return e===Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_LARGE||e===Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_XLARGE}(),exports.isHandheld=!exports.isTablet,exports.Globals={},exports.Models={},exports.Models.instance=function(e){return exports.Models[e]||(exports.Models[e]=exports.createModel(e))},exports.Collections={},exports.Collections.instance=function(e){return exports.Collections[e]||(exports.Collections[e]=exports.createCollection(e))},exports.CFG=require("alloy/CFG"),exports.Android={},exports.Android.menuItemCreateArgs=["itemId","groupId","title","order","actionView","checkable","checked","enabled","icon","showAsAction","titleCondensed","visible"];
Example #8
0
function ucfirst(e){return e?e[0].toUpperCase()+e.substr(1):e}function addNamespace(e){return(CONST.IMPLICIT_NAMESPACES[e]||CONST.NAMESPACE_DEFAULT)+"."+e}function processStyle(e,t,o,r,n){r=r||{},r.classes=o,t.apiName&&(r.apiName=t.apiName),t.id&&(r.id=t.id),t.applyProperties(exports.createStyle(e,r,n))}function isTabletFallback(){return Math.min(Ti.Platform.displayCaps.platformHeight,Ti.Platform.displayCaps.platformWidth)>=700}var _=require("alloy/underscore")._,Backbone=require("alloy/backbone"),CONST=require("alloy/constants");exports.version="1.3.0",exports._=_,exports.Backbone=Backbone;var DEFAULT_WIDGET="widget",TI_VERSION=Ti.version,MW320_CHECK=!0&&TI_VERSION>="3.2.0",IDENTITY_TRANSFORM=void 0,RESET={bottom:null,left:null,right:null,top:null,height:null,width:null,shadowColor:null,shadowOffset:null,backgroundImage:null,backgroundRepeat:null,center:null,layout:null,backgroundSelectedColor:null,backgroundSelectedImage:null,opacity:1,touchEnabled:!0,enabled:!0,horizontalWrap:!0,zIndex:0,backgroundColor:null,font:null,visible:!0,color:null,transform:null,backgroundGradient:{},borderColor:"transparent",borderRadius:null,borderWidth:null};exports.M=function(e,t,o){var r,n=(t||{}).config||{},s=n.adapter||{},l={},a={};s.type?(r=require("alloy/sync/"+s.type),l.sync=function(e,t,o){r.sync(e,t,o)}):l.sync=function(e,t){Ti.API.warn("Execution of "+e+"#sync() function on a model that does not support persistence"),Ti.API.warn("model: "+JSON.stringify(t.toJSON()))},l.defaults=n.defaults,o&&(a.migrations=o),r&&_.isFunction(r.beforeModelCreate)&&(n=r.beforeModelCreate(n,e)||n);var i=Backbone.Model.extend(l,a);return i.prototype.config=n,_.isFunction(t.extendModel)&&(i=t.extendModel(i)||i),r&&_.isFunction(r.afterModelCreate)&&r.afterModelCreate(i,e),i},exports.C=function(e,t,o){var r,n={model:o},s=(o?o.prototype.config:{})||{};s.adapter&&s.adapter.type?(r=require("alloy/sync/"+s.adapter.type),n.sync=function(e,t,o){r.sync(e,t,o)}):n.sync=function(e,t){Ti.API.warn("Execution of "+e+"#sync() function on a collection that does not support persistence"),Ti.API.warn("model: "+JSON.stringify(t.toJSON()))};var l=Backbone.Collection.extend(n);return l.prototype.config=s,_.isFunction(t.extendCollection)&&(l=t.extendCollection(l)||l),r&&_.isFunction(r.afterCollectionCreate)&&r.afterCollectionCreate(l),l},exports.UI={},exports.UI.create=function(controller,apiName,opts){opts=opts||{};var baseName,ns,parts=apiName.split(".");if(1===parts.length)baseName=apiName,ns=opts.ns||CONST.IMPLICIT_NAMESPACES[baseName]||CONST.NAMESPACE_DEFAULT;else{if(!(parts.length>1))throw"Alloy.UI.create() failed: No API name was given in the second parameter";baseName=parts[parts.length-1],ns=parts.slice(0,parts.length-1).join(".")}opts.apiName=ns+"."+baseName,baseName=baseName[0].toUpperCase()+baseName.substr(1);var style=exports.createStyle(controller,opts);return eval(ns)["create"+baseName](style)},exports.createStyle=function(e,t,o){var r,n;if(!t)return{};r=_.isArray(t.classes)?t.classes.slice(0):_.isString(t.classes)?t.classes.split(/\s+/):[],n=t.apiName,n&&-1===n.indexOf(".")&&(n=addNamespace(n));var s;s=require(e&&_.isObject(e)?"alloy/widgets/"+e.widgetId+"/styles/"+e.name:"alloy/styles/"+e);var l,a,i={};for(l=0,a=s.length;a>l;l++){var p=s[l],c=p.key;if(p.isApi&&-1===c.indexOf(".")&&(c=(CONST.IMPLICIT_NAMESPACES[c]||CONST.NAMESPACE_DEFAULT)+"."+c),p.isId&&t.id&&p.key===t.id||p.isClass&&_.contains(r,p.key));else{if(!p.isApi)continue;if(-1===p.key.indexOf(".")&&(p.key=addNamespace(p.key)),p.key!==n)continue}p.queries&&p.queries.formFactor&&!Alloy[p.queries.formFactor]||_.extend(i,p.style)}var u=_.omit(t,[CONST.CLASS_PROPERTY,CONST.APINAME_PROPERTY]);return _.extend(i,u),i[CONST.CLASS_PROPERTY]=r,i[CONST.APINAME_PROPERTY]=n,MW320_CHECK&&delete i[CONST.APINAME_PROPERTY],o?_.defaults(i,o):i},exports.addClass=function(e,t,o,r){if(!o)return void(r&&(MW320_CHECK&&delete r.apiName,t.applyProperties(r)));var n=t[CONST.CLASS_PROPERTY]||[],s=n.length;o=_.isString(o)?o.split(/\s+/):o;var l=_.union(n,o||[]);return s===l.length?void(r&&(MW320_CHECK&&delete r.apiName,t.applyProperties(r))):void processStyle(e,t,l,r)},exports.removeClass=function(e,t,o,r){o=o||[];var n=t[CONST.CLASS_PROPERTY]||[],s=n.length;if(!s||!o.length)return void(r&&(MW320_CHECK&&delete r.apiName,t.applyProperties(r)));o=_.isString(o)?o.split(/\s+/):o;var l=_.difference(n,o);return s===l.length?void(r&&(MW320_CHECK&&delete r.apiName,t.applyProperties(r))):void processStyle(e,t,l,r,RESET)},exports.resetClass=function(e,t,o,r){o=o||[],o=_.isString(o)?o.split(/\s+/):o,processStyle(e,t,o,r,RESET)},exports.createWidget=function(e,t,o){return"undefined"!=typeof t&&null!==t&&_.isObject(t)&&!_.isString(t)&&(o=t,t=DEFAULT_WIDGET),new(require("alloy/widgets/"+e+"/controllers/"+(t||DEFAULT_WIDGET)))(o)},exports.createController=function(e,t){return new(require("alloy/controllers/"+e))(t)},exports.createModel=function(e,t){return new(require("alloy/models/"+ucfirst(e)).Model)(t)},exports.createCollection=function(e,t){return new(require("alloy/models/"+ucfirst(e)).Collection)(t)},exports.isTablet=function(){return Math.min(Ti.Platform.displayCaps.platformHeight,Ti.Platform.displayCaps.platformWidth)>=400}(),exports.isHandheld=!exports.isTablet,exports.Globals={},exports.Models={},exports.Models.instance=function(e){return exports.Models[e]||(exports.Models[e]=exports.createModel(e))},exports.Collections={},exports.Collections.instance=function(e){return exports.Collections[e]||(exports.Collections[e]=exports.createCollection(e))},exports.CFG=require("alloy/CFG");