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