diff --git a/build/MagnusBilling-current.tar.gz b/build/MagnusBilling-current.tar.gz index 591a1764..c840ea1d 100644 Binary files a/build/MagnusBilling-current.tar.gz and b/build/MagnusBilling-current.tar.gz differ diff --git a/classic/src/view/did/Bulk.js b/classic/src/view/did/Bulk.js new file mode 100755 index 00000000..c7876659 --- /dev/null +++ b/classic/src/view/did/Bulk.js @@ -0,0 +1,175 @@ +/** + * Classe que define a window import csv de "Rate" + * + * ======================================= + * ################################### + * MagnusBilling + * + * @package MagnusBilling + * @author Adilson Leffa Magnus. + * @copyright Todos os direitos reservados. + * ################################### + * ======================================= + * MagnusSolution.com + * 08/11/2012 + */ +Ext.define('MBilling.view.did.Bulk', { + extend: 'Ext.window.Window', + alias: 'widget.didbulk', + autoShow: true, + modal: true, + layout: 'fit', + iconCls: 'icon-import-csv', + title: t('Bulk destination'), + width: 400, + height: window.isThemeNeptune || window.isThemeCrisp ? 295 : window.isThemeTriton ? 390 : 270, + labelWidthFields: 120, + htmlTipInfo: '', + fieldsImport: [], + fil: [], + initComponent: function() { + var me = this, + filters = me.list.filters.getFilterData(); + if (!filters || filters == 0) { + Ext.ux.Alert.alert('Alert', t('Use filters'), 'information'); + me.items = [{}] + } else { + me.fil = filters; + me.items = [{ + xtype: 'form', + reference: 'didbilkPanel', + bodyPadding: 5, + defaults: { + anchor: '0', + enableKeyEvents: true, + labelWidth: me.labelWidthFields, + msgTarget: 'side', + plugins: 'markallowblank', + allowBlank: false + }, + items: [{ + xtype: 'userlookup', + name: 'id_user', + fieldLabel: t('Username'), + allowBlank: false + }, { + xtype: 'fieldset', + style: 'margin-top:25px; overflow: visible;', + title: t('DID destination'), + collapsible: true, + collapsed: false, + defaults: { + labelWidth: 90, + anchor: '100%', + labelAlign: me.labelAlignFields + }, + items: [{ + xtype: 'didtypecombo', + name: 'voip_call', + fieldLabel: t('Type'), + listeners: { + select: function(combo, records, eOpts) { + me.onSelectMethod(combo, records) + }, + scope: this + } + }, { + xtype: 'textfield', + name: 'destination', + fieldLabel: t('Destination'), + value: '', + allowBlank: true, + hidden: true + }, { + xtype: 'ivrlookup', + name: 'id_ivr', + fieldLabel: t('IVR'), + allowBlank: true, + hidden: true + }, { + xtype: 'queuelookup', + name: 'id_queue', + fieldLabel: t('Queue'), + allowBlank: true, + hidden: true + }, { + xtype: 'siplookup', + name: 'id_sip', + fieldLabel: t('Sip user'), + allowBlank: true + }, { + xtype: 'textarea', + name: 'context', + fieldLabel: t('Context'), + allowBlank: true, + emptyText: t('Asterisk dial plan. Example: exten => _X.=>1,Dial(SIP/3333@39.5.5.5,30); )'), + height: 300, + anchor: '100%', + hidden: true + }] + }] + }]; + } + me.title = me.title + (me.titleModule ? ' - ' + me.titleModule : ''); + me.bbar = [{ + width: 150, + iconCls: 'icon-import-csv', + text: t('Bulk DID Destination'), + scope: me, + handler: me.onBulk + }]; + me.callParent(arguments); + }, + onSelectMethod: function(combo, records) { + this.showFieldsRelated(records.getData().showFields); + }, + showFieldsRelated: function(showFields) { + var me = this, + getForm = me.down('form'); + fields = getForm.getForm().getFields(); + fields.each(function(field) { + if (field.name == 'id_user') { + field.setVisible(true); + } else { + field.setVisible(showFields.indexOf(field.name) !== -1); + } + }); + }, + onBulk: function(btn) { + var me = this, + store = me.list.getStore(); + if (!me.down('form').isValid()) { + return; + } + Ext.Ajax.setTimeout(1000000); + me.down('form').submit({ + url: 'index.php/diddestination/bulkdestinatintion', + scope: me, + params: { + filters: Ext.encode(me.fil) + }, + success: function(form, action) { + var obj = Ext.decode(action.response.responseText); + if (obj.success) { + Ext.ux.Alert.alert(t('Success'), obj.msg, 'success'); + } else { + Ext.ux.Alert.alert(t('Error'), obj.errors, 'error'); + } + btn.enable(); + me.list.setLoading(false); + store.load(); + me.close(); + }, + failure: function(form, action) { + var obj = Ext.decode(action.response.responseText), + errors = Helper.Util.convertErrorsJsonToString(obj.errors); + if (!Ext.isObject(obj.errors)) { + Ext.ux.Alert.alert(me.titleError, t(errors), 'error'); + } else { + form.markInvalid(obj.errors); + Ext.ux.Alert.alert(me.titleWarning, t(errors), 'error'); + } + } + }); + } +}); \ No newline at end of file diff --git a/classic/src/view/did/Controller.js b/classic/src/view/did/Controller.js index 2c77e76d..47711c34 100755 --- a/classic/src/view/did/Controller.js +++ b/classic/src/view/did/Controller.js @@ -20,6 +20,7 @@ */ Ext.define('MBilling.view.did.Controller', { extend: 'Ext.ux.app.ViewController', + requires: ['MBilling.view.did.Bulk'], alias: 'controller.did', isSubmitForm: true, init: function() { diff --git a/classic/src/view/did/List.js b/classic/src/view/did/List.js index 8f13f7e6..1a268697 100755 --- a/classic/src/view/did/List.js +++ b/classic/src/view/did/List.js @@ -32,6 +32,11 @@ Ext.define('MBilling.view.did.List', { iconCls: 'icon-delete', handler: 'onRelease', disabled: false + }, { + text: t('Bulk DID'), + iconCls: 'icon-delete', + handler: 'onBulk', + hidden: !App.user.isAdmin || window.isTablet }]; if (App.user.isClient) { me.buttonImportCsv = false; diff --git a/protected/controllers/DiddestinationController.php b/protected/controllers/DiddestinationController.php index 0c699809..7b87427e 100755 --- a/protected/controllers/DiddestinationController.php +++ b/protected/controllers/DiddestinationController.php @@ -173,6 +173,104 @@ public function checkRelation($values) } + public function actionbulkdestinatintion() + { + $this->isNewRecord = true; + $values = $this->getAttributesRequest(); + + + + $_GET['filter'] = $values['filters']; + + $id_user = $values['id_user']; + + $this->setfilter($_GET); + + $modelDid = Did::model()->findAll($this->filter, $this->paramsFilter); + + foreach ($modelDid as $key => $did) { + + $values['id_did'] = $did->id; + + if ($did->id_user == null && $did->reserved == 0) { + + //isnewDID + + $modelDiddestination = new Diddestination(); + $modelDiddestination->id_did = $did->id; + $modelDiddestination->id_user = $id_user; + $modelDiddestination->voip_call = $values['voip_call']; + $modelDiddestination->priority = 1; + if (strlen($values['destination']) && $values['destination'] != 'undefined') { + $modelDiddestination->destination = $values['destination']; + } + if (strlen($values['id_ivr']) && $values['id_ivr'] != 'undefined') { + $modelDiddestination->id_ivr = $values['id_ivr']; + } + + if (strlen($values['id_queue']) && $values['id_queue'] != 'undefined') { + $modelDiddestination->id_queue = $values['id_queue']; + } + + if (strlen($values['id_sip']) && $values['id_sip'] != 'undefined') { + $modelDiddestination->id_sip = $values['id_sip']; + } + + if (strlen($values['context']) && $values['context'] != 'undefined') { + $modelDiddestination->context = $values['context']; + } + + $values = $this->beforeSave($values); + + $modelDiddestination->save(); + + $this->afterSave($modelDiddestination, $values); + + } else { + //update destination + + $modelDiddestination = Diddestination::model()->find('id_did = :key', [':key' => $did->id]); + + if (isset($modelDiddestination)) { + if ($modelDiddestination->id_user == $id_user) { + //update destination + $modelDiddestination->voip_call = $values['voip_call']; + if (strlen($values['destination']) && $values['destination'] != 'undefined') { + $modelDiddestination->destination = $values['destination']; + } + if (strlen($values['id_ivr']) && $values['id_ivr'] != 'undefined') { + $modelDiddestination->id_ivr = $values['id_ivr']; + } + + if (strlen($values['id_queue']) && $values['id_queue'] != 'undefined') { + $modelDiddestination->id_queue = $values['id_queue']; + } + + if (strlen($values['id_sip']) && $values['id_sip'] != 'undefined') { + $modelDiddestination->id_sip = $values['id_sip']; + } + + if (strlen($values['context']) && $values['context'] != 'undefined') { + $modelDiddestination->context = $values['context']; + } + $values = $this->beforeSave($values); + $modelDiddestination->save(); + + } else { + continue; + } + } + } + } + + AsteriskAccess::instance()->generateSipDid(); + echo json_encode(array( + $this->nameSuccess => $this->success, + $this->nameMsg => $this->msg, + )); + + } + public function afterSave($model, $values) { AsteriskAccess::instance()->writeDidContext();