Skip to content

Commit f6e5345

Browse files
magnussolutioncallcenter-magnus
authored andcommitted
did destination bulk
1 parent c37de88 commit f6e5345

File tree

5 files changed

+279
-0
lines changed

5 files changed

+279
-0
lines changed

build/MagnusBilling-current.tar.gz

-2.32 KB
Binary file not shown.

classic/src/view/did/Bulk.js

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/**
2+
* Classe que define a window import csv de "Rate"
3+
*
4+
* =======================================
5+
* ###################################
6+
* MagnusBilling
7+
*
8+
* @package MagnusBilling
9+
* @author Adilson Leffa Magnus.
10+
* @copyright Todos os direitos reservados.
11+
* ###################################
12+
* =======================================
13+
* MagnusSolution.com <[email protected]>
14+
* 08/11/2012
15+
*/
16+
Ext.define('MBilling.view.did.Bulk', {
17+
extend: 'Ext.window.Window',
18+
alias: 'widget.didbulk',
19+
autoShow: true,
20+
modal: true,
21+
layout: 'fit',
22+
iconCls: 'icon-import-csv',
23+
title: t('Bulk destination'),
24+
width: 400,
25+
height: window.isThemeNeptune || window.isThemeCrisp ? 295 : window.isThemeTriton ? 390 : 270,
26+
labelWidthFields: 120,
27+
htmlTipInfo: '',
28+
fieldsImport: [],
29+
fil: [],
30+
initComponent: function() {
31+
var me = this,
32+
filters = me.list.filters.getFilterData();
33+
if (!filters || filters == 0) {
34+
Ext.ux.Alert.alert('Alert', t('Use filters'), 'information');
35+
me.items = [{}]
36+
} else {
37+
me.fil = filters;
38+
me.items = [{
39+
xtype: 'form',
40+
reference: 'didbilkPanel',
41+
bodyPadding: 5,
42+
defaults: {
43+
anchor: '0',
44+
enableKeyEvents: true,
45+
labelWidth: me.labelWidthFields,
46+
msgTarget: 'side',
47+
plugins: 'markallowblank',
48+
allowBlank: false
49+
},
50+
items: [{
51+
xtype: 'userlookup',
52+
name: 'id_user',
53+
fieldLabel: t('Username'),
54+
allowBlank: false
55+
}, {
56+
xtype: 'fieldset',
57+
style: 'margin-top:25px; overflow: visible;',
58+
title: t('DID destination'),
59+
collapsible: true,
60+
collapsed: false,
61+
defaults: {
62+
labelWidth: 90,
63+
anchor: '100%',
64+
labelAlign: me.labelAlignFields
65+
},
66+
items: [{
67+
xtype: 'didtypecombo',
68+
name: 'voip_call',
69+
fieldLabel: t('Type'),
70+
listeners: {
71+
select: function(combo, records, eOpts) {
72+
me.onSelectMethod(combo, records)
73+
},
74+
scope: this
75+
}
76+
}, {
77+
xtype: 'textfield',
78+
name: 'destination',
79+
fieldLabel: t('Destination'),
80+
value: '',
81+
allowBlank: true,
82+
hidden: true
83+
}, {
84+
xtype: 'ivrlookup',
85+
name: 'id_ivr',
86+
fieldLabel: t('IVR'),
87+
allowBlank: true,
88+
hidden: true
89+
}, {
90+
xtype: 'queuelookup',
91+
name: 'id_queue',
92+
fieldLabel: t('Queue'),
93+
allowBlank: true,
94+
hidden: true
95+
}, {
96+
xtype: 'siplookup',
97+
name: 'id_sip',
98+
fieldLabel: t('Sip user'),
99+
allowBlank: true
100+
}, {
101+
xtype: 'textarea',
102+
name: 'context',
103+
fieldLabel: t('Context'),
104+
allowBlank: true,
105+
emptyText: t('Asterisk dial plan. Example: exten => _X.=>1,Dial(SIP/[email protected],30); )'),
106+
height: 300,
107+
anchor: '100%',
108+
hidden: true
109+
}]
110+
}]
111+
}];
112+
}
113+
me.title = me.title + (me.titleModule ? ' - ' + me.titleModule : '');
114+
me.bbar = [{
115+
width: 150,
116+
iconCls: 'icon-import-csv',
117+
text: t('Bulk DID Destination'),
118+
scope: me,
119+
handler: me.onBulk
120+
}];
121+
me.callParent(arguments);
122+
},
123+
onSelectMethod: function(combo, records) {
124+
this.showFieldsRelated(records.getData().showFields);
125+
},
126+
showFieldsRelated: function(showFields) {
127+
var me = this,
128+
getForm = me.down('form');
129+
fields = getForm.getForm().getFields();
130+
fields.each(function(field) {
131+
if (field.name == 'id_user') {
132+
field.setVisible(true);
133+
} else {
134+
field.setVisible(showFields.indexOf(field.name) !== -1);
135+
}
136+
});
137+
},
138+
onBulk: function(btn) {
139+
var me = this,
140+
store = me.list.getStore();
141+
if (!me.down('form').isValid()) {
142+
return;
143+
}
144+
Ext.Ajax.setTimeout(1000000);
145+
me.down('form').submit({
146+
url: 'index.php/diddestination/bulkdestinatintion',
147+
scope: me,
148+
params: {
149+
filters: Ext.encode(me.fil)
150+
},
151+
success: function(form, action) {
152+
var obj = Ext.decode(action.response.responseText);
153+
if (obj.success) {
154+
Ext.ux.Alert.alert(t('Success'), obj.msg, 'success');
155+
} else {
156+
Ext.ux.Alert.alert(t('Error'), obj.errors, 'error');
157+
}
158+
btn.enable();
159+
me.list.setLoading(false);
160+
store.load();
161+
me.close();
162+
},
163+
failure: function(form, action) {
164+
var obj = Ext.decode(action.response.responseText),
165+
errors = Helper.Util.convertErrorsJsonToString(obj.errors);
166+
if (!Ext.isObject(obj.errors)) {
167+
Ext.ux.Alert.alert(me.titleError, t(errors), 'error');
168+
} else {
169+
form.markInvalid(obj.errors);
170+
Ext.ux.Alert.alert(me.titleWarning, t(errors), 'error');
171+
}
172+
}
173+
});
174+
}
175+
});

classic/src/view/did/Controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
Ext.define('MBilling.view.did.Controller', {
2222
extend: 'Ext.ux.app.ViewController',
23+
requires: ['MBilling.view.did.Bulk'],
2324
alias: 'controller.did',
2425
isSubmitForm: true,
2526
init: function() {

classic/src/view/did/List.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ Ext.define('MBilling.view.did.List', {
3232
iconCls: 'icon-delete',
3333
handler: 'onRelease',
3434
disabled: false
35+
}, {
36+
text: t('Bulk DID'),
37+
iconCls: 'icon-delete',
38+
handler: 'onBulk',
39+
hidden: !App.user.isAdmin || window.isTablet
3540
}];
3641
if (App.user.isClient) {
3742
me.buttonImportCsv = false;

protected/controllers/DiddestinationController.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,104 @@ public function checkRelation($values)
173173

174174
}
175175

176+
public function actionbulkdestinatintion()
177+
{
178+
$this->isNewRecord = true;
179+
$values = $this->getAttributesRequest();
180+
181+
182+
183+
$_GET['filter'] = $values['filters'];
184+
185+
$id_user = $values['id_user'];
186+
187+
$this->setfilter($_GET);
188+
189+
$modelDid = Did::model()->findAll($this->filter, $this->paramsFilter);
190+
191+
foreach ($modelDid as $key => $did) {
192+
193+
$values['id_did'] = $did->id;
194+
195+
if ($did->id_user == null && $did->reserved == 0) {
196+
197+
//isnewDID
198+
199+
$modelDiddestination = new Diddestination();
200+
$modelDiddestination->id_did = $did->id;
201+
$modelDiddestination->id_user = $id_user;
202+
$modelDiddestination->voip_call = $values['voip_call'];
203+
$modelDiddestination->priority = 1;
204+
if (strlen($values['destination']) && $values['destination'] != 'undefined') {
205+
$modelDiddestination->destination = $values['destination'];
206+
}
207+
if (strlen($values['id_ivr']) && $values['id_ivr'] != 'undefined') {
208+
$modelDiddestination->id_ivr = $values['id_ivr'];
209+
}
210+
211+
if (strlen($values['id_queue']) && $values['id_queue'] != 'undefined') {
212+
$modelDiddestination->id_queue = $values['id_queue'];
213+
}
214+
215+
if (strlen($values['id_sip']) && $values['id_sip'] != 'undefined') {
216+
$modelDiddestination->id_sip = $values['id_sip'];
217+
}
218+
219+
if (strlen($values['context']) && $values['context'] != 'undefined') {
220+
$modelDiddestination->context = $values['context'];
221+
}
222+
223+
$values = $this->beforeSave($values);
224+
225+
$modelDiddestination->save();
226+
227+
$this->afterSave($modelDiddestination, $values);
228+
229+
} else {
230+
//update destination
231+
232+
$modelDiddestination = Diddestination::model()->find('id_did = :key', [':key' => $did->id]);
233+
234+
if (isset($modelDiddestination)) {
235+
if ($modelDiddestination->id_user == $id_user) {
236+
//update destination
237+
$modelDiddestination->voip_call = $values['voip_call'];
238+
if (strlen($values['destination']) && $values['destination'] != 'undefined') {
239+
$modelDiddestination->destination = $values['destination'];
240+
}
241+
if (strlen($values['id_ivr']) && $values['id_ivr'] != 'undefined') {
242+
$modelDiddestination->id_ivr = $values['id_ivr'];
243+
}
244+
245+
if (strlen($values['id_queue']) && $values['id_queue'] != 'undefined') {
246+
$modelDiddestination->id_queue = $values['id_queue'];
247+
}
248+
249+
if (strlen($values['id_sip']) && $values['id_sip'] != 'undefined') {
250+
$modelDiddestination->id_sip = $values['id_sip'];
251+
}
252+
253+
if (strlen($values['context']) && $values['context'] != 'undefined') {
254+
$modelDiddestination->context = $values['context'];
255+
}
256+
$values = $this->beforeSave($values);
257+
$modelDiddestination->save();
258+
259+
} else {
260+
continue;
261+
}
262+
}
263+
}
264+
}
265+
266+
AsteriskAccess::instance()->generateSipDid();
267+
echo json_encode(array(
268+
$this->nameSuccess => $this->success,
269+
$this->nameMsg => $this->msg,
270+
));
271+
272+
}
273+
176274
public function afterSave($model, $values)
177275
{
178276
AsteriskAccess::instance()->writeDidContext();

0 commit comments

Comments
 (0)