createWindow: function(type, params) { var Constructor = $.isFunction(type) ? type : $.String.getObject(type, AD.UI); var $window = new Constructor($.extend({ parent: this }, params)); return $window; },
extend: function(name, definition, instanceMethods) { // Determine the base model class to derive from based on the connectionType specified in the model definition var BaseModel = null; var staticProperties = $.extend(true, { __adModule: definition._adModule, __adModel: definition._adModel }, ADModel.staticProperties, definition); // Lookup the connection type name in the ConnectionTypes array and assign it the default value if it could not be found var connectionTypes = AD.Defaults.Model.ConnectionTypes; var connection = connectionTypes[staticProperties.connectionType || AD.Defaults.Model.defaultConnectionType]; if (connection === connectionTypes.local || connection === connectionTypes.synced) { var LocalModel = null; if (staticProperties.type === 'single') { LocalModel = AD.Model.ModelSQL; } else if (staticProperties.type === 'multilingual') { LocalModel = AD.Model.ModelSQLMultilingual; } else { // Default to the basic ModelSQL console.warn('Unknown model type: ['+staticProperties.type+']! Defaulting to single (AD.Model.ModelSQL)'); LocalModel = AD.Model.ModelSQL; } if (connection === connectionTypes.local) { // Derive from the determined local model BaseModel = LocalModel; } else if (connection === connectionTypes.synced) { // Derive from the SyncedModel model BaseModel = AD.Model.SyncedModel; staticProperties.LocalModel = LocalModel; } } else if (connection === connectionTypes.server) { // Derive from the ServerModel model BaseModel = AD.Model.ServerModel; } else { console.error('Invalid connection type ['+connection+']!'); return null; } $.extend(instanceMethods, ADModel.prototypeProperties); if (staticProperties.autoIncrementKey && staticProperties.autoIncrementKey !== staticProperties.primaryKey) { // For classes whose autoincremented key is different from the primary key, // create a getter for the class' primaryKey. This getter will create a // unique key generated from the autoincremented key and the device id. instanceMethods['get'+$.String.classize(staticProperties.primaryKey)] = instanceMethods.getGuid; } var Model = BaseModel.extend(name, staticProperties, instanceMethods); // Create the cache only if the model's static 'cache' property equals true if (definition.cache === true) { // Create the cache class and save it to Model.Cache var Cache = $.Model.Cache(Model.name+'.Cache', { Model: Model }, {}); // Create the cache, but do not actually build the cache until refreshCaches is called // This overwrites the cache=true property Model.cache = new Cache({ createCache: false }); } // Store the model in AD.Models AD.Models[Model.shortName] = Model; return Model; },