|
7 | 7 |
|
8 | 8 | function newDatePicker($compile, jQuery) { |
9 | 9 | var controllerName = 'vm'; |
| 10 | + |
10 | 11 | return { |
11 | 12 | restrict: 'A', |
12 | 13 | require: '?ngModel', |
13 | 14 | scope: true, |
14 | 15 | terminal: true, |
15 | 16 | priority: 1, |
16 | 17 | 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'); |
42 | 30 | element.removeAttr('new-date-picker'); |
| 31 | + |
43 | 32 | element.after(wrapper); |
44 | | - wrapper.prepend(element); |
45 | 33 |
|
| 34 | + wrapper.prepend(element); |
46 | 35 | 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); |
84 | 37 |
|
85 | | - // format = 'MM/yyyy'; |
86 | | - // } |
| 38 | + // scope.dateRangePicker = $(element); |
87 | 39 |
|
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 = {}; |
101 | 41 |
|
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 | + }); |
133 | 54 | $compile(element)(scope); |
134 | 55 | }; |
135 | 56 | }, |
136 | 57 | 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 | + }; |
143 | 69 | }, |
144 | 70 | controllerAs: controllerName, |
145 | 71 | }; |
|
0 commit comments