Built motion from commit 1038d87.|0.0.141
[motion.git] / server / models / fax_account.js
index 71a9227..0c47fad 100644 (file)
-/**
- * Chat Website Model
- */
-
-var crypto = require('crypto');
+'use strict';
 
 module.exports = function(sequelize, DataTypes) {
 
        var FaxAccount = sequelize.define('FaxAccount', {
+               name: {
+                       type: DataTypes.STRING,
+                       validate: {
+                               notEmpty: true
+                       }
+               },
                description: DataTypes.STRING,
-               name: DataTypes.STRING,
-               phone: {
+               ecm: {
+                       type: DataTypes.ENUM('yes', 'no'),
+                       defaultValue: 'yes'
+               },
+               headerinfo: {
+                       type: DataTypes.STRING,
+                       defaultValue: 'xCALLY Motion Fax'
+               },
+               localstationid: {
                        type: DataTypes.STRING,
                        unique: true
                },
-               ecm: {
+               minrate: {
+                       type: DataTypes.ENUM('2400', '4800', '7200', '9600', '12000', '14400'),
+                       defaultValue: '4800'
+               },
+               maxrate: {
+                       type: DataTypes.ENUM('2400', '4800', '7200', '9600', '12000', '14400'),
+                       defaultValue: '14400'
+               },
+               modem: {
+                       type: DataTypes.STRING,
+                       defaultValue: 'v17,v27,v29'
+               },
+               gateway: {
+                       type: DataTypes.STRING,
+                       defaultValue: 'no',
+                       validate: {
+                               is: /^(?:yes|no|[0-9]+)$/
+                       }
+               },
+               faxdetect: {
+                       type: DataTypes.STRING,
+                       defaultValue: 'no',
+                       validate: {
+                               is: /^(?:yes|no|t38|cng|[0-9]+)$/
+                       }
+               },
+               t38timeout: {
+                       type: DataTypes.INTEGER,
+                       defaultValue: 5000,
+                       validate: {
+                               min: 1000
+                       }
+               },
+               tech: {
+                       type: DataTypes.ENUM('SIP', 'IAX', 'DADHI', 'KHOMP'),
+                       defaultValue: 'SIP'
+               },
+               fidelity: {
                        type: DataTypes.BOOLEAN,
                        defaultValue: false
                },
-               faxheader: DataTypes.STRING,
-               localid: DataTypes.STRING,
-               maxrate: {
-                       type: DataTypes.ENUM('9600', '14400', '33600'),
-                       defaultValue: '33600'
+               timeout: {
+                       type: DataTypes.INTEGER,
+                       defaultValue: 0
+               },
+               acceptUrl: {
+                       type: DataTypes.STRING
+               },
+               rejectUrl: {
+                       type: DataTypes.STRING
+               },
+               acceptMethod: {
+                       type: DataTypes.ENUM('GET', 'POST')
+               },
+               rejectMethod: {
+                       type: DataTypes.ENUM('GET', 'POST')
+               },
+               actions: {
+                       type: DataTypes.STRING,
+                       get: function() {
+                               return this.getDataValue('actions') ? JSON.parse(this.getDataValue('actions')) : [];
+                       },
+                       set: function(val) {
+                               return this.setDataValue('actions', JSON.stringify(val));
+                       }
+               },
+               closeUrl: {
+                       type: DataTypes.STRING
+               },
+               closeMethod: {
+                       type: DataTypes.ENUM('GET', 'POST')
                },
-               minrate: {
-                       type: DataTypes.ENUM('9600', '14400', '33600'),
-                       defaultValue: '9600'
-               }
        }, {
                tableName: 'fax_accounts',
                associate: function(models) {
-                       // FaxAccount.belongsTo(models.Trunk);
+                       FaxAccount.belongsTo(models.Trunk);
                        FaxAccount.hasMany(models.FaxRoom);
                        FaxAccount.hasMany(models.FaxApplication);
+                       FaxAccount.hasMany(models.VoiceExtension, {
+                               onDelete: 'cascade',
+                               hooks: true
+                       });
+                       FaxAccount.belongsTo(models.List);
+                       FaxAccount.hasMany(models.FaxDisposition);
+
+                       // SCOPES
+                       FaxAccount.addScope('default', {
+                               include: [{
+                                       model: models.FaxApplication,
+                                       include: [{
+                                               model: models.User,
+                                               attributes: ['id',
+                                                       'name',
+                                                       'email',
+                                                       'internal',
+                                                       'fullname'
+                                               ]
+                                       }, {
+                                               model: models.FaxQueue
+                                       }]
+                               }]
+                       });
                }
        });