2 var util = require('util');
3 var reverseMustache = require('reverse-mustache');
5 module.exports = function(sequelize, DataTypes) {
6 var VoiceExtension = sequelize.define('VoiceExtension', {
8 type: DataTypes.STRING,
10 unique: 'compositeIndex',
13 is: /[A-Za-z0-9._\+*!\-\[\]]+$/i
17 type: DataTypes.STRING,
19 unique: 'compositeIndex'
22 type: DataTypes.STRING,
25 unique: 'compositeIndex'
28 type: DataTypes.STRING,
33 type: DataTypes.STRING,
38 type: DataTypes.STRING(4096),
42 // 'this' allows you to access attributes of the instance
43 if (!this.getDataValue('id')) {
45 if (this.getDataValue('app') === 'Dial' && this.getDataValue('appType') === 'outboundDial') {
46 appdata = reverseMustache({
47 template: 'SIP/{{trunk}}/{{prefix}}${EXTEN:{{cutdigits}}},{{timeout}},{{options}},{{url}}',
48 content: this.getDataValue('appdata')
51 return [appdata.trunk, this.getDataValue('callerID') || '', appdata.prefix, appdata.timeout, appdata.options, appdata.url];
53 return ['', '', '', '', '', '', ''];
55 } else if (this.getDataValue('app') === 'Dial' && this.getDataValue('appType') === 'externalDial') {
56 appdata = reverseMustache({
57 template: 'SIP/{{trunk}}/{{phone}},{{timeout}},{{options}},{{url}}',
58 content: this.getDataValue('appdata')
61 return [appdata.trunk, appdata.phone, appdata.timeout, appdata.options, appdata.url];
63 return ['', '', '', '', ''];
65 } else if (this.getDataValue('app') === 'Dial' && this.getDataValue('appType') === 'internalDial') {
66 appdata = reverseMustache({
67 template: 'SIP/{{internal}},{{timeout}},{{options}},{{url}}',
68 content: this.getDataValue('appdata')
71 return [appdata.internal, appdata.timeout, appdata.options, appdata.url];
73 return ['', '', '', ''];
75 } else if (this.getDataValue('app') === 'Set' || this.getDataValue('appType') === 'custom') {
76 return [this.getDataValue('appdata')];
77 } else if (this.getDataValue('app') === 'Queue' && this.getDataValue('appType') !== 'custom') {
78 appdata = reverseMustache({
79 template: '{{queue}},{{options}},{{url}},{{announceoverride}},{{timeout}},{{agi}},{{macro}},{{gosub}},{{rule}},{{position}}',
80 content: this.getDataValue('appdata')
83 return [appdata.queue, appdata.options, appdata.url, appdata.announceoverride, appdata.timeout, appdata.agi, appdata.macro, appdata.gosub, appdata.rule, appdata.position];
85 appdata = reverseMustache({ // for retrocompatibility
86 template: '{{queue}},{{options}},{{url}},{{announceoverride}},{{timeout}}',
87 content: this.getDataValue('appdata')
90 return [appdata.queue, appdata.options, appdata.url, appdata.announceoverride, appdata.timeout, '', '', '', '', ''];
92 return ['', '', '', '', '', '', '', '', '', ''];
96 return this.getDataValue('appdata').split(',');
99 return this.getDataValue('appdata');
104 type: DataTypes.ENUM('inbound', 'outbound', 'internal', 'inbound-fax', 'outbound-fax', 'system', 'any'),
108 type: DataTypes.STRING,
111 type: DataTypes.STRING,
114 type: DataTypes.INTEGER,
117 type: DataTypes.BOOLEAN,
121 type: DataTypes.STRING,
125 type: DataTypes.STRING,
129 type: DataTypes.BOOLEAN,
133 type: DataTypes.INTEGER
136 type: DataTypes.STRING,
140 type: DataTypes.BOOLEAN,
144 tableName: 'voice_extensions',
145 associate: function(models) {
146 VoiceExtension.hasMany(models.VoiceExtension, {
152 VoiceExtension.addScope('application', {
154 model: models.VoiceExtension,
160 attributes: ['app', 'interval', 'IntervalId', 'callerID', 'appdata', 'type', 'appType', 'answer']
164 VoiceExtension.addScope('routes', {
166 VoiceExtensionId: null
172 return VoiceExtension;