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,
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')];
78 return this.getDataValue('appdata').split(',');
81 return this.getDataValue('appdata');
86 type: DataTypes.ENUM('inbound', 'outbound', 'internal', 'inbound-fax', 'outbound-fax', 'system', 'any'),
90 type: DataTypes.STRING,
93 type: DataTypes.STRING,
96 type: DataTypes.INTEGER,
99 type: DataTypes.BOOLEAN,
103 type: DataTypes.STRING,
107 type: DataTypes.STRING,
111 type: DataTypes.BOOLEAN,
115 type: DataTypes.INTEGER
118 tableName: 'voice_extensions',
119 associate: function(models) {
120 VoiceExtension.hasMany(models.VoiceExtension, {
126 VoiceExtension.addScope('application', {
128 model: models.VoiceExtension,
134 attributes: ['app', 'interval', 'IntervalId', 'callerID', 'appdata', 'type', 'appType']
138 VoiceExtension.addScope('routes', {
140 VoiceExtensionId: null
146 return VoiceExtension;