Skip to content
Code-Schnipsel Gruppen Projekte
Commit 199f394f erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

refactor: customer -> create contact person address

Übergeordneter 9a76e74d
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
<?php
/**
* This file contains package_quiqqer_customer_ajax_backend_customer_addAddress
*/
/**
* Add a new address to the user
*
* @return string
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_customer_ajax_backend_customer_addAddress',
function ($userId) {
return QUI::getUsers()->get($userId)->addAddress()->getId();
},
['userId'],
'Permission::checkAdminUser'
);
......@@ -81,6 +81,21 @@ define('package/quiqqer/customer/bin/backend/classes/Handler', [
resolve(CustomerPanel);
});
});
},
/**
* add a address to customer
*
* @param userId
* @return {Promise}
*/
addAddressToCustomer: function (userId) {
return new Promise(function (resolve) {
QUIAjax.post('package_quiqqer_customer_ajax_backend_customer_addAddress', resolve, {
'package': 'quiqqer/customer',
userId : userId
});
});
}
});
});
......@@ -118,7 +118,12 @@ define('package/quiqqer/customer/bin/backend/controls/customer/AddressEdit', [
try {
mail = JSON.decode(result.mail);
if (typeOf(mail) !== 'array') {
mail = [];
}
} catch (e) {
mail = [];
}
mail.forEach(function (entry) {
......@@ -127,7 +132,12 @@ define('package/quiqqer/customer/bin/backend/controls/customer/AddressEdit', [
try {
phone = JSON.decode(result.phone);
if (typeOf(phone) !== 'array') {
phone = [];
}
} catch (e) {
phone = [];
}
phone.forEach(function (entry) {
......
......@@ -788,38 +788,53 @@ define('package/quiqqer/customer/bin/backend/controls/customer/Panel', [
});
});
}).then(function () {
return self.$User.getAddressList();
}).then(function (addresses) {
return self.$refreshContactAddressList();
}).then(function () {
var Select = Form.elements['quiqqer.erp.customer.contact.person'],
Button = self.getElm().getElement('[name="edit-contact-person"]');
Select.set('html', '');
new Element('option', {
value: '',
html : ''
}).inject(Select);
for (var i = 0, len = addresses.length; i < len; i++) {
new Element('option', {
value: addresses[i].id,
html : addresses[i].text
}).inject(Select);
}
if (self.$User.getAttribute('quiqqer.erp.customer.contact.person')) {
Select.value = self.$User.getAttribute('quiqqer.erp.customer.contact.person');
}
Button.disabled = Select.value === '';
Button.disabled = false;
Select.addEvent('change', function () {
Button.disabled = Select.value === '';
if (Select.value === '') {
Button.set('html', '<span class="fa fa-plus"></span>');
return;
}
Button.set('html', '<span class="fa fa-edit"></span>');
});
Button.addEvent('click', function (e) {
e.stop();
// create
if (Select.value === '') {
// add new address
Button.set('html', '<span class="fa fa-spinner fa-spin"></span>');
require(['package/quiqqer/customer/bin/backend/Handler'], function (Handler) {
Handler.addAddressToCustomer(self.$User.getId()).then(function (addressId) {
new AddressEditWindow({
addressId: parseInt(addressId)
}).open();
// refresh list
self.$User.load().then(function () {
return self.$refreshContactAddressList();
}).then(function () {
Select.value = addressId;
Button.set('html', '<span class="fa fa-edit"></span>');
});
});
});
return;
}
new AddressEditWindow({
addressId: parseInt(Select.value)
}).open();
......@@ -1451,6 +1466,34 @@ define('package/quiqqer/customer/bin/backend/controls/customer/Panel', [
Row.setStyle('display', 'none');
}
});
},
/**
* refresh the contact address list
*
* @return {Promise<void>}
*/
$refreshContactAddressList: function () {
var self = this;
return this.$User.getAddressList().then(function (addresses) {
var Form = self.getContent().getElement('form'),
Select = Form.elements['quiqqer.erp.customer.contact.person'];
Select.set('html', '');
new Element('option', {
value: '',
html : ''
}).inject(Select);
for (var i = 0, len = addresses.length; i < len; i++) {
new Element('option', {
value: addresses[i].id,
html : addresses[i].text
}).inject(Select);
}
});
}
//endregion
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren