Skip to content

Commit b0653fe

Browse files
committed
feat(4665): init create a new date picker
1 parent 11f732e commit b0653fe

File tree

7 files changed

+157
-230
lines changed

7 files changed

+157
-230
lines changed

dist/lets.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/directives/crud/lets-crud-filter.directive.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
field.notnull = false;
4040
field.name = field.name;
4141

42-
if (field.customOptions.file){
42+
if (field.customOptions != undefined && field.customOptions.file){
4343
delete field.customOptions.file;
4444
}
4545
if(field.customOptions.multiselect){
@@ -325,4 +325,4 @@
325325
}
326326
}
327327
}
328-
})();
328+
})();

src/directives/framework/lets-fw-datepicker-new.directive.js

Lines changed: 41 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -7,139 +7,65 @@
77

88
function newDatePicker($compile, jQuery) {
99
var controllerName = 'vm';
10+
1011
return {
1112
restrict: 'A',
1213
require: '?ngModel',
1314
scope: true,
1415
terminal: true,
1516
priority: 1,
1617
compile: function (element, attrs) {
17-
var wrapper = angular.element(`
18-
<div class="input-group">
19-
<span class="input-group-btn">
20-
21-
<button type="button" class="btn btn-default"><i class="glyphicon glyphicon-calendar"></i></button>
22-
</span>
23-
</div>`);
24-
25-
function setAttributeIfNotExists(name, value) {
26-
var oldValue = element.attr(name);
27-
if (!angular.isDefined(oldValue) || oldValue === false) {
28-
element.attr(name, value);
29-
}
30-
}
31-
// console.log({controllerName: controllerName});
32-
33-
controllerName = Object.assign(controllerName, options);
34-
console.log({obj_: controllerName});
35-
// setAttributeIfNotExists('type', 'text');
36-
// setAttributeIfNotExists('is-open', controllerName + '.popupOpen');
37-
// setAttributeIfNotExists('show-button-bar', false);
38-
// setAttributeIfNotExists('show-weeks', false);
39-
// setAttributeIfNotExists('datepicker-options', 'datepickerOptions');
40-
41-
element.addClass('form-control');
18+
var _input = element.find('input');
19+
20+
// var wrapper = angular.element('<span></span>');
21+
var wrapper = angular.element('<div class="input-group">' + '<span class="input-group-btn">' + '<button type="button" class="btn btn-default" ng-click="' + controllerName + '.openPopup($event)"><i class="glyphicon glyphicon-calendar"></i></button>' + '</span>' + '</div>');
22+
// function setAttributeIfNotExists(name, value) {
23+
// var oldValue = element.attr(name);
24+
// if (!angular.isDefined(oldValue) || oldValue === false) {
25+
// element.attr(name, value);
26+
// }
27+
// }
28+
// element.addClass('form-control');
29+
// setAttributeIfNotExists('picker-open"', controllerName + '.popupOpen');
4230
element.removeAttr('new-date-picker');
31+
4332
element.after(wrapper);
44-
wrapper.prepend(element);
4533

34+
wrapper.prepend(element);
4635
return function (scope, element) {
47-
// var options = {
48-
// locale: {
49-
// format: 'DD/MM/YYYY',
50-
// minYear: 1901,
51-
// maxYear: parseInt(moment().format('YYYY'), 10),
52-
// applyLabel: 'Aplicar',
53-
// cancelLabel: 'Cancelar',
54-
// daysOfWeek: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'],
55-
// monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
56-
// },
57-
// singleDatePicker: true,
58-
// showDropdowns: false,
59-
// timePicker: false,
60-
// firstDay: 1,
61-
// };
62-
63-
if (scope.data === undefined) scope.data = {};
64-
65-
// if (!scope.field) {
66-
// scope.field = {customOptions: []};
67-
// if (attrs.fwDatePickerNgModelParent) {
68-
// options.initDate = new Date(scope.$parent[attrs.ngModel]);
69-
// scope.$parent[attrs.ngModel] = angular.copy(options.initDate);
70-
// } else {
71-
// options.initDate = new Date(scope[attrs.ngModel]);
72-
// scope[attrs.ngModel] = angular.copy(options.initDate);
73-
// }
74-
// } else if (scope.data[scope.field.name] != null) {
75-
// options.initDate = new Date(scope.data[scope.field.name]);
76-
// scope.data[scope.field.name] = angular.copy(options.initDate);
77-
// }
78-
79-
// var format = 'dd/MM/yyyy';
80-
81-
// if (scope.field.customOptions.monthpicker !== undefined) {
82-
// options.datepickerMode = "'month'";
83-
// options.minMode = 'month';
36+
// console.log(attrs, element, element, _input, scope);
8437

85-
// format = 'MM/yyyy';
86-
// }
38+
// scope.dateRangePicker = $(element);
8739

88-
// element.find('input').attr('datepicker-popup', format);
89-
90-
// element.find('input').blur(function () {
91-
// if (!moment(this.value, format).isValid() && this.value !== '') {
92-
// scope.field.error = true;
93-
// } else {
94-
// scope.field.error = false;
95-
// }
96-
// });
97-
98-
// element.find('input').focus(function (e) {
99-
// scope.vm.openPopup(e);
100-
// });
40+
if (scope.data === undefined) scope.data = {};
10141

102-
scope.dateRangePicker = {
103-
date: {startDate: moment().subtract(1, 'years'), endDate: moment().add(1, 'years')},
104-
picker: null,
105-
singleDatePicker: true,
106-
options: {
107-
pickerClasses: 'custom-display',
108-
buttonClasses: 'btn',
109-
applyButtonClasses: 'btn-primary',
110-
cancelButtonClasses: 'btn-danger',
111-
locale: {
112-
applyLabel: 'Aplicar',
113-
cancelLabel: 'Cancelar',
114-
daysOfWeek: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'],
115-
monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
116-
customRangeLabel: 'Custom range',
117-
separator: '/',
118-
format: 'DD/MM/YYYY',
119-
minYear: 1901,
120-
maxYear: parseInt(moment().format('YYYY'), 10), //will give you 2017-01-06
121-
},
122-
// ranges: {
123-
// 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
124-
// 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
125-
// },
126-
eventHandlers: {
127-
'apply.daterangepicker': function (event, picker) {
128-
console.log('applied');
129-
},
130-
},
131-
},
132-
};
42+
// var tmp_id = element.find('input');
43+
// setTimeout(function () {
44+
// this.input_id = 'input#' + tmp_id.get(0).name;
45+
// }, 300);
46+
47+
element.find('input').blur(function () {
48+
if (!moment(this.value, format).isValid() && this.value !== '') {
49+
scope.field.error = true;
50+
} else {
51+
scope.field.error = false;
52+
}
53+
});
13354
$compile(element)(scope);
13455
};
13556
},
13657
controller: function ($scope) {
137-
// this.popupOpen = false;
138-
// this.openPopup = function ($event) {
139-
// $event.preventDefault();
140-
// $event.stopPropagation();
141-
// this.popupOpen = true;
142-
// };
58+
this.popupOpen = false;
59+
this.openPopup = function ($event, id) {
60+
$event.preventDefault();
61+
$event.stopPropagation();
62+
console.log('newDatePicker42', $scope);
63+
console.log('newDatePicker_id', id);
64+
console.log('newDatePicker_sid', $event);
65+
66+
// $(input_id).click();
67+
this.popupOpen = true;
68+
};
14369
},
14470
controllerAs: controllerName,
14571
};
Lines changed: 91 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,93 @@
11
(function () {
2-
'use strict';
3-
4-
angular.module('letsAngular')
5-
.directive('fwDynamic', fwDynamic);
6-
7-
fwDynamic.$inject = ['viaCEP', '$timeout', '$compile', 'jQuery', '$filter'];
8-
9-
function fwDynamic(viaCEP, $timeout, $compile, jQuery, $filter) {
10-
var FLOAT_REGEXP_1 = /^\$?\d+.(\d{3})*(\,\d*)$/; //Numbers like: 1.123,56
11-
var FLOAT_REGEXP_2 = /^\$?\d+,(\d{3})*(\.\d*)$/; //Numbers like: 1,123.56
12-
var FLOAT_REGEXP_3 = /^\$?\d+(\.\d*)?$/; //Numbers like: 1123.56
13-
var FLOAT_REGEXP_4 = /^\$?\d+(\,\d*)?$/; //Numbers like: 1123,56
14-
15-
return {
16-
restrict: 'A',
17-
link: {
18-
post: function postLink(scope, $el, attrs, controller) {
19-
if (!controller) {
20-
controller = $el.controller('ngModel');
21-
}
22-
23-
if (scope.field.type == 'date') {
24-
$el.mask('99/99/9999');
25-
26-
} else if (scope.field.customOptions.cpf != undefined) {
27-
$el.mask('999.999.999-99');
28-
29-
} else if (scope.field.customOptions.cnpj != undefined) {
30-
$el.mask('99.999.999/9999-99');
31-
32-
} else if (scope.field.customOptions.customMask != undefined) {
33-
$el.mask(scope.field.customOptions.customMask);
34-
35-
} else if (scope.field.type == 'float') {
36-
if (scope.field.customOptions.currency != undefined) {
37-
$el.mask("#.##0,00", { reverse: true });
38-
controller.$parsers.unshift(function (value) {
39-
return parseFloat($el.cleanVal(),10)/100;
40-
});
41-
controller.$formatters.unshift(function (value) {
42-
return $el.masked(value ? parseFloat(value).toFixed(2) : null);
43-
});
44-
} else {
45-
46-
}
47-
}else if (scope.field.customOptions.documento !== undefined) {
48-
49-
var cpfOrCnpj = function (val) {
50-
return val.replace(/\D/g, '').length >= 12 ? '00.000.000/0000-00' : '000.000.000-009' ;
51-
},
52-
docOptions = {
53-
onKeyPress: function (val, e, field, options) {
54-
field.mask(cpfOrCnpj.apply({}, arguments), options);
55-
}
56-
};
57-
58-
$timeout(function () {
59-
$el.mask(cpfOrCnpj, docOptions);
60-
}, 10);
61-
62-
63-
} else if (scope.field.customOptions.telefone != undefined) {
64-
var SPMaskBehavior = function (val) {
65-
return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009';
66-
},
67-
spOptions = {
68-
onKeyPress: function (val, e, field, options) {
69-
field.mask(SPMaskBehavior.apply({}, arguments), options);
70-
}
71-
};
72-
73-
$timeout(function () {
74-
$el.mask(SPMaskBehavior, spOptions);
75-
}, 100);
76-
77-
} else if (scope.field.customOptions.cep != undefined) {
78-
79-
$el.blur(function () {
80-
81-
if (!this.value){
82-
return false;
83-
}
84-
85-
var $scope = angular.element(this).scope();
86-
var dataVar = jQuery(this).parent().attr('fw-data');
87-
viaCEP.get(this.value).then(function (response) {
88-
var map = $scope.field.customOptions.cep;
89-
90-
$scope.data[map.address] = response.logradouro;
91-
$scope.data[map.district] = response.bairro;
92-
$scope.data[map.city] = response.localidade;
93-
$scope.data[map.state] = response.uf;
94-
$scope.data[map.ibge] = response.ibge;
95-
$scope.data[map.gia] = response.gia;
96-
97-
$scope.$emit('viacep complete', response);
98-
});
99-
});
100-
}
101-
}
102-
}
103-
}
104-
}
2+
'use strict';
3+
4+
angular.module('letsAngular').directive('fwDynamic', fwDynamic);
5+
6+
fwDynamic.$inject = ['viaCEP', '$timeout', '$compile', 'jQuery', '$filter'];
7+
8+
function fwDynamic(viaCEP, $timeout, $compile, jQuery, $filter) {
9+
var FLOAT_REGEXP_1 = /^\$?\d+.(\d{3})*(\,\d*)$/; //Numbers like: 1.123,56
10+
var FLOAT_REGEXP_2 = /^\$?\d+,(\d{3})*(\.\d*)$/; //Numbers like: 1,123.56
11+
var FLOAT_REGEXP_3 = /^\$?\d+(\.\d*)?$/; //Numbers like: 1123.56
12+
var FLOAT_REGEXP_4 = /^\$?\d+(\,\d*)?$/; //Numbers like: 1123,56
13+
14+
return {
15+
restrict: 'A',
16+
link: {
17+
post: function postLink(scope, $el, attrs, controller) {
18+
if (!controller) {
19+
controller = $el.controller('ngModel');
20+
}
21+
22+
if (scope.field.type == 'date') {
23+
$el.mask('99/99/9999');
24+
} else if (scope.field.customOptions != undefined && scope.field.customOptions.cpf != undefined && scope.field.customOptions.cpf != null) {
25+
$el.mask('999.999.999-99');
26+
} else if (scope.field.customOptions != undefined && scope.field.customOptions.cnpj != undefined) {
27+
$el.mask('99.999.999/9999-99');
28+
} else if (scope.field.customOptions != undefined && scope.field.customOptions.customMask != undefined) {
29+
$el.mask(scope.field.customOptions.customMask);
30+
} else if (scope.field.customOptions != undefined && scope.field.type == 'float') {
31+
if (scope.field.customOptions != undefined && scope.field.customOptions.currency != undefined) {
32+
$el.mask('#.##0,00', {reverse: true});
33+
controller.$parsers.unshift(function (value) {
34+
return parseFloat($el.cleanVal(), 10) / 100;
35+
});
36+
controller.$formatters.unshift(function (value) {
37+
return $el.masked(value ? parseFloat(value).toFixed(2) : null);
38+
});
39+
} else {
40+
}
41+
} else if (scope.field.customOptions != undefined && scope.field.customOptions.documento !== undefined) {
42+
var cpfOrCnpj = function (val) {
43+
return val.replace(/\D/g, '').length >= 12 ? '00.000.000/0000-00' : '000.000.000-009';
44+
},
45+
docOptions = {
46+
onKeyPress: function (val, e, field, options) {
47+
field.mask(cpfOrCnpj.apply({}, arguments), options);
48+
},
49+
};
50+
51+
$timeout(function () {
52+
$el.mask(cpfOrCnpj, docOptions);
53+
}, 10);
54+
} else if (scope.field.customOptions != undefined && scope.field.customOptions.telefone != undefined) {
55+
var SPMaskBehavior = function (val) {
56+
return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009';
57+
},
58+
spOptions = {
59+
onKeyPress: function (val, e, field, options) {
60+
field.mask(SPMaskBehavior.apply({}, arguments), options);
61+
},
62+
};
63+
64+
$timeout(function () {
65+
$el.mask(SPMaskBehavior, spOptions);
66+
}, 100);
67+
} else if (scope.field.customOptions != undefined && scope.field.customOptions.cep != undefined) {
68+
$el.blur(function () {
69+
if (!this.value) {
70+
return false;
71+
}
72+
73+
var $scope = angular.element(this).scope();
74+
var dataVar = jQuery(this).parent().attr('fw-data');
75+
viaCEP.get(this.value).then(function (response) {
76+
var map = $scope.field.customOptions.cep;
77+
78+
$scope.data[map.address] = response.logradouro;
79+
$scope.data[map.district] = response.bairro;
80+
$scope.data[map.city] = response.localidade;
81+
$scope.data[map.state] = response.uf;
82+
$scope.data[map.ibge] = response.ibge;
83+
$scope.data[map.gia] = response.gia;
84+
85+
$scope.$emit('viacep complete', response);
86+
});
87+
});
88+
}
89+
},
90+
},
91+
};
92+
}
10593
})();

0 commit comments

Comments
 (0)