From aab970e667ebe9d93f6261afc9288189ab0ed536 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Tue, 17 Dec 2019 09:11:28 +0100 Subject: [PATCH] client.phone section --- back/models/user-phone-type.json | 10 +++- db/changes/10100-allSaints/00-ACL.sql | 2 +- db/dump/fixtures.sql | 30 +++++------ e2e/helpers/selectors.js | 2 - .../02_edit_basic_data.spec.js | 36 ------------- modules/client/back/methods/client/getCard.js | 2 + modules/client/back/methods/client/summary.js | 3 ++ modules/client/back/models/client.json | 7 ++- modules/client/front/basic-data/index.html | 14 ------ modules/client/front/contact/index.js | 35 ------------- modules/client/front/index.js | 2 +- modules/client/front/index/index.html | 4 -- .../front/{contact => phones}/index.html | 47 +++++++++-------- modules/client/front/phones/index.js | 44 ++++++++++++++++ modules/client/front/phones/index.spec.js | 50 +++++++++++++++++++ modules/client/front/routes.json | 10 ++-- modules/client/front/summary/index.html | 8 ++- 17 files changed, 164 insertions(+), 142 deletions(-) delete mode 100644 modules/client/front/contact/index.js rename modules/client/front/{contact => phones}/index.html (51%) create mode 100644 modules/client/front/phones/index.js create mode 100644 modules/client/front/phones/index.spec.js diff --git a/back/models/user-phone-type.json b/back/models/user-phone-type.json index 479f02d6fd..9410bd8db2 100644 --- a/back/models/user-phone-type.json +++ b/back/models/user-phone-type.json @@ -14,5 +14,13 @@ "description": { "type": "String" } - } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] } diff --git a/db/changes/10100-allSaints/00-ACL.sql b/db/changes/10100-allSaints/00-ACL.sql index ea1ba706b7..39b52df5dd 100644 --- a/db/changes/10100-allSaints/00-ACL.sql +++ b/db/changes/10100-allSaints/00-ACL.sql @@ -1 +1 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('UserPhone', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'); +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('UserPhone', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index b57575e02c..53bb9ff238 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -205,23 +205,23 @@ INSERT INTO `vn`.`contactChannel`(`id`, `name`) (4, 'GCN Channel'), (5, 'The Newspaper'); -INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`fax`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`,`mailAddress`,`cplusTerIdNifFk`,`hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`) +INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`fax`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`,`mailAddress`,`cplusTerIdNifFk`,`hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`) VALUES - (101, 'Bruce Wayne', '84612325V', 'Batman', 'Alfred', '1007 Mountain Drive, Gotham', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), - (102, 'Petter Parker', '87945234L', 'Spider man', 'Aunt May', '20 Ingram Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), - (103, 'Clark Kent', '06815934E', 'Super man', 'lois lane', '344 Clinton Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 0, 19, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), - (104, 'Tony Stark', '06089160W', 'Iron man', 'Pepper Potts', '10880 Malibu Point', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), - (105, 'Max Eisenhardt', '251628698', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 8, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1), - (106, 'DavidCharlesHaller', '53136686Q', 'Legion', 'Charles Xavier', 'Evil hideout', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1), - (107, 'Hank Pym', '09854837G', 'Ant man', 'Hawk', 'Anthill', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1), - (108, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1), - (109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1), - (110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1), - (111, 'Missing', NULL, 'Missing man', 'Anton', 'The space', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1), - (112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1); + (101, 'Bruce Wayne', '84612325V', 'Batman', 'Alfred', '1007 Mountain Drive, Gotham', 'Silla', 46460, 333333333, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), + (102, 'Petter Parker', '87945234L', 'Spider man', 'Aunt May', '20 Ingram Street', 'Silla', 46460, 333333333, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), + (103, 'Clark Kent', '06815934E', 'Super man', 'lois lane', '344 Clinton Street', 'Silla', 46460, 333333333, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 0, 19, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), + (104, 'Tony Stark', '06089160W', 'Iron man', 'Pepper Potts', '10880 Malibu Point', 'Silla', 46460, 333333333, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), + (105, 'Max Eisenhardt', '251628698', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Silla', 46460, 333333333, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 8, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1), + (106, 'DavidCharlesHaller', '53136686Q', 'Legion', 'Charles Xavier', 'Evil hideout', 'Silla', 46460, 333333333, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1), + (107, 'Hank Pym', '09854837G', 'Ant man', 'Hawk', 'Anthill', 'Silla', 46460, 333333333, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1), + (108, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 333333333, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1), + (109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 333333333, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1), + (110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 333333333, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1), + (111, 'Missing', NULL, 'Missing man', 'Anton', 'The space', 'Silla', 46460, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1), + (112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city', 'Silla', 46460, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1); -INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `phone`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) - SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'SILLA', 46460, 623111111, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, CURDATE(), 1 +INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) + SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'SILLA', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, CURDATE(), 1 FROM `account`.`role` `r` WHERE `r`.`hasLogin` = 1; diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index d752b265fa..daff34db8c 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -50,8 +50,6 @@ export default { basicDataButton: 'vn-left-menu a[ui-sref="client.card.basicData"]', nameInput: 'vn-textfield[ng-model="$ctrl.client.name"] input', contactInput: 'vn-textfield[ng-model="$ctrl.client.contact"] input', - phoneInput: 'vn-textfield[ng-model="$ctrl.client.phone"] input', - mobileInput: 'vn-textfield[ng-model="$ctrl.client.mobile"] input', emailInput: 'vn-textfield[ng-model="$ctrl.client.email"] input', salesPersonAutocomplete: 'vn-autocomplete[ng-model="$ctrl.client.salesPersonFk"]', channelAutocomplete: 'vn-autocomplete[ng-model="$ctrl.client.contactChannelFk"]', diff --git a/e2e/paths/02-client-module/02_edit_basic_data.spec.js b/e2e/paths/02-client-module/02_edit_basic_data.spec.js index 988ad82c8a..dc0631613e 100644 --- a/e2e/paths/02-client-module/02_edit_basic_data.spec.js +++ b/e2e/paths/02-client-module/02_edit_basic_data.spec.js @@ -27,10 +27,6 @@ describe('Client Edit basicData path', () => { .write(selectors.clientBasicData.nameInput, 'Ptonomy Wallace') .clearInput(selectors.clientBasicData.contactInput) .write(selectors.clientBasicData.contactInput, 'David Haller') - .clearInput(selectors.clientBasicData.phoneInput) - .write(selectors.clientBasicData.phoneInput, '987654321') - .clearInput(selectors.clientBasicData.mobileInput) - .write(selectors.clientBasicData.mobileInput, '123456789') .clearInput(selectors.clientBasicData.emailInput) .write(selectors.clientBasicData.emailInput, 'PWallace@verdnatura.es') .autocompleteSearch(selectors.clientBasicData.channelAutocomplete, 'Rumors on the streets') @@ -55,20 +51,6 @@ describe('Client Edit basicData path', () => { expect(result).toEqual('David Haller'); }); - it('should confirm the landline phone number have been added', async() => { - const result = await nightmare - .waitToGetProperty(selectors.clientBasicData.phoneInput, 'value'); - - expect(result).toEqual('987654321'); - }); - - it('should confirm the mobile phone number have been added', async() => { - const result = await nightmare - .waitToGetProperty(selectors.clientBasicData.mobileInput, 'value'); - - expect(result).toEqual('123456789'); - }); - it('should confirm the email have been edited', async() => { const result = await nightmare .waitToGetProperty(selectors.clientBasicData.emailInput, 'value'); @@ -108,10 +90,6 @@ describe('Client Edit basicData path', () => { .write(selectors.clientBasicData.nameInput, 'Ororo Munroe') .clearInput(selectors.clientBasicData.contactInput) .write(selectors.clientBasicData.contactInput, 'Black Panther') - .clearInput(selectors.clientBasicData.phoneInput) - .write(selectors.clientBasicData.phoneInput, '123456789') - .clearInput(selectors.clientBasicData.mobileInput) - .write(selectors.clientBasicData.mobileInput, '987654321') .clearInput(selectors.clientBasicData.emailInput) .write(selectors.clientBasicData.emailInput, 'Storm@verdnatura.es') .autocompleteSearch(selectors.clientBasicData.salesPersonAutocomplete, 'replenisherNick') @@ -137,20 +115,6 @@ describe('Client Edit basicData path', () => { expect(result).toEqual('Black Panther'); }); - it('should now confirm the landline phone number have been added', async() => { - const result = await nightmare - .waitToGetProperty(selectors.clientBasicData.phoneInput, 'value'); - - expect(result).toEqual('123456789'); - }); - - it('should now confirm the mobile phone number have been added', async() => { - const result = await nightmare - .waitToGetProperty(selectors.clientBasicData.mobileInput, 'value'); - - expect(result).toEqual('987654321'); - }); - it('should now confirm the email have been edited', async() => { const result = await nightmare .waitToGetProperty(selectors.clientBasicData.emailInput, 'value'); diff --git a/modules/client/back/methods/client/getCard.js b/modules/client/back/methods/client/getCard.js index 6c69d32a8e..e3b0edf8a1 100644 --- a/modules/client/back/methods/client/getCard.js +++ b/modules/client/back/methods/client/getCard.js @@ -60,6 +60,8 @@ module.exports = function(Self) { scope: { fields: ['id', 'name', 'active'] } + }, { + relation: 'phones' } ] }); diff --git a/modules/client/back/methods/client/summary.js b/modules/client/back/methods/client/summary.js index 155d95d9ed..13e898f091 100644 --- a/modules/client/back/methods/client/summary.js +++ b/modules/client/back/methods/client/summary.js @@ -53,6 +53,9 @@ module.exports = Self => { } } }, + { + relation: 'phones' + }, { relation: 'country', scope: { diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index c62ae38322..4529b3caf9 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -200,6 +200,11 @@ "type": "hasOne", "model": "ClaimRatio", "foreignKey": "clientFk" - } + }, + "phones": { + "type": "hasMany", + "model": "UserPhone", + "foreignKey": "userFk" + } } } \ No newline at end of file diff --git a/modules/client/front/basic-data/index.html b/modules/client/front/basic-data/index.html index 8c00f7a187..fbf883d98b 100644 --- a/modules/client/front/basic-data/index.html +++ b/modules/client/front/basic-data/index.html @@ -31,20 +31,6 @@ info="You can save multiple emails"> - - - - - - { - this.$scope.watcher.notifySaved(); - this.$scope.model.refresh(); - }); - } -} - -Controller.$inject = ['$scope', '$stateParams', '$translate']; - -ngModule.component('vnClientContact', { - template: require('./index.html'), - controller: Controller, - bindings: { - client: '<' - } -}); diff --git a/modules/client/front/index.js b/modules/client/front/index.js index 324046206a..514319ee24 100644 --- a/modules/client/front/index.js +++ b/modules/client/front/index.js @@ -30,7 +30,7 @@ import './credit-insurance/index'; import './credit-insurance/create'; import './credit-insurance/insurance/index'; import './credit-insurance/insurance/create'; -import './contact'; +import './phones'; import './sample/index'; import './sample/create'; import './web-payment'; diff --git a/modules/client/front/index/index.html b/modules/client/front/index/index.html index 35a5234aae..184f187278 100644 --- a/modules/client/front/index/index.html +++ b/modules/client/front/index/index.html @@ -25,10 +25,6 @@ label="Id" value="{{::client.id}}"> - - diff --git a/modules/client/front/contact/index.html b/modules/client/front/phones/index.html similarity index 51% rename from modules/client/front/contact/index.html rename to modules/client/front/phones/index.html index 2cefdd86d6..c0966ce0f1 100644 --- a/modules/client/front/contact/index.html +++ b/modules/client/front/phones/index.html @@ -1,45 +1,48 @@ + + + url="UserPhones" + data="$ctrl.phones"> + data="$ctrl.phones">
- - - + + + + ng-model="clientPhone.phone"> + ng-click="model.remove($index)" + tabindex="-1"> @@ -48,4 +51,4 @@ - \ No newline at end of file + diff --git a/modules/client/front/phones/index.js b/modules/client/front/phones/index.js new file mode 100644 index 0000000000..9839d27d78 --- /dev/null +++ b/modules/client/front/phones/index.js @@ -0,0 +1,44 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +class Controller extends Section { + get client() { + return this._client; + } + + set client(value) { + this._client = value; + if (value) + this.setLink(value); + } + + setLink(value) { + this.$.$applyAsync(()=> { + this.$.model.link = {userFk: value.id}; + this.$.model.refresh(); + }); + } + + onSubmit() { + this.$.watcher.check(); + return this.$.model.save().then(() => { + this.$.watcher.updateOriginalData(); + this.$.watcher.notifySaved(); + this.card.reload(); + }); + } + + add() { + this.$.model.insert(); + } +} + + +ngModule.component('vnClientPhones', { + template: require('./index.html'), + controller: Controller, + require: {card: '^vnClientCard'}, + bindings: { + client: '<' + } +}); diff --git a/modules/client/front/phones/index.spec.js b/modules/client/front/phones/index.spec.js new file mode 100644 index 0000000000..3d0befd685 --- /dev/null +++ b/modules/client/front/phones/index.spec.js @@ -0,0 +1,50 @@ +import './index'; +import watcher from 'core/mocks/watcher'; + +describe('Component vnClientPhones', () => { + let controller; + let $element; + let $scope; + + beforeEach(ngModule('client')); + + beforeEach(angular.mock.inject(($componentController, $rootScope) => { + $scope = $rootScope.$new(); + $element = angular.element('
'); + $scope.watcher = watcher; + $scope.model = { + link: 1, + save: () => {} + }; + controller = $componentController('vnClientPhones', {$element, $scope}); + controller.card = {reload: () => {}}; + })); + + describe('setLink()', () => { + it('set the link in the model and refreshes it', () => { + spyOn(controller.$, '$applyAsync'); + let value = {id: 106}; + controller.setLink(value); + + expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function)); + }); + }); + + describe('onSubmit()', () => { + it('should call watcher functions, reload the card and save the model', done => { + spyOn(controller.$.watcher, 'check'); + spyOn(controller.$.model, 'save').and.returnValue(Promise.resolve()); + + spyOn(controller.$.watcher, 'updateOriginalData'); + spyOn(controller.$.watcher, 'notifySaved'); + spyOn(controller.card, 'reload'); + controller.onSubmit(); + controller.onSubmit().then(() => { + expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith(); + expect(controller.$.watcher.notifySaved).toHaveBeenCalledWith(); + expect(controller.card.reload).toHaveBeenCalledWith(); + done(); + }).catch(done.fail); + }); + }); +}); diff --git a/modules/client/front/routes.json b/modules/client/front/routes.json index ef0d8cc7ad..6d96bd2842 100644 --- a/modules/client/front/routes.json +++ b/modules/client/front/routes.json @@ -26,7 +26,7 @@ {"state": "client.card.webAccess", "icon": "cloud"}, {"state": "client.card.mandate", "icon": "pan_tool"}, {"state": "client.card.creditInsurance.index", "icon": "icon-solunion"}, - {"state": "client.card.contact", "icon": "contact_phone"}, + {"state": "client.card.phones", "icon": "contact_phone"}, {"state": "client.card.sample.index", "icon": "mail"}, {"state": "client.card.webPayment", "icon": "icon-onlinepayment"}, {"state": "client.card.dms.index", "icon": "cloud_upload"} @@ -282,10 +282,10 @@ "client": "$ctrl.client" } }, { - "url": "/contact", - "state": "client.card.contact", - "component": "vn-client-contact", - "description": "Contacts", + "url": "/phones", + "state": "client.card.phones", + "component": "vn-client-phones", + "description": "Client phones", "params": { "client": "$ctrl.client" } diff --git a/modules/client/front/summary/index.html b/modules/client/front/summary/index.html index eccf458734..7016a19ffa 100644 --- a/modules/client/front/summary/index.html +++ b/modules/client/front/summary/index.html @@ -12,11 +12,9 @@ - - - +