Skip to content

Commit d4a99c0

Browse files
committed
feat(4665): new date complete
1 parent 75ce16d commit d4a99c0

File tree

9 files changed

+484
-457
lines changed

9 files changed

+484
-457
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: 304 additions & 326 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//Set options for dropzone
1616
for (var y in scope.headers.fields) {
1717
var field = scope.headers.fields[y];
18-
if (field.customOptions.file) {
18+
if (field.customOptions && field.customOptions.file) {
1919
scope.dzOptions = {
2020
url: appSettings.API_URL + 'upload/' + field.customOptions.file.container + '/upload',
2121
acceptedFiles: field.customOptions.file.acceptedFiles,

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

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,64 @@
1414
scope: true,
1515
terminal: true,
1616
priority: 1,
17-
link: function (scope, element, attrs, controller) {
18-
element.addClass('form-control');
19-
// setAttributeIfNotExists('picker-open"', controllerName + '.popupOpen');
20-
element.removeAttr('new-date-picker');
21-
22-
element.on('click', function ($event) {
23-
$event.preventDefault();
24-
$event.stopPropagation();
25-
console.log(attrs.name);
26-
});
27-
$compile(element)(scope);
28-
},
29-
controller: function ($scope) {
30-
console.log('newDate', {scope: $scope});
17+
link: {
18+
post: function postLink(scope, element, attrs, controller) {
19+
// scope['dataReference'] = $(element);
20+
element.addClass('form-control');
21+
var tmp = JSON.parse(attrs.field);
22+
var singleDatePicker = true;
23+
if (typeof tmp.filter == 'object' && tmp.filter.range === true && tmp.filter._edit === true) {
24+
singleDatePicker = false;
25+
}
26+
var startDate = moment().startOf('month');
27+
var endDate = moment();
28+
var _date = !singleDatePicker ? '{date: {startDate: ' + startDate + ', endDate: ' + endDate + ' }, ' : '{';
29+
var options =
30+
_date +
31+
' minYear: 1901,' +
32+
" maxYear: parseInt(moment().format('YYYY'), 10)," +
33+
" applyButtonClasses: 'btn-primary'," +
34+
" cancelButtonClasses: 'btn-default'," +
35+
' showDropdowns: false,' +
36+
' singleDatePicker:' +
37+
singleDatePicker +
38+
',' +
39+
' locale: {' +
40+
" format: 'DD/MM/YYYY'," +
41+
" separator: ' - '," +
42+
" applyLabel: 'Aplicar'," +
43+
" cancelLabel: 'Cancelar'," +
44+
" daysOfWeek: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb']," +
45+
" monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro']," +
46+
' },' +
47+
' }';
48+
element.attr('options', options.toString());
49+
element.removeAttr('new-date-picker');
50+
51+
element.on('apply.daterangepicker', function ($event, picker) {
52+
console.log(picker);
53+
});
54+
55+
// element.on('cancel.daterangepicker', function ($event, picker) {
56+
// picker.setStartDate(null);
57+
// picker.setEndDate(null);
58+
// });
59+
60+
element.on('show.daterangepicker', function ($event, picker) {
61+
if (!singleDatePicker) {
62+
console.log(picker);
63+
picker.setStartDate(startDate);
64+
picker.setEndDate(endDate);
65+
}
66+
});
67+
68+
// console.log({attrs: attrs, controller: controller, scope: scope, element: element, optiondg: options.toString()}, tmp);
69+
// console.log(scope, element);
70+
71+
$compile(element)(scope);
72+
},
3173
},
74+
controller: function ($scope) {},
3275
controllerAs: controllerName,
3376
};
3477
}

src/directives/framework/lets-fw-detail-data.directive.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
if (field.customOptions.hour) {
3030
return moment(data[field.name]).format('DD/MM/YYYY HH:mm');
3131
} else {
32+
// console.log(data[field.name])
3233
return moment(data[field.name]).format('DD/MM/YYYY');
3334
}
3435

src/directives/framework/lets-fw-dynamic.directive.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
controller = $el.controller('ngModel');
2020
}
2121

22-
if (scope.field.type == 'date') {
22+
if (scope.field && scope.field.type == 'date') {
2323
$el.mask('99/99/9999');
24-
} else if (scope.field.customOptions != undefined && scope.field.customOptions.cpf != undefined && scope.field.customOptions.cpf != null) {
24+
} else if (scope.field && scope.field.customOptions != undefined && scope.field.customOptions.cpf != undefined && scope.field.customOptions.cpf != null) {
2525
$el.mask('999.999.999-99');
2626
} else if (scope.field.customOptions != undefined && scope.field.customOptions.cnpj != undefined) {
2727
$el.mask('99.999.999/9999-99');
Lines changed: 111 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,113 @@
11
(function () {
2-
'use strict';
3-
4-
angular.module('letsAngular')
5-
.directive('fwInput', fwInput);
6-
7-
fwInput.$inject = ['viaCEP', '$timeout', '$compile', 'jQuery', '$sce'];
8-
9-
function fwInput(viaCEP, $timeout, $compile, jQuery, $sce) {
10-
return {
11-
restrict: 'E',
12-
scope: true,
13-
templateUrl: 'lets/views/framework/input.html',
14-
replace: true,
15-
link: {
16-
17-
pre: function preLink(scope, $el, attrs, controller) {
18-
19-
var dataVar = $el.attr('fw-data');
20-
21-
if (!scope.field.customOptions.events) {
22-
scope.field.customOptions['events'] = {};
23-
}
24-
25-
scope.fieldHtml = function () {
26-
return $sce.trustAsHtml(scope.field.toString());
27-
}
28-
29-
if (dataVar != 'data') {
30-
scope.data = scope[dataVar];
31-
}
32-
33-
if(dataVar=="detail_data"){
34-
var detail = scope.detail_key;
35-
36-
if (scope.field.autocomplete !== false){
37-
scope.autocomplete = function (field, val) {
38-
return scope.autocompleteDetail(detail, field, val);
39-
}
40-
41-
scope.autocompleteSelect = function ($item, $model, $label) {
42-
return scope.autocompleteDetailSelect(detail, $item, $model, $label);
43-
}
44-
}
45-
46-
if (scope.field.customOptions.file != undefined) {
47-
scope.download = function (field, id) {
48-
return scope.downloadDetail(detail, field, id, scope.data);
49-
}
50-
}
51-
}
52-
53-
if (scope.field.customOptions.cep != undefined) {
54-
55-
$el.find('input.main-input').blur(function () {
56-
var $scope = angular.element(this).scope();
57-
58-
viaCEP.get(this.value).then(function (response) {
59-
var map = $scope.field.customOptions.cep;
60-
61-
$scope.data[map.address] = response.logradouro;
62-
$scope.data[map.district] = response.bairro;
63-
$scope.data[map.city] = response.localidade;
64-
$scope.data[map.state] = response.uf;
65-
66-
scope.$$phase || scope.$apply();
67-
});
68-
});
69-
}
70-
else if (scope.field.customOptions.multiple != undefined && scope.field.customOptions.multiple == true) {
71-
var a = $compile($el.contents())(scope);
72-
}
73-
74-
jQuery($el).on('blur', ':input[ng-model]', function (e) {
75-
try {
76-
if (angular.element(this).scope().field.customOptions.events.blur != undefined) {
77-
angular.element(this).scope().field.customOptions.events.blur.call(this, e);
78-
}
79-
}
80-
catch (e) {
81-
}
82-
83-
84-
});
85-
86-
scope.isEmpty = function (obj) {
87-
return Object.keys(obj).length;
88-
}
89-
}
90-
91-
}
92-
93-
}
94-
}
2+
'use strict';
3+
4+
angular.module('letsAngular').directive('fwInput', fwInput);
5+
6+
fwInput.$inject = ['viaCEP', '$timeout', '$compile', 'jQuery', '$sce'];
7+
8+
function fwInput(viaCEP, $timeout, $compile, jQuery, $sce) {
9+
return {
10+
restrict: 'E',
11+
scope: true,
12+
templateUrl: 'lets/views/framework/input.html',
13+
replace: true,
14+
link: {
15+
pre: function preLink(scope, $el, attrs, controller) {
16+
var dataVar = $el.attr('fw-data');
17+
18+
if (scope.field && scope.field.customOptions && typeof scope.field.customOptions == 'object' && !scope.field.customOptions.events) {
19+
scope.field.customOptions['events'] = {};
20+
}
21+
22+
scope.fieldHtml = function () {
23+
return $sce.trustAsHtml(scope.field.toString());
24+
};
25+
26+
if (dataVar != 'data') {
27+
scope.data = scope[dataVar];
28+
}
29+
// console.log('scopes', scope, dataVar);
30+
31+
if (dataVar == 'detail_data') {
32+
var detail = scope.detail_key;
33+
34+
if (scope.field && scope.field.autocomplete !== false) {
35+
scope.autocomplete = function (field, val) {
36+
return scope.autocompleteDetail(detail, field, val);
37+
};
38+
39+
scope.autocompleteSelect = function ($item, $model, $label) {
40+
return scope.autocompleteDetailSelect(detail, $item, $model, $label);
41+
};
42+
}
43+
44+
if (scope.field && scope.field.customOptions && scope.field.customOptions.file != undefined) {
45+
scope.download = function (field, id) {
46+
return scope.downloadDetail(detail, field, id, scope.data);
47+
};
48+
}
49+
}
50+
51+
// if (scope.type == 'date') {
52+
// console.log(scope, $el, attrs, controller, dataVar);
53+
// scope.options = {
54+
// date: {startDate: moment().subtract(1, 'years'), endDate: moment().add(1, 'years')},
55+
// picker: null,
56+
// options: {
57+
// pickerClasses: 'custom-display', //angular-daterangepicker extra
58+
// buttonClasses: 'btn',
59+
// applyButtonClasses: 'btn-primary',
60+
// cancelButtonClasses: 'btn-danger',
61+
// locale: {
62+
// separator: ' - ',
63+
// format: 'DD/MM/YYYY',
64+
// applyLabel: 'Aplicar',
65+
// cancelLabel: 'Cancelar',
66+
// daysOfWeek: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'],
67+
// monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
68+
// },
69+
// },
70+
// };
71+
// }
72+
73+
if (scope.field && scope.field.customOptions && scope.field.customOptions.cep != undefined) {
74+
$el.find('input.main-input').blur(function () {
75+
var $scope = angular.element(this).scope();
76+
77+
viaCEP.get(this.value).then(function (response) {
78+
var map = $scope.field.customOptions.cep;
79+
80+
$scope.data[map.address] = response.logradouro;
81+
$scope.data[map.district] = response.bairro;
82+
$scope.data[map.city] = response.localidade;
83+
$scope.data[map.state] = response.uf;
84+
85+
scope.$$phase || scope.$apply();
86+
});
87+
});
88+
} else if (scope.field && scope.field.customOptions && scope.field.customOptions.multiple != undefined && scope.field.customOptions.multiple == true) {
89+
var a = $compile($el.contents())(scope);
90+
}
91+
92+
jQuery($el).on('blur', ':input[ng-model]', function (e) {
93+
try {
94+
if (angular.element(this).scope().field.customOptions.events.blur != undefined) {
95+
angular.element(this).scope().field.customOptions.events.blur.call(this, e);
96+
}
97+
} catch (e) {}
98+
});
99+
100+
scope.openDate = function (__scope) {
101+
// console.log(nome, nome);
102+
console.log({__scope: __scope});
103+
$('input#' + __scope.name).click();
104+
};
105+
106+
scope.isEmpty = function (obj) {
107+
return Object.keys(obj).length;
108+
};
109+
},
110+
},
111+
};
112+
}
95113
})();

src/views/crud/crud-filter.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</div>
2323

2424
<div class="busca-avancada row" collapse="!showBuscaAvancada">
25-
<div class="form-group" style="margin-bottom: 10px; margin-right: 0px; min-width: 200px;" ng-repeat="field in fieldsFilter track by $index" ng-class="field.filter.customClass ? field.filter.customClass : (field.filter.range===true ? 'col-sm-2' : 'col-sm-3')">
25+
<div class="form-group" style="margin-bottom: 10px; margin-right: 0px; min-width: 200px;" ng-repeat="field in fieldsFilter track by $index" ng-class="field.filter.customClass ? field.filter.customClass : (field.type != 'date' && field.filter.range===true ? 'col-sm-2' : 'col-sm-3')">
2626
<label for="{{field.name}}" class="control-label" style="font-size:12px; margin-bottom: 0px;font-weight: 600">{{field.label}}</label>
2727
<fw-input fw-data="data"></fw-input>
2828
</div>
@@ -35,4 +35,4 @@
3535
<div class="clearfix"></div>
3636
</div>
3737
</form>
38-
</div>
38+
</div>

src/views/framework/input.html

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,32 +136,19 @@
136136
date-range-picker
137137
class="form-control date-picker"
138138
new-date-picker="true"
139-
options="{
140-
minYear: 1901,
141-
maxYear: parseInt(moment().format('YYYY'),10),
142-
singleDatePicker: true,
143-
showDropdowns: false,
144-
locale: {
145-
separator: '/',
146-
format: 'DD/MM/YYYY',
147-
applyLabel: 'Aplicar',
148-
cancelLabel: 'Cancelar',
149-
daysOfWeek: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'],
150-
monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
151-
}
152-
}"
153139
id="{{ field.name }}"
154140
name="{{ field.name }}"
155141
autocomplete="off"
142+
field="{{ field }}"
156143
fw-dynamic
157144
ng-disabled="field.disabled"
158145
placeholder="DD/MM/YYYY"
159-
ng-model-options="{fieldInfo: field, allowInvalid: true}"
146+
ng-model-options="{ fieldInfo: field, allowInvalid: true }"
160147
type="text"
161148
ng-model="$parent.data[field.name]"
162149
/>
163150
<span class="input-group-btn">
164-
<button type="button" class="btn btn-default" ng-click="$('{{field.name}}').click()">
151+
<button type="button" class="btn btn-default" ng-click="openDate(field)">
165152
<i class="glyphicon glyphicon-calendar"></i>
166153
</button>
167154
</span>

0 commit comments

Comments
 (0)