Built motion from commit c56b56e.|0.0.125
[motion.git] / server / models / fax_account.js
1 /**
2  * Chat Website Model
3  */
4
5 var crypto = require('crypto');
6
7 module.exports = function(sequelize, DataTypes) {
8
9         var FaxAccount = sequelize.define('FaxAccount', {
10                 name: {
11                         type: DataTypes.STRING,
12                         validate: {
13                                 notEmpty: true
14                         }
15                 },
16                 description: DataTypes.STRING,
17                 ecm: {
18                         type: DataTypes.ENUM('yes', 'no'),
19                         defaultValue: 'yes'
20                 },
21                 headerinfo: {
22                         type: DataTypes.STRING,
23                         defaultValue: 'xCALLY Motion Fax'
24                 },
25                 localstationid: {
26                         type: DataTypes.STRING,
27                         unique: true
28                 },
29                 minrate: {
30                         type: DataTypes.ENUM('2400', '4800', '7200', '9600', '12000', '14400'),
31                         defaultValue: '4800'
32                 },
33                 maxrate: {
34                         type: DataTypes.ENUM('2400', '4800', '7200', '9600', '12000', '14400'),
35                         defaultValue: '14400'
36                 },
37                 modem: {
38                         type: DataTypes.STRING,
39                         defaultValue: 'v17,v27,v29'
40                 },
41                 gateway: {
42                         type: DataTypes.STRING,
43                         defaultValue: 'no',
44                         validate: {
45                                 is: /^(?:yes|no|[0-9]+)$/
46                         }
47                 },
48                 faxdetect: {
49                         type: DataTypes.STRING,
50                         defaultValue: 'no',
51                         validate: {
52                                 is: /^(?:yes|no|t38|cng|[0-9]+)$/
53                         }
54                 },
55                 t38timeout: {
56                         type: DataTypes.INTEGER,
57                         defaultValue: 5000,
58                         validate: {
59                                 min: 1000
60                         }
61                 },
62                 tech: {
63                         type: DataTypes.ENUM('SIP', 'IAX', 'DADHI', 'KHOMP'),
64                         defaultValue: 'SIP'
65                 },
66                 fidelity: {
67                         type: DataTypes.BOOLEAN,
68                         defaultValue: false
69                 },
70                 timeout: {
71                         type: DataTypes.INTEGER,
72                         defaultValue: 0
73                 },
74                 acceptUrl: {
75                         type: DataTypes.STRING
76                 },
77                 rejectUrl: {
78                         type: DataTypes.STRING
79                 },
80                 acceptMethod: {
81                         type: DataTypes.ENUM('GET', 'POST')
82                 },
83                 rejectMethod: {
84                         type: DataTypes.ENUM('GET', 'POST')
85                 },
86                 actions: {
87                         type: DataTypes.STRING,
88                         get: function() {
89                                 return this.getDataValue('actions') ? JSON.parse(this.getDataValue('actions')) : [];
90                         },
91                         set: function(val) {
92                                 return this.setDataValue('actions', JSON.stringify(val));
93                         }
94                 }
95         }, {
96                 tableName: 'fax_accounts',
97                 associate: function(models) {
98                         FaxAccount.belongsTo(models.Trunk);
99                         FaxAccount.hasMany(models.FaxRoom);
100                         FaxAccount.hasMany(models.FaxApplication);
101                         FaxAccount.hasMany(models.VoiceExtension, {
102                                 onDelete: 'cascade',
103                                 hooks: true
104                         });
105                         FaxAccount.belongsTo(models.List);
106                         FaxAccount.hasMany(models.FaxDisposition);
107
108                         // SCOPES
109                         FaxAccount.addScope('default', {
110                                 include: [{
111                                         model: models.FaxApplication,
112                                         include: [{
113                                                 model: models.User,
114                                                 attributes: ['id',
115                                                         'name',
116                                                         'email',
117                                                         'internal',
118                                                         'fullname'
119                                                 ]
120                                         }, {
121                                                 model: models.FaxQueue
122                                         }]
123                                 }]
124                         });
125
126                 }
127         });
128
129         return FaxAccount;
130 };