Commit 8cc9a9728d9daf14e6f5cf5862a1b65ee84778cd
Exists in
master
Merge branch 'master' into 'develop'
Master See merge request !16
Showing
4 changed files
Show diff stats
src/js/controller.js
... | ... | @@ -34,17 +34,36 @@ angular.module('focaModal') |
34 | 34 | } |
35 | 35 | ]) |
36 | 36 | .controller('focaModalPromptController', [ |
37 | - '$uibModalInstance', '$scope', 'titulo', 'initValue', 'textarea', 'readonly', | |
38 | - function($uibModalInstance, $scope, titulo, initValue, textarea, readonly) { | |
39 | - $scope.readonly = readonly; | |
40 | - $scope.textarea = textarea; | |
41 | - $scope.titulo = titulo; | |
42 | - $scope.value = initValue; | |
37 | + '$uibModalInstance', '$scope', 'options', 'focaModalService', | |
38 | + function($uibModalInstance, $scope, options, focaModalService) { | |
39 | + | |
40 | + $scope.options = options; | |
43 | 41 | $scope.cancelar = function() { |
44 | 42 | $uibModalInstance.dismiss(); |
45 | 43 | }; |
46 | - $scope.aceptar = function() { | |
47 | - $uibModalInstance.close($scope.value); | |
44 | + $scope.aceptar = function(key) { | |
45 | + if (key === 13) { | |
46 | + if (options.email && !validateEmails($scope.options.value)) { | |
47 | + focaModalService.alert('Ingrese email/s válido/s'); | |
48 | + return; | |
49 | + } | |
50 | + | |
51 | + $uibModalInstance.close($scope.options.value); | |
52 | + } | |
48 | 53 | }; |
54 | + | |
55 | + function validateEmails(emails) { | |
56 | + var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | |
57 | + var arr = emails.split(','); | |
58 | + var result = true; | |
59 | + | |
60 | + arr.forEach(function(email) { | |
61 | + var val = String(email).trim().toLowerCase(); | |
62 | + | |
63 | + if(!re.test(val)) result = false; | |
64 | + }); | |
65 | + | |
66 | + return result; | |
67 | + } | |
49 | 68 | } |
50 | 69 | ]); |
src/js/controllerModal.js
src/js/service.js
... | ... | @@ -71,18 +71,13 @@ angular.module('focaModal') |
71 | 71 | } |
72 | 72 | ); |
73 | 73 | }, |
74 | - prompt: function(titulo, initValue, textarea, readonly){ | |
75 | - textarea = textarea ? true : false; | |
76 | - readonly = readonly ? true : false; | |
74 | + prompt: function(options) { | |
77 | 75 | return $uibModal.open({ |
78 | 76 | templateUrl: 'modal-prompt.html', |
79 | 77 | controller: 'focaModalPromptController', |
80 | 78 | size: 'md', |
81 | 79 | resolve: { |
82 | - titulo: function() {return titulo;}, | |
83 | - initValue: function() {return initValue;}, | |
84 | - textarea: function() {return textarea;}, | |
85 | - readonly: function() {return readonly;} | |
80 | + options: function() {return options;}, | |
86 | 81 | } |
87 | 82 | }) |
88 | 83 | .result.then( |
src/views/modal-prompt.html
1 | 1 | <div class="modal-header"> |
2 | - <h4 ng-bind="titulo"></h4> | |
2 | + <h4 ng-bind="options.titulo"></h4> | |
3 | 3 | </div> |
4 | 4 | <div class="modal-body"> |
5 | 5 | <input |
6 | 6 | type="text" |
7 | 7 | class="form-control" |
8 | - ng-model="value" | |
9 | - ng-show="!textarea" | |
10 | - ng-readonly="readonly"> | |
8 | + ng-model="options.value" | |
9 | + ng-show="!options.textarea" | |
10 | + ng-readonly="options.readonly" | |
11 | + ng-keypress="aceptar($event.keyCode)"> | |
11 | 12 | |
12 | 13 | <textarea |
13 | 14 | rows="5" |
14 | 15 | class="form-control text-uppercase" |
15 | - ng-model="value" | |
16 | - ng-show="textarea" | |
17 | - ng-readonly="readonly"></textarea> | |
16 | + ng-model="options.value" | |
17 | + ng-show="options.textarea" | |
18 | + ng-readonly="options.readonly" | |
19 | + ng-keypress="aceptar($event.keyCode)"></textarea> | |
18 | 20 | </div> |
19 | 21 | <div class="modal-footer"> |
20 | - <button class="btn btn-primary" ng-click="aceptar()" foca-focus="true">Aceptar</button> | |
22 | + <button class="btn btn-primary" ng-click="aceptar(13)" foca-focus="true">Aceptar</button> | |
21 | 23 | <button class="btn btn-default" ng-click="cancelar()">Cancelar</button> |
22 | 24 | </div> |